diff --git a/glassfish-runner/jms-tck/j2ee.pass b/glassfish-runner/jms-tck/j2ee.pass
new file mode 100644
index 0000000000..8859170690
--- /dev/null
+++ b/glassfish-runner/jms-tck/j2ee.pass
@@ -0,0 +1,17 @@
+
+#
+# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v. 2.0, which is available at
+# http://www.eclipse.org/legal/epl-2.0.
+#
+# This Source Code may also be made available under the following Secondary
+# Licenses when the conditions for such availability set forth in the
+# Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+# version 2 with the GNU Classpath Exception, which is available at
+# https://www.gnu.org/software/classpath/license.html.
+#
+# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+#
+AS_ADMIN_USERPASSWORD=j2ee
\ No newline at end of file
diff --git a/glassfish-runner/jms-tck/javajoe.pass b/glassfish-runner/jms-tck/javajoe.pass
new file mode 100644
index 0000000000..d69a7520e5
--- /dev/null
+++ b/glassfish-runner/jms-tck/javajoe.pass
@@ -0,0 +1,16 @@
+#
+# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved.
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v. 2.0, which is available at
+# http://www.eclipse.org/legal/epl-2.0.
+#
+# This Source Code may also be made available under the following Secondary
+# Licenses when the conditions for such availability set forth in the
+# Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+# version 2 with the GNU Classpath Exception, which is available at
+# https://www.gnu.org/software/classpath/license.html.
+#
+# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+#
+AS_ADMIN_USERPASSWORD=javajoe
diff --git a/glassfish-runner/jms-tck/pom.xml b/glassfish-runner/jms-tck/pom.xml
new file mode 100644
index 0000000000..57c210d774
--- /dev/null
+++ b/glassfish-runner/jms-tck/pom.xml
@@ -0,0 +1,565 @@
+
+
+ jakarta
+ glassfish.jms-tck
+ 10.0.0-SNAPSHOT
+ jar
+ 4.0.0
+
+ org.glassfish
+ standalone-tck
+ 10.0.0
+ ../pom.xml
+
+
+ jakarta.jms-tck
+ 3.1.0
+ admin
+ admin
+ /tmp/ripassword
+ ${admin.pass.file}.encoded
+ /tmp/ri_admin_objects
+ java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory
+ java.naming.provider.url=file:///${jndi.fs.dir}
+ ${project.build.directory}/${glassfish.toplevel.dir}/mq
+ ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/bin/asadmin
+ ${ri.home}/bin/imqusermgr
+
+ ${ri.home}/bin/imqobjmgr
+
+ ${ri.home}/bin/imqcmd
+
+ ${ri.home}/bin/imqbrokerd
+
+
+
+
+
+ org.junit
+ junit-bom
+ ${junit.jupiter.version}
+ pom
+ import
+
+
+
+
+
+ org.junit.jupiter
+ junit-jupiter
+ ${junit.jupiter.version}
+
+
+ jakartatck
+ common
+ ${project.version}
+
+
+ org.jboss.arquillian.container
+ arquillian-glassfish-managed-6
+ 1.0.0.Alpha1
+
+
+ org.glassfish.hk2
+ hk2-locator
+
+
+
+
+ jakartatck
+ jms-tck
+ 10.0.0-SNAPSHOT
+
+
+ org.glassfish.main.common
+ simple-glassfish-api
+ ${glassfish.container.version}
+
+
+ org.jboss.arquillian.junit5
+ arquillian-junit5-container
+ 1.7.0.Alpha14
+
+
+ org.jboss.arquillian.junit5
+ arquillian-junit5-core
+ 1.7.0.Alpha14
+
+
+ org.glassfish.hk2
+ hk2-locator
+ 3.0.3
+
+
+
+
+ full
+
+ true
+
+
+ glassfish
+
+
+
+ web
+
+ web
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+ 3.2.0
+
+
+ unpack
+ pre-integration-test
+
+ unpack
+
+
+
+
+ org.glassfish.main.distributions
+ ${glassfish-artifact-id}
+ ${glassfish.container.version}
+ zip
+ true
+ ${project.build.directory}
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-antrun-plugin
+ 3.0.0
+
+
+ init
+ pre-integration-test
+
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+ encodeAdminPassword
+ pre-integration-test
+
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ startbkr
+ pre-integration-test
+
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ create.tck.users
+ pre-integration-test
+
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+
+ create.tck.jms.objects
+ pre-integration-test
+
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ list.tck.jms.objects
+ pre-integration-test
+
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ exec-maven-plugin
+ org.codehaus.mojo
+
+
+ StopDomain1
+ pre-integration-test
+
+ exec
+
+
+ ${exec.asadmin}
+
+ stop-domain
+
+
+
+
+ StartDomain1
+ pre-integration-test
+
+ exec
+
+
+ ${exec.asadmin}
+
+ start-domain
+
+
+
+
+ Enable Trace requests
+ pre-integration-test
+
+ exec
+
+
+ ${exec.asadmin}
+
+ set
+ server-config.network-config.protocols.protocol.http-listener-1.http.trace-enabled=true
+
+
+
+
+ Delete User j2ee
+ pre-integration-test
+
+ exec
+
+
+ ${exec.asadmin}
+
+ --passwordfile
+ ${project.basedir}/j2ee.pass
+ delete-file-user
+ j2ee
+
+
+ 0
+ 1
+
+
+
+
+ Add User j2ee
+ pre-integration-test
+
+ exec
+
+
+ ${exec.asadmin}
+
+ --passwordfile
+ ${project.basedir}/j2ee.pass
+ create-file-user
+ --groups
+ staff:mgr
+ j2ee
+
+
+
+
+ Delete User javajoe
+ pre-integration-test
+
+ exec
+
+
+ ${exec.asadmin}
+
+ --passwordfile
+ ${project.basedir}/javajoe.pass
+ delete-file-user
+ javajoe
+
+
+ 0
+ 1
+
+
+
+
+ Add User javajoe
+ pre-integration-test
+
+ exec
+
+
+ ${exec.asadmin}
+
+ --passwordfile
+ ${project.basedir}/javajoe.pass
+ create-file-user
+ --groups
+ guest
+ javajoe
+
+
+
+
+ list users
+ pre-integration-test
+
+ exec
+
+
+ ${exec.asadmin}
+
+ list-file-users
+
+
+
+
+ StopDomain
+ pre-integration-test
+
+ exec
+
+
+ ${exec.asadmin}
+
+ stop-domain
+
+
+
+
+
+
+ maven-failsafe-plugin
+ 3.0.0-M5
+
+
+ gf-tests
+
+ integration-test
+ verify
+
+
+
+ **/ee*/**
+
+
+ ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/jakarta.jms-api.jar
+ ${project.build.directory}/${glassfish.toplevel.dir}/glassfish/modules/glassfish-corba-omgapi.jar
+ ${project.build.directory}/${glassfish.toplevel.dir}/javadb/lib/derbyclient.jar
+ ${project.build.directory}/${glassfish.toplevel.dir}/javadb/lib/derby.jar
+ ${project.build.directory}/${glassfish.toplevel.dir}/mq/lib/imq.jar
+ ${project.build.directory}/${glassfish.toplevel.dir}/mq/lib/jms.jar
+ ${project.build.directory}/${glassfish.toplevel.dir}/mq/lib/fscontext.jar
+
+ jakartatck:jms-tck
+
+ ${project.build.directory}/${glassfish.toplevel.dir}
+ j2ee
+ j2ee
+ javajoe
+ javajoe
+ 10000
+ standalone
+ localhost
+ 8080
+ standalone
+ /tmp
+
+
+ ${project.build.directory}/${glassfish.toplevel.dir}
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/glassfish-runner/jms-tck/src/test/resources/jndi.properties b/glassfish-runner/jms-tck/src/test/resources/jndi.properties
new file mode 100644
index 0000000000..50c75accbc
--- /dev/null
+++ b/glassfish-runner/jms-tck/src/test/resources/jndi.properties
@@ -0,0 +1,28 @@
+#
+# Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+#
+# This program and the accompanying materials are made available under the
+# terms of the Eclipse Public License v. 2.0, which is available at
+# http://www.eclipse.org/legal/epl-2.0.
+#
+# This Source Code may also be made available under the following Secondary
+# Licenses when the conditions for such availability set forth in the
+# Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+# version 2 with the GNU Classpath Exception, which is available at
+# https://www.gnu.org/software/classpath/license.html.
+#
+# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+#
+
+# Properties for establishing initial JNDI Context. These properties
+# are automatically read by JNDI during new InitialContext() as long
+# as this file is in the search path. For JMS TCK the Open Message
+# Queue uses the JNDI FileSystem Context Provider.
+#
+# If on a WINDOWS based system then the path below will need to contain
+# the drive letter in the path. The path below is for UNIX based systems.
+# So for WINDOWS platforms the (java.naming.provider.url) MUST BE:
+# java.naming.provider.url=file:///C:/tmp/ri_admin_objects
+#
+java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory
+java.naming.provider.url=file:///tmp/ri_admin_objects
diff --git a/glassfish-runner/pom.xml b/glassfish-runner/pom.xml
index 6f3e0fb61c..4f80194162 100644
--- a/glassfish-runner/pom.xml
+++ b/glassfish-runner/pom.xml
@@ -45,6 +45,14 @@
glassfish
+ 11
+ 11
+
+ 3.0.0
+ 2.1.0
+ 3.1.0
+ jakarta-restful-ws-tck
+
7.0.0
glassfish7
3.1.0
diff --git a/jms/pom.xml b/jms/pom.xml
index ea4e259691..4bf96a1aa8 100644
--- a/jms/pom.xml
+++ b/jms/pom.xml
@@ -26,11 +26,19 @@
11.0.0-SNAPSHOT
- jms
+ jms-tck
jar
JMS
- JMS
+ JMS TCK tests
+
+
+ 1.7.0.Alpha14
+ 5.9.1
+ 11
+ 11
+ ${project.version}
+
@@ -61,6 +69,21 @@
jakarta.annotation
jakarta.annotation-api
+
+ org.junit.jupiter
+ junit-jupiter
+ ${junit.jupiter.version}
+
+
+ org.jboss.arquillian.junit5
+ arquillian-junit5-container
+ ${arquillian.junit}
+
+
+ org.jboss.arquillian.junit5
+ arquillian-junit5-core
+ ${arquillian.junit}
+
diff --git a/jms/src/main/java/com/sun/ts/lib/implementation/sun/jms/SunRIJMSObjects.java b/jms/src/main/java/com/sun/ts/lib/implementation/sun/jms/SunRIJMSObjects.java
new file mode 100644
index 0000000000..a5feeb52b9
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/lib/implementation/sun/jms/SunRIJMSObjects.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package com.sun.ts.lib.implementation.sun.jms;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import com.sun.ts.lib.porting.TSJMSObjectsInterface;
+import com.sun.ts.lib.util.TestUtil;
+
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.QueueConnectionFactory;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicConnectionFactory;
+
+/**
+ * This is an implementation of the TSJMSObjectsInterface. An implementation of
+ * this class must be supplied by any JMS implementation wishing to get JMS
+ * adminsitered objects: ConnectionFactories, queues and topics.
+ *
+ * @author Dianne Jiao
+ */
+
+public class SunRIJMSObjects implements TSJMSObjectsInterface {
+ private static Context jndiContext = null;
+
+ private static QueueConnectionFactory qcf = null;
+
+ private static TopicConnectionFactory tcf = null;
+
+ private static ConnectionFactory cf = null;
+
+ private jakarta.jms.Topic testTopic = null;
+
+ private jakarta.jms.Queue testQueue = null;
+
+ private void getJNDIContext() throws Exception {
+
+ if (jndiContext == null) {
+ try {
+ TestUtil.logTrace("Getting initial context");
+ jndiContext = new InitialContext();
+ } catch (javax.naming.NamingException ne) {
+ TestUtil.logErr("Could not create JNDI context because: ", ne);
+ TestUtil.printStackTrace(ne);
+ throw ne;
+ }
+ }
+ }
+
+ /**
+ * This method allows individual implementation to get the Queue
+ */
+
+ public jakarta.jms.Queue getQueue(String name) throws Exception {
+ getJNDIContext();
+
+ try {
+ testQueue = (jakarta.jms.Queue) jndiContext.lookup(name);
+ } catch (Exception e) {
+ TestUtil.logErr("Failed to lookup Queue");
+ TestUtil.printStackTrace(e);
+ throw e;
+ }
+ return testQueue;
+ }
+
+ /**
+ * This method allows individual implementation to get the Topic
+ */
+
+ public Topic getTopic(String name) throws Exception {
+ getJNDIContext();
+
+ try {
+ testTopic = (Topic) jndiContext.lookup(name);
+ } catch (Exception e) {
+ TestUtil.logErr("Failed to lookup Topic");
+ TestUtil.printStackTrace(e);
+ throw e;
+ }
+ return testTopic;
+ }
+
+ /**
+ * This method allows individual implementation to get the
+ * QueueConnectionFactory
+ */
+
+ public QueueConnectionFactory getQueueConnectionFactory(String name) throws Exception {
+ getJNDIContext();
+
+ try {
+ qcf = (QueueConnectionFactory) jndiContext.lookup(name);
+ } catch (Exception e) {
+ TestUtil.logErr("Failed to lookup QueueConnectionFactory");
+ TestUtil.printStackTrace(e);
+ throw e;
+ }
+ return qcf;
+ }
+
+ /**
+ * This method allows individual implementation to get the
+ * TopicConnectionFactory
+ */
+
+ public TopicConnectionFactory getTopicConnectionFactory(String name) throws Exception {
+ getJNDIContext();
+
+ try {
+ tcf = (TopicConnectionFactory) jndiContext.lookup(name);
+ } catch (Exception e) {
+ TestUtil.logErr("Failed to lookup TopicConnectionFactory");
+ TestUtil.printStackTrace(e);
+ throw e;
+ }
+ return tcf;
+ }
+
+ /**
+ * This method allows individual implementation to get the ConnectionFactory
+ */
+
+ public ConnectionFactory getConnectionFactory(String name) throws Exception {
+ getJNDIContext();
+
+ try {
+ cf = (ConnectionFactory) jndiContext.lookup(name);
+ } catch (Exception e) {
+ TestUtil.logErr("Failed to lookup ConnectionFactory");
+ TestUtil.printStackTrace(e);
+ throw e;
+ }
+ return cf;
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueConnection/ClosedQueueConnectionTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueConnection/ClosedQueueConnectionTests.java
deleted file mode 100644
index d3663c798d..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueConnection/ClosedQueueConnectionTests.java
+++ /dev/null
@@ -1,472 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.appclient.closedQueueConnection;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.ExceptionListener;
-import jakarta.jms.JMSException;
-import jakarta.jms.Message;
-import jakarta.jms.MessageListener;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueSender;
-import jakarta.jms.QueueSession;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-
-/**
- * JMS TS tests. Testing method calls on closed QueueConnection objects.
- */
-public class ClosedQueueConnectionTests extends ServiceEETest {
- private static final String TestName = "com.sun.ts.tests.jms.core.appclient.closedQueueConnection.ClosedQueueConnectionTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ClosedQueueConnectionTests theTests = new ClosedQueueConnectionTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed connection for testing. Passes any
- * exceptions up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndCloseConnection(int type) throws Exception {
- if ((type == JmsTool.QUEUE) || (type == JmsTool.TX_QUEUE)) {
- tool = new JmsTool(type, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- logTrace("Closing queue Connection");
- tool.getDefaultQueueConnection().close();
- }
- logTrace("Connection closed");
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'users' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
- queues = new ArrayList(2);
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: closedQueueConnectionSetClientIDTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:270; JMS:JAVADOC:526;
- * JMS:JAVADOC:514;
- *
- * @test_Strategy: Close default Connection and call setClientID() method on
- * it. Check for IllegalStateException.
- */
- public void closedQueueConnectionSetClientIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call setClientID");
- try {
- tool.getDefaultQueueConnection().setClientID("foo");
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSetClientIDTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSetExceptionListenerTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:270; JMS:JAVADOC:526;
- * JMS:JAVADOC:520; JMS:JAVADOC:483;
- *
- * @test_Strategy: Close default Connection and call the setExceptionListener
- * method on it. Check for IllegalStateException.
- */
- public void closedQueueConnectionSetExceptionListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call setExceptionListener");
- try {
- ExceptionListener foo = new ExceptionListener() {
-
- public void onException(JMSException jmsE) {
- }
-
- };
-
- tool.getDefaultQueueConnection().setExceptionListener(foo);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSetExceptionListenerTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionGetMessageListenerTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:270; JMS:JAVADOC:526;
- * JMS:JAVADOC:328;
- *
- * @test_Strategy: Close default receiver and call the getMessageListener()
- * method on the QueueReceiver associated with it. Check for
- * IllegalStateException.
- */
- public void closedQueueConnectionGetMessageListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getMessageListener");
- try {
- MessageListener foo = tool.getDefaultQueueReceiver()
- .getMessageListener();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionGetMessageListenerTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSetMessageListenerTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:270; JMS:JAVADOC:526;
- * JMS:JAVADOC:330; JMS:JAVADOC:325;
- *
- * @test_Strategy: Close default receiver and call the setMessageListener
- * method on the QueueReceiver associated with it. Check for
- * IllegalStateException.
- */
- public void closedQueueConnectionSetMessageListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call setMessageListener");
- try {
- MessageListener foo = new MessageListener() {
-
- public void onMessage(Message m) {
- }
-
- };
-
- tool.getDefaultQueueReceiver().setMessageListener(foo);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSetMessageListenerTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionGetExceptionListenerTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:270; JMS:JAVADOC:526;
- * JMS:JAVADOC:518;
- *
- * @test_Strategy: Close default Connection and call the
- * getExceptionListener() method on it. Check for IllegalStateException.
- */
- public void closedQueueConnectionGetExceptionListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getExceptionListener");
- try {
- ExceptionListener foo = tool.getDefaultQueueConnection()
- .getExceptionListener();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionGetExceptionListenerTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionStopTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:270; JMS:JAVADOC:526;
- * JMS:JAVADOC:524;
- *
- * @test_Strategy: Close default Connection and call the stop method on it.
- * Check for IllegalStateException.
- */
- public void closedQueueConnectionStopTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call stop");
- try {
- tool.getDefaultQueueConnection().stop();
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionStopTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionAckTest
- *
- * @assertion_ids: JMS:JAVADOC:272; JMS:SPEC:106; JMS:JAVADOC:794;
- *
- * @test_Strategy: Send and receive single message. Close the queue
- * connection, call acknowledge, then verify that IllegalStateException is
- * thrown.
- */
- public void closedQueueConnectionAckTest() throws Exception {
- boolean pass = true;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- QueueSession qSession = null;
- QueueReceiver qReceiver = null;
- QueueSender qSender = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueReceiver().close();
- tool.getDefaultQueueSession().close();
-
- TestUtil.logTrace("Creating new session");
- qSession = tool.getDefaultQueueConnection().createQueueSession(false,
- Session.CLIENT_ACKNOWLEDGE);
- qReceiver = qSession.createReceiver(tool.getDefaultQueue());
- qSender = qSession.createSender(tool.getDefaultQueue());
- tool.getDefaultQueueConnection().start();
-
- TestUtil.logMsg("Creating 1 TextMessage");
- messageSent = qSession.createTextMessage();
- messageSent.setText("Message from closedQueueConnectionAckTest");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "closedQueueConnectionAckTest");
-
- TestUtil.logMsg("Sending a TextMessage");
- qSender.send(messageSent);
-
- TestUtil.logMsg("Receiving TextMessage");
- messageReceived = (TextMessage) qReceiver.receive(timeout);
- TestUtil.logMsg("Closing DefaultQueueConnection");
- qReceiver.close();
- qSender.close();
- qSession.close();
- tool.getDefaultQueueConnection().close();
-
- try {
- if (messageReceived == null) {
- pass = false;
- TestUtil.logErr("Didnot receive any message!!");
- } else {
- messageReceived.acknowledge();
- pass = false;
- TestUtil.logErr("Should not be here!");
- }
- } catch (jakarta.jms.IllegalStateException is) {
- TestUtil.logMsg(
- "Pass: IllegalStateException thrown by acknowledge as expected");
- } catch (Exception e) {
- pass = false;
- TestUtil.logErr("Expected IllegalStateException, got", e);
- }
-
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueConnectionAckTest");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueConnection/ClosedQueueConnectionTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueConnection/ClosedQueueConnectionTestsIT.java
new file mode 100644
index 0000000000..4ba924867c
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueConnection/ClosedQueueConnectionTestsIT.java
@@ -0,0 +1,457 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.appclient.closedQueueConnection;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.ExceptionListener;
+import jakarta.jms.JMSException;
+import jakarta.jms.Message;
+import jakarta.jms.MessageListener;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueSender;
+import jakarta.jms.QueueSession;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+
+/**
+ * JMS TS tests. Testing method calls on closed QueueConnection objects.
+ */
+
+public class ClosedQueueConnectionTestsIT {
+ private static final String TestName = "com.sun.ts.tests.jms.core.appclient.closedQueueConnection.ClosedQueueConnectionTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedQueueConnectionTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed connection for testing. Passes any
+ * exceptions up to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndCloseConnection(int type) throws Exception {
+ if ((type == JmsTool.QUEUE) || (type == JmsTool.TX_QUEUE)) {
+ tool = new JmsTool(type, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Closing queue Connection");
+ tool.getDefaultQueueConnection().close();
+ }
+ logger.log(Logger.Level.TRACE, "Connection closed");
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'users' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+ queues = new ArrayList(2);
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: closedQueueConnectionSetClientIDTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:270; JMS:JAVADOC:526;
+ * JMS:JAVADOC:514;
+ *
+ * @test_Strategy: Close default Connection and call setClientID() method on it.
+ * Check for IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSetClientIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call setClientID");
+ try {
+ tool.getDefaultQueueConnection().setClientID("foo");
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSetClientIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSetExceptionListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:270; JMS:JAVADOC:526;
+ * JMS:JAVADOC:520; JMS:JAVADOC:483;
+ *
+ * @test_Strategy: Close default Connection and call the setExceptionListener
+ * method on it. Check for IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSetExceptionListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call setExceptionListener");
+ try {
+ ExceptionListener foo = new ExceptionListener() {
+
+ public void onException(JMSException jmsE) {
+ }
+
+ };
+
+ tool.getDefaultQueueConnection().setExceptionListener(foo);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSetExceptionListenerTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionGetMessageListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:270; JMS:JAVADOC:526;
+ * JMS:JAVADOC:328;
+ *
+ * @test_Strategy: Close default receiver and call the getMessageListener()
+ * method on the QueueReceiver associated with it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionGetMessageListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getMessageListener");
+ try {
+ MessageListener foo = tool.getDefaultQueueReceiver().getMessageListener();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionGetMessageListenerTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSetMessageListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:270; JMS:JAVADOC:526;
+ * JMS:JAVADOC:330; JMS:JAVADOC:325;
+ *
+ * @test_Strategy: Close default receiver and call the setMessageListener method
+ * on the QueueReceiver associated with it. Check for IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSetMessageListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call setMessageListener");
+ try {
+ MessageListener foo = new MessageListener() {
+
+ public void onMessage(Message m) {
+ }
+
+ };
+
+ tool.getDefaultQueueReceiver().setMessageListener(foo);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSetMessageListenerTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionGetExceptionListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:270; JMS:JAVADOC:526;
+ * JMS:JAVADOC:518;
+ *
+ * @test_Strategy: Close default Connection and call the getExceptionListener()
+ * method on it. Check for IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionGetExceptionListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getExceptionListener");
+ try {
+ ExceptionListener foo = tool.getDefaultQueueConnection().getExceptionListener();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionGetExceptionListenerTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionStopTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:270; JMS:JAVADOC:526;
+ * JMS:JAVADOC:524;
+ *
+ * @test_Strategy: Close default Connection and call the stop method on it.
+ * Check for IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionStopTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call stop");
+ try {
+ tool.getDefaultQueueConnection().stop();
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionStopTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionAckTest
+ *
+ * @assertion_ids: JMS:JAVADOC:272; JMS:SPEC:106; JMS:JAVADOC:794;
+ *
+ * @test_Strategy: Send and receive single message. Close the queue connection,
+ * call acknowledge, then verify that IllegalStateException is thrown.
+ */
+ @Test
+ public void closedQueueConnectionAckTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ QueueSession qSession = null;
+ QueueReceiver qReceiver = null;
+ QueueSender qSender = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueReceiver().close();
+ tool.getDefaultQueueSession().close();
+
+ logger.log(Logger.Level.TRACE, "Creating new session");
+ qSession = tool.getDefaultQueueConnection().createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
+ qReceiver = qSession.createReceiver(tool.getDefaultQueue());
+ qSender = qSession.createSender(tool.getDefaultQueue());
+ tool.getDefaultQueueConnection().start();
+
+ logger.log(Logger.Level.INFO, "Creating 1 TextMessage");
+ messageSent = qSession.createTextMessage();
+ messageSent.setText("Message from closedQueueConnectionAckTest");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "closedQueueConnectionAckTest");
+
+ logger.log(Logger.Level.INFO, "Sending a TextMessage");
+ qSender.send(messageSent);
+
+ logger.log(Logger.Level.INFO, "Receiving TextMessage");
+ messageReceived = (TextMessage) qReceiver.receive(timeout);
+ logger.log(Logger.Level.INFO, "Closing DefaultQueueConnection");
+ qReceiver.close();
+ qSender.close();
+ qSession.close();
+ tool.getDefaultQueueConnection().close();
+
+ try {
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didnot receive any message!!");
+ } else {
+ messageReceived.acknowledge();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Should not be here!");
+ }
+ } catch (jakarta.jms.IllegalStateException is) {
+ logger.log(Logger.Level.INFO, "Pass: IllegalStateException thrown by acknowledge as expected");
+ } catch (Exception e) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, got", e);
+ }
+
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueConnectionAckTest");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueReceiver/ClosedQueueReceiverIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueReceiver/ClosedQueueReceiverIT.java
new file mode 100644
index 0000000000..d6e7aec503
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueReceiver/ClosedQueueReceiverIT.java
@@ -0,0 +1,239 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.appclient.closedQueueReceiver;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.Message;
+import jakarta.jms.MessageListener;
+
+
+public class ClosedQueueReceiverIT {
+ private static final String TestName = "com.sun.ts.tests.jms.core.appclient.closedQueueReceiver.ClosedQueueReceiverTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedQueueReceiverIT.class.getName());
+
+ // JMS objects
+ private static JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed receiver for testing. Passes any exceptions
+ * up to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndCloseReceiver() throws Exception {
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Closing queue receiver");
+ tool.getDefaultQueueReceiver().close();
+ logger.log(Logger.Level.TRACE, "Receiver closed");
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ /**
+ * Method Declaration.
+ *
+ *
+ * @param args
+ * @param p
+ *
+ * @exception Fault
+ *
+ * @see
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+ queues = new ArrayList(2);
+ // get ready for new test
+ logger.log(Logger.Level.TRACE, "Getting Administrator and deleting any leftover destinations.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: closedQueueReceiverGetMessageListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:328;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueReceiverGetMessageListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseReceiver();
+ logger.log(Logger.Level.TRACE, "Try to call getMessageListener");
+ try {
+ MessageListener foo = tool.getDefaultQueueReceiver().getMessageListener();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueReceiverGetMessageListenerTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueReceiverSetMessageListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:330; JMS:JAVADOC:325;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueReceiverSetMessageListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseReceiver();
+ logger.log(Logger.Level.TRACE, "Try to call setMessageListener");
+ try {
+ MessageListener foo = new MessageListener() {
+
+ public void onMessage(Message m) {
+ }
+
+ };
+
+ tool.getDefaultQueueReceiver().setMessageListener(foo);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueReceiverSetMessageListenerTest", e);
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueReceiver/ClosedQueueReceiverTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueReceiver/ClosedQueueReceiverTests.java
deleted file mode 100644
index 8501822531..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueReceiver/ClosedQueueReceiverTests.java
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.appclient.closedQueueReceiver;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.Message;
-import jakarta.jms.MessageListener;
-
-public class ClosedQueueReceiverTests extends ServiceEETest {
- private static final String TestName = "com.sun.ts.tests.jms.core.appclient.closedQueueReceiver.ClosedQueueReceiverTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- // JMS objects
- private static JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ClosedQueueReceiverTests theTests = new ClosedQueueReceiverTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed receiver for testing. Passes any
- * exceptions up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndCloseReceiver() throws Exception {
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- logTrace("Closing queue receiver");
- tool.getDefaultQueueReceiver().close();
- logTrace("Receiver closed");
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- /**
- * Method Declaration.
- *
- *
- * @param args
- * @param p
- *
- * @exception Fault
- *
- * @see
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
- queues = new ArrayList(2);
- // get ready for new test
- logTrace("Getting Administrator and deleting any leftover destinations.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: closedQueueReceiverGetMessageListenerTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:328;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueReceiverGetMessageListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseReceiver();
- logTrace("Try to call getMessageListener");
- try {
- MessageListener foo = tool.getDefaultQueueReceiver()
- .getMessageListener();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueReceiverGetMessageListenerTest", e);
- }
- }
-
- /*
- * @testName: closedQueueReceiverSetMessageListenerTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:330; JMS:JAVADOC:325;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueReceiverSetMessageListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseReceiver();
- logTrace("Try to call setMessageListener");
- try {
- MessageListener foo = new MessageListener() {
-
- public void onMessage(Message m) {
- }
-
- };
-
- tool.getDefaultQueueReceiver().setMessageListener(foo);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueReceiverSetMessageListenerTest", e);
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueSession/ClosedQueueSessionTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueSession/ClosedQueueSessionTests.java
deleted file mode 100644
index c3fdc81db0..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueSession/ClosedQueueSessionTests.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.appclient.closedQueueSession;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.Message;
-import jakarta.jms.MessageListener;
-
-/**
- * JMS TS tests. Testing method calls on closed QueueSession objects.
- */
-public class ClosedQueueSessionTests extends ServiceEETest {
- private static final String TestName = "com.sun.ts.tests.jms.core.appclient.closedQueueSession.ClosedQueueSessionTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- // JMS objects
- private static JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- */
- public static void main(String[] args) {
- ClosedQueueSessionTests theTests = new ClosedQueueSessionTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed session for testing. Passes any exceptions
- * up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndCloseSession(int type, String user, String password)
- throws Exception {
- if ((type == JmsTool.QUEUE) || (type == JmsTool.TX_QUEUE)) {
- tool = new JmsTool(type, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logMsg("Closing queue session");
- tool.getDefaultQueueSession().close();
- }
- logMsg("Session closed");
- }
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
-
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- logMsg("Didn't get expected exception");
- throw new Exception("Didn't catch expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
- queues = new ArrayList(2);
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: closedQueueSessionGetMessageListenerTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:328;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionGetMessageListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call getMessageListener");
- try {
- MessageListener foo = tool.getDefaultQueueReceiver()
- .getMessageListener();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSessionGetMessageListenerTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionSetMessageListenerTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:330; JMS:JAVADOC:325;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionSetMessageListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call setMessageListener");
- try {
- MessageListener foo = new MessageListener() {
-
- public void onMessage(Message m) {
- }
-
- };
-
- tool.getDefaultQueueReceiver().setMessageListener(foo);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSessionSetMessageListenerTest", e);
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueSession/ClosedQueueSessionTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueSession/ClosedQueueSessionTestsIT.java
new file mode 100644
index 0000000000..8527be0e17
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedQueueSession/ClosedQueueSessionTestsIT.java
@@ -0,0 +1,245 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.appclient.closedQueueSession;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.Message;
+import jakarta.jms.MessageListener;
+
+/**
+ * JMS TS tests. Testing method calls on closed QueueSession objects.
+ */
+
+public class ClosedQueueSessionTestsIT {
+ private static final String TestName = "com.sun.ts.tests.jms.core.appclient.closedQueueSession.ClosedQueueSessionTests";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedQueueSessionTestsIT.class.getName());
+
+ // JMS objects
+ private static JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed session for testing. Passes any exceptions
+ * up to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndCloseSession(int type, String user, String password) throws Exception {
+ if ((type == JmsTool.QUEUE) || (type == JmsTool.TX_QUEUE)) {
+ tool = new JmsTool(type, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.INFO, "Closing queue session");
+ tool.getDefaultQueueSession().close();
+ }
+ logger.log(Logger.Level.INFO, "Session closed");
+ }
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't catch expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+ queues = new ArrayList(2);
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: closedQueueSessionGetMessageListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:328;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionGetMessageListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getMessageListener");
+ try {
+ MessageListener foo = tool.getDefaultQueueReceiver().getMessageListener();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionGetMessageListenerTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionSetMessageListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:330; JMS:JAVADOC:325;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionSetMessageListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setMessageListener");
+ try {
+ MessageListener foo = new MessageListener() {
+
+ public void onMessage(Message m) {
+ }
+
+ };
+
+ tool.getDefaultQueueReceiver().setMessageListener(foo);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionSetMessageListenerTest", e);
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedTopicConnection/ClosedTopicConnectionTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedTopicConnection/ClosedTopicConnectionTests.java
deleted file mode 100644
index 7d48f6a77c..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedTopicConnection/ClosedTopicConnectionTests.java
+++ /dev/null
@@ -1,396 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.appclient.closedTopicConnection;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.ExceptionListener;
-import jakarta.jms.JMSException;
-import jakarta.jms.Message;
-import jakarta.jms.MessageListener;
-
-/**
- * JMS product tests. Testing method calls on closed TopicConnection objects.
- */
-public class ClosedTopicConnectionTests extends ServiceEETest {
- private static final String TestName = "com.sun.ts.tests.jms.core.appclient.closedTopicConnection.ClosedTopicConnectionTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- // JMS objects
- private static JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ClosedTopicConnectionTests theTests = new ClosedTopicConnectionTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed connection for testing. Passes any
- * exceptions up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndCloseConnection(int type, String user, String password)
- throws Exception {
- if ((type == JmsTool.TOPIC) || (type == JmsTool.TX_TOPIC)) {
- tool = new JmsTool(type, user, password, mode);
- tool.getDefaultTopicConnection().start();
-
- logTrace("Closing queue Connection");
- tool.getDefaultTopicConnection().close();
- }
- logTrace("Connection closed");
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Topic and/or
- * Topic Connection, as well as a default Topic and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'numProducers' in ts.jte must be null");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
-
- // get ready for new test
- logTrace("Getting Administrator and deleting any leftover destinations.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logTrace("Cleanup: Closing Topic and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: closedTopicConnectionGetExceptionListenerTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:518;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionGetExceptionListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- logTrace("Try to call getExceptionListener");
- try {
- ExceptionListener foo = tool.getDefaultTopicConnection()
- .getExceptionListener();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionGetExceptionListenerTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionSetClientIDTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:514;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionSetClientIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- logTrace("Try to call setClientID");
- try {
- tool.getDefaultTopicConnection().setClientID("foo");
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionSetClientIDTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionSetExceptionListenerTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:520; JMS:JAVADOC:483;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionSetExceptionListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- logTrace("Try to call setExceptionListener");
- try {
- ExceptionListener foo = new ExceptionListener() {
-
- public void onException(JMSException jmsE) {
- }
-
- };
-
- tool.getDefaultTopicConnection().setExceptionListener(foo);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionSetExceptionListenerTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionGetMessageListenerTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:328;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionGetMessageListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- logTrace("Try to call getMessageListener");
- try {
- MessageListener foo = tool.getDefaultTopicSubscriber()
- .getMessageListener();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionGetMessageListenerTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionSetMessageListenerTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:330; JMS:JAVADOC:325;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionSetMessageListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- logTrace("Try to call setMessageListener");
- try {
- MessageListener foo = new MessageListener() {
-
- public void onMessage(Message m) {
- }
-
- };
-
- tool.getDefaultTopicSubscriber().setMessageListener(foo);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionSetMessageListenerTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionStopTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:524;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionStopTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call stop");
- try {
- tool.getDefaultTopicConnection().stop();
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionStopTest", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedTopicConnection/ClosedTopicConnectionTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedTopicConnection/ClosedTopicConnectionTestsIT.java
new file mode 100644
index 0000000000..ca810c675b
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedTopicConnection/ClosedTopicConnectionTestsIT.java
@@ -0,0 +1,378 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.appclient.closedTopicConnection;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.ExceptionListener;
+import jakarta.jms.JMSException;
+import jakarta.jms.Message;
+import jakarta.jms.MessageListener;
+
+/**
+ * JMS product tests. Testing method calls on closed TopicConnection objects.
+ */
+
+public class ClosedTopicConnectionTestsIT {
+ private static final String TestName = "com.sun.ts.tests.jms.core.appclient.closedTopicConnection.ClosedTopicConnectionTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedTopicConnectionTestsIT.class.getName());
+
+ // JMS objects
+ private static JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed connection for testing. Passes any
+ * exceptions up to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndCloseConnection(int type, String user, String password) throws Exception {
+ if ((type == JmsTool.TOPIC) || (type == JmsTool.TX_TOPIC)) {
+ tool = new JmsTool(type, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Closing queue Connection");
+ tool.getDefaultTopicConnection().close();
+ }
+ logger.log(Logger.Level.TRACE, "Connection closed");
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Topic and/or
+ * Topic Connection, as well as a default Topic and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'numProducers' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+
+ // get ready for new test
+ logger.log(Logger.Level.TRACE, "Getting Administrator and deleting any leftover destinations.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.TRACE, "Cleanup: Closing Topic and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: closedTopicConnectionGetExceptionListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:518;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionGetExceptionListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getExceptionListener");
+ try {
+ ExceptionListener foo = tool.getDefaultTopicConnection().getExceptionListener();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionGetExceptionListenerTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionSetClientIDTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:514;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionSetClientIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setClientID");
+ try {
+ tool.getDefaultTopicConnection().setClientID("foo");
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionSetClientIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionSetExceptionListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:520; JMS:JAVADOC:483;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionSetExceptionListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setExceptionListener");
+ try {
+ ExceptionListener foo = new ExceptionListener() {
+
+ public void onException(JMSException jmsE) {
+ }
+
+ };
+
+ tool.getDefaultTopicConnection().setExceptionListener(foo);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionSetExceptionListenerTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionGetMessageListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:328;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionGetMessageListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getMessageListener");
+ try {
+ MessageListener foo = tool.getDefaultTopicSubscriber().getMessageListener();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionGetMessageListenerTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionSetMessageListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:330; JMS:JAVADOC:325;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionSetMessageListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setMessageListener");
+ try {
+ MessageListener foo = new MessageListener() {
+
+ public void onMessage(Message m) {
+ }
+
+ };
+
+ tool.getDefaultTopicSubscriber().setMessageListener(foo);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionSetMessageListenerTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionStopTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:524;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionStopTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call stop");
+ try {
+ tool.getDefaultTopicConnection().stop();
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionStopTest", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedTopicSession/ClosedTopicSessionTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedTopicSession/ClosedTopicSessionTests.java
deleted file mode 100644
index f1d2eef04a..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedTopicSession/ClosedTopicSessionTests.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.appclient.closedTopicSession;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.Message;
-import jakarta.jms.MessageListener;
-
-public class ClosedTopicSessionTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.ee.ejbjspservlet.closedTopicSession.ClosedTopicSessionTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- // Harness req's
- private Properties props = null;
-
- // JMS object
- private static JmsTool tool = null;
-
- // properties read from ts.jte file
- long timeout;
-
- private String jmsUser;
-
- private String jmsPassword;
-
- private String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ClosedTopicSessionTests theTests = new ClosedTopicSessionTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed session for testing. Passes any exceptions
- * up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndCloseSession(int type) throws Exception {
- if ((type == JmsTool.TOPIC) || (type == JmsTool.TX_TOPIC)) {
- tool = new JmsTool(type, jmsUser, jmsPassword, mode);
- tool.getDefaultTopicConnection().start();
- logMsg("Closing topic session");
- tool.getDefaultTopicSession().close();
- }
- logMsg("Session closed");
- }
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- logMsg("Didn't get expected exception");
- throw new Exception("Didn't catch expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout;user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- logTrace("In setup");
- // get props
- jmsUser = p.getProperty("user");
- jmsPassword = p.getProperty("password");
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- mode = p.getProperty("platform.mode");
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: closedTopicSessionSetMessageListenerTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:330; JMS:JAVADOC:325;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
- public void closedTopicSessionSetMessageListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call setMessageListener");
- try {
- MessageListener foo = new MessageListener() {
- public void onMessage(Message m) {
- }
-
- };
-
- tool.getDefaultTopicSubscriber().setMessageListener(foo);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionSetMessageListenerTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionGetMessageListenerTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:328;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionGetMessageListenerTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call getMessageListener");
- try {
- MessageListener foo = tool.getDefaultTopicSubscriber()
- .getMessageListener();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionGetMessageListenerTest", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedTopicSession/ClosedTopicSessionTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedTopicSession/ClosedTopicSessionTestsIT.java
new file mode 100644
index 0000000000..4ca59884ec
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/closedTopicSession/ClosedTopicSessionTestsIT.java
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.appclient.closedTopicSession;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.Message;
+import jakarta.jms.MessageListener;
+
+
+public class ClosedTopicSessionTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.ee.ejbjspservlet.closedTopicSession.ClosedTopicSessionTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedTopicSessionTestsIT.class.getName());
+
+ // Harness req's
+ private Properties props = null;
+
+ // JMS object
+ private static JmsTool tool = null;
+
+ // properties read
+ long timeout;
+
+ private String jmsUser;
+
+ private String jmsPassword;
+
+ private String mode;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed session for testing. Passes any exceptions
+ * up to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndCloseSession(int type) throws Exception {
+ if ((type == JmsTool.TOPIC) || (type == JmsTool.TX_TOPIC)) {
+ tool = new JmsTool(type, jmsUser, jmsPassword, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "Closing topic session");
+ tool.getDefaultTopicSession().close();
+ }
+ logger.log(Logger.Level.INFO, "Session closed");
+ }
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't catch expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout;user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, "In setup");
+ // get props
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ mode = System.getProperty("platform.mode");
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: closedTopicSessionSetMessageListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:330; JMS:JAVADOC:325;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionSetMessageListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call setMessageListener");
+ try {
+ MessageListener foo = new MessageListener() {
+ public void onMessage(Message m) {
+ }
+
+ };
+
+ tool.getDefaultTopicSubscriber().setMessageListener(foo);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionSetMessageListenerTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionGetMessageListenerTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:328;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionGetMessageListenerTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call getMessageListener");
+ try {
+ MessageListener foo = tool.getDefaultTopicSubscriber().getMessageListener();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionGetMessageListenerTest", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/invalidDest/InvalidDestTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/invalidDest/InvalidDestTests.java
deleted file mode 100644
index 70c4f992b1..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/invalidDest/InvalidDestTests.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.appclient.invalidDest;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.Connection;
-import jakarta.jms.InvalidDestinationException;
-import jakarta.jms.Session;
-import jakarta.jms.Topic;
-
-public class InvalidDestTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.appclient.invalidDest.InvalidDestTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- // JMS objects
- private static JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- InvalidDestTests theTests = new InvalidDestTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- }
-
- /* Tests */
- /*
- * @testName: invalidDestinationTests
- *
- * @assertion_ids: JMS:JAVADOC:502; JMS:JAVADOC:504; JMS:JAVADOC:510;
- * JMS:JAVADOC:638; JMS:JAVADOC:639; JMS:JAVADOC:641; JMS:JAVADOC:643;
- * JMS:JAVADOC:644; JMS:JAVADOC:646; JMS:JAVADOC:647; JMS:JAVADOC:649;
- *
- * @test_Strategy: 1. Create a Session with Topic Configuration, using a null
- * Destination/Topic to verify InvalidDestinationException is thrown with
- * various methods
- */
-
- public void invalidDestinationTests() throws Exception {
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- boolean pass = true;
- Topic dummyT = null;
-
- JmsTool tool = new JmsTool(JmsTool.COMMON_T, user, password, lookup,
- mode);
- tool.getDefaultConnection().close();
-
- Connection newConn = tool.getNewConnection(JmsTool.COMMON_T, user,
- password, lookup);
- if (newConn.getClientID() == null) {
- newConn.setClientID("cts");
- }
- Session newSession = newConn.createSession(false,
- Session.AUTO_ACKNOWLEDGE);
-
- try {
- newSession.unsubscribe("foo");
- logErr(
- "Error: unsubscribe(foo) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from unsubscribe(foo)");
- } catch (Exception e) {
- logErr("Error: unsubscribe(foo) throw incorrect Exception: ", e);
- pass = false;
- }
-
- try {
- newSession.createDurableSubscriber(dummyT, "cts");
- logErr(
- "Error: createDurableSubscriber(null, String) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createDurableSubscriber(null, String)");
- } catch (Exception e) {
- logErr(
- "Error: createDurableSubscriber(null, String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- newSession.createDurableSubscriber(dummyT, "cts", "TEST = 'test'",
- true);
- logErr("Error: createDurableSubscriber(null, String, String, boolean) "
- + "didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createDurableSubscriber(null, String, String, boolean)");
- } catch (Exception e) {
- logErr(
- "Error: createDurableSubscriber(null, String, String, boolean) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- newConn.close();
- } catch (Exception ex) {
- logErr("Error closing new Connection", ex);
- }
-
- if (pass != true)
- throw new Exception("invalidDestinationTests");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("invalidDestinationTests");
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/invalidDest/InvalidDestTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/invalidDest/InvalidDestTestsIT.java
new file mode 100644
index 0000000000..360bfaf131
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/invalidDest/InvalidDestTestsIT.java
@@ -0,0 +1,202 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.appclient.invalidDest;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.Connection;
+import jakarta.jms.InvalidDestinationException;
+import jakarta.jms.Session;
+import jakarta.jms.Topic;
+
+
+public class InvalidDestTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.appclient.invalidDest.InvalidDestTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final Logger logger = (Logger) System.getLogger(InvalidDestTestsIT.class.getName());
+
+ // JMS objects
+ private static JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ }
+
+ /* Tests */
+ /*
+ * @testName: invalidDestinationTests
+ *
+ * @assertion_ids: JMS:JAVADOC:502; JMS:JAVADOC:504; JMS:JAVADOC:510;
+ * JMS:JAVADOC:638; JMS:JAVADOC:639; JMS:JAVADOC:641; JMS:JAVADOC:643;
+ * JMS:JAVADOC:644; JMS:JAVADOC:646; JMS:JAVADOC:647; JMS:JAVADOC:649;
+ *
+ * @test_Strategy: 1. Create a Session with Topic Configuration, using a null
+ * Destination/Topic to verify InvalidDestinationException is thrown with
+ * various methods
+ */
+ @Test
+ public void invalidDestinationTests() throws Exception {
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ boolean pass = true;
+ Topic dummyT = null;
+
+ JmsTool tool = new JmsTool(JmsTool.COMMON_T, user, password, lookup, mode);
+ tool.getDefaultConnection().close();
+
+ Connection newConn = tool.getNewConnection(JmsTool.COMMON_T, user, password, lookup);
+ if (newConn.getClientID() == null) {
+ newConn.setClientID("cts");
+ }
+ Session newSession = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ try {
+ newSession.unsubscribe("foo");
+ logger.log(Logger.Level.ERROR,
+ "Error: unsubscribe(foo) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO, "Got expected InvalidDestinationException from unsubscribe(foo)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unsubscribe(foo) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ newSession.createDurableSubscriber(dummyT, "cts");
+ logger.log(Logger.Level.ERROR,
+ "Error: createDurableSubscriber(null, String) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createDurableSubscriber(null, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error: createDurableSubscriber(null, String) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ newSession.createDurableSubscriber(dummyT, "cts", "TEST = 'test'", true);
+ logger.log(Logger.Level.ERROR, "Error: createDurableSubscriber(null, String, String, boolean) "
+ + "didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createDurableSubscriber(null, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error: createDurableSubscriber(null, String, String, boolean) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ newConn.close();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing new Connection", ex);
+ }
+
+ if (pass != true)
+ throw new Exception("invalidDestinationTests");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("invalidDestinationTests");
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/queueconn/QueueConnTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/queueconn/QueueConnTests.java
deleted file mode 100644
index 586b276e1a..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/queueconn/QueueConnTests.java
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.appclient.queueconn;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.QueueConnection;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueSender;
-import jakarta.jms.QueueSession;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-
-public class QueueConnTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.appclient.queueconn.QueueConnTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- QueueConnTests theTests = new QueueConnTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue
- * Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
- queues = new ArrayList(2);
- connections = new ArrayList(5);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- TestUtil.logMsg("Cleanup: Closing Queue Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: connStoppedQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:272; JMS:SPEC:100; JMS:SPEC:98; JMS:SPEC:99;
- * JMS:JAVADOC:522; JMS:JAVADOC:524; JMS:JAVADOC:120; JMS:JAVADOC:221;
- * JMS:JAVADOC:198; JMS:JAVADOC:334;
- *
- * @test_Strategy: Stop the connection. Send a msg; start the connection and
- * receive the msg. Should get the message
- */
-
- public void connStoppedQueueTest() throws Exception {
- boolean pass = true;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- tool.getDefaultQueueConnection().stop();
-
- TestUtil.logTrace("Creating 1 TextMessage");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("Message from connStoppedQueueTest");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "connStoppedQueueTest");
-
- TestUtil.logTrace("Sending a TextMessage");
- tool.getDefaultQueueSender().send(messageSent);
-
- TestUtil.logTrace("Receiving message");
- tool.getDefaultQueueConnection().start();
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Pass: Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- } catch (Exception e) {
- TestUtil.logErr("connStoppedQueueTest failed: ", e);
- throw new Exception("connStoppedQueueTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionNoForcedAckTest
- *
- * @assertion_ids: JMS:JAVADOC:272; JMS:SPEC:105; JMS:JAVADOC:429;
- * JMS:SPEC:115;
- *
- * @test_Strategy: Send and receive single message, don't acknowledge it.
- * close the queue connection, get the message with a second connection.
- */
-
- public void closedQueueConnectionNoForcedAckTest() throws Exception {
- boolean pass = true;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- QueueSession qSession = null;
- QueueReceiver qReceiver = null;
- QueueSender qSender = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
-
- QueueConnection newConn = (QueueConnection) tool
- .getNewConnection(JmsTool.QUEUE, user, password);
- connections.add(newConn);
-
- qSession = newConn.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
- tool.getDefaultQueueReceiver().close();
- tool.getDefaultQueueSession().close();
-
- qReceiver = qSession.createReceiver(tool.getDefaultQueue());
- qSender = qSession.createSender(tool.getDefaultQueue());
- TestUtil.logMsg("create a new connection");
- newConn.start();
-
- TestUtil.logMsg("Creating 1 TextMessage");
- messageSent = qSession.createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "closedQueueConnectionNoForcedAckTest");
- TestUtil.logMsg("Sending a TextMessage");
- qSender.send(messageSent);
-
- TestUtil.logMsg("Receive the TextMessage");
- messageReceived = (TextMessage) qReceiver.receive(timeout);
- qReceiver.close();
- TestUtil.logMsg("Close the connection with no ack of message received");
- newConn.close();
-
- TestUtil.logMsg(
- "Use default connection to retrieve the unacknowledged message");
- qSession = tool.getDefaultQueueConnection().createQueueSession(false,
- Session.CLIENT_ACKNOWLEDGE);
- qReceiver = qSession.createReceiver(tool.getDefaultQueue());
- tool.getDefaultQueueConnection().start();
-
- messageReceived = (TextMessage) qReceiver.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logErr("Fail: no message received.");
- pass = false;
- } else if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Pass: received correct msg");
- } else {
- TestUtil.logErr("Fail: didnt get correct msg");
- pass = false;
- }
-
- try {
- messageReceived.acknowledge();
- } catch (Exception e) {
- pass = false;
- TestUtil.logErr("Exception thrown on ack!", e);
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueConnectionNoForcedAckTest");
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/queueconn/QueueConnTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/queueconn/QueueConnTestsIT.java
new file mode 100644
index 0000000000..6a5f3cb755
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/queueconn/QueueConnTestsIT.java
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.appclient.queueconn;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.QueueConnection;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueSender;
+import jakarta.jms.QueueSession;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+
+
+public class QueueConnTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.appclient.queueconn.QueueConnTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(QueueConnTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue Connection,
+ * as well as a default Queue and Topic. Tests that require multiple
+ * Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+ queues = new ArrayList(2);
+ connections = new ArrayList(5);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: connStoppedQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:272; JMS:SPEC:100; JMS:SPEC:98; JMS:SPEC:99;
+ * JMS:JAVADOC:522; JMS:JAVADOC:524; JMS:JAVADOC:120; JMS:JAVADOC:221;
+ * JMS:JAVADOC:198; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Stop the connection. Send a msg; start the connection and
+ * receive the msg. Should get the message
+ */
+ @Test
+ public void connStoppedQueueTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ tool.getDefaultQueueConnection().stop();
+
+ logger.log(Logger.Level.TRACE, "Creating 1 TextMessage");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("Message from connStoppedQueueTest");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "connStoppedQueueTest");
+
+ logger.log(Logger.Level.TRACE, "Sending a TextMessage");
+ tool.getDefaultQueueSender().send(messageSent);
+
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ tool.getDefaultQueueConnection().start();
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Pass: Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "connStoppedQueueTest failed: ", e);
+ throw new Exception("connStoppedQueueTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionNoForcedAckTest
+ *
+ * @assertion_ids: JMS:JAVADOC:272; JMS:SPEC:105; JMS:JAVADOC:429; JMS:SPEC:115;
+ *
+ * @test_Strategy: Send and receive single message, don't acknowledge it. close
+ * the queue connection, get the message with a second connection.
+ */
+ @Test
+ public void closedQueueConnectionNoForcedAckTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ QueueSession qSession = null;
+ QueueReceiver qReceiver = null;
+ QueueSender qSender = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+
+ QueueConnection newConn = (QueueConnection) tool.getNewConnection(JmsTool.QUEUE, user, password);
+ connections.add(newConn);
+
+ qSession = newConn.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
+ tool.getDefaultQueueReceiver().close();
+ tool.getDefaultQueueSession().close();
+
+ qReceiver = qSession.createReceiver(tool.getDefaultQueue());
+ qSender = qSession.createSender(tool.getDefaultQueue());
+ logger.log(Logger.Level.INFO, "create a new connection");
+ newConn.start();
+
+ logger.log(Logger.Level.INFO, "Creating 1 TextMessage");
+ messageSent = qSession.createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "closedQueueConnectionNoForcedAckTest");
+ logger.log(Logger.Level.INFO, "Sending a TextMessage");
+ qSender.send(messageSent);
+
+ logger.log(Logger.Level.INFO, "Receive the TextMessage");
+ messageReceived = (TextMessage) qReceiver.receive(timeout);
+ qReceiver.close();
+ logger.log(Logger.Level.INFO, "Close the connection with no ack of message received");
+ newConn.close();
+
+ logger.log(Logger.Level.INFO, "Use default connection to retrieve the unacknowledged message");
+ qSession = tool.getDefaultQueueConnection().createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
+ qReceiver = qSession.createReceiver(tool.getDefaultQueue());
+ tool.getDefaultQueueConnection().start();
+
+ messageReceived = (TextMessage) qReceiver.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "Fail: no message received.");
+ pass = false;
+ } else if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Pass: received correct msg");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: didnt get correct msg");
+ pass = false;
+ }
+
+ try {
+ messageReceived.acknowledge();
+ } catch (Exception e) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Exception thrown on ack!", e);
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueConnectionNoForcedAckTest");
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/queuetests/QueueTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/queuetests/QueueTests.java
deleted file mode 100644
index a7466fcf40..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/queuetests/QueueTests.java
+++ /dev/null
@@ -1,1141 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.appclient.queuetests;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.DoneLatch;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.common.SerialTestMessageListenerImpl;
-import com.sun.ts.tests.jms.common.SessionThread;
-
-import jakarta.jms.ExceptionListener;
-import jakarta.jms.InvalidClientIDException;
-import jakarta.jms.InvalidDestinationException;
-import jakarta.jms.JMSException;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.MessageListener;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueConnection;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueRequestor;
-import jakarta.jms.QueueSender;
-import jakarta.jms.QueueSession;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-import jakarta.jms.TopicConnection;
-
-public class QueueTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.appclient.queuetests.QueueTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- QueueTests theTests = new QueueTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue
- * Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null ");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
-
- // for cleanup purposes - set up an array list of the queues the tests use
- // add default queue
- queues = new ArrayList(10);
- connections = new ArrayList(5);
- TestUtil.logMsg("adding the default queue to the queue cleaner lsit\n");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- tool.doClientQueueTestCleanup(connections, queues);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /*
- * @testName: receiveNullClosedSessionQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:12; JMS:JAVADOC:13;
- *
- * @test_Strategy: Create a session in a separate thread that calls receive()
- * and replies to the message. Have the thread call receive() again with no
- * message sent. Close the thread's session and the receive() call should
- * return, finishing the thread's run() method. Verify that the thread is no
- * longer running.
- */
- public void receiveNullClosedSessionQueueTest() throws Exception {
- int waitTime = 15; // seconds
-
- try {
-
- // create Queue setup
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- logMsg("Close default QueueReceiver");
- tool.getDefaultQueueReceiver().close();
- tool.getDefaultQueueConnection().start();
-
- // create QueueRequestor for reply
- logMsg("Create QueueRequestor");
- QueueRequestor qReq = new QueueRequestor(tool.getDefaultQueueSession(),
- tool.getDefaultQueue());
-
- // create a thread to receive
- logMsg("Create SessionThread");
- SessionThread sT = new SessionThread(tool.getDefaultQueueConnection(),
- (TopicConnection) null);
-
- logMsg("Tell SessionThread to respond to messages");
- sT.setReplyToMessages(true);
- logMsg("Create Receiver in SessionThread");
- sT.createConsumer(tool.getDefaultQueue());
- logMsg("Tell receiver to keep receiving\n(it will throw an "
- + "exception and stop when it receives the null message)");
- sT.setStayAlive(true);
- logMsg("Start the SessionThread");
- sT.start();
-
- // send/receive one message and close thread's session
- logMsg("Send one message and receive reply");
- Message tempMsg = tool.getDefaultQueueSession().createMessage();
-
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "receiveNullClosedSessionQueueTest");
- qReq.request(tempMsg);
-
- logMsg("Wait " + waitTime + " seconds for receive() to start again "
- + "before closing session...");
- for (int i = 0; i < 100000; i++) {
- }
- logMsg("Close the SessionThread's QueueSession");
- sT.getQueueSession().close();
-
- // wait for session to close. Using TS timeout here
- logMsg(
- "Wait for thread to close (will close after receiving null message)");
- sT.join();
-
- // check to see if thread is still waiting
- if (sT.isAlive()) {
- logErr(
- "thread still waiting on receive() -- BAD [could be timing problem]");
- throw new Exception("receive() call still waiting");
- } else {
- logMsg("receive() properly received a null message -- GOOD");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("receiveNullClosedSessionQueueTest");
- }
- }
- /* Tests */
-
- /*
- * @testName: setClientIDLateQueueTest
- *
- * @assertion_ids: JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:94; JMS:SPEC:91;
- *
- * @test_Strategy: create a connection, send and receive a msg, then set the
- * ClientID verify that IllegalStateException is thrown.
- *
- */
- public void setClientIDLateQueueTest() throws Exception {
- boolean booleanValue = true;
- boolean pass = true;
-
- try {
- MapMessage messageSent;
- MapMessage messageReceived;
- QueueConnection qConn;
- QueueSession qSess;
- Queue queue;
- QueueSender qSender;
- QueueReceiver qRec;
-
- // set up queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- qConn = (QueueConnection) tool.getNewConnection(JmsTool.QUEUE, user,
- password);
- connections.add(qConn);
- qSess = qConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- queue = tool.createNewQueue("testQueue2");
- // add testQueue2 to our cleanup list
- queues.add(queue);
- qSender = qSess.createSender(queue);
- qRec = qSess.createReceiver(queue);
- qConn.start();
-
- logTrace("Creating 1 message");
- messageSent = qSess.createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "setClientIDLateQueueTest");
- messageSent.setBoolean("booleanValue", booleanValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- qSender.send(messageSent);
- logTrace("Receiving message");
- messageReceived = (MapMessage) qRec.receive(timeout);
- // read the boolean
- messageReceived.getBoolean("booleanValue");
-
- logTrace("Attempt to set Client ID too late");
- try {
- qConn.setClientID("setClientIDLateQueueTest");
- pass = false;
- logMsg("Error: Illegal state exception was not thrown");
- } catch (jakarta.jms.IllegalStateException is) {
- logTrace("Pass: IllegalStateException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("setClientIDLateQueueTest");
- }
- }
-
- /*
- * @testName: autoAckMsgListenerQueueTest
- *
- * @assertion_ids: JMS:SPEC:132; JMS:SPEC:136;
- *
- * @test_Strategy: Set up a receiver with a messagelistener. Send two messages
- * to the destination. The message listener will receive the messages and
- * automatically call recover() after the send one. It will verify that the
- * second message only is received a second time. After waiting for the
- * message listener to finish, the test checks the state of the listener.
- */
- public void autoAckMsgListenerQueueTest() throws Exception {
- try {
- Message messageSent = null;
- AutoAckMsgListener mListener = null;
-
- // create queue setup with message listener
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- logTrace("Create and set MessageListener.");
- mListener = new AutoAckMsgListener(new DoneLatch(),
- tool.getDefaultQueueSession());
- tool.getDefaultQueueReceiver().setMessageListener(mListener);
-
- // create and send messages
- logTrace("Send and receive two messages");
- messageSent = tool.getDefaultQueueSession().createMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "autoAckMsgListenerQueueTest");
- messageSent.setBooleanProperty("lastMessage", false);
- tool.getDefaultQueueSender().send(messageSent);
- messageSent.setBooleanProperty("lastMessage", true);
- tool.getDefaultQueueSender().send(messageSent);
-
- tool.getDefaultQueueConnection().start();
-
- // wait until message is received
- logTrace(
- "waiting until message has been received by message listener...");
- mListener.monitor.waitTillDone();
-
- // check message listener status
- if (mListener.getPassed() == false) {
- throw new Exception("failed");
- }
- } catch (Exception e) {
- logMsg("Error: " + e);
- throw new Exception("autoAckMsgListenerQueueTest", e);
- }
- }
-
- /*
- * @testName: serialMsgListenerQueueTest
- *
- * @assertion_ids: JMS:SPEC:120; JMS:SPEC:121; JMS:SPEC:136;
- *
- * @test_Strategy: Create queue sessions with two receivers and message
- * listeners for two queues. Send multiple messages to the queues and then
- * start the connection to begin receiving messages. The message listeners
- * perform a Thread.sleep() in the onMessage() method, checking for concurrent
- * use of the other listener. The test is over when the harness determines
- * that the last message has been received.
- */
- public void serialMsgListenerQueueTest() throws Exception {
- try {
- TextMessage tMsg[] = new TextMessage[numMessages];
- Queue newQ;
- QueueReceiver qRec1;
- QueueReceiver qRec2;
- QueueSender qSender1;
- QueueSender qSender2;
- SerialTestMessageListenerImpl myListener1;
- SerialTestMessageListenerImpl myListener2;
-
- // set up tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueReceiver().close();
- newQ = tool.createNewQueue("testQueue2");
- queues.add(newQ);
-
- // set up receivers
- qRec1 = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue());
- qRec2 = tool.getDefaultQueueSession().createReceiver(newQ);
-
- // set up message listeners
- logMsg("Create two message listeners");
- myListener1 = new SerialTestMessageListenerImpl();
- myListener2 = new SerialTestMessageListenerImpl();
- qRec1.setMessageListener(myListener1);
- qRec2.setMessageListener(myListener2);
-
- // create message producers
- qSender1 = tool.getDefaultQueueSession()
- .createSender(tool.getDefaultQueue());
- qSender2 = tool.getDefaultQueueSession().createSender(newQ);
-
- // create and send messages before starting connection
- for (int i = 0; i < numMessages; i++) {
- logMsg("Create and send message " + i);
- tMsg[i] = tool.getDefaultQueueSession().createTextMessage();
- tMsg[i].setText("serialMsgListenerQueueTest" + i);
- tMsg[i].setStringProperty("COM_SUN_JMS_TESTNAME",
- "serialMsgListenerQueueTest" + i);
-
- // set flag on last message and send to both queues
- if (i == (numMessages - 1)) {
- tMsg[i].setBooleanProperty("COM_SUN_JMS_TEST_LASTMESSAGE", true);
- qSender1.send(tMsg[i]);
- qSender2.send(tMsg[i]);
- } else { // send to one queue or the other
- tMsg[i].setBooleanProperty("COM_SUN_JMS_TEST_LASTMESSAGE", false);
- if (i % 2 == 0) {
- qSender1.send(tMsg[i]);
- } else {
- qSender2.send(tMsg[i]);
- }
- }
- }
- logMsg("Start connection");
- tool.getDefaultQueueConnection().start();
-
- // wait until test is over
- myListener1.monitor.waitTillDone();
- myListener2.monitor.waitTillDone();
- if ((myListener1.testFailed == true)
- || (myListener2.testFailed == true)) {
- logMsg("Test failed in message listener");
- throw new Exception(
- "Concurrent use of MessageListener or JMSException");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("serialMsgListenerQueueTest");
- }
- }
-
- /*
- * @testName: setGetChangeClientIDQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:272; JMS:SPEC:90; JMS:SPEC:93; JMS:JAVADOC:514;
- * JMS:JAVADOC:512; JMS:JAVADOC:650; JMS:JAVADOC:651;
- *
- * @test_Strategy: Test setClientID()/getClientID(). Make sure that the
- * clientID set is the clientID returned. Then try and reset the clientID.
- * Verify that the IllegalStateException is thrown. 1. use a
- * QueueConnectionFactory that has no ClientID set, then call setClientID
- * twice. Then try and set the clientID on a second connection to the clientID
- * value of the first connection. Verify the InvalidClientIDException is
- * thrown.
- */
- public void setGetChangeClientIDQueueTest() throws Exception {
- boolean pass = true;
- QueueConnection qc, qc2 = null;
-
- try {
- tool = new JmsTool(JmsTool.QUEUE_FACTORY, user, password, mode);
-
- qc = (QueueConnection) tool.getNewConnection(JmsTool.QUEUE, user,
- password);
- connections.add(qc);
-
- qc2 = (QueueConnection) tool.getNewConnection(JmsTool.QUEUE, user,
- password);
- connections.add(qc2);
-
- TestUtil.logMsg("Setting clientID!");
- qc.setClientID("ctstest");
-
- TestUtil.logMsg("Getting clientID!");
- String clientid = qc.getClientID();
-
- if (!clientid.equals("ctstest")) {
- TestUtil.logErr(
- "getClientID() returned " + clientid + ", expected ctstest");
- pass = false;
- } else {
- TestUtil.logMsg("setClientID/getClientID correct");
- }
-
- TestUtil.logMsg("Resetting clientID! (excpect IllegalStateException)");
- qc.setClientID("changeIt");
- TestUtil.logErr("Failed: No exception on ClientID reset");
- pass = false;
- } catch (InvalidClientIDException e) {
- TestUtil.logErr("Incorrect exception received: " + e.getMessage());
- pass = false;
- } catch (jakarta.jms.IllegalStateException ee) {
- TestUtil.logMsg("Expected Exception received: " + ee.getMessage());
- } catch (Exception eee) {
- TestUtil.logErr("Incorrect exception received: " + eee.getMessage());
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Set clientID on second connection to value of clientID on first connection");
- TestUtil.logMsg("Expect InvalidClientIDException");
- qc2.setClientID("ctstest");
- TestUtil
- .logErr("Failed: No exception on ClientID when one already exists");
- pass = false;
- } catch (InvalidClientIDException e) {
- TestUtil.logMsg("Expected exception received: " + e.getMessage());
- } catch (Exception eee) {
- TestUtil.logErr("Incorrect exception received: " + eee.getMessage());
- pass = false;
- }
- if (!pass) {
- throw new Exception("setGetChangeClientIDQueueTest");
- }
- }
-
- /*
- * @testName: setGetExceptionListenerTest
- *
- * @assertion_ids: JMS:JAVADOC:518; JMS:JAVADOC:520;
- *
- * @test_Strategy: Test setExceptionListener()/getExceptionListener() API's.
- */
- public void setGetExceptionListenerTest() throws Exception {
- boolean pass = true;
- QueueConnection qc = null;
-
- try {
- TestUtil.logMsg("Setup JmsTool for QUEUE");
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
-
- TestUtil.logMsg("Create ExceptionListener");
- ExceptionListener foo = new ExceptionListener() {
-
- public void onException(JMSException e) {
- }
- };
-
- TestUtil.logMsg("Call setExceptionListener on Connection object");
- tool.getDefaultQueueConnection().setExceptionListener(foo);
-
- ExceptionListener foo2 = tool.getDefaultQueueConnection()
- .getExceptionListener();
- if (!foo2.equals(foo)) {
- TestUtil
- .logErr("getExceptionListener doesn't match setExceptionListener");
- pass = false;
- }
- } catch (Exception eee) {
- TestUtil.logErr("Unexpected exception received: " + eee.getMessage());
- pass = false;
- }
- if (!pass) {
- throw new Exception("setGetExceptionListenerTest");
- }
- }
-
- private static class AutoAckMsgListener implements MessageListener {
- private boolean passed;
-
- QueueSession session;
-
- final DoneLatch monitor;
-
- public AutoAckMsgListener(DoneLatch latch, QueueSession qSession) {
- this.monitor = latch;
- this.session = qSession;
- }
-
- // get state of test
- public boolean getPassed() {
- return passed;
- }
-
- // will receive two messages
- public void onMessage(Message message) {
- try {
- if (message.getBooleanProperty("lastMessage") == false) {
- TestUtil.logTrace("Received first message.");
- if (message.getJMSRedelivered() == true) {
-
- // should not re-receive this one
- TestUtil.logMsg("Error: received first message twice");
- passed = false;
- }
- } else {
- if (message.getJMSRedelivered() == false) {
-
- // received second message for first time
- TestUtil.logTrace("Received second message. Calling recover()");
- session.recover();
- } else {
-
- // should be redelivered after recover
- TestUtil.logTrace("Received second message again as expected");
- passed = true;
- monitor.allDone();
- }
- }
- } catch (JMSException e) {
- TestUtil.printStackTrace(e);
- TestUtil.logMsg("Exception caught in message listener:\n" + e);
- passed = false;
- monitor.allDone();
- }
-
- }
- }
-
- /*
- * @testName: reverseReceiveClientAckTest
- *
- * @assertion_ids: JMS:SPEC:123; JMS:SPEC:129; JMS:SPEC:91;
- *
- * @test_Strategy: Send x messages to x Queues from x senders. In a different
- * session using client_acknowledge, create x QueueReceivers. Send the
- * messages in order 1,2,3...x. Receive them in order x...3,2,1, calling
- * session.recover() after receiving 1 message. All x messages should be
- * received. ("x" is specified by the numMessages parameter in ts.jte file.)
- *
- * Note: default QueueReceiver can stay open, since testing is done with newly
- * created Destinations
- */
- public void reverseReceiveClientAckTest() throws Exception {
- boolean pass = true;
-
- try {
-
- // create Queue Connection
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- Queue q[] = new Queue[numMessages];
- QueueSender qSender[] = new QueueSender[numMessages];
- QueueReceiver qReceiver[] = new QueueReceiver[numMessages];
- Message msg[] = new Message[numMessages];
-
- // create destinations using default session
- for (int i = 0; i < numMessages; i++) {
- TestUtil.logMsg("Creating Queue " + i + " of " + (numMessages - 1)
- + " (" + numMessages + " total)");
- q[i] = tool.createNewQueue("testQ" + i);
- queues.add(q[i]);
- }
-
- // use default session for sending
- TestUtil.logMsg("Creating " + numMessages + " senders");
- for (int i = 0; i < numMessages; i++) {
- TestUtil.logMsg("sender " + i);
- qSender[i] = tool.getDefaultQueueSession().createSender(q[i]);
- }
-
- // create session for receiving
- TestUtil.logMsg("Creating CLIENT_ACKNOWLEDGE session for receiving");
- QueueSession receiveSession = tool.getDefaultQueueConnection()
- .createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
-
- // create receivers for receive session
- TestUtil
- .logMsg("Creating " + numMessages + " receivers in receive session");
- for (int i = 0; i < numMessages; i++) {
- TestUtil.logMsg("receiver " + i);
- qReceiver[i] = receiveSession.createReceiver(q[i]);
- }
-
- // start the connection
- tool.getDefaultQueueConnection().start();
-
- // send messages: 1,2,3,...
- Message tempMsg = null;
-
- for (int i = 0; i < numMessages; i++) {
- TestUtil.logMsg("Sending message " + i);
- tempMsg = tool.getDefaultQueueSession().createMessage();
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "reverseReceiveClientAckTest");
- qSender[i].send(tempMsg);
- }
-
- // receive messages: ...,3,2,1
- TestUtil.logMsg(
- "Receive messages 0-" + (numMessages - 1) + " in reverse order");
- for (int i = (numMessages - 1); i >= 0; i--) {
- TestUtil.logMsg("Receive message " + i);
- msg[i] = qReceiver[i].receive(timeout);
- if (msg[i] == null) {
- TestUtil.logErr("Did not receive message from receiver[" + i + "]");
- pass = false;
- } else {
- TestUtil.logMsg("msg = " + msg[i]);
- TestUtil.logMsg("Acknowledge message " + i);
- msg[i].acknowledge();
- }
-
- // recover after receiving 1 message
- if (i == (numMessages - 1)) {
- TestUtil.logMsg("session.recover()");
- receiveSession.recover();
- }
- }
-
- TestUtil.logMsg(
- "Try receiving message from all receivers again (should not receive any)");
- for (int i = (numMessages - 1); i >= 0; i--) {
- msg[i] = qReceiver[i].receive(timeout);
- if (msg[i] != null) {
- TestUtil.logErr(
- "Received message from receiver[" + i + "], expected none");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("reverseReceiveClientAckTest");
- } finally {
- try {
- TestUtil.logMsg("Cleanup: Closing Queue Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- } catch (Exception e) {
- TestUtil.logErr("An error occurred while cleaning", e);
- throw new Exception("Cleanup failed!", e);
- }
- }
- if (!pass) {
- throw new Exception("reverseReceiveClientAckTest");
- }
- }
-
- /*
- * @testName: clientAckQueueTest
- *
- * @assertion_ids: JMS:SPEC:131; JMS:JAVADOC:122; JMS:SPEC:91;
- *
- * @test_Strategy: Send three messages to Queue. Receive all three and call
- * acknowledge on msg 2. Send and receive message 4. Recover and attempt to
- * receive msg 4.
- */
- public void clientAckQueueTest() throws Exception {
- boolean pass = true;
-
- try {
- TextMessage sent1 = null;
- TextMessage sent2 = null;
- TextMessage sent3 = null;
- TextMessage sent4 = null;
-
- TextMessage rec2 = null;
- TextMessage rec4 = null;
-
- QueueSession qSess = null;
- QueueReceiver qRec = null;
- QueueSender qSender = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueReceiver().close();
- tool.getDefaultQueueSession().close();
-
- qSess = tool.getDefaultQueueConnection().createQueueSession(false,
- Session.CLIENT_ACKNOWLEDGE);
- TestUtil.logMsg("Start connection");
- tool.getDefaultQueueConnection().start();
-
- // create two messages
- sent1 = qSess.createTextMessage();
- sent1.setText("test message 1");
- sent1.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckQueueTest1");
- sent2 = qSess.createTextMessage();
- sent2.setText("test message 2");
- sent2.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckQueueTest2");
- sent3 = qSess.createTextMessage();
- sent3.setText("test message 3");
- sent3.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckQueueTest3");
-
- sent4 = qSess.createTextMessage();
- sent4.setText("test message 4");
- sent4.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckQueueTest4");
-
- // create CLIENT_ACK session and consumer
- qRec = qSess.createReceiver(tool.getDefaultQueue());
- qSender = qSess.createSender(tool.getDefaultQueue());
-
- // send messages
- TestUtil.logTrace("Send three messages");
- qSender.send(sent1);
- qSender.send(sent2);
- qSender.send(sent3);
-
- // receive messages and acknowledge second
- TestUtil.logTrace("Receive three messages");
- qRec.receive(timeout);
- TestUtil.logTrace("Received the first message");
- rec2 = (TextMessage) qRec.receive(timeout);
- TestUtil.logTrace("Received the second message");
- qRec.receive(timeout);
- TestUtil.logTrace("Received the third message");
-
- // acknowledging msg 2 of the 3 received messages should acknowledge all 3
- // messages.
- TestUtil.logTrace("Acknowledging the second message");
- rec2.acknowledge();
-
- // send and receive message 4
- TestUtil.logTrace("Send the fourth message");
- qSender.send(sent4);
- TestUtil.logTrace("Receive the fourth message");
- rec4 = (TextMessage) qRec.receive(timeout);
- TestUtil.logTrace("Received the fourth message");
-
- // recover and attempt to receive fourth message
- TestUtil.logTrace("Call session.recover()");
- qSess.recover();
- TestUtil.logTrace(
- "Attempt to receive unacked message - the fourth message again");
- rec4 = (TextMessage) qRec.receive(timeout);
- if (rec4 == null) {
- pass = false;
- TestUtil.logErr("Did not receive unacked message");
- } else {
- if (!rec4.getText().equals(sent4.getText())) {
- pass = false;
- TestUtil.logErr("Received wrong message: " + rec4.getText());
- } else {
- TestUtil.logMsg("Re-received message: " + rec4.getText());
- }
- TestUtil.logTrace("Acknowledge the received message");
- rec4.acknowledge();
- }
-
- if (!pass)
- throw new Exception("clientAckQueueTest Failed!!");
-
- } catch (Exception e) {
- TestUtil.logErr("Error: ", e);
- throw new Exception("clientAckQueueTest", e);
- } finally {
- try {
- TestUtil.logMsg("Cleanup: Closing Queue Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- } catch (Exception e) {
- TestUtil.logErr("An error occurred while cleaning", e);
- throw new Exception("Cleanup failed!", e);
- }
- }
- }
-
- /*
- * @testName: nonAckMsgsRedeliveredQueueTest
- *
- * @assertion_ids: JMS:SPEC:145; JMS:JAVADOC:122; JMS:SPEC:91;
- *
- * @test_Strategy: Send messages to a queue that has a single QueueReceiver in
- * a CLIENT_ACKNOWLEDGE session. Receive all the messages and close the
- * session without acknowledging the messages. Create a new receiver and
- * verify that all the messages may still be received from the queue.
- */
- public void nonAckMsgsRedeliveredQueueTest() throws Exception {
- boolean pass = true;
-
- try {
- TextMessage tempMsg;
-
- // create default QueueSession for sending messages
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- TestUtil.logTrace(
- "Close QueueReceiver in default session -- only want one for Queue");
- tool.getDefaultQueueReceiver().close();
- tool.getDefaultQueueSession().close();
-
- // create client_ack session for queue
- QueueSession qSession = tool.getDefaultQueueConnection()
- .createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
- QueueReceiver qReceiver = qSession.createReceiver(tool.getDefaultQueue());
- QueueSender qSender = qSession.createSender(tool.getDefaultQueue());
-
- // start connection
- tool.getDefaultQueueConnection().start();
-
- // send messages
- for (int i = 0; i < numMessages; i++) {
- tempMsg = qSession.createTextMessage();
- tempMsg.setText("test message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "nonAckMsgsRedeliveredQueueTest" + i);
- qSender.send(tempMsg);
- TestUtil.logTrace("sent message " + i);
- }
-
- // receive messages but do not acknowledge them
- for (int i = 0; i < numMessages; i++) {
- tempMsg = (TextMessage) qReceiver.receive(timeout);
- if (tempMsg == null) {
- pass = false;
- TestUtil.logErr("Did not receive message " + i);
- } else {
- TestUtil.logTrace("received message " + i);
- }
- }
- // close session
- qSender.close();
- qReceiver.close();
- qSession.close();
-
- // create new receiver and receive messages
- qSession = tool.getDefaultQueueConnection().createQueueSession(false,
- Session.AUTO_ACKNOWLEDGE);
- qReceiver = qSession.createReceiver(tool.getDefaultQueue());
- for (int i = 0; i < numMessages; i++) {
- tempMsg = (TextMessage) qReceiver.receive(timeout);
- if (tempMsg == null) {
- pass = false;
- TestUtil.logErr("Did not receive message " + i);
- } else {
- TestUtil.logTrace(
- "received message \"" + tempMsg.getText() + "\" second time");
- }
- }
-
- if (!pass)
- throw new Exception("nonAckMsgsRedeliveredQueueTest failed!!!");
- } catch (Exception e) {
- TestUtil.logErr("nonAckMsgsRedeliveredQueueTest failed: ", e);
- throw new Exception("nonAckMsgsRedeliveredQueueTest failed", e);
- } finally {
- try {
- TestUtil.logMsg("Cleanup: Closing Queue Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- } catch (Exception e) {
- TestUtil.logErr("An error occurred while cleaning", e);
- throw new Exception("Cleanup failed!", e);
- }
- }
- }
-
- /*
- * @testName: queueRequestorSimpleSendAndRecvTest
- *
- * @assertion_ids: JMS:JAVADOC:12; JMS:JAVADOC:13; JMS:JAVADOC:15;
- * JMS:SPEC:273;
- *
- * @test_Strategy: Send and receive simple JMS message using QueueRequestor
- * helper class. Tests the following API's:
- *
- * QueueRequestor(QueueSession, Queue) QueueRequestor.request(Message)
- * QueueRequestor.close()
- */
- public void queueRequestorSimpleSendAndRecvTest() throws Exception {
- boolean pass = true;
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- QueueRequestor qreq = null;
-
- // set up test tool for Queue
- TestUtil.logMsg("Set up JmsTool for QUEUE");
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logMsg("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("This is the request message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueRequestorSimpleSendAndRecvTest");
-
- // set up MessageListener
- TestUtil.logMsg("Set up MessageListener");
- tool.getDefaultQueueReceiver().setMessageListener(
- new RequestorMsgListener(tool.getDefaultQueueSession()));
-
- // set up QueueRequestor
- TestUtil.logMsg(
- "Set up QueueRequestor for request/response message exchange");
- QueueSession newqs = tool.getDefaultQueueConnection()
- .createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- qreq = new QueueRequestor(newqs, tool.getDefaultQueue());
- TestUtil.logMsg(
- "Send message request and receive message response using QueueRequestor");
- TestUtil
- .logMsg("Message request text: \"" + messageSent.getText() + "\"");
- messageReceived = (TextMessage) qreq.request(messageSent);
-
- // Check to see if correct message received
- TestUtil.logMsg(
- "Message response text: \"" + messageReceived.getText() + "\"");
- if (messageReceived.getText().equals("This is the response message")) {
- TestUtil.logMsg("Received correct response message");
- } else {
- TestUtil.logErr("Received incorrect response message");
- pass = false;
- }
-
- // Close the QueueRequestor
- TestUtil.logMsg("Close QueueRequestor");
- qreq.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("queueRequestorSimpleSendAndRecvTest failed");
- }
- if (!pass) {
- throw new Exception("queueRequestorSimpleSendAndRecvTest failed");
- }
- }
-
- /*
- * @testName: queueRequestorExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:832; JMS:JAVADOC:833; JMS:JAVADOC:16;
- *
- * @test_Strategy: Test negative exception cases for QueueRequestor API's.
- * Tests the following exceptions: InvalidDestinationException, JMSException.
- */
- public void queueRequestorExceptionTests() throws Exception {
- boolean pass = true;
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- Queue invalidDest = null;
- QueueRequestor qreq = null;
-
- // set up test tool for Queue
- TestUtil.logMsg("Set up JmsTool for QUEUE");
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- // set up MessageListener
- TestUtil.logMsg("Set up MessageListener");
- tool.getDefaultQueueReceiver().setMessageListener(
- new RequestorMsgListener(tool.getDefaultQueueSession()));
-
- QueueSession newqs = tool.getDefaultQueueConnection()
- .createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
-
- // Try and set up QueueRequestor with InvalidDestination
- try {
- TestUtil.logMsg("Set up QueueRequestor with InvalidDestination");
- qreq = new QueueRequestor(newqs, invalidDest);
- TestUtil.logErr("Didn't throw InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Caught expected InvalidDestinationException");
- }
-
- // Try and set up QueueRequestor with closed QueueSession
- try {
- TestUtil.logMsg("Set up QueueRequestor with a closed QueueSession");
- newqs.close();
- qreq = new QueueRequestor(newqs, tool.getDefaultQueue());
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- }
- tool.closeAllConnections(connections);
-
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logMsg("Set up QueueRequestor");
- qreq = new QueueRequestor(tool.getDefaultQueueSession(),
- tool.getDefaultQueue());
-
- TestUtil.logMsg("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueRequestorExceptionTests");
-
- // Close the QueueRequestor
- TestUtil.logMsg("Close QueueRequestor");
- qreq.close();
-
- TestUtil.logMsg(
- "Try a request/response message exchange on a closed QueueRequestor");
- try {
- messageReceived = (TextMessage) qreq.request(messageSent);
- if (messageReceived != null)
- TestUtil.logMsg("messageReceived=" + messageReceived.getText());
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- qreq.close();
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("queueRequestorExceptionTests failed");
- }
- if (!pass) {
- throw new Exception("queueRequestorExceptionTests failed");
- }
- }
-
- private static class RequestorMsgListener implements MessageListener {
- QueueSession session = null;
-
- boolean pass = false;
-
- public RequestorMsgListener(QueueSession session) {
- this.session = session;
- }
-
- public boolean getPass() {
- return pass;
- }
-
- public void onMessage(Message message) {
- try {
- TestUtil.logMsg("RequestorMsgListener.onMessage()");
- if (message instanceof TextMessage) {
- TextMessage tmsg = (TextMessage) message;
- TestUtil.logMsg("Request message=" + tmsg.getText());
- if (tmsg.getText().equals("This is the request message")) {
- TestUtil.logMsg("Received request message is correct");
- pass = true;
- } else {
- TestUtil.logErr("Received request message is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Received request message is not a TextMessage");
- pass = false;
- }
- Queue replyQ = (Queue) message.getJMSReplyTo();
- QueueSender sender = session.createSender(replyQ);
- TextMessage responseMsg = session.createTextMessage();
- responseMsg.setText("This is the response message");
- responseMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "RequestorMsgListenerResponseMsg");
- TestUtil.logMsg("Sending back response message");
- sender.send(responseMsg);
- } catch (JMSException e) {
- TestUtil.printStackTrace(e);
- TestUtil.logMsg("Exception caught in RequestorMsgListener:\n" + e);
- }
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/queuetests/QueueTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/queuetests/QueueTestsIT.java
new file mode 100644
index 0000000000..768acab373
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/queuetests/QueueTestsIT.java
@@ -0,0 +1,1099 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.appclient.queuetests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.DoneLatch;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.common.SerialTestMessageListenerImpl;
+import com.sun.ts.tests.jms.common.SessionThread;
+
+import jakarta.jms.ExceptionListener;
+import jakarta.jms.InvalidClientIDException;
+import jakarta.jms.InvalidDestinationException;
+import jakarta.jms.JMSException;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.MessageListener;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueConnection;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueRequestor;
+import jakarta.jms.QueueSender;
+import jakarta.jms.QueueSession;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+import jakarta.jms.TopicConnection;
+
+
+public class QueueTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.appclient.queuetests.QueueTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(QueueTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue Connection,
+ * as well as a default Queue and Topic. Tests that require multiple
+ * Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+
+ // for cleanup purposes - set up an array list of the queues the tests use
+ // add default queue
+ queues = new ArrayList(10);
+ connections = new ArrayList(5);
+ logger.log(Logger.Level.INFO, "adding the default queue to the queue cleaner lsit\n");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: receiveNullClosedSessionQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:12; JMS:JAVADOC:13;
+ *
+ * @test_Strategy: Create a session in a separate thread that calls receive()
+ * and replies to the message. Have the thread call receive() again with no
+ * message sent. Close the thread's session and the receive() call should
+ * return, finishing the thread's run() method. Verify that the thread is no
+ * longer running.
+ */
+ @Test
+ public void receiveNullClosedSessionQueueTest() throws Exception {
+ int waitTime = 15; // seconds
+
+ try {
+
+ // create Queue setup
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ logger.log(Logger.Level.INFO, "Close default QueueReceiver");
+ tool.getDefaultQueueReceiver().close();
+ tool.getDefaultQueueConnection().start();
+
+ // create QueueRequestor for reply
+ logger.log(Logger.Level.INFO, "Create QueueRequestor");
+ QueueRequestor qReq = new QueueRequestor(tool.getDefaultQueueSession(), tool.getDefaultQueue());
+
+ // create a thread to receive
+ logger.log(Logger.Level.INFO, "Create SessionThread");
+ SessionThread sT = new SessionThread(tool.getDefaultQueueConnection(), (TopicConnection) null);
+
+ logger.log(Logger.Level.INFO, "Tell SessionThread to respond to messages");
+ sT.setReplyToMessages(true);
+ logger.log(Logger.Level.INFO, "Create Receiver in SessionThread");
+ sT.createConsumer(tool.getDefaultQueue());
+ logger.log(Logger.Level.INFO, "Tell receiver to keep receiving\n(it will throw an "
+ + "exception and stop when it receives the null message)");
+ sT.setStayAlive(true);
+ logger.log(Logger.Level.INFO, "Start the SessionThread");
+ sT.start();
+
+ // send/receive one message and close thread's session
+ logger.log(Logger.Level.INFO, "Send one message and receive reply");
+ Message tempMsg = tool.getDefaultQueueSession().createMessage();
+
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "receiveNullClosedSessionQueueTest");
+ qReq.request(tempMsg);
+
+ logger.log(Logger.Level.INFO,
+ "Wait " + waitTime + " seconds for receive() to start again " + "before closing session...");
+ for (int i = 0; i < 100000; i++) {
+ }
+ logger.log(Logger.Level.INFO, "Close the SessionThread's QueueSession");
+ sT.getQueueSession().close();
+
+ // wait for session to close. Using TS timeout here
+ logger.log(Logger.Level.INFO, "Wait for thread to close (will close after receiving null message)");
+ sT.join();
+
+ // check to see if thread is still waiting
+ if (sT.isAlive()) {
+ logger.log(Logger.Level.ERROR, "thread still waiting on receive() -- BAD [could be timing problem]");
+ throw new Exception("receive() call still waiting");
+ } else {
+ logger.log(Logger.Level.INFO, "receive() properly received a null message -- GOOD");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("receiveNullClosedSessionQueueTest");
+ }
+ }
+ /* Tests */
+
+ /*
+ * @testName: setClientIDLateQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:94; JMS:SPEC:91;
+ *
+ * @test_Strategy: create a connection, send and receive a msg, then set the
+ * ClientID verify that IllegalStateException is thrown.
+ *
+ */
+ @Test
+ public void setClientIDLateQueueTest() throws Exception {
+ boolean booleanValue = true;
+ boolean pass = true;
+
+ try {
+ MapMessage messageSent;
+ MapMessage messageReceived;
+ QueueConnection qConn;
+ QueueSession qSess;
+ Queue queue;
+ QueueSender qSender;
+ QueueReceiver qRec;
+
+ // set up queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ qConn = (QueueConnection) tool.getNewConnection(JmsTool.QUEUE, user, password);
+ connections.add(qConn);
+ qSess = qConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ queue = tool.createNewQueue("testQueue2");
+ // add testQueue2 to our cleanup list
+ queues.add(queue);
+ qSender = qSess.createSender(queue);
+ qRec = qSess.createReceiver(queue);
+ qConn.start();
+
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = qSess.createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "setClientIDLateQueueTest");
+ messageSent.setBoolean("booleanValue", booleanValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ qSender.send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) qRec.receive(timeout);
+ // read the boolean
+ messageReceived.getBoolean("booleanValue");
+
+ logger.log(Logger.Level.TRACE, "Attempt to set Client ID too late");
+ try {
+ qConn.setClientID("setClientIDLateQueueTest");
+ pass = false;
+ logger.log(Logger.Level.INFO, "Error: Illegal state exception was not thrown");
+ } catch (jakarta.jms.IllegalStateException is) {
+ logger.log(Logger.Level.TRACE, "Pass: IllegalStateException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("setClientIDLateQueueTest");
+ }
+ }
+
+ /*
+ * @testName: autoAckMsgListenerQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:132; JMS:SPEC:136;
+ *
+ * @test_Strategy: Set up a receiver with a messagelistener. Send two messages
+ * to the destination. The message listener will receive the messages and
+ * automatically call recover() after the send one. It will verify that the
+ * second message only is received a second time. After waiting for the message
+ * listener to finish, the test checks the state of the listener.
+ */
+ @Test
+ public void autoAckMsgListenerQueueTest() throws Exception {
+ try {
+ Message messageSent = null;
+ AutoAckMsgListener mListener = null;
+
+ // create queue setup with message listener
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ logger.log(Logger.Level.TRACE, "Create and set MessageListener.");
+ mListener = new AutoAckMsgListener(new DoneLatch(), tool.getDefaultQueueSession());
+ tool.getDefaultQueueReceiver().setMessageListener(mListener);
+
+ // create and send messages
+ logger.log(Logger.Level.TRACE, "Send and receive two messages");
+ messageSent = tool.getDefaultQueueSession().createMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "autoAckMsgListenerQueueTest");
+ messageSent.setBooleanProperty("lastMessage", false);
+ tool.getDefaultQueueSender().send(messageSent);
+ messageSent.setBooleanProperty("lastMessage", true);
+ tool.getDefaultQueueSender().send(messageSent);
+
+ tool.getDefaultQueueConnection().start();
+
+ // wait until message is received
+ logger.log(Logger.Level.TRACE, "waiting until message has been received by message listener...");
+ mListener.monitor.waitTillDone();
+
+ // check message listener status
+ if (mListener.getPassed() == false) {
+ throw new Exception("failed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Error: " + e);
+ throw new Exception("autoAckMsgListenerQueueTest", e);
+ }
+ }
+
+ /*
+ * @testName: serialMsgListenerQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:120; JMS:SPEC:121; JMS:SPEC:136;
+ *
+ * @test_Strategy: Create queue sessions with two receivers and message
+ * listeners for two queues. Send multiple messages to the queues and then start
+ * the connection to begin receiving messages. The message listeners perform a
+ * Thread.sleep() in the onMessage() method, checking for concurrent use of the
+ * other listener. The test is over when the harness determines that the last
+ * message has been received.
+ */
+ @Test
+ public void serialMsgListenerQueueTest() throws Exception {
+ try {
+ TextMessage tMsg[] = new TextMessage[numMessages];
+ Queue newQ;
+ QueueReceiver qRec1;
+ QueueReceiver qRec2;
+ QueueSender qSender1;
+ QueueSender qSender2;
+ SerialTestMessageListenerImpl myListener1;
+ SerialTestMessageListenerImpl myListener2;
+
+ // set up tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueReceiver().close();
+ newQ = tool.createNewQueue("testQueue2");
+ queues.add(newQ);
+
+ // set up receivers
+ qRec1 = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue());
+ qRec2 = tool.getDefaultQueueSession().createReceiver(newQ);
+
+ // set up message listeners
+ logger.log(Logger.Level.INFO, "Create two message listeners");
+ myListener1 = new SerialTestMessageListenerImpl();
+ myListener2 = new SerialTestMessageListenerImpl();
+ qRec1.setMessageListener(myListener1);
+ qRec2.setMessageListener(myListener2);
+
+ // create message producers
+ qSender1 = tool.getDefaultQueueSession().createSender(tool.getDefaultQueue());
+ qSender2 = tool.getDefaultQueueSession().createSender(newQ);
+
+ // create and send messages before starting connection
+ for (int i = 0; i < numMessages; i++) {
+ logger.log(Logger.Level.INFO, "Create and send message " + i);
+ tMsg[i] = tool.getDefaultQueueSession().createTextMessage();
+ tMsg[i].setText("serialMsgListenerQueueTest" + i);
+ tMsg[i].setStringProperty("COM_SUN_JMS_TESTNAME", "serialMsgListenerQueueTest" + i);
+
+ // set flag on last message and send to both queues
+ if (i == (numMessages - 1)) {
+ tMsg[i].setBooleanProperty("COM_SUN_JMS_TEST_LASTMESSAGE", true);
+ qSender1.send(tMsg[i]);
+ qSender2.send(tMsg[i]);
+ } else { // send to one queue or the other
+ tMsg[i].setBooleanProperty("COM_SUN_JMS_TEST_LASTMESSAGE", false);
+ if (i % 2 == 0) {
+ qSender1.send(tMsg[i]);
+ } else {
+ qSender2.send(tMsg[i]);
+ }
+ }
+ }
+ logger.log(Logger.Level.INFO, "Start connection");
+ tool.getDefaultQueueConnection().start();
+
+ // wait until test is over
+ myListener1.monitor.waitTillDone();
+ myListener2.monitor.waitTillDone();
+ if ((myListener1.testFailed == true) || (myListener2.testFailed == true)) {
+ logger.log(Logger.Level.INFO, "Test failed in message listener");
+ throw new Exception("Concurrent use of MessageListener or JMSException");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("serialMsgListenerQueueTest");
+ }
+ }
+
+ /*
+ * @testName: setGetChangeClientIDQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:272; JMS:SPEC:90; JMS:SPEC:93; JMS:JAVADOC:514;
+ * JMS:JAVADOC:512; JMS:JAVADOC:650; JMS:JAVADOC:651;
+ *
+ * @test_Strategy: Test setClientID()/getClientID(). Make sure that the clientID
+ * set is the clientID returned. Then try and reset the clientID. Verify that
+ * the IllegalStateException is thrown. 1. use a QueueConnectionFactory that has
+ * no ClientID set, then call setClientID twice. Then try and set the clientID
+ * on a second connection to the clientID value of the first connection. Verify
+ * the InvalidClientIDException is thrown.
+ */
+ @Test
+ public void setGetChangeClientIDQueueTest() throws Exception {
+ boolean pass = true;
+ QueueConnection qc, qc2 = null;
+
+ try {
+ tool = new JmsTool(JmsTool.QUEUE_FACTORY, user, password, mode);
+
+ qc = (QueueConnection) tool.getNewConnection(JmsTool.QUEUE, user, password);
+ connections.add(qc);
+
+ qc2 = (QueueConnection) tool.getNewConnection(JmsTool.QUEUE, user, password);
+ connections.add(qc2);
+
+ logger.log(Logger.Level.INFO, "Setting clientID!");
+ qc.setClientID("ctstest");
+
+ logger.log(Logger.Level.INFO, "Getting clientID!");
+ String clientid = qc.getClientID();
+
+ if (!clientid.equals("ctstest")) {
+ logger.log(Logger.Level.ERROR, "getClientID() returned " + clientid + ", expected ctstest");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "setClientID/getClientID correct");
+ }
+
+ logger.log(Logger.Level.INFO, "Resetting clientID! (excpect IllegalStateException)");
+ qc.setClientID("changeIt");
+ logger.log(Logger.Level.ERROR, "Failed: No exception on ClientID reset");
+ pass = false;
+ } catch (InvalidClientIDException e) {
+ logger.log(Logger.Level.ERROR, "Incorrect exception received: " + e.getMessage());
+ pass = false;
+ } catch (jakarta.jms.IllegalStateException ee) {
+ logger.log(Logger.Level.INFO, "Expected Exception received: " + ee.getMessage());
+ } catch (Exception eee) {
+ logger.log(Logger.Level.ERROR, "Incorrect exception received: " + eee.getMessage());
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO, "Set clientID on second connection to value of clientID on first connection");
+ logger.log(Logger.Level.INFO, "Expect InvalidClientIDException");
+ qc2.setClientID("ctstest");
+ logger.log(Logger.Level.ERROR, "Failed: No exception on ClientID when one already exists");
+ pass = false;
+ } catch (InvalidClientIDException e) {
+ logger.log(Logger.Level.INFO, "Expected exception received: " + e.getMessage());
+ } catch (Exception eee) {
+ logger.log(Logger.Level.ERROR, "Incorrect exception received: " + eee.getMessage());
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("setGetChangeClientIDQueueTest");
+ }
+ }
+
+ /*
+ * @testName: setGetExceptionListenerTest
+ *
+ * @assertion_ids: JMS:JAVADOC:518; JMS:JAVADOC:520;
+ *
+ * @test_Strategy: Test setExceptionListener()/getExceptionListener() API's.
+ */
+ @Test
+ public void setGetExceptionListenerTest() throws Exception {
+ boolean pass = true;
+ QueueConnection qc = null;
+
+ try {
+ logger.log(Logger.Level.INFO, "Setup JmsTool for QUEUE");
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+
+ logger.log(Logger.Level.INFO, "Create ExceptionListener");
+ ExceptionListener foo = new ExceptionListener() {
+
+ public void onException(JMSException e) {
+ }
+ };
+
+ logger.log(Logger.Level.INFO, "Call setExceptionListener on Connection object");
+ tool.getDefaultQueueConnection().setExceptionListener(foo);
+
+ ExceptionListener foo2 = tool.getDefaultQueueConnection().getExceptionListener();
+ if (!foo2.equals(foo)) {
+ logger.log(Logger.Level.ERROR, "getExceptionListener doesn't match setExceptionListener");
+ pass = false;
+ }
+ } catch (Exception eee) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception received: " + eee.getMessage());
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("setGetExceptionListenerTest");
+ }
+ }
+
+ private static class AutoAckMsgListener implements MessageListener {
+ private boolean passed;
+
+ QueueSession session;
+
+ final DoneLatch monitor;
+
+ public AutoAckMsgListener(DoneLatch latch, QueueSession qSession) {
+ this.monitor = latch;
+ this.session = qSession;
+ }
+
+ // get state of test
+ public boolean getPassed() {
+ return passed;
+ }
+
+ // will receive two messages
+ public void onMessage(Message message) {
+ try {
+ if (message.getBooleanProperty("lastMessage") == false) {
+ logger.log(Logger.Level.TRACE, "Received first message.");
+ if (message.getJMSRedelivered() == true) {
+
+ // should not re-receive this one
+ logger.log(Logger.Level.INFO, "Error: received first message twice");
+ passed = false;
+ }
+ } else {
+ if (message.getJMSRedelivered() == false) {
+
+ // received second message for first time
+ logger.log(Logger.Level.TRACE, "Received second message. Calling recover()");
+ session.recover();
+ } else {
+
+ // should be redelivered after recover
+ logger.log(Logger.Level.TRACE, "Received second message again as expected");
+ passed = true;
+ monitor.allDone();
+ }
+ }
+ } catch (JMSException e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Exception caught in message listener:\n" + e);
+ passed = false;
+ monitor.allDone();
+ }
+
+ }
+ }
+
+ /*
+ * @testName: reverseReceiveClientAckTest
+ *
+ * @assertion_ids: JMS:SPEC:123; JMS:SPEC:129; JMS:SPEC:91;
+ *
+ * @test_Strategy: Send x messages to x Queues from x senders. In a different
+ * session using client_acknowledge, create x QueueReceivers. Send the messages
+ * in order 1,2,3...x. Receive them in order x...3,2,1, calling
+ * session.recover() after receiving 1 message. All x messages should be
+ * received. ("x" is specified by the numMessages parameter in ts.jte file.)
+ *
+ * Note: default QueueReceiver can stay open, since testing is done with newly
+ * created Destinations
+ */
+ @Test
+ public void reverseReceiveClientAckTest() throws Exception {
+ boolean pass = true;
+
+ try {
+
+ // create Queue Connection
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ Queue q[] = new Queue[numMessages];
+ QueueSender qSender[] = new QueueSender[numMessages];
+ QueueReceiver qReceiver[] = new QueueReceiver[numMessages];
+ Message msg[] = new Message[numMessages];
+
+ // create destinations using default session
+ for (int i = 0; i < numMessages; i++) {
+ logger.log(Logger.Level.INFO,
+ "Creating Queue " + i + " of " + (numMessages - 1) + " (" + numMessages + " total)");
+ q[i] = tool.createNewQueue("testQ" + i);
+ queues.add(q[i]);
+ }
+
+ // use default session for sending
+ logger.log(Logger.Level.INFO, "Creating " + numMessages + " senders");
+ for (int i = 0; i < numMessages; i++) {
+ logger.log(Logger.Level.INFO, "sender " + i);
+ qSender[i] = tool.getDefaultQueueSession().createSender(q[i]);
+ }
+
+ // create session for receiving
+ logger.log(Logger.Level.INFO, "Creating CLIENT_ACKNOWLEDGE session for receiving");
+ QueueSession receiveSession = tool.getDefaultQueueConnection().createQueueSession(false,
+ Session.CLIENT_ACKNOWLEDGE);
+
+ // create receivers for receive session
+ logger.log(Logger.Level.INFO, "Creating " + numMessages + " receivers in receive session");
+ for (int i = 0; i < numMessages; i++) {
+ logger.log(Logger.Level.INFO, "receiver " + i);
+ qReceiver[i] = receiveSession.createReceiver(q[i]);
+ }
+
+ // start the connection
+ tool.getDefaultQueueConnection().start();
+
+ // send messages: 1,2,3,...
+ Message tempMsg = null;
+
+ for (int i = 0; i < numMessages; i++) {
+ logger.log(Logger.Level.INFO, "Sending message " + i);
+ tempMsg = tool.getDefaultQueueSession().createMessage();
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "reverseReceiveClientAckTest");
+ qSender[i].send(tempMsg);
+ }
+
+ // receive messages: ...,3,2,1
+ logger.log(Logger.Level.INFO, "Receive messages 0-" + (numMessages - 1) + " in reverse order");
+ for (int i = (numMessages - 1); i >= 0; i--) {
+ logger.log(Logger.Level.INFO, "Receive message " + i);
+ msg[i] = qReceiver[i].receive(timeout);
+ if (msg[i] == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive message from receiver[" + i + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "msg = " + msg[i]);
+ logger.log(Logger.Level.INFO, "Acknowledge message " + i);
+ msg[i].acknowledge();
+ }
+
+ // recover after receiving 1 message
+ if (i == (numMessages - 1)) {
+ logger.log(Logger.Level.INFO, "session.recover()");
+ receiveSession.recover();
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Try receiving message from all receivers again (should not receive any)");
+ for (int i = (numMessages - 1); i >= 0; i--) {
+ msg[i] = qReceiver[i].receive(timeout);
+ if (msg[i] != null) {
+ logger.log(Logger.Level.ERROR, "Received message from receiver[" + i + "], expected none");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("reverseReceiveClientAckTest");
+ } finally {
+ try {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning", e);
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+ if (!pass) {
+ throw new Exception("reverseReceiveClientAckTest");
+ }
+ }
+
+ /*
+ * @testName: clientAckQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:131; JMS:JAVADOC:122; JMS:SPEC:91;
+ *
+ * @test_Strategy: Send three messages to Queue. Receive all three and call
+ * acknowledge on msg 2. Send and receive message 4. Recover and attempt to
+ * receive msg 4.
+ */
+ @Test
+ public void clientAckQueueTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ TextMessage sent1 = null;
+ TextMessage sent2 = null;
+ TextMessage sent3 = null;
+ TextMessage sent4 = null;
+
+ TextMessage rec2 = null;
+ TextMessage rec4 = null;
+
+ QueueSession qSess = null;
+ QueueReceiver qRec = null;
+ QueueSender qSender = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueReceiver().close();
+ tool.getDefaultQueueSession().close();
+
+ qSess = tool.getDefaultQueueConnection().createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
+ logger.log(Logger.Level.INFO, "Start connection");
+ tool.getDefaultQueueConnection().start();
+
+ // create two messages
+ sent1 = qSess.createTextMessage();
+ sent1.setText("test message 1");
+ sent1.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckQueueTest1");
+ sent2 = qSess.createTextMessage();
+ sent2.setText("test message 2");
+ sent2.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckQueueTest2");
+ sent3 = qSess.createTextMessage();
+ sent3.setText("test message 3");
+ sent3.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckQueueTest3");
+
+ sent4 = qSess.createTextMessage();
+ sent4.setText("test message 4");
+ sent4.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckQueueTest4");
+
+ // create CLIENT_ACK session and consumer
+ qRec = qSess.createReceiver(tool.getDefaultQueue());
+ qSender = qSess.createSender(tool.getDefaultQueue());
+
+ // send messages
+ logger.log(Logger.Level.TRACE, "Send three messages");
+ qSender.send(sent1);
+ qSender.send(sent2);
+ qSender.send(sent3);
+
+ // receive messages and acknowledge second
+ logger.log(Logger.Level.TRACE, "Receive three messages");
+ qRec.receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received the first message");
+ rec2 = (TextMessage) qRec.receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received the second message");
+ qRec.receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received the third message");
+
+ // acknowledging msg 2 of the 3 received messages should acknowledge all 3
+ // messages.
+ logger.log(Logger.Level.TRACE, "Acknowledging the second message");
+ rec2.acknowledge();
+
+ // send and receive message 4
+ logger.log(Logger.Level.TRACE, "Send the fourth message");
+ qSender.send(sent4);
+ logger.log(Logger.Level.TRACE, "Receive the fourth message");
+ rec4 = (TextMessage) qRec.receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received the fourth message");
+
+ // recover and attempt to receive fourth message
+ logger.log(Logger.Level.TRACE, "Call session.recover()");
+ qSess.recover();
+ logger.log(Logger.Level.TRACE, "Attempt to receive unacked message - the fourth message again");
+ rec4 = (TextMessage) qRec.receive(timeout);
+ if (rec4 == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Did not receive unacked message");
+ } else {
+ if (!rec4.getText().equals(sent4.getText())) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received wrong message: " + rec4.getText());
+ } else {
+ logger.log(Logger.Level.INFO, "Re-received message: " + rec4.getText());
+ }
+ logger.log(Logger.Level.TRACE, "Acknowledge the received message");
+ rec4.acknowledge();
+ }
+
+ if (!pass)
+ throw new Exception("clientAckQueueTest Failed!!");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: ", e);
+ throw new Exception("clientAckQueueTest", e);
+ } finally {
+ try {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning", e);
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: nonAckMsgsRedeliveredQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:145; JMS:JAVADOC:122; JMS:SPEC:91;
+ *
+ * @test_Strategy: Send messages to a queue that has a single QueueReceiver in a
+ * CLIENT_ACKNOWLEDGE session. Receive all the messages and close the session
+ * without acknowledging the messages. Create a new receiver and verify that all
+ * the messages may still be received from the queue.
+ */
+ @Test
+ public void nonAckMsgsRedeliveredQueueTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ TextMessage tempMsg;
+
+ // create default QueueSession for sending messages
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ logger.log(Logger.Level.TRACE, "Close QueueReceiver in default session -- only want one for Queue");
+ tool.getDefaultQueueReceiver().close();
+ tool.getDefaultQueueSession().close();
+
+ // create client_ack session for queue
+ QueueSession qSession = tool.getDefaultQueueConnection().createQueueSession(false,
+ Session.CLIENT_ACKNOWLEDGE);
+ QueueReceiver qReceiver = qSession.createReceiver(tool.getDefaultQueue());
+ QueueSender qSender = qSession.createSender(tool.getDefaultQueue());
+
+ // start connection
+ tool.getDefaultQueueConnection().start();
+
+ // send messages
+ for (int i = 0; i < numMessages; i++) {
+ tempMsg = qSession.createTextMessage();
+ tempMsg.setText("test message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "nonAckMsgsRedeliveredQueueTest" + i);
+ qSender.send(tempMsg);
+ logger.log(Logger.Level.TRACE, "sent message " + i);
+ }
+
+ // receive messages but do not acknowledge them
+ for (int i = 0; i < numMessages; i++) {
+ tempMsg = (TextMessage) qReceiver.receive(timeout);
+ if (tempMsg == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Did not receive message " + i);
+ } else {
+ logger.log(Logger.Level.TRACE, "received message " + i);
+ }
+ }
+ // close session
+ qSender.close();
+ qReceiver.close();
+ qSession.close();
+
+ // create new receiver and receive messages
+ qSession = tool.getDefaultQueueConnection().createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ qReceiver = qSession.createReceiver(tool.getDefaultQueue());
+ for (int i = 0; i < numMessages; i++) {
+ tempMsg = (TextMessage) qReceiver.receive(timeout);
+ if (tempMsg == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Did not receive message " + i);
+ } else {
+ logger.log(Logger.Level.TRACE, "received message \"" + tempMsg.getText() + "\" second time");
+ }
+ }
+
+ if (!pass)
+ throw new Exception("nonAckMsgsRedeliveredQueueTest failed!!!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "nonAckMsgsRedeliveredQueueTest failed: ", e);
+ throw new Exception("nonAckMsgsRedeliveredQueueTest failed", e);
+ } finally {
+ try {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning", e);
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: queueRequestorSimpleSendAndRecvTest
+ *
+ * @assertion_ids: JMS:JAVADOC:12; JMS:JAVADOC:13; JMS:JAVADOC:15; JMS:SPEC:273;
+ *
+ * @test_Strategy: Send and receive simple JMS message using QueueRequestor
+ * helper class. Tests the following API's:
+ *
+ * QueueRequestor(QueueSession, Queue) QueueRequestor.request(Message)
+ * QueueRequestor.close()
+ */
+ @Test
+ public void queueRequestorSimpleSendAndRecvTest() throws Exception {
+ boolean pass = true;
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ QueueRequestor qreq = null;
+
+ // set up test tool for Queue
+ logger.log(Logger.Level.INFO, "Set up JmsTool for QUEUE");
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("This is the request message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "queueRequestorSimpleSendAndRecvTest");
+
+ // set up MessageListener
+ logger.log(Logger.Level.INFO, "Set up MessageListener");
+ tool.getDefaultQueueReceiver().setMessageListener(new RequestorMsgListener(tool.getDefaultQueueSession()));
+
+ // set up QueueRequestor
+ logger.log(Logger.Level.INFO, "Set up QueueRequestor for request/response message exchange");
+ QueueSession newqs = tool.getDefaultQueueConnection().createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ qreq = new QueueRequestor(newqs, tool.getDefaultQueue());
+ logger.log(Logger.Level.INFO, "Send message request and receive message response using QueueRequestor");
+ logger.log(Logger.Level.INFO, "Message request text: \"" + messageSent.getText() + "\"");
+ messageReceived = (TextMessage) qreq.request(messageSent);
+
+ // Check to see if correct message received
+ logger.log(Logger.Level.INFO, "Message response text: \"" + messageReceived.getText() + "\"");
+ if (messageReceived.getText().equals("This is the response message")) {
+ logger.log(Logger.Level.INFO, "Received correct response message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect response message");
+ pass = false;
+ }
+
+ // Close the QueueRequestor
+ logger.log(Logger.Level.INFO, "Close QueueRequestor");
+ qreq.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueRequestorSimpleSendAndRecvTest failed");
+ }
+ if (!pass) {
+ throw new Exception("queueRequestorSimpleSendAndRecvTest failed");
+ }
+ }
+
+ /*
+ * @testName: queueRequestorExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:832; JMS:JAVADOC:833; JMS:JAVADOC:16;
+ *
+ * @test_Strategy: Test negative exception cases for QueueRequestor API's. Tests
+ * the following exceptions: InvalidDestinationException, JMSException.
+ */
+ @Test
+ public void queueRequestorExceptionTests() throws Exception {
+ boolean pass = true;
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ Queue invalidDest = null;
+ QueueRequestor qreq = null;
+
+ // set up test tool for Queue
+ logger.log(Logger.Level.INFO, "Set up JmsTool for QUEUE");
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ // set up MessageListener
+ logger.log(Logger.Level.INFO, "Set up MessageListener");
+ tool.getDefaultQueueReceiver().setMessageListener(new RequestorMsgListener(tool.getDefaultQueueSession()));
+
+ QueueSession newqs = tool.getDefaultQueueConnection().createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Try and set up QueueRequestor with InvalidDestination
+ try {
+ logger.log(Logger.Level.INFO, "Set up QueueRequestor with InvalidDestination");
+ qreq = new QueueRequestor(newqs, invalidDest);
+ logger.log(Logger.Level.ERROR, "Didn't throw InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected InvalidDestinationException");
+ }
+
+ // Try and set up QueueRequestor with closed QueueSession
+ try {
+ logger.log(Logger.Level.INFO, "Set up QueueRequestor with a closed QueueSession");
+ newqs.close();
+ qreq = new QueueRequestor(newqs, tool.getDefaultQueue());
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ }
+ tool.closeAllConnections(connections);
+
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.INFO, "Set up QueueRequestor");
+ qreq = new QueueRequestor(tool.getDefaultQueueSession(), tool.getDefaultQueue());
+
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "queueRequestorExceptionTests");
+
+ // Close the QueueRequestor
+ logger.log(Logger.Level.INFO, "Close QueueRequestor");
+ qreq.close();
+
+ logger.log(Logger.Level.INFO, "Try a request/response message exchange on a closed QueueRequestor");
+ try {
+ messageReceived = (TextMessage) qreq.request(messageSent);
+ if (messageReceived != null)
+ logger.log(Logger.Level.INFO, "messageReceived=" + messageReceived.getText());
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ qreq.close();
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueRequestorExceptionTests failed");
+ }
+ if (!pass) {
+ throw new Exception("queueRequestorExceptionTests failed");
+ }
+ }
+
+ private static class RequestorMsgListener implements MessageListener {
+ QueueSession session = null;
+
+ boolean pass = false;
+
+ public RequestorMsgListener(QueueSession session) {
+ this.session = session;
+ }
+
+ public boolean getPass() {
+ return pass;
+ }
+
+ public void onMessage(Message message) {
+ try {
+ logger.log(Logger.Level.INFO, "RequestorMsgListener.onMessage()");
+ if (message instanceof TextMessage) {
+ TextMessage tmsg = (TextMessage) message;
+ logger.log(Logger.Level.INFO, "Request message=" + tmsg.getText());
+ if (tmsg.getText().equals("This is the request message")) {
+ logger.log(Logger.Level.INFO, "Received request message is correct");
+ pass = true;
+ } else {
+ logger.log(Logger.Level.ERROR, "Received request message is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Received request message is not a TextMessage");
+ pass = false;
+ }
+ Queue replyQ = (Queue) message.getJMSReplyTo();
+ QueueSender sender = session.createSender(replyQ);
+ TextMessage responseMsg = session.createTextMessage();
+ responseMsg.setText("This is the response message");
+ responseMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "RequestorMsgListenerResponseMsg");
+ logger.log(Logger.Level.INFO, "Sending back response message");
+ sender.send(responseMsg);
+ } catch (JMSException e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Exception caught in RequestorMsgListener:\n" + e);
+ }
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/topictests/TopicTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/topictests/TopicTests.java
deleted file mode 100644
index 5a9ac20b17..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/topictests/TopicTests.java
+++ /dev/null
@@ -1,1118 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id: TopicTests.java 64776 2012-02-06 17:54:30Z af70133 $
- */
-package com.sun.ts.tests.jms.core.appclient.topictests;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.DoneLatch;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.common.SerialTestMessageListenerImpl;
-import com.sun.ts.tests.jms.common.SessionThread;
-
-import jakarta.jms.ExceptionListener;
-import jakarta.jms.InvalidClientIDException;
-import jakarta.jms.InvalidDestinationException;
-import jakarta.jms.JMSException;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.MessageListener;
-import jakarta.jms.QueueConnection;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicConnection;
-import jakarta.jms.TopicPublisher;
-import jakarta.jms.TopicRequestor;
-import jakarta.jms.TopicSession;
-import jakarta.jms.TopicSubscriber;
-
-public class TopicTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.appclient.topictests.TopicTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- ArrayList topics = null;
-
- ArrayList connections = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- TopicTests theTests = new TopicTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Topic
- * Connection, as well as a default Topic and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null ");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
-
- // for cleanup purposes - set up an array list of the topics the tests use
- // add default topic
- connections = new ArrayList(5);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /*
- * @testName: receiveNullClosedSessionTopicTest
- *
- * @assertion_ids: JMS:JAVADOC:12; JMS:JAVADOC:13;
- *
- * @test_Strategy: Create a session in a separate thread that calls receive()
- * and replies to the message. Have the thread call receive() again with no
- * message sent. Close the thread's session and the receive() call should
- * return, finishing the thread's run() method. Verify that the thread is no
- * longer running.
- */
- public void receiveNullClosedSessionTopicTest() throws Exception {
- int waitTime = 15; // seconds
-
- try {
-
- // create Topic setup
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- logMsg("Close default TopicSubscriber");
- tool.getDefaultTopicSubscriber().close();
- tool.getDefaultTopicConnection().start();
-
- // create TopicRequestor for reply
- logMsg("Create TopicRequestor");
- TopicRequestor qReq = new TopicRequestor(tool.getDefaultTopicSession(),
- tool.getDefaultTopic());
-
- // create a thread to receive
- logMsg("Create SessionThread");
- SessionThread sT = new SessionThread((QueueConnection) null,
- tool.getDefaultTopicConnection());
-
- logMsg("Tell SessionThread to respond to messages");
- sT.setReplyToMessages(true);
- logMsg("Create Subscriber in SessionThread");
- sT.createConsumer(tool.getDefaultTopic());
- logMsg("Tell receiver to keep receiving\n(it will throw an "
- + "exception and stop when it receives the null message)");
- sT.setStayAlive(true);
- logMsg("Start the SessionThread");
- sT.start();
-
- // send/receive one message and close thread's session
- logMsg("Send one message and receive reply");
- Message tempMsg = tool.getDefaultTopicSession().createMessage();
-
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "receiveNullClosedSessionTopicTest");
- qReq.request(tempMsg);
-
- logMsg("Wait " + waitTime + " seconds for receive() to start again "
- + "before closing session...");
- for (int i = 0; i < 100000; i++) {
- }
- logMsg("Close the SessionThread's TopicSession");
- sT.getTopicSession().close();
-
- // wait for session to close. Using TS timeout here
- logMsg(
- "Wait for thread to close (will close after receiving null message)");
- sT.join();
-
- // check to see if thread is still waiting
- if (sT.isAlive()) {
- logErr(
- "thread still waiting on receive() -- BAD [could be timing problem]");
- throw new Exception("receive() call still waiting");
- } else {
- logMsg("receive() properly received a null message -- GOOD");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("receiveNullClosedSessionTopicTest");
- }
- }
- /* Tests */
-
- /*
- * @testName: setClientIDLateTopicTest
- *
- * @assertion_ids: JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:94; JMS:SPEC:91;
- *
- * @test_Strategy: create a connection, send and receive a msg, then set the
- * ClientID verify that IllegalStateException is thrown.
- *
- */
- public void setClientIDLateTopicTest() throws Exception {
- boolean booleanValue = true;
- boolean pass = true;
- String lookup = "MyTopicConnectionFactory";
-
- try {
- MapMessage messageSent;
- MapMessage messageReceived;
- TopicConnection tConn;
- TopicSession tSess;
- Topic topic;
- TopicPublisher tPublisher;
- TopicSubscriber tSub;
-
- // set up topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tConn = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, user,
- password, lookup);
- connections.add(tConn);
- tSess = tConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- topic = tool.createNewTopic("MY_TOPIC2");
- tPublisher = tSess.createPublisher(topic);
- tSub = tSess.createSubscriber(topic);
- tConn.start();
-
- logTrace("Creating 1 message");
- messageSent = tSess.createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "setClientIDLateTopicTest");
- messageSent.setBoolean("booleanValue", booleanValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tPublisher.publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (MapMessage) tSub.receive(timeout);
- // read the boolean
- messageReceived.getBoolean("booleanValue");
-
- logTrace("Attempt to set Client ID too late");
- try {
- tConn.setClientID("setClientIDLateTopicTest");
- pass = false;
- logMsg("Error: Illegal state exception was not thrown");
- } catch (jakarta.jms.IllegalStateException is) {
- logTrace("Pass: IllegalStateException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("setClientIDLateTopicTest");
- }
- }
-
- /*
- * @testName: autoAckMsgListenerTopicTest
- *
- * @assertion_ids: JMS:SPEC:132; JMS:SPEC:136;
- *
- * @test_Strategy: Set up a receiver with a messagelistener. Send two messages
- * to the destination. The message listener will receive the messages and
- * automatically call recover() after the send one. It will verify that the
- * second message only is received a second time. After waiting for the
- * message listener to finish, the test checks the state of the listener.
- */
- public void autoAckMsgListenerTopicTest() throws Exception {
- try {
- Message messageSent = null;
- AutoAckMsgListener mListener = null;
-
- // create topic setup with message listener
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- logTrace("Create and set MessageListener.");
- mListener = new AutoAckMsgListener(new DoneLatch(),
- tool.getDefaultTopicSession());
- tool.getDefaultTopicSubscriber().setMessageListener(mListener);
-
- // create and send messages
- logTrace("Send and receive two messages");
- messageSent = tool.getDefaultTopicSession().createMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "autoAckMsgListenerTopicTest");
- messageSent.setBooleanProperty("lastMessage", false);
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageSent.setBooleanProperty("lastMessage", true);
- tool.getDefaultTopicPublisher().publish(messageSent);
-
- tool.getDefaultTopicConnection().start();
-
- // wait until message is received
- logTrace(
- "waiting until message has been received by message listener...");
- mListener.monitor.waitTillDone();
-
- // check message listener status
- if (mListener.getPassed() == false) {
- throw new Exception("failed");
- }
- } catch (Exception e) {
- logMsg("Error: " + e);
- throw new Exception("autoAckMsgListenerTopicTest", e);
- }
- }
-
- /*
- * @testName: serialMsgListenerTopicTest
- *
- * @assertion_ids: JMS:SPEC:120; JMS:SPEC:121; JMS:SPEC:136;
- *
- * @test_Strategy: Create topic sessions with two receivers and message
- * listeners for two topics. Send multiple messages to the topics and then
- * start the connection to begin receiving messages. The message listeners
- * perform a Thread.sleep() in the onMessage() method, checking for concurrent
- * use of the other listener. The test is over when the harness determines
- * that the last message has been received.
- */
- public void serialMsgListenerTopicTest() throws Exception {
- try {
- TextMessage tMsg[] = new TextMessage[numMessages];
- Topic newT;
- TopicSubscriber tSub1;
- TopicSubscriber tSub2;
- TopicPublisher tPublisher1;
- TopicPublisher tPublisher2;
- SerialTestMessageListenerImpl myListener1;
- SerialTestMessageListenerImpl myListener2;
-
- // set up tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicSubscriber().close();
- newT = tool.createNewTopic("MY_TOPIC2");
-
- // set up receivers
- tSub1 = tool.getDefaultTopicSession()
- .createSubscriber(tool.getDefaultTopic());
- tSub2 = tool.getDefaultTopicSession().createSubscriber(newT);
-
- // set up message listeners
- logMsg("Create two message listeners");
- myListener1 = new SerialTestMessageListenerImpl();
- myListener2 = new SerialTestMessageListenerImpl();
- tSub1.setMessageListener(myListener1);
- tSub2.setMessageListener(myListener2);
-
- // create message producers
- tPublisher1 = tool.getDefaultTopicSession()
- .createPublisher(tool.getDefaultTopic());
- tPublisher2 = tool.getDefaultTopicSession().createPublisher(newT);
-
- // create and send messages before starting connection
- for (int i = 0; i < numMessages; i++) {
- logMsg("Create and send message " + i);
- tMsg[i] = tool.getDefaultTopicSession().createTextMessage();
- tMsg[i].setText("serialMsgListenerTopicTest" + i);
- tMsg[i].setStringProperty("COM_SUN_JMS_TESTNAME",
- "serialMsgListenerTopicTest" + i);
-
- // set flag on last message and send to both topics
- if (i == (numMessages - 1)) {
- tMsg[i].setBooleanProperty("COM_SUN_JMS_TEST_LASTMESSAGE", true);
- tPublisher1.publish(tMsg[i]);
- tPublisher2.publish(tMsg[i]);
- } else { // send to one topic or the other
- tMsg[i].setBooleanProperty("COM_SUN_JMS_TEST_LASTMESSAGE", false);
- if (i % 2 == 0) {
- tPublisher1.publish(tMsg[i]);
- } else {
- tPublisher2.publish(tMsg[i]);
- }
- }
- }
- logMsg("Start connection");
- tool.getDefaultTopicConnection().start();
-
- // wait until test is over
- myListener1.monitor.waitTillDone();
- myListener2.monitor.waitTillDone();
- if ((myListener1.testFailed == true)
- || (myListener2.testFailed == true)) {
- logMsg("Test failed in message listener");
- throw new Exception(
- "Concurrent use of MessageListener or JMSException");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("serialMsgListenerTopicTest");
- }
- }
-
- /*
- * @testName: setGetChangeClientIDTopicTest
- *
- * @assertion_ids: JMS:JAVADOC:272; JMS:SPEC:90; JMS:SPEC:93; JMS:JAVADOC:514;
- * JMS:JAVADOC:512; JMS:JAVADOC:650; JMS:JAVADOC:651;
- *
- * @test_Strategy: Test setClientID()/getClientID(). Make sure that the
- * clientID set is the clientID returned. Then try and reset the clientID.
- * Verify that the IllegalStateException is thrown. 1. use a
- * TopicConnectionFactory that has no ClientID set, then call setClientID
- * twice. Then try and set the clientID on a second connection to the clientID
- * value of the first connection. Verify the InvalidClientIDException is
- * thrown.
- */
- public void setGetChangeClientIDTopicTest() throws Exception {
- boolean pass = true;
- TopicConnection tc, tc2 = null;
- String lookup = "MyTopicConnectionFactory";
-
- try {
- tool = new JmsTool(JmsTool.TOPIC_FACTORY, user, password, mode);
-
- tc = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, user,
- password, lookup);
- connections.add(tc);
-
- tc2 = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, user,
- password, lookup);
- connections.add(tc2);
-
- TestUtil.logMsg("Setting clientID!");
- tc.setClientID("ctstest");
-
- TestUtil.logMsg("Getting clientID!");
- String clientid = tc.getClientID();
-
- if (!clientid.equals("ctstest")) {
- TestUtil.logErr(
- "getClientID() returned " + clientid + ", expected ctstest");
- pass = false;
- } else {
- TestUtil.logMsg("setClientID/getClientID correct");
- }
-
- TestUtil.logMsg("Resetting clientID! (excpect IllegalStateException)");
- tc.setClientID("changeIt");
- TestUtil.logErr("Failed: No exception on ClientID reset");
- pass = false;
- } catch (InvalidClientIDException e) {
- TestUtil.logErr("Incorrect exception received: " + e.getMessage());
- pass = false;
- } catch (jakarta.jms.IllegalStateException ee) {
- TestUtil.logMsg("Expected Exception received: " + ee.getMessage());
- } catch (Exception eee) {
- TestUtil.logErr("Incorrect exception received: " + eee.getMessage());
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Set clientID on second connection to value of clientID on first connection");
- TestUtil.logMsg("Expect InvalidClientIDException");
- tc2.setClientID("ctstest");
- TestUtil
- .logErr("Failed: No exception on ClientID when one already exists");
- pass = false;
- } catch (InvalidClientIDException e) {
- TestUtil.logMsg("Expected exception received: " + e.getMessage());
- } catch (Exception eee) {
- TestUtil.logErr("Incorrect exception received: " + eee.getMessage());
- pass = false;
- }
- if (!pass) {
- throw new Exception("setGetChangeClientIDTopicTest");
- }
- }
-
- /*
- * @testName: setGetExceptionListenerTest
- *
- * @assertion_ids: JMS:JAVADOC:518; JMS:JAVADOC:520;
- *
- * @test_Strategy: Test setExceptionListener()/getExceptionListener() API's.
- */
- public void setGetExceptionListenerTest() throws Exception {
- boolean pass = true;
- TopicConnection tc = null;
-
- try {
- TestUtil.logMsg("Setup JmsTool for TOPIC");
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
-
- TestUtil.logMsg("Create ExceptionListener");
- ExceptionListener foo = new ExceptionListener() {
-
- public void onException(JMSException e) {
- }
- };
-
- TestUtil.logMsg("Call setExceptionListener on Connection object");
- tool.getDefaultTopicConnection().setExceptionListener(foo);
-
- ExceptionListener foo2 = tool.getDefaultTopicConnection()
- .getExceptionListener();
- if (!foo2.equals(foo)) {
- TestUtil
- .logErr("getExceptionListener doesn't match setExceptionListener");
- pass = false;
- }
- } catch (Exception eee) {
- TestUtil.logErr("Unexpected exception received: " + eee.getMessage());
- pass = false;
- }
- if (!pass) {
- throw new Exception("setGetExceptionListenerTest");
- }
- }
-
- private static class AutoAckMsgListener implements MessageListener {
- private boolean passed;
-
- TopicSession session;
-
- final DoneLatch monitor;
-
- public AutoAckMsgListener(DoneLatch latch, TopicSession tSession) {
- this.monitor = latch;
- this.session = tSession;
- }
-
- // get state of test
- public boolean getPassed() {
- return passed;
- }
-
- // will receive two messages
- public void onMessage(Message message) {
- try {
- if (message.getBooleanProperty("lastMessage") == false) {
- TestUtil.logTrace("Received first message.");
- if (message.getJMSRedelivered() == true) {
-
- // should not re-receive this one
- TestUtil.logMsg("Error: received first message twice");
- passed = false;
- }
- } else {
- if (message.getJMSRedelivered() == false) {
-
- // received second message for first time
- TestUtil.logTrace("Received second message. Calling recover()");
- session.recover();
- } else {
-
- // should be redelivered after recover
- TestUtil.logTrace("Received second message again as expected");
- passed = true;
- monitor.allDone();
- }
- }
- } catch (JMSException e) {
- TestUtil.printStackTrace(e);
- TestUtil.logMsg("Exception caught in message listener:\n" + e);
- passed = false;
- monitor.allDone();
- }
-
- }
- }
-
- /*
- * @testName: reverseReceiveClientAckTest
- *
- * @assertion_ids: JMS:SPEC:123; JMS:SPEC:129; JMS:SPEC:91;
- *
- * @test_Strategy: Send x messages to x Topics from x senders. In a different
- * session using client_acknowledge, create x TopicSubscribers. Send the
- * messages in order 1,2,3...x. Receive them in order x...3,2,1, calling
- * session.recover() after receiving 1 message. All x messages should be
- * received. ("x" is specified by the numMessages parameter in ts.jte file.)
- *
- * Note: default TopicSubscriber can stay open, since testing is done with
- * newly created Destinations
- */
- public void reverseReceiveClientAckTest() throws Exception {
- boolean pass = true;
-
- try {
-
- // create Topic Connection
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- Topic t[] = new Topic[numMessages];
- TopicPublisher tPublisher[] = new TopicPublisher[numMessages];
- TopicSubscriber tSubscriber[] = new TopicSubscriber[numMessages];
- Message msg[] = new Message[numMessages];
-
- // create destinations using default session
- for (int i = 0; i < numMessages; i++) {
- TestUtil.logMsg("Creating Topic " + i + " of " + (numMessages - 1)
- + " (" + numMessages + " total)");
- t[i] = tool.createNewTopic("testT" + i);
- }
-
- // use default session for sending
- TestUtil.logMsg("Creating " + numMessages + " senders");
- for (int i = 0; i < numMessages; i++) {
- TestUtil.logMsg("sender " + i);
- tPublisher[i] = tool.getDefaultTopicSession().createPublisher(t[i]);
- }
-
- // create session for receiving
- TestUtil.logMsg("Creating CLIENT_ACKNOWLEDGE session for receiving");
- TopicSession receiveSession = tool.getDefaultTopicConnection()
- .createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
-
- // create receivers for receive session
- TestUtil
- .logMsg("Creating " + numMessages + " receivers in receive session");
- for (int i = 0; i < numMessages; i++) {
- TestUtil.logMsg("receiver " + i);
- tSubscriber[i] = receiveSession.createSubscriber(t[i]);
- }
-
- // start the connection
- tool.getDefaultTopicConnection().start();
-
- // send messages: 1,2,3,...
- Message tempMsg = null;
-
- for (int i = 0; i < numMessages; i++) {
- TestUtil.logMsg("Sending message " + i);
- tempMsg = tool.getDefaultTopicSession().createMessage();
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "reverseReceiveClientAckTest");
- tPublisher[i].publish(tempMsg);
- }
-
- // receive messages: ...,3,2,1
- TestUtil.logMsg(
- "Receive messages 0-" + (numMessages - 1) + " in reverse order");
- for (int i = (numMessages - 1); i >= 0; i--) {
- TestUtil.logMsg("Receive message " + i);
- msg[i] = tSubscriber[i].receive(timeout);
- if (msg[i] == null) {
- TestUtil.logErr("Did not receive message from subscriber[" + i + "]");
- pass = false;
- } else {
- TestUtil.logMsg("msg = " + msg[i]);
- TestUtil.logMsg("Acknowledge message " + i);
- msg[i].acknowledge();
- }
-
- // recover after receiving 1 message
- if (i == (numMessages - 1)) {
- TestUtil.logMsg("session.recover()");
- receiveSession.recover();
- }
- }
-
- TestUtil.logMsg(
- "Try receiving message from all subscribers again (should not receive any)");
- for (int i = (numMessages - 1); i >= 0; i--) {
- msg[i] = tSubscriber[i].receive(timeout);
- if (msg[i] != null) {
- TestUtil.logErr(
- "Received message from subscriber[" + i + "], expected none");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("reverseReceiveClientAckTest");
- }
- if (!pass) {
- throw new Exception("reverseReceiveClientAckTest");
- }
- }
-
- /*
- * @testName: clientAckTopicTest
- *
- * @assertion_ids: JMS:SPEC:131; JMS:JAVADOC:122; JMS:SPEC:91;
- *
- * @test_Strategy: Send three messages to Topic. Receive all three and call
- * acknowledge on msg 2. Send and receive message 4. Recover and attempt to
- * receive msg 4.
- */
- public void clientAckTopicTest() throws Exception {
- boolean pass = true;
-
- try {
- TextMessage sent1 = null;
- TextMessage sent2 = null;
- TextMessage sent3 = null;
- TextMessage sent4 = null;
-
- TextMessage rec2 = null;
- TextMessage rec4 = null;
-
- TopicSession tSess = null;
- TopicSubscriber tSub = null;
- TopicPublisher tPublisher = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicSubscriber().close();
- tool.getDefaultTopicSession().close();
-
- tSess = tool.getDefaultTopicConnection().createTopicSession(false,
- Session.CLIENT_ACKNOWLEDGE);
- TestUtil.logMsg("Start connection");
- tool.getDefaultTopicConnection().start();
-
- // create two messages
- sent1 = tSess.createTextMessage();
- sent1.setText("test message 1");
- sent1.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckTopicTest1");
- sent2 = tSess.createTextMessage();
- sent2.setText("test message 2");
- sent2.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckTopicTest2");
- sent3 = tSess.createTextMessage();
- sent3.setText("test message 3");
- sent3.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckTopicTest3");
-
- sent4 = tSess.createTextMessage();
- sent4.setText("test message 4");
- sent4.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckTopicTest4");
-
- // create CLIENT_ACK session and consumer
- tSub = tSess.createSubscriber(tool.getDefaultTopic());
- tPublisher = tSess.createPublisher(tool.getDefaultTopic());
-
- // send messages
- TestUtil.logTrace("Send three messages");
- tPublisher.publish(sent1);
- tPublisher.publish(sent2);
- tPublisher.publish(sent3);
-
- // receive messages and acknowledge second
- TestUtil.logTrace("Receive three messages");
- tSub.receive(timeout);
- TestUtil.logTrace("Received the first message");
- rec2 = (TextMessage) tSub.receive(timeout);
- TestUtil.logTrace("Received the second message");
- tSub.receive(timeout);
- TestUtil.logTrace("Received the third message");
-
- // acknowledging msg 2 of the 3 received messages should acknowledge all 3
- // messages.
- TestUtil.logTrace("Acknowledging the second message");
- rec2.acknowledge();
-
- // send and receive message 4
- TestUtil.logTrace("Send the fourth message");
- tPublisher.publish(sent4);
- TestUtil.logTrace("Receive the fourth message");
- rec4 = (TextMessage) tSub.receive(timeout);
- TestUtil.logTrace("Received the fourth message");
-
- // recover and attempt to receive fourth message
- TestUtil.logTrace("Call session.recover()");
- tSess.recover();
- TestUtil.logTrace(
- "Attempt to receive unacked message - the fourth message again");
- rec4 = (TextMessage) tSub.receive(timeout);
- if (rec4 == null) {
- pass = false;
- TestUtil.logErr("Did not receive unacked message");
- } else {
- if (!rec4.getText().equals(sent4.getText())) {
- pass = false;
- TestUtil.logErr("Received wrong message: " + rec4.getText());
- } else {
- TestUtil.logMsg("Re-received message: " + rec4.getText());
- }
- TestUtil.logTrace("Acknowledge the received message");
- rec4.acknowledge();
- }
-
- if (!pass)
- throw new Exception("clientAckTopicTest Failed!!");
-
- } catch (Exception e) {
- TestUtil.logErr("Error: ", e);
- throw new Exception("clientAckTopicTest", e);
- }
- }
-
- /*
- * @testName: nonAckMsgsRedeliveredTopicTest
- *
- * @assertion_ids: JMS:SPEC:145; JMS:JAVADOC:122; JMS:SPEC:91;
- *
- * @test_Strategy: Send messages to a topic that has a single TopicSubscriber
- * in a CLIENT_ACKNOWLEDGE session. Receive all the messages without
- * acknowledging the messages and call session recover. Verify that all the
- * messages may still be received from the topic.
- */
- public void nonAckMsgsRedeliveredTopicTest() throws Exception {
- boolean pass = true;
-
- try {
- TextMessage tempMsg;
-
- // create default TopicSession for sending messages
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- TestUtil.logTrace(
- "Close TopicSubscriber in default session -- only want one for Topic");
- tool.getDefaultTopicSubscriber().close();
- tool.getDefaultTopicSession().close();
-
- // create client_ack session for topic
- TopicSession tSession = tool.getDefaultTopicConnection()
- .createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
- TopicSubscriber tSubscriber = tSession
- .createSubscriber(tool.getDefaultTopic());
- TopicPublisher tPublisher = tSession
- .createPublisher(tool.getDefaultTopic());
-
- // start connection
- tool.getDefaultTopicConnection().start();
-
- // send messages
- for (int i = 0; i < numMessages; i++) {
- tempMsg = tSession.createTextMessage();
- tempMsg.setText("test message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "nonAckMsgsRedeliveredTopicTest" + i);
- tPublisher.publish(tempMsg);
- TestUtil.logTrace("sent message " + i);
- }
-
- // receive messages but do not acknowledge them
- for (int i = 0; i < numMessages; i++) {
- tempMsg = (TextMessage) tSubscriber.receive(timeout);
- if (tempMsg == null) {
- pass = false;
- TestUtil.logErr("Did not receive message " + i);
- } else {
- TestUtil.logTrace("received message " + i);
- }
- }
- TestUtil.logTrace("Call session recover()");
- tSession.recover();
-
- // receive messages again but this time acknowlege them
- for (int i = 0; i < numMessages; i++) {
- tempMsg = (TextMessage) tSubscriber.receive(timeout);
- if (tempMsg != null)
- tempMsg.acknowledge();
- if (tempMsg == null) {
- pass = false;
- TestUtil.logErr("Did not receive message " + i);
- } else {
- TestUtil.logTrace(
- "received message \"" + tempMsg.getText() + "\" second time");
- }
- }
- // try receiving one more message
- tempMsg = (TextMessage) tSubscriber.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("Should not have received a message");
- pass = false;
- }
- tPublisher.close();
- tSubscriber.close();
- tSession.close();
-
- if (!pass)
- throw new Exception("nonAckMsgsRedeliveredTopicTest failed!!!");
- } catch (Exception e) {
- TestUtil.logErr("nonAckMsgsRedeliveredTopicTest failed: ", e);
- throw new Exception("nonAckMsgsRedeliveredTopicTest failed", e);
- }
- }
-
- /*
- * @testName: topicRequestorSimpleSendAndRecvTest
- *
- * @assertion_ids: JMS:JAVADOC:5; JMS:JAVADOC:6; JMS:JAVADOC:8; JMS:SPEC:170;
- *
- * @test_Strategy: Send and receive simple JMS message using TopicRequestor
- * helper class. Tests the following API's:
- *
- * TopicRequestor(TopicSession, Topic) TopicRequestor.request(Message)
- * TopicRequestor.close()
- */
- public void topicRequestorSimpleSendAndRecvTest() throws Exception {
- boolean pass = true;
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TopicRequestor treq = null;
-
- // set up test tool for Topic
- TestUtil.logMsg("Set up JmsTool for TOPIC");
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logMsg("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("This is the request message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicRequestorSimpleSendAndRecvTest");
-
- // set up MessageListener
- TestUtil.logMsg("Set up MessageListener");
- tool.getDefaultTopicSubscriber().setMessageListener(
- new RequestorMsgListener(tool.getDefaultTopicSession()));
-
- // set up TopicRequestor
- TestUtil.logMsg(
- "Set up TopicRequestor for request/response message exchange");
- TopicSession newts = tool.getDefaultTopicConnection()
- .createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- treq = new TopicRequestor(newts, tool.getDefaultTopic());
- TestUtil.logMsg(
- "Send message request and receive message response using TopicRequestor");
- TestUtil
- .logMsg("Message request text: \"" + messageSent.getText() + "\"");
- messageReceived = (TextMessage) treq.request(messageSent);
-
- // Check to see if correct message received
- TestUtil.logMsg(
- "Message response text: \"" + messageReceived.getText() + "\"");
- if (messageReceived.getText().equals("This is the response message")) {
- TestUtil.logMsg("Received correct response message");
- } else {
- TestUtil.logErr("Received incorrect response message");
- pass = false;
- }
-
- // Close the TopicRequestor
- TestUtil.logMsg("Close TopicRequestor");
- treq.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("topicRequestorSimpleSendAndRecvTest");
- }
- if (!pass) {
- throw new Exception("topicRequestorSimpleSendAndRecvTest failed");
- }
- }
-
- /*
- * @testName: topicRequestorExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:830; JMS:JAVADOC:831; JMS:JAVADOC:9;
- *
- * @test_Strategy: Test negative exception cases for TopicRequestor API's.
- * Tests the following exceptions: InvalidDestinationException, JMSException.
- */
- public void topicRequestorExceptionTests() throws Exception {
- boolean pass = true;
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- Topic invalidDest = null;
- TopicRequestor treq = null;
-
- // set up test tool for Topic
- TestUtil.logMsg("Set up JmsTool for TOPIC");
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
-
- // set up MessageListener
- TestUtil.logMsg("Set up MessageListener");
- tool.getDefaultTopicSubscriber().setMessageListener(
- new RequestorMsgListener(tool.getDefaultTopicSession()));
-
- TopicSession newts = tool.getDefaultTopicConnection()
- .createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
-
- // Try and set up TopicRequestor with InvalidDestination
- try {
- TestUtil.logMsg("Set up TopicRequestor with InvalidDestination");
- treq = new TopicRequestor(newts, invalidDest);
- TestUtil.logErr("Didn't throw InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Caught expected InvalidDestinationException");
- }
-
- // Try and set up TopicRequestor with closed TopicSession
- try {
- TestUtil.logMsg("Set up TopicRequestor with a closed TopicSession");
- newts.close();
- treq = new TopicRequestor(newts, tool.getDefaultTopic());
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- }
- tool.closeAllConnections(connections);
-
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logMsg("Set up TopicRequestor");
- treq = new TopicRequestor(tool.getDefaultTopicSession(),
- tool.getDefaultTopic());
-
- TestUtil.logMsg("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicRequestorExceptionTests");
-
- // Close the TopicRequestor
- TestUtil.logMsg("Close TopicRequestor");
- treq.close();
-
- TestUtil.logMsg(
- "Try a request/response message exchange on a closed TopicRequestor");
- try {
- messageReceived = (TextMessage) treq.request(messageSent);
- if (messageReceived != null)
- TestUtil.logMsg("messageReceived=" + messageReceived.getText());
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("topicRequestorExceptionTests");
- }
- if (!pass) {
- throw new Exception("topicRequestorExceptionTests failed");
- }
- }
-
- private static class RequestorMsgListener implements MessageListener {
- TopicSession session = null;
-
- boolean pass = false;
-
- public RequestorMsgListener(TopicSession session) {
- this.session = session;
- }
-
- public boolean getPass() {
- return pass;
- }
-
- public void onMessage(Message message) {
- try {
- TestUtil.logMsg("RequestorMsgListener.onMessage()");
- if (message instanceof TextMessage) {
- TextMessage tmsg = (TextMessage) message;
- TestUtil.logMsg("Request message=" + tmsg.getText());
- if (tmsg.getText().equals("This is the request message")) {
- TestUtil.logMsg("Received request message is correct");
- pass = true;
- } else {
- TestUtil.logErr("Received request message is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Received request message is not a TextMessage");
- pass = false;
- }
- Topic replyT = (Topic) message.getJMSReplyTo();
- TopicPublisher publisher = session.createPublisher(replyT);
- TextMessage responseMsg = session.createTextMessage();
- responseMsg.setText("This is the response message");
- responseMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "RequestorMsgListenerResponseMsg");
- TestUtil.logMsg("Sending back response message");
- publisher.publish(responseMsg);
- } catch (JMSException e) {
- TestUtil.printStackTrace(e);
- TestUtil.logMsg("Exception caught in RequestorMsgListener:\n" + e);
- }
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/topictests/TopicTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/topictests/TopicTestsIT.java
new file mode 100644
index 0000000000..6327346b1f
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/topictests/TopicTestsIT.java
@@ -0,0 +1,1078 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id: TopicTests.java 64776 2012-02-06 17:54:30Z af70133 $
+ */
+package com.sun.ts.tests.jms.core.appclient.topictests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.DoneLatch;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.common.SerialTestMessageListenerImpl;
+import com.sun.ts.tests.jms.common.SessionThread;
+
+import jakarta.jms.ExceptionListener;
+import jakarta.jms.InvalidClientIDException;
+import jakarta.jms.InvalidDestinationException;
+import jakarta.jms.JMSException;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.MessageListener;
+import jakarta.jms.QueueConnection;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicConnection;
+import jakarta.jms.TopicPublisher;
+import jakarta.jms.TopicRequestor;
+import jakarta.jms.TopicSession;
+import jakarta.jms.TopicSubscriber;
+
+
+public class TopicTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.appclient.topictests.TopicTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(TopicTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ ArrayList topics = null;
+
+ ArrayList connections = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Topic Connection,
+ * as well as a default Topic and Topic. Tests that require multiple
+ * Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+
+ // for cleanup purposes - set up an array list of the topics the tests use
+ // add default topic
+ connections = new ArrayList(5);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: receiveNullClosedSessionTopicTest
+ *
+ * @assertion_ids: JMS:JAVADOC:12; JMS:JAVADOC:13;
+ *
+ * @test_Strategy: Create a session in a separate thread that calls receive()
+ * and replies to the message. Have the thread call receive() again with no
+ * message sent. Close the thread's session and the receive() call should
+ * return, finishing the thread's run() method. Verify that the thread is no
+ * longer running.
+ */
+ @Test
+ public void receiveNullClosedSessionTopicTest() throws Exception {
+ int waitTime = 15; // seconds
+
+ try {
+
+ // create Topic setup
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ logger.log(Logger.Level.INFO, "Close default TopicSubscriber");
+ tool.getDefaultTopicSubscriber().close();
+ tool.getDefaultTopicConnection().start();
+
+ // create TopicRequestor for reply
+ logger.log(Logger.Level.INFO, "Create TopicRequestor");
+ TopicRequestor qReq = new TopicRequestor(tool.getDefaultTopicSession(), tool.getDefaultTopic());
+
+ // create a thread to receive
+ logger.log(Logger.Level.INFO, "Create SessionThread");
+ SessionThread sT = new SessionThread((QueueConnection) null, tool.getDefaultTopicConnection());
+
+ logger.log(Logger.Level.INFO, "Tell SessionThread to respond to messages");
+ sT.setReplyToMessages(true);
+ logger.log(Logger.Level.INFO, "Create Subscriber in SessionThread");
+ sT.createConsumer(tool.getDefaultTopic());
+ logger.log(Logger.Level.INFO, "Tell receiver to keep receiving\n(it will throw an "
+ + "exception and stop when it receives the null message)");
+ sT.setStayAlive(true);
+ logger.log(Logger.Level.INFO, "Start the SessionThread");
+ sT.start();
+
+ // send/receive one message and close thread's session
+ logger.log(Logger.Level.INFO, "Send one message and receive reply");
+ Message tempMsg = tool.getDefaultTopicSession().createMessage();
+
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "receiveNullClosedSessionTopicTest");
+ qReq.request(tempMsg);
+
+ logger.log(Logger.Level.INFO,
+ "Wait " + waitTime + " seconds for receive() to start again " + "before closing session...");
+ for (int i = 0; i < 100000; i++) {
+ }
+ logger.log(Logger.Level.INFO, "Close the SessionThread's TopicSession");
+ sT.getTopicSession().close();
+
+ // wait for session to close. Using TS timeout here
+ logger.log(Logger.Level.INFO, "Wait for thread to close (will close after receiving null message)");
+ sT.join();
+
+ // check to see if thread is still waiting
+ if (sT.isAlive()) {
+ logger.log(Logger.Level.ERROR, "thread still waiting on receive() -- BAD [could be timing problem]");
+ throw new Exception("receive() call still waiting");
+ } else {
+ logger.log(Logger.Level.INFO, "receive() properly received a null message -- GOOD");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("receiveNullClosedSessionTopicTest");
+ }
+ }
+ /* Tests */
+
+ /*
+ * @testName: setClientIDLateTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:94; JMS:SPEC:91;
+ *
+ * @test_Strategy: create a connection, send and receive a msg, then set the
+ * ClientID verify that IllegalStateException is thrown.
+ *
+ */
+ @Test
+ public void setClientIDLateTopicTest() throws Exception {
+ boolean booleanValue = true;
+ boolean pass = true;
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+ MapMessage messageSent;
+ MapMessage messageReceived;
+ TopicConnection tConn;
+ TopicSession tSess;
+ Topic topic;
+ TopicPublisher tPublisher;
+ TopicSubscriber tSub;
+
+ // set up topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tConn = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, user, password, lookup);
+ connections.add(tConn);
+ tSess = tConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ topic = tool.createNewTopic("MY_TOPIC2");
+ tPublisher = tSess.createPublisher(topic);
+ tSub = tSess.createSubscriber(topic);
+ tConn.start();
+
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tSess.createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "setClientIDLateTopicTest");
+ messageSent.setBoolean("booleanValue", booleanValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher.publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tSub.receive(timeout);
+ // read the boolean
+ messageReceived.getBoolean("booleanValue");
+
+ logger.log(Logger.Level.TRACE, "Attempt to set Client ID too late");
+ try {
+ tConn.setClientID("setClientIDLateTopicTest");
+ pass = false;
+ logger.log(Logger.Level.INFO, "Error: Illegal state exception was not thrown");
+ } catch (jakarta.jms.IllegalStateException is) {
+ logger.log(Logger.Level.TRACE, "Pass: IllegalStateException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("setClientIDLateTopicTest");
+ }
+ }
+
+ /*
+ * @testName: autoAckMsgListenerTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:132; JMS:SPEC:136;
+ *
+ * @test_Strategy: Set up a receiver with a messagelistener. Send two messages
+ * to the destination. The message listener will receive the messages and
+ * automatically call recover() after the send one. It will verify that the
+ * second message only is received a second time. After waiting for the message
+ * listener to finish, the test checks the state of the listener.
+ */
+ @Test
+ public void autoAckMsgListenerTopicTest() throws Exception {
+ try {
+ Message messageSent = null;
+ AutoAckMsgListener mListener = null;
+
+ // create topic setup with message listener
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ logger.log(Logger.Level.TRACE, "Create and set MessageListener.");
+ mListener = new AutoAckMsgListener(new DoneLatch(), tool.getDefaultTopicSession());
+ tool.getDefaultTopicSubscriber().setMessageListener(mListener);
+
+ // create and send messages
+ logger.log(Logger.Level.TRACE, "Send and receive two messages");
+ messageSent = tool.getDefaultTopicSession().createMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "autoAckMsgListenerTopicTest");
+ messageSent.setBooleanProperty("lastMessage", false);
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageSent.setBooleanProperty("lastMessage", true);
+ tool.getDefaultTopicPublisher().publish(messageSent);
+
+ tool.getDefaultTopicConnection().start();
+
+ // wait until message is received
+ logger.log(Logger.Level.TRACE, "waiting until message has been received by message listener...");
+ mListener.monitor.waitTillDone();
+
+ // check message listener status
+ if (mListener.getPassed() == false) {
+ throw new Exception("failed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Error: " + e);
+ throw new Exception("autoAckMsgListenerTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: serialMsgListenerTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:120; JMS:SPEC:121; JMS:SPEC:136;
+ *
+ * @test_Strategy: Create topic sessions with two receivers and message
+ * listeners for two topics. Send multiple messages to the topics and then start
+ * the connection to begin receiving messages. The message listeners perform a
+ * Thread.sleep() in the onMessage() method, checking for concurrent use of the
+ * other listener. The test is over when the harness determines that the last
+ * message has been received.
+ */
+ @Test
+ public void serialMsgListenerTopicTest() throws Exception {
+ try {
+ TextMessage tMsg[] = new TextMessage[numMessages];
+ Topic newT;
+ TopicSubscriber tSub1;
+ TopicSubscriber tSub2;
+ TopicPublisher tPublisher1;
+ TopicPublisher tPublisher2;
+ SerialTestMessageListenerImpl myListener1;
+ SerialTestMessageListenerImpl myListener2;
+
+ // set up tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicSubscriber().close();
+ newT = tool.createNewTopic("MY_TOPIC2");
+
+ // set up receivers
+ tSub1 = tool.getDefaultTopicSession().createSubscriber(tool.getDefaultTopic());
+ tSub2 = tool.getDefaultTopicSession().createSubscriber(newT);
+
+ // set up message listeners
+ logger.log(Logger.Level.INFO, "Create two message listeners");
+ myListener1 = new SerialTestMessageListenerImpl();
+ myListener2 = new SerialTestMessageListenerImpl();
+ tSub1.setMessageListener(myListener1);
+ tSub2.setMessageListener(myListener2);
+
+ // create message producers
+ tPublisher1 = tool.getDefaultTopicSession().createPublisher(tool.getDefaultTopic());
+ tPublisher2 = tool.getDefaultTopicSession().createPublisher(newT);
+
+ // create and send messages before starting connection
+ for (int i = 0; i < numMessages; i++) {
+ logger.log(Logger.Level.INFO, "Create and send message " + i);
+ tMsg[i] = tool.getDefaultTopicSession().createTextMessage();
+ tMsg[i].setText("serialMsgListenerTopicTest" + i);
+ tMsg[i].setStringProperty("COM_SUN_JMS_TESTNAME", "serialMsgListenerTopicTest" + i);
+
+ // set flag on last message and send to both topics
+ if (i == (numMessages - 1)) {
+ tMsg[i].setBooleanProperty("COM_SUN_JMS_TEST_LASTMESSAGE", true);
+ tPublisher1.publish(tMsg[i]);
+ tPublisher2.publish(tMsg[i]);
+ } else { // send to one topic or the other
+ tMsg[i].setBooleanProperty("COM_SUN_JMS_TEST_LASTMESSAGE", false);
+ if (i % 2 == 0) {
+ tPublisher1.publish(tMsg[i]);
+ } else {
+ tPublisher2.publish(tMsg[i]);
+ }
+ }
+ }
+ logger.log(Logger.Level.INFO, "Start connection");
+ tool.getDefaultTopicConnection().start();
+
+ // wait until test is over
+ myListener1.monitor.waitTillDone();
+ myListener2.monitor.waitTillDone();
+ if ((myListener1.testFailed == true) || (myListener2.testFailed == true)) {
+ logger.log(Logger.Level.INFO, "Test failed in message listener");
+ throw new Exception("Concurrent use of MessageListener or JMSException");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("serialMsgListenerTopicTest");
+ }
+ }
+
+ /*
+ * @testName: setGetChangeClientIDTopicTest
+ *
+ * @assertion_ids: JMS:JAVADOC:272; JMS:SPEC:90; JMS:SPEC:93; JMS:JAVADOC:514;
+ * JMS:JAVADOC:512; JMS:JAVADOC:650; JMS:JAVADOC:651;
+ *
+ * @test_Strategy: Test setClientID()/getClientID(). Make sure that the clientID
+ * set is the clientID returned. Then try and reset the clientID. Verify that
+ * the IllegalStateException is thrown. 1. use a TopicConnectionFactory that has
+ * no ClientID set, then call setClientID twice. Then try and set the clientID
+ * on a second connection to the clientID value of the first connection. Verify
+ * the InvalidClientIDException is thrown.
+ */
+ @Test
+ public void setGetChangeClientIDTopicTest() throws Exception {
+ boolean pass = true;
+ TopicConnection tc, tc2 = null;
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+ tool = new JmsTool(JmsTool.TOPIC_FACTORY, user, password, mode);
+
+ tc = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, user, password, lookup);
+ connections.add(tc);
+
+ tc2 = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, user, password, lookup);
+ connections.add(tc2);
+
+ logger.log(Logger.Level.INFO, "Setting clientID!");
+ tc.setClientID("ctstest");
+
+ logger.log(Logger.Level.INFO, "Getting clientID!");
+ String clientid = tc.getClientID();
+
+ if (!clientid.equals("ctstest")) {
+ logger.log(Logger.Level.ERROR, "getClientID() returned " + clientid + ", expected ctstest");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "setClientID/getClientID correct");
+ }
+
+ logger.log(Logger.Level.INFO, "Resetting clientID! (excpect IllegalStateException)");
+ tc.setClientID("changeIt");
+ logger.log(Logger.Level.ERROR, "Failed: No exception on ClientID reset");
+ pass = false;
+ } catch (InvalidClientIDException e) {
+ logger.log(Logger.Level.ERROR, "Incorrect exception received: " + e.getMessage());
+ pass = false;
+ } catch (jakarta.jms.IllegalStateException ee) {
+ logger.log(Logger.Level.INFO, "Expected Exception received: " + ee.getMessage());
+ } catch (Exception eee) {
+ logger.log(Logger.Level.ERROR, "Incorrect exception received: " + eee.getMessage());
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO, "Set clientID on second connection to value of clientID on first connection");
+ logger.log(Logger.Level.INFO, "Expect InvalidClientIDException");
+ tc2.setClientID("ctstest");
+ logger.log(Logger.Level.ERROR, "Failed: No exception on ClientID when one already exists");
+ pass = false;
+ } catch (InvalidClientIDException e) {
+ logger.log(Logger.Level.INFO, "Expected exception received: " + e.getMessage());
+ } catch (Exception eee) {
+ logger.log(Logger.Level.ERROR, "Incorrect exception received: " + eee.getMessage());
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("setGetChangeClientIDTopicTest");
+ }
+ }
+
+ /*
+ * @testName: setGetExceptionListenerTest
+ *
+ * @assertion_ids: JMS:JAVADOC:518; JMS:JAVADOC:520;
+ *
+ * @test_Strategy: Test setExceptionListener()/getExceptionListener() API's.
+ */
+ @Test
+ public void setGetExceptionListenerTest() throws Exception {
+ boolean pass = true;
+ TopicConnection tc = null;
+
+ try {
+ logger.log(Logger.Level.INFO, "Setup JmsTool for TOPIC");
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+
+ logger.log(Logger.Level.INFO, "Create ExceptionListener");
+ ExceptionListener foo = new ExceptionListener() {
+
+ public void onException(JMSException e) {
+ }
+ };
+
+ logger.log(Logger.Level.INFO, "Call setExceptionListener on Connection object");
+ tool.getDefaultTopicConnection().setExceptionListener(foo);
+
+ ExceptionListener foo2 = tool.getDefaultTopicConnection().getExceptionListener();
+ if (!foo2.equals(foo)) {
+ logger.log(Logger.Level.ERROR, "getExceptionListener doesn't match setExceptionListener");
+ pass = false;
+ }
+ } catch (Exception eee) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception received: " + eee.getMessage());
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("setGetExceptionListenerTest");
+ }
+ }
+
+ private static class AutoAckMsgListener implements MessageListener {
+ private boolean passed;
+
+ TopicSession session;
+
+ final DoneLatch monitor;
+
+ public AutoAckMsgListener(DoneLatch latch, TopicSession tSession) {
+ this.monitor = latch;
+ this.session = tSession;
+ }
+
+ // get state of test
+ public boolean getPassed() {
+ return passed;
+ }
+
+ // will receive two messages
+ public void onMessage(Message message) {
+ try {
+ if (message.getBooleanProperty("lastMessage") == false) {
+ logger.log(Logger.Level.TRACE, "Received first message.");
+ if (message.getJMSRedelivered() == true) {
+
+ // should not re-receive this one
+ logger.log(Logger.Level.INFO, "Error: received first message twice");
+ passed = false;
+ }
+ } else {
+ if (message.getJMSRedelivered() == false) {
+
+ // received second message for first time
+ logger.log(Logger.Level.TRACE, "Received second message. Calling recover()");
+ session.recover();
+ } else {
+
+ // should be redelivered after recover
+ logger.log(Logger.Level.TRACE, "Received second message again as expected");
+ passed = true;
+ monitor.allDone();
+ }
+ }
+ } catch (JMSException e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Exception caught in message listener:\n" + e);
+ passed = false;
+ monitor.allDone();
+ }
+
+ }
+ }
+
+ /*
+ * @testName: reverseReceiveClientAckTest
+ *
+ * @assertion_ids: JMS:SPEC:123; JMS:SPEC:129; JMS:SPEC:91;
+ *
+ * @test_Strategy: Send x messages to x Topics from x senders. In a different
+ * session using client_acknowledge, create x TopicSubscribers. Send the
+ * messages in order 1,2,3...x. Receive them in order x...3,2,1, calling
+ * session.recover() after receiving 1 message. All x messages should be
+ * received. ("x" is specified by the numMessages parameter in ts.jte file.)
+ *
+ * Note: default TopicSubscriber can stay open, since testing is done with newly
+ * created Destinations
+ */
+ @Test
+ public void reverseReceiveClientAckTest() throws Exception {
+ boolean pass = true;
+
+ try {
+
+ // create Topic Connection
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ Topic t[] = new Topic[numMessages];
+ TopicPublisher tPublisher[] = new TopicPublisher[numMessages];
+ TopicSubscriber tSubscriber[] = new TopicSubscriber[numMessages];
+ Message msg[] = new Message[numMessages];
+
+ // create destinations using default session
+ for (int i = 0; i < numMessages; i++) {
+ logger.log(Logger.Level.INFO,
+ "Creating Topic " + i + " of " + (numMessages - 1) + " (" + numMessages + " total)");
+ t[i] = tool.createNewTopic("testT" + i);
+ }
+
+ // use default session for sending
+ logger.log(Logger.Level.INFO, "Creating " + numMessages + " senders");
+ for (int i = 0; i < numMessages; i++) {
+ logger.log(Logger.Level.INFO, "sender " + i);
+ tPublisher[i] = tool.getDefaultTopicSession().createPublisher(t[i]);
+ }
+
+ // create session for receiving
+ logger.log(Logger.Level.INFO, "Creating CLIENT_ACKNOWLEDGE session for receiving");
+ TopicSession receiveSession = tool.getDefaultTopicConnection().createTopicSession(false,
+ Session.CLIENT_ACKNOWLEDGE);
+
+ // create receivers for receive session
+ logger.log(Logger.Level.INFO, "Creating " + numMessages + " receivers in receive session");
+ for (int i = 0; i < numMessages; i++) {
+ logger.log(Logger.Level.INFO, "receiver " + i);
+ tSubscriber[i] = receiveSession.createSubscriber(t[i]);
+ }
+
+ // start the connection
+ tool.getDefaultTopicConnection().start();
+
+ // send messages: 1,2,3,...
+ Message tempMsg = null;
+
+ for (int i = 0; i < numMessages; i++) {
+ logger.log(Logger.Level.INFO, "Sending message " + i);
+ tempMsg = tool.getDefaultTopicSession().createMessage();
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "reverseReceiveClientAckTest");
+ tPublisher[i].publish(tempMsg);
+ }
+
+ // receive messages: ...,3,2,1
+ logger.log(Logger.Level.INFO, "Receive messages 0-" + (numMessages - 1) + " in reverse order");
+ for (int i = (numMessages - 1); i >= 0; i--) {
+ logger.log(Logger.Level.INFO, "Receive message " + i);
+ msg[i] = tSubscriber[i].receive(timeout);
+ if (msg[i] == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive message from subscriber[" + i + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "msg = " + msg[i]);
+ logger.log(Logger.Level.INFO, "Acknowledge message " + i);
+ msg[i].acknowledge();
+ }
+
+ // recover after receiving 1 message
+ if (i == (numMessages - 1)) {
+ logger.log(Logger.Level.INFO, "session.recover()");
+ receiveSession.recover();
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Try receiving message from all subscribers again (should not receive any)");
+ for (int i = (numMessages - 1); i >= 0; i--) {
+ msg[i] = tSubscriber[i].receive(timeout);
+ if (msg[i] != null) {
+ logger.log(Logger.Level.ERROR, "Received message from subscriber[" + i + "], expected none");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("reverseReceiveClientAckTest");
+ }
+ if (!pass) {
+ throw new Exception("reverseReceiveClientAckTest");
+ }
+ }
+
+ /*
+ * @testName: clientAckTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:131; JMS:JAVADOC:122; JMS:SPEC:91;
+ *
+ * @test_Strategy: Send three messages to Topic. Receive all three and call
+ * acknowledge on msg 2. Send and receive message 4. Recover and attempt to
+ * receive msg 4.
+ */
+ @Test
+ public void clientAckTopicTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ TextMessage sent1 = null;
+ TextMessage sent2 = null;
+ TextMessage sent3 = null;
+ TextMessage sent4 = null;
+
+ TextMessage rec2 = null;
+ TextMessage rec4 = null;
+
+ TopicSession tSess = null;
+ TopicSubscriber tSub = null;
+ TopicPublisher tPublisher = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicSubscriber().close();
+ tool.getDefaultTopicSession().close();
+
+ tSess = tool.getDefaultTopicConnection().createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
+ logger.log(Logger.Level.INFO, "Start connection");
+ tool.getDefaultTopicConnection().start();
+
+ // create two messages
+ sent1 = tSess.createTextMessage();
+ sent1.setText("test message 1");
+ sent1.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckTopicTest1");
+ sent2 = tSess.createTextMessage();
+ sent2.setText("test message 2");
+ sent2.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckTopicTest2");
+ sent3 = tSess.createTextMessage();
+ sent3.setText("test message 3");
+ sent3.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckTopicTest3");
+
+ sent4 = tSess.createTextMessage();
+ sent4.setText("test message 4");
+ sent4.setStringProperty("COM_SUN_JMS_TESTNAME", "clientAckTopicTest4");
+
+ // create CLIENT_ACK session and consumer
+ tSub = tSess.createSubscriber(tool.getDefaultTopic());
+ tPublisher = tSess.createPublisher(tool.getDefaultTopic());
+
+ // send messages
+ logger.log(Logger.Level.TRACE, "Send three messages");
+ tPublisher.publish(sent1);
+ tPublisher.publish(sent2);
+ tPublisher.publish(sent3);
+
+ // receive messages and acknowledge second
+ logger.log(Logger.Level.TRACE, "Receive three messages");
+ tSub.receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received the first message");
+ rec2 = (TextMessage) tSub.receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received the second message");
+ tSub.receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received the third message");
+
+ // acknowledging msg 2 of the 3 received messages should acknowledge all 3
+ // messages.
+ logger.log(Logger.Level.TRACE, "Acknowledging the second message");
+ rec2.acknowledge();
+
+ // send and receive message 4
+ logger.log(Logger.Level.TRACE, "Send the fourth message");
+ tPublisher.publish(sent4);
+ logger.log(Logger.Level.TRACE, "Receive the fourth message");
+ rec4 = (TextMessage) tSub.receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received the fourth message");
+
+ // recover and attempt to receive fourth message
+ logger.log(Logger.Level.TRACE, "Call session.recover()");
+ tSess.recover();
+ logger.log(Logger.Level.TRACE, "Attempt to receive unacked message - the fourth message again");
+ rec4 = (TextMessage) tSub.receive(timeout);
+ if (rec4 == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Did not receive unacked message");
+ } else {
+ if (!rec4.getText().equals(sent4.getText())) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received wrong message: " + rec4.getText());
+ } else {
+ logger.log(Logger.Level.INFO, "Re-received message: " + rec4.getText());
+ }
+ logger.log(Logger.Level.TRACE, "Acknowledge the received message");
+ rec4.acknowledge();
+ }
+
+ if (!pass)
+ throw new Exception("clientAckTopicTest Failed!!");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: ", e);
+ throw new Exception("clientAckTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: nonAckMsgsRedeliveredTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:145; JMS:JAVADOC:122; JMS:SPEC:91;
+ *
+ * @test_Strategy: Send messages to a topic that has a single TopicSubscriber in
+ * a CLIENT_ACKNOWLEDGE session. Receive all the messages without acknowledging
+ * the messages and call session recover. Verify that all the messages may still
+ * be received from the topic.
+ */
+ @Test
+ public void nonAckMsgsRedeliveredTopicTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ TextMessage tempMsg;
+
+ // create default TopicSession for sending messages
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ logger.log(Logger.Level.TRACE, "Close TopicSubscriber in default session -- only want one for Topic");
+ tool.getDefaultTopicSubscriber().close();
+ tool.getDefaultTopicSession().close();
+
+ // create client_ack session for topic
+ TopicSession tSession = tool.getDefaultTopicConnection().createTopicSession(false,
+ Session.CLIENT_ACKNOWLEDGE);
+ TopicSubscriber tSubscriber = tSession.createSubscriber(tool.getDefaultTopic());
+ TopicPublisher tPublisher = tSession.createPublisher(tool.getDefaultTopic());
+
+ // start connection
+ tool.getDefaultTopicConnection().start();
+
+ // send messages
+ for (int i = 0; i < numMessages; i++) {
+ tempMsg = tSession.createTextMessage();
+ tempMsg.setText("test message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "nonAckMsgsRedeliveredTopicTest" + i);
+ tPublisher.publish(tempMsg);
+ logger.log(Logger.Level.TRACE, "sent message " + i);
+ }
+
+ // receive messages but do not acknowledge them
+ for (int i = 0; i < numMessages; i++) {
+ tempMsg = (TextMessage) tSubscriber.receive(timeout);
+ if (tempMsg == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Did not receive message " + i);
+ } else {
+ logger.log(Logger.Level.TRACE, "received message " + i);
+ }
+ }
+ logger.log(Logger.Level.TRACE, "Call session recover()");
+ tSession.recover();
+
+ // receive messages again but this time acknowlege them
+ for (int i = 0; i < numMessages; i++) {
+ tempMsg = (TextMessage) tSubscriber.receive(timeout);
+ if (tempMsg != null)
+ tempMsg.acknowledge();
+ if (tempMsg == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Did not receive message " + i);
+ } else {
+ logger.log(Logger.Level.TRACE, "received message \"" + tempMsg.getText() + "\" second time");
+ }
+ }
+ // try receiving one more message
+ tempMsg = (TextMessage) tSubscriber.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR, "Should not have received a message");
+ pass = false;
+ }
+ tPublisher.close();
+ tSubscriber.close();
+ tSession.close();
+
+ if (!pass)
+ throw new Exception("nonAckMsgsRedeliveredTopicTest failed!!!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "nonAckMsgsRedeliveredTopicTest failed: ", e);
+ throw new Exception("nonAckMsgsRedeliveredTopicTest failed", e);
+ }
+ }
+
+ /*
+ * @testName: topicRequestorSimpleSendAndRecvTest
+ *
+ * @assertion_ids: JMS:JAVADOC:5; JMS:JAVADOC:6; JMS:JAVADOC:8; JMS:SPEC:170;
+ *
+ * @test_Strategy: Send and receive simple JMS message using TopicRequestor
+ * helper class. Tests the following API's:
+ *
+ * TopicRequestor(TopicSession, Topic) TopicRequestor.request(Message)
+ * TopicRequestor.close()
+ */
+ @Test
+ public void topicRequestorSimpleSendAndRecvTest() throws Exception {
+ boolean pass = true;
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TopicRequestor treq = null;
+
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "Set up JmsTool for TOPIC");
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("This is the request message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "topicRequestorSimpleSendAndRecvTest");
+
+ // set up MessageListener
+ logger.log(Logger.Level.INFO, "Set up MessageListener");
+ tool.getDefaultTopicSubscriber()
+ .setMessageListener(new RequestorMsgListener(tool.getDefaultTopicSession()));
+
+ // set up TopicRequestor
+ logger.log(Logger.Level.INFO, "Set up TopicRequestor for request/response message exchange");
+ TopicSession newts = tool.getDefaultTopicConnection().createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ treq = new TopicRequestor(newts, tool.getDefaultTopic());
+ logger.log(Logger.Level.INFO, "Send message request and receive message response using TopicRequestor");
+ logger.log(Logger.Level.INFO, "Message request text: \"" + messageSent.getText() + "\"");
+ messageReceived = (TextMessage) treq.request(messageSent);
+
+ // Check to see if correct message received
+ logger.log(Logger.Level.INFO, "Message response text: \"" + messageReceived.getText() + "\"");
+ if (messageReceived.getText().equals("This is the response message")) {
+ logger.log(Logger.Level.INFO, "Received correct response message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect response message");
+ pass = false;
+ }
+
+ // Close the TopicRequestor
+ logger.log(Logger.Level.INFO, "Close TopicRequestor");
+ treq.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicRequestorSimpleSendAndRecvTest");
+ }
+ if (!pass) {
+ throw new Exception("topicRequestorSimpleSendAndRecvTest failed");
+ }
+ }
+
+ /*
+ * @testName: topicRequestorExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:830; JMS:JAVADOC:831; JMS:JAVADOC:9;
+ *
+ * @test_Strategy: Test negative exception cases for TopicRequestor API's. Tests
+ * the following exceptions: InvalidDestinationException, JMSException.
+ */
+ @Test
+ public void topicRequestorExceptionTests() throws Exception {
+ boolean pass = true;
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ Topic invalidDest = null;
+ TopicRequestor treq = null;
+
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "Set up JmsTool for TOPIC");
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+
+ // set up MessageListener
+ logger.log(Logger.Level.INFO, "Set up MessageListener");
+ tool.getDefaultTopicSubscriber()
+ .setMessageListener(new RequestorMsgListener(tool.getDefaultTopicSession()));
+
+ TopicSession newts = tool.getDefaultTopicConnection().createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // Try and set up TopicRequestor with InvalidDestination
+ try {
+ logger.log(Logger.Level.INFO, "Set up TopicRequestor with InvalidDestination");
+ treq = new TopicRequestor(newts, invalidDest);
+ logger.log(Logger.Level.ERROR, "Didn't throw InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected InvalidDestinationException");
+ }
+
+ // Try and set up TopicRequestor with closed TopicSession
+ try {
+ logger.log(Logger.Level.INFO, "Set up TopicRequestor with a closed TopicSession");
+ newts.close();
+ treq = new TopicRequestor(newts, tool.getDefaultTopic());
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ }
+ tool.closeAllConnections(connections);
+
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "Set up TopicRequestor");
+ treq = new TopicRequestor(tool.getDefaultTopicSession(), tool.getDefaultTopic());
+
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "topicRequestorExceptionTests");
+
+ // Close the TopicRequestor
+ logger.log(Logger.Level.INFO, "Close TopicRequestor");
+ treq.close();
+
+ logger.log(Logger.Level.INFO, "Try a request/response message exchange on a closed TopicRequestor");
+ try {
+ messageReceived = (TextMessage) treq.request(messageSent);
+ if (messageReceived != null)
+ logger.log(Logger.Level.INFO, "messageReceived=" + messageReceived.getText());
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicRequestorExceptionTests");
+ }
+ if (!pass) {
+ throw new Exception("topicRequestorExceptionTests failed");
+ }
+ }
+
+ private static class RequestorMsgListener implements MessageListener {
+ TopicSession session = null;
+
+ boolean pass = false;
+
+ public RequestorMsgListener(TopicSession session) {
+ this.session = session;
+ }
+
+ public boolean getPass() {
+ return pass;
+ }
+
+ public void onMessage(Message message) {
+ try {
+ logger.log(Logger.Level.INFO, "RequestorMsgListener.onMessage()");
+ if (message instanceof TextMessage) {
+ TextMessage tmsg = (TextMessage) message;
+ logger.log(Logger.Level.INFO, "Request message=" + tmsg.getText());
+ if (tmsg.getText().equals("This is the request message")) {
+ logger.log(Logger.Level.INFO, "Received request message is correct");
+ pass = true;
+ } else {
+ logger.log(Logger.Level.ERROR, "Received request message is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Received request message is not a TextMessage");
+ pass = false;
+ }
+ Topic replyT = (Topic) message.getJMSReplyTo();
+ TopicPublisher publisher = session.createPublisher(replyT);
+ TextMessage responseMsg = session.createTextMessage();
+ responseMsg.setText("This is the response message");
+ responseMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "RequestorMsgListenerResponseMsg");
+ logger.log(Logger.Level.INFO, "Sending back response message");
+ publisher.publish(responseMsg);
+ } catch (JMSException e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Exception caught in RequestorMsgListener:\n" + e);
+ }
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/txqueuetests/TxQueueTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/txqueuetests/TxQueueTests.java
deleted file mode 100644
index c2e82b548b..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/txqueuetests/TxQueueTests.java
+++ /dev/null
@@ -1,1006 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.appclient.txqueuetests;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.Connection;
-import jakarta.jms.Destination;
-import jakarta.jms.MessageConsumer;
-import jakarta.jms.MessageProducer;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueConnection;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueSender;
-import jakarta.jms.QueueSession;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-
-public class TxQueueTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.appclient.txqueuetests.TxQueueTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- TxQueueTests theTests = new TxQueueTests();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
- queues = new ArrayList(2);
- connections = new ArrayList(2);
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: simpleSendReceiveTxQueueTest
- *
- * @assertion_ids: JMS:SPEC:122; JMS:SPEC:123; JMS:SPEC:124; JMS:SPEC:125;
- *
- * @test_Strategy: Send and receive single message to verify that Queues are
- * working in a transacted session.
- */
- public void simpleSendReceiveTxQueueTest() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
- logMsg("Start connection");
- tool.getDefaultQueueConnection().start();
-
- // send and receive message
- logMsg("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("transaction message test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "simpleSendReceiveTxQueueTest");
- logMsg("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logMsg("Call commit");
- tool.getDefaultQueueSession().commit();
- logMsg("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logMsg("Call commit");
- tool.getDefaultQueueSession().commit();
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- logMsg("Message text: \"" + messageReceived.getText() + "\"");
- logMsg("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("simpleSendReceiveQueueTxTest");
- }
- }
-
- /*
- * @testName: commitAckMsgQueueTest
- *
- * @assertion_ids: JMS:SPEC:130;
- *
- * @test_Strategy: Create tx_session and receive one message from a queue.
- * Call commit() and close session. Create non_tx new session and send/receive
- * message. Should only receive the one message.
- */
- public void commitAckMsgQueueTest() throws Exception {
- try {
- TextMessage mSent = null;
- TextMessage mReceived = null;
- QueueSession qSess = null;
- QueueSender qSender = null;
- QueueReceiver qRec = null;
- String msg = "test message for commitAckMsgTest";
-
- // close default session and create tx AUTO_ACK session
- tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
- tool.getDefaultQueueReceiver().close();
- qSess = tool.getDefaultQueueSession();
- qSender = tool.getDefaultQueueSender();
- qRec = qSess.createReceiver(tool.getDefaultQueue());
- tool.getDefaultQueueConnection().start();
-
- // send message
- logTrace("Send first message");
- mSent = qSess.createTextMessage();
- mSent.setBooleanProperty("lastMessage", false);
- mSent.setText(msg);
- mSent.setStringProperty("COM_SUN_JMS_TESTNAME", "commitAckMsgQueueTest1");
- qSender.send(mSent);
- qSess.commit();
-
- logTrace("Send second message");
- mSent.setBooleanProperty("lastMessage", true);
- qSender.send(mSent);
- qSess.commit();
-
- logTrace(
- "Message sent. Receive with tx session, do not call acknowledge().");
- mReceived = (TextMessage) qRec.receive(timeout);
- if (mReceived == null) {
- logMsg("Did not receive message!");
- throw new Exception("Did not receive message first time");
- }
- logTrace("Received message: \"" + mReceived.getText() + "\"");
-
- // commit and close session
- logTrace("Call commit() without calling acknowledge().");
- qSess.commit();
- logTrace("Close session and create new one.");
- qSess.close();
- // create new (non-tx) session
- qSess = tool.getDefaultQueueConnection().createQueueSession(false,
- Session.AUTO_ACKNOWLEDGE);
- qRec = qSess.createReceiver(tool.getDefaultQueue());
-
- // check for messages; should receive second message
- mReceived = (TextMessage) qRec.receive(timeout);
- if (mReceived == null) {
- logMsg("Did not receive message!");
- throw new Exception("Did not receive expected message");
- } else if (mReceived.getBooleanProperty("lastMessage") == false) {
- logMsg(
- "Received orignal message again. Was not acknowledged by commit().");
- throw new Exception("Message not acknowledged by commit");
- } else if (mReceived.getBooleanProperty("lastMessage") == true) {
- logMsg("Pass: received proper message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("commitAckMsgQueueTest");
- }
- }
-
- /*
- * @testName: rollbackRecoverQueueTest
- *
- * @assertion_ids: JMS:SPEC:130;
- *
- * @test_Strategy: Create tx_session and receive one message from a queue.
- * Call rollback() and close session. Create new session and receive message.
- */
- public void rollbackRecoverQueueTest() throws Exception {
- try {
- TextMessage mSent = null;
- TextMessage mReceived = null;
- QueueSession qSess = null;
- QueueSender qSender = null;
- QueueReceiver qRec = null;
- String msg = "test message for rollbackRecoverTest";
-
- // close default session and create tx AUTO_ACK session
- tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
- tool.getDefaultQueueSession().close();
- qSess = tool.getDefaultQueueConnection().createQueueSession(true, 0);
- qSender = qSess.createSender(tool.getDefaultQueue());
- qRec = qSess.createReceiver(tool.getDefaultQueue());
- tool.getDefaultQueueConnection().start();
-
- // send message
- mSent = qSess.createTextMessage();
- mSent.setText(msg);
- mSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "rollbackRecoverQueueTest");
- qSender.send(mSent);
- qSess.commit();
-
- // receive message
- logTrace("Message sent. Receive with tx session, do not acknowledge.");
- mReceived = (TextMessage) qRec.receive(timeout);
- if (mReceived == null) {
- logMsg("Did not receive message!");
- throw new Exception("Did not receive message first time");
- }
- logTrace("Received message: \"" + mReceived.getText() + "\"");
-
- // rollback and close session
- logTrace("Call rollback() without acknowledging message.");
- qSess.rollback();
- logTrace("Close session and create new one.");
- qSess.close();
-
- // create new (non-tx) session
- qSess = tool.getDefaultQueueConnection().createQueueSession(false,
- Session.AUTO_ACKNOWLEDGE);
- qRec = qSess.createReceiver(tool.getDefaultQueue());
-
- // check for messages; should receive one
- mReceived = (TextMessage) qRec.receive(timeout);
- if (mReceived == null) {
- logMsg("Did not receive message!");
- throw new Exception("Did not receive expected message");
- }
- if (mReceived.getText().equals(msg)) {
- logMsg("Received orignal message again. Was not acknowledged.");
- } else {
- throw new Exception("Received unexpected message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("rollbackRecoverQueueTest");
- }
- }
-
- /*
- * @testName: redeliveredFlagTxQueueTest
- *
- * @assertion_ids: JMS:SPEC:129; JMS:JAVADOC:371; JMS:SPEC:13;
- *
- * @test_Strategy: Send message to a queue and receive it with a CLIENT_ACK
- * session. Check that the redelivered flag is FALSE. Call rollback and
- * receive the message again. Check that the flag is now TRUE.
- */
- public void redeliveredFlagTxQueueTest() throws Exception {
- try {
- TextMessage tMsg = null;
- QueueSession qSess = null;
- QueueReceiver qRec = null;
-
- // create queue setup with CLIENT_ACK session for receiving
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueReceiver().close();
- qSess = tool.getDefaultQueueConnection().createQueueSession(true,
- Session.CLIENT_ACKNOWLEDGE);
- qRec = qSess.createReceiver(tool.getDefaultQueue());
- tool.getDefaultQueueConnection().start();
-
- // create and send message
- logTrace("send and receive one message");
- tMsg = tool.getDefaultQueueSession().createTextMessage();
- tMsg.setText("test message for redelivered flag");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "redeliveredFlagTxQueueTest");
- tool.getDefaultQueueSender().send(tMsg);
- qSess.commit();
-
- // receive message and check flag
- tMsg = (TextMessage) qRec.receive(timeout);
- if (tMsg == null) {
- logMsg("Did not receive expected message!");
- throw new Exception("Did not receive message");
- }
- logTrace("Message received. Check redelivered flag.");
- boolean redelivered = tMsg.getJMSRedelivered();
-
- logTrace("redelivered = " + redelivered);
- if (redelivered == true) {
- throw new Exception("Message redelivered flag should be false");
- }
-
- // rollback, receive, check flag
- logTrace("calling rollback()");
- qSess.rollback();
- logTrace("receive message again");
- tMsg = (TextMessage) qRec.receive(timeout);
- qSess.commit();
- redelivered = tMsg.getJMSRedelivered();
- logTrace("redelivered flag = " + redelivered);
- if (redelivered == false) {
- throw new Exception("Message redelivered flag should be true");
- }
- } catch (Exception e) {
- logMsg("Error: " + e);
- throw new Exception("redeliveredFlagTxQueueTest", e);
- }
- }
-
- /*
- * @testName: transactionRollbackOnSessionCloseRecQTest
- *
- * @assertion_ids: JMS:SPEC:104;
- *
- * @test_Strategy: Use the default queue session, receiver and sender. Set up
- * an additional queue session and sender. Send and receive a transacted
- * message. Send another transacted message, but close the session after
- * receive with no commit. Verify that the message is rolled back to the queue
- */
- public void transactionRollbackOnSessionCloseRecQTest() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TextMessage messageReceived2 = null;
-
- // set up test tool for Queue for transacted session
- tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
- logTrace("Start connection");
- tool.getDefaultQueueConnection().start();
-
- // send and receive message
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("transaction message test");
- logTrace("Sending message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "transactionRollbackOnSessionCloseRecQTest");
- tool.getDefaultQueueSender().send(messageSent);
- tool.getDefaultQueueSession().commit();
- logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- tool.getDefaultQueueSession().commit();
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // Create another Queue Session, and queue sender
- QueueSession newQSess = tool.getDefaultQueueConnection()
- .createQueueSession(true, 0);
- messageSent.setText("part 2");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- tool.getDefaultQueueSession().commit();
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("close session - don't do a commit on receive");
- tool.getDefaultQueueSession().close();
-
- QueueReceiver qReceiver = newQSess.createReceiver(tool.getDefaultQueue());
- messageReceived2 = (TextMessage) qReceiver.receive(timeout);
- newQSess.commit();
- if (messageReceived.getText().equals(messageReceived2.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Message2 text: \"" + messageReceived2.getText() + "\"");
- logTrace("Received correct message");
- } else {
- throw new Exception(
- "received message not rolled back to q on close session");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("transactionRollbackOnSessionCloseRecQTest");
- }
- }
-
- /*
- * @testName: transactionRollbackOnSendQTest
- *
- * @assertion_ids: JMS:SPEC:123;
- *
- * @test_Strategy: Use the default queue session, receiver and sender. Set up
- * an additional queue session and sender. Send and receive a transacted
- * message. Send another transacted message, but rollback after the send.
- * Verify that the message is not received.
- */
- public void transactionRollbackOnSendQTest() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- logTrace("Start connection");
- tool.getDefaultQueueConnection().start();
-
- // Create another queue session and sender
- QueueSession newQSess = tool.getDefaultQueueConnection()
- .createQueueSession(true, 0);
- QueueSender newSender = newQSess.createSender(tool.getDefaultQueue());
-
- // send and receive message
- logTrace("Creating 1 message");
- messageSent = newQSess.createTextMessage();
- messageSent.setBooleanProperty("lastMessage", false);
- messageSent.setText("transaction message test");
- logTrace("Sending message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "transactionRollbackOnSendQTest");
- newSender.send(messageSent);
- logTrace("Call commit");
- newQSess.commit();
- logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // Send another message, but rollback the session.
- logTrace("Send a message, but then rollback");
- newSender.send(messageSent);
- newQSess.rollback();
-
- logTrace("Send 3rd message");
- messageSent.setBooleanProperty("lastMessage", true);
- newSender.send(messageSent);
- newQSess.commit();
-
- logTrace("Attempt to receive last message only");
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- if (messageReceived == null) {
- throw new Exception("Fail: Should have received message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
- logTrace("Pass: last msg received, proper message was rolledback");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("transactionRollbackOnSendQTest");
- }
- }
-
- /*
- * @testName: transactionRollbackOnRecQTest
- *
- * @assertion_ids: JMS:SPEC:123;
- *
- * @test_Strategy: Use the default queue session, receiver and sender. Set up
- * an additional queue session and sender. Send and receive a transacted
- * message. Send another transacted message, but rollback the session after
- * receive. Verify that the message is rolled back to the queue
- */
- public void transactionRollbackOnRecQTest() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TextMessage messageReceived2 = null;
-
- // set up test tool for Queue for transacted session
- tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
- logTrace("Start connection");
- tool.getDefaultQueueConnection().start();
-
- // send and receive message
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("transaction message test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "transactionRollbackOnRecQTest");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Call commit");
- tool.getDefaultQueueSession().commit();
- logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("Call commit");
- tool.getDefaultQueueSession().commit();
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
- // Send another message
- // Verify that now the message will not be received.
- messageSent.setText("receive rollback");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
-
- // commit.
- tool.getDefaultQueueSession().commit();
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("rollback session on receive");
- tool.getDefaultQueueSession().rollback();
- logTrace("Message should have been recovered");
- messageReceived2 = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- tool.getDefaultQueueSession().commit();
- if (messageReceived2 == null) {
- throw new Exception("Fail: message not recovered");
- }
- if (messageReceived.getText().equals(messageReceived2.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Message2 text: \"" + messageReceived2.getText() + "\"");
- logTrace("Pass: Message rolled back to the Q");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("transactionRollbackOnRecQTest");
- }
- }
-
- /*
- * @testName: txRollbackOnConnectionCloseRecQTest
- *
- * @assertion_ids: JMS:SPEC:104;
- *
- * @test_Strategy: Use the default queue session, receiver and sender. Set up
- * an additional queue session and sender. Send and receive a transacted
- * message. Send another transacted message, but close the connection after
- * receive with no commit. Verify that the message is rolled back to the queue
- */
- public void txRollbackOnConnectionCloseRecQTest() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TextMessage messageReceived2 = null;
-
- // set up test tool for Queue for transacted session
- tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
- logTrace("Start connection");
- tool.getDefaultQueueConnection().start();
- tool.getDefaultQueueReceiver().close();
- // open a new connection
- logTrace("Creating new Connection");
- QueueConnection newQConn = (QueueConnection) tool
- .getNewConnection(JmsTool.QUEUE, user, password);
- connections.add(newQConn);
-
- // Create another Queue Session, queue receiver and queue sender
- QueueSession newQSess = newQConn.createQueueSession(true,
- Session.AUTO_ACKNOWLEDGE);
- QueueSender qSender = newQSess.createSender(tool.getDefaultQueue());
- QueueReceiver qReceiver = newQSess.createReceiver(tool.getDefaultQueue());
-
- newQConn.start();
-
- // send and receive message
- logTrace("Creating 1 message");
- messageSent = newQSess.createTextMessage();
- messageSent.setText("transaction message test");
- logTrace("Sending message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "txRollbackOnConnectionCloseRecQTest");
- qSender.send(messageSent);
- logTrace("Call commit");
- newQSess.commit();
- logTrace("Receiving message");
- messageReceived = (TextMessage) qReceiver.receive(timeout);
- logTrace("Call commit");
- newQSess.commit();
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // Send another message
- // Verify that now the message will not be received.
- messageSent.setText("part 2");
- logTrace("Sending message");
- qSender.send(messageSent);
-
- // commit.
- newQSess.commit();
- messageReceived = (TextMessage) qReceiver.receive(timeout);
- logTrace("close connection - don't do a commit on receive");
- newQConn.close();
- tool.getDefaultQueueConnection().start();
-
- QueueReceiver qR = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue());
- messageReceived2 = (TextMessage) qR.receive(timeout);
- logTrace("Receive was not commited, message should be restored");
- tool.getDefaultQueueSession().commit();
- if (messageReceived == null) {
- throw new Exception(
- "Fail:received message not rolled back to q on close session");
- }
- if (messageReceived.getText().equals(messageReceived2.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Message2 text: \"" + messageReceived2.getText() + "\"");
- logTrace("Pass: message restored to Q");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("txRollbackOnConnectionCloseRecQTest");
- }
- }
-
- /*
- * @testName: txCloseRolledBackSessionRecQTest
- *
- * @assertion_ids: JMS:SPEC:104;
- *
- * @test_Strategy: Use the default queue session, receiver and sender. Set up
- * an additional queue session and sender. Send and receive a transacted
- * message. Send another transacted message, do a rollback and close the
- * sesion after receive with no commit. Verify that the message is rolled back
- * to the queue.
- */
- public void txCloseRolledBackSessionRecQTest() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TextMessage messageReceived2 = null;
-
- // set up test tool for Queue for transacted session
- tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
- logTrace("Start connection");
- tool.getDefaultQueueConnection().start();
-
- // Create another Queue Session, queue receiver and queue sender
- QueueSession newQSess = tool.getDefaultQueueConnection()
- .createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
- QueueSender qSender = newQSess.createSender(tool.getDefaultQueue());
-
- tool.getDefaultQueueReceiver().close();
- QueueReceiver qReceiver = newQSess.createReceiver(tool.getDefaultQueue());
- // send and receive message
- logTrace("Creating 1 message");
- messageSent = newQSess.createTextMessage();
- messageSent.setText("transaction message test");
- logTrace("Sending message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "txCloseRolledBackSessionRecQTest");
- qSender.send(messageSent);
- logTrace("Call commit");
- newQSess.commit();
- logTrace("Receiving message");
- messageReceived = (TextMessage) qReceiver.receive(timeout);
- logTrace("Call commit");
- newQSess.commit();
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // Send another message
- // Verify that now the message will not be received.
- messageSent.setText("part 2");
- logTrace("Sending message");
- qSender.send(messageSent);
-
- // commit.
- newQSess.commit();
- messageReceived = (TextMessage) qReceiver.receive(timeout);
- newQSess.rollback();
- logTrace("close session - don't do a commit on receive");
- newQSess.close();
- tool.getDefaultQueueConnection().start();
- QueueReceiver qR = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue());
- messageReceived2 = (TextMessage) qR.receive(timeout);
-
- tool.getDefaultQueueSession().commit();
- if (messageReceived.getText().equals(messageReceived2.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Message2 text: \"" + messageReceived2.getText() + "\"");
- logTrace("Received correct message");
- } else {
- throw new Exception(
- "received message not rolled back to q on close session");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("txCloseRolledBackSessionRecQTest");
- }
- }
-
- /*
- * @testName: txMultiQTest
- *
- * @assertion_ids: JMS:SPEC:125;
- *
- * @test_Strategy: Use 2 destination Queues - the default and create a new
- * one. In the default session Send and commit a message to MY_QUEUE Create a
- * new newQSess, qSender and qReceiver for Q2. Send a msg to Q2. - no commit
- * yet Have qReceiver request a msg - expect none - send was not committed.
- * Request a msg with the default receiver - expect a msg from MY_QUEUE commit
- * the send form newQSess - for Q2. Verify qReceiver receives message from Q2.
- *
- */
- public void txMultiQTest() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageSent2 = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Queue for transacted session
- tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
- logTrace("Start connection");
- tool.getDefaultQueueConnection().start();
-
- // Create another Queue Session, queue receiver and queue sender
- QueueSession newQSess = tool.getDefaultQueueConnection()
- .createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
- QueueSession newQSess1 = tool.getDefaultQueueConnection()
- .createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- Queue newQueue = tool.createNewQueue("Q2");
- QueueSender qSender = newQSess.createSender(newQueue);
- QueueReceiver qReceiver = newQSess1.createReceiver(newQueue);
- queues.add(newQueue);
-
- // send and commit a message MY_QUEUE
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("This is from MY_QUEUE");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "txMultiQTest");
- tool.getDefaultQueueSender().send(messageSent);
- tool.getDefaultQueueSession().commit();
-
- // send a message to Q2 without commit.
- messageSent2 = newQSess.createTextMessage();
- messageSent2.setText("This is from Q2");
- messageSent2.setStringProperty("COM_SUN_JMS_TESTNAME", "txMultiQTest");
- qSender.send(messageSent2);
-
- // qReceiver is from NewQ session - it's Q is "Q2" -
- logTrace("Verify there is no msg to receive");
- messageReceived = (TextMessage) qReceiver.receive(timeout);
- if (messageReceived != null) {
- throw new Exception(
- "Error: Did not commit send - should not have received a msg!");
- }
-
- // commit new sessions send
- newQSess.commit();
-
- // Now look at the default Q - should be a committed msg to receive.
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Did not get the committed msg from MY_QUEUE!");
- }
- logTrace(" msg received for default q is: " + messageReceived.getText());
-
- // Verify that this is the correct message
- if (messageReceived.getText().equals(messageSent.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- } else {
- throw new Exception("This was not the expected message!!");
- }
-
- // commit the receive from MY_QUEUE
- tool.getDefaultQueueSession().commit();
-
- // now there should be a message to receive. from Q2
- // qReceiver is from NewQ session - it's Queue is "Q2" -
- logTrace("Now there should be a message to receive");
- messageReceived = (TextMessage) qReceiver.receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Error: Should have received a msg!");
- } else {
- logTrace("Msg recvd = " + messageReceived);
- }
- logTrace(" msg received for Q2 is: " + messageReceived.getText());
-
- // Verify that this is the correct message
- if (messageReceived.getText().equals(messageSent2.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- } else {
- throw new Exception("This was not the expected message!!");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("txMultiQTest");
- }
- }
-
- /*
- * @testName: commitRollbackMultiMsgsTest
- *
- * @assertion_ids: JMS:JAVADOC:231; JMS:JAVADOC:221; JMS:JAVADOC:244;
- * JMS:JAVADOC:242; JMS:JAVADOC:229; JMS:JAVADOC:504; JMS:JAVADOC:510;
- * JMS:JAVADOC:597; JMS:JAVADOC:334;
- *
- * @test_Strategy: Test the following APIs:
- *
- * ConnectionFactory.createConnection(String, String)
- * Connection.createSession(boolean, int) Session.createTextMessage(String)
- * Session.createConsumer(Destination) Session.createProducer(Destination)
- * Session.commit() Session.rollback() MessageProducer.send(Message)
- * MessagingConsumer.receive(long timeout)
- *
- * 1. Create Session with SESSION_TRANSACTED. This is done in the setup()
- * routine. 2. Send x messages to a Queue. 3. Call rollback() to rollback the
- * sent messages. 4. Create a MessageConsumer to consume the messages in the
- * Queue. Should not receive any messages since the sent messages were rolled
- * back. Verify that no messages are received. 5. Send x messages to a Queue.
- * 6. Call commit() to commit the sent messages. 7. Create a MessageConsumer
- * to consume the messages in the Queue. Should receive all the messages since
- * the sent messages were committed. Verify that all messages are received.
- */
- public void commitRollbackMultiMsgsTest() throws Exception {
- boolean pass = true;
- int numMessages = 3;
- try {
- TextMessage tempMsg = null;
-
- // set up JmsTool for COMMON_QTX setup
- tool = new JmsTool(JmsTool.COMMON_QTX, user, password, mode);
- Destination destination = tool.getDefaultDestination();
- Session session = tool.getDefaultSession();
- Connection connection = tool.getDefaultConnection();
- MessageProducer producer = tool.getDefaultProducer();
- MessageConsumer consumer = tool.getDefaultConsumer();
- Queue queue = (Queue) destination;
- connection.start();
- queues.add(queue);
-
- // Send "numMessages" messages to Queue and call rollback
- TestUtil.logMsg(
- "Send " + numMessages + " messages to Queue and call rollback()");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "commitRollbackMultiMsgsTest" + i);
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- session.rollback();
-
- TestUtil.logMsg(
- "Should not consume any messages in Queue since rollback() was called");
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("Received message " + tempMsg.getText()
- + ", expected NULL (NO MESSAGES)");
- pass = false;
- }
-
- // Send "numMessages" messages to Queue and call commit
- TestUtil.logMsg(
- "Send " + numMessages + " messages to Queue and call commit()");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "commitRollbackMultiMsgsTest" + i);
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- session.commit();
-
- TestUtil.logMsg(
- "Should consume all messages in Queue since commit() was called");
- for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("MessageConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + msgCount + " missing from Queue");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + msgCount)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + msgCount + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received message: " + tempMsg.getText());
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("commitRollbackMultiMsgsTest");
- }
-
- if (!pass) {
- throw new Exception("commitRollbackMultiMsgsTest failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/txqueuetests/TxQueueTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/txqueuetests/TxQueueTestsIT.java
new file mode 100644
index 0000000000..87e808df19
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/txqueuetests/TxQueueTestsIT.java
@@ -0,0 +1,970 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.appclient.txqueuetests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.Connection;
+import jakarta.jms.Destination;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueConnection;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueSender;
+import jakarta.jms.QueueSession;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+
+public class TxQueueTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.appclient.txqueuetests.TxQueueTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ private static final Logger logger = (Logger) System.getLogger(TxQueueTestsIT.class.getName());
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+ queues = new ArrayList(2);
+ connections = new ArrayList(2);
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: simpleSendReceiveTxQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:122; JMS:SPEC:123; JMS:SPEC:124; JMS:SPEC:125;
+ *
+ * @test_Strategy: Send and receive single message to verify that Queues are
+ * working in a transacted session.
+ */
+ @Test
+ public void simpleSendReceiveTxQueueTest() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
+ logger.log(Logger.Level.INFO, "Start connection");
+ tool.getDefaultQueueConnection().start();
+
+ // send and receive message
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("transaction message test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "simpleSendReceiveTxQueueTest");
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.INFO, "Call commit");
+ tool.getDefaultQueueSession().commit();
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.INFO, "Call commit");
+ tool.getDefaultQueueSession().commit();
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("simpleSendReceiveQueueTxTest");
+ }
+ }
+
+ /*
+ * @testName: commitAckMsgQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:130;
+ *
+ * @test_Strategy: Create tx_session and receive one message from a queue. Call
+ * commit() and close session. Create non_tx new session and send/receive
+ * message. Should only receive the one message.
+ */
+ @Test
+ public void commitAckMsgQueueTest() throws Exception {
+ try {
+ TextMessage mSent = null;
+ TextMessage mReceived = null;
+ QueueSession qSess = null;
+ QueueSender qSender = null;
+ QueueReceiver qRec = null;
+ String msg = "test message for commitAckMsgTest";
+
+ // close default session and create tx AUTO_ACK session
+ tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
+ tool.getDefaultQueueReceiver().close();
+ qSess = tool.getDefaultQueueSession();
+ qSender = tool.getDefaultQueueSender();
+ qRec = qSess.createReceiver(tool.getDefaultQueue());
+ tool.getDefaultQueueConnection().start();
+
+ // send message
+ logger.log(Logger.Level.TRACE, "Send first message");
+ mSent = qSess.createTextMessage();
+ mSent.setBooleanProperty("lastMessage", false);
+ mSent.setText(msg);
+ mSent.setStringProperty("COM_SUN_JMS_TESTNAME", "commitAckMsgQueueTest1");
+ qSender.send(mSent);
+ qSess.commit();
+
+ logger.log(Logger.Level.TRACE, "Send second message");
+ mSent.setBooleanProperty("lastMessage", true);
+ qSender.send(mSent);
+ qSess.commit();
+
+ logger.log(Logger.Level.TRACE, "Message sent. Receive with tx session, do not call acknowledge().");
+ mReceived = (TextMessage) qRec.receive(timeout);
+ if (mReceived == null) {
+ logger.log(Logger.Level.INFO, "Did not receive message!");
+ throw new Exception("Did not receive message first time");
+ }
+ logger.log(Logger.Level.TRACE, "Received message: \"" + mReceived.getText() + "\"");
+
+ // commit and close session
+ logger.log(Logger.Level.TRACE, "Call commit() without calling acknowledge().");
+ qSess.commit();
+ logger.log(Logger.Level.TRACE, "Close session and create new one.");
+ qSess.close();
+ // create new (non-tx) session
+ qSess = tool.getDefaultQueueConnection().createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ qRec = qSess.createReceiver(tool.getDefaultQueue());
+
+ // check for messages; should receive second message
+ mReceived = (TextMessage) qRec.receive(timeout);
+ if (mReceived == null) {
+ logger.log(Logger.Level.INFO, "Did not receive message!");
+ throw new Exception("Did not receive expected message");
+ } else if (mReceived.getBooleanProperty("lastMessage") == false) {
+ logger.log(Logger.Level.INFO, "Received orignal message again. Was not acknowledged by commit().");
+ throw new Exception("Message not acknowledged by commit");
+ } else if (mReceived.getBooleanProperty("lastMessage") == true) {
+ logger.log(Logger.Level.INFO, "Pass: received proper message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("commitAckMsgQueueTest");
+ }
+ }
+
+ /*
+ * @testName: rollbackRecoverQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:130;
+ *
+ * @test_Strategy: Create tx_session and receive one message from a queue. Call
+ * rollback() and close session. Create new session and receive message.
+ */
+ @Test
+ public void rollbackRecoverQueueTest() throws Exception {
+ try {
+ TextMessage mSent = null;
+ TextMessage mReceived = null;
+ QueueSession qSess = null;
+ QueueSender qSender = null;
+ QueueReceiver qRec = null;
+ String msg = "test message for rollbackRecoverTest";
+
+ // close default session and create tx AUTO_ACK session
+ tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
+ tool.getDefaultQueueSession().close();
+ qSess = tool.getDefaultQueueConnection().createQueueSession(true, 0);
+ qSender = qSess.createSender(tool.getDefaultQueue());
+ qRec = qSess.createReceiver(tool.getDefaultQueue());
+ tool.getDefaultQueueConnection().start();
+
+ // send message
+ mSent = qSess.createTextMessage();
+ mSent.setText(msg);
+ mSent.setStringProperty("COM_SUN_JMS_TESTNAME", "rollbackRecoverQueueTest");
+ qSender.send(mSent);
+ qSess.commit();
+
+ // receive message
+ logger.log(Logger.Level.TRACE, "Message sent. Receive with tx session, do not acknowledge.");
+ mReceived = (TextMessage) qRec.receive(timeout);
+ if (mReceived == null) {
+ logger.log(Logger.Level.INFO, "Did not receive message!");
+ throw new Exception("Did not receive message first time");
+ }
+ logger.log(Logger.Level.TRACE, "Received message: \"" + mReceived.getText() + "\"");
+
+ // rollback and close session
+ logger.log(Logger.Level.TRACE, "Call rollback() without acknowledging message.");
+ qSess.rollback();
+ logger.log(Logger.Level.TRACE, "Close session and create new one.");
+ qSess.close();
+
+ // create new (non-tx) session
+ qSess = tool.getDefaultQueueConnection().createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ qRec = qSess.createReceiver(tool.getDefaultQueue());
+
+ // check for messages; should receive one
+ mReceived = (TextMessage) qRec.receive(timeout);
+ if (mReceived == null) {
+ logger.log(Logger.Level.INFO, "Did not receive message!");
+ throw new Exception("Did not receive expected message");
+ }
+ if (mReceived.getText().equals(msg)) {
+ logger.log(Logger.Level.INFO, "Received orignal message again. Was not acknowledged.");
+ } else {
+ throw new Exception("Received unexpected message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("rollbackRecoverQueueTest");
+ }
+ }
+
+ /*
+ * @testName: redeliveredFlagTxQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:129; JMS:JAVADOC:371; JMS:SPEC:13;
+ *
+ * @test_Strategy: Send message to a queue and receive it with a CLIENT_ACK
+ * session. Check that the redelivered flag is FALSE. Call rollback and receive
+ * the message again. Check that the flag is now TRUE.
+ */
+ @Test
+ public void redeliveredFlagTxQueueTest() throws Exception {
+ try {
+ TextMessage tMsg = null;
+ QueueSession qSess = null;
+ QueueReceiver qRec = null;
+
+ // create queue setup with CLIENT_ACK session for receiving
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueReceiver().close();
+ qSess = tool.getDefaultQueueConnection().createQueueSession(true, Session.CLIENT_ACKNOWLEDGE);
+ qRec = qSess.createReceiver(tool.getDefaultQueue());
+ tool.getDefaultQueueConnection().start();
+
+ // create and send message
+ logger.log(Logger.Level.TRACE, "send and receive one message");
+ tMsg = tool.getDefaultQueueSession().createTextMessage();
+ tMsg.setText("test message for redelivered flag");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "redeliveredFlagTxQueueTest");
+ tool.getDefaultQueueSender().send(tMsg);
+ qSess.commit();
+
+ // receive message and check flag
+ tMsg = (TextMessage) qRec.receive(timeout);
+ if (tMsg == null) {
+ logger.log(Logger.Level.INFO, "Did not receive expected message!");
+ throw new Exception("Did not receive message");
+ }
+ logger.log(Logger.Level.TRACE, "Message received. Check redelivered flag.");
+ boolean redelivered = tMsg.getJMSRedelivered();
+
+ logger.log(Logger.Level.TRACE, "redelivered = " + redelivered);
+ if (redelivered == true) {
+ throw new Exception("Message redelivered flag should be false");
+ }
+
+ // rollback, receive, check flag
+ logger.log(Logger.Level.TRACE, "calling rollback()");
+ qSess.rollback();
+ logger.log(Logger.Level.TRACE, "receive message again");
+ tMsg = (TextMessage) qRec.receive(timeout);
+ qSess.commit();
+ redelivered = tMsg.getJMSRedelivered();
+ logger.log(Logger.Level.TRACE, "redelivered flag = " + redelivered);
+ if (redelivered == false) {
+ throw new Exception("Message redelivered flag should be true");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Error: " + e);
+ throw new Exception("redeliveredFlagTxQueueTest", e);
+ }
+ }
+
+ /*
+ * @testName: transactionRollbackOnSessionCloseRecQTest
+ *
+ * @assertion_ids: JMS:SPEC:104;
+ *
+ * @test_Strategy: Use the default queue session, receiver and sender. Set up an
+ * additional queue session and sender. Send and receive a transacted message.
+ * Send another transacted message, but close the session after receive with no
+ * commit. Verify that the message is rolled back to the queue
+ */
+ @Test
+ public void transactionRollbackOnSessionCloseRecQTest() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TextMessage messageReceived2 = null;
+
+ // set up test tool for Queue for transacted session
+ tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
+ logger.log(Logger.Level.TRACE, "Start connection");
+ tool.getDefaultQueueConnection().start();
+
+ // send and receive message
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("transaction message test");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "transactionRollbackOnSessionCloseRecQTest");
+ tool.getDefaultQueueSender().send(messageSent);
+ tool.getDefaultQueueSession().commit();
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ tool.getDefaultQueueSession().commit();
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // Create another Queue Session, and queue sender
+ QueueSession newQSess = tool.getDefaultQueueConnection().createQueueSession(true, 0);
+ messageSent.setText("part 2");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ tool.getDefaultQueueSession().commit();
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "close session - don't do a commit on receive");
+ tool.getDefaultQueueSession().close();
+
+ QueueReceiver qReceiver = newQSess.createReceiver(tool.getDefaultQueue());
+ messageReceived2 = (TextMessage) qReceiver.receive(timeout);
+ newQSess.commit();
+ if (messageReceived.getText().equals(messageReceived2.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Message2 text: \"" + messageReceived2.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("received message not rolled back to q on close session");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("transactionRollbackOnSessionCloseRecQTest");
+ }
+ }
+
+ /*
+ * @testName: transactionRollbackOnSendQTest
+ *
+ * @assertion_ids: JMS:SPEC:123;
+ *
+ * @test_Strategy: Use the default queue session, receiver and sender. Set up an
+ * additional queue session and sender. Send and receive a transacted message.
+ * Send another transacted message, but rollback after the send. Verify that the
+ * message is not received.
+ */
+ @Test
+ public void transactionRollbackOnSendQTest() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ logger.log(Logger.Level.TRACE, "Start connection");
+ tool.getDefaultQueueConnection().start();
+
+ // Create another queue session and sender
+ QueueSession newQSess = tool.getDefaultQueueConnection().createQueueSession(true, 0);
+ QueueSender newSender = newQSess.createSender(tool.getDefaultQueue());
+
+ // send and receive message
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = newQSess.createTextMessage();
+ messageSent.setBooleanProperty("lastMessage", false);
+ messageSent.setText("transaction message test");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "transactionRollbackOnSendQTest");
+ newSender.send(messageSent);
+ logger.log(Logger.Level.TRACE, "Call commit");
+ newQSess.commit();
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // Send another message, but rollback the session.
+ logger.log(Logger.Level.TRACE, "Send a message, but then rollback");
+ newSender.send(messageSent);
+ newQSess.rollback();
+
+ logger.log(Logger.Level.TRACE, "Send 3rd message");
+ messageSent.setBooleanProperty("lastMessage", true);
+ newSender.send(messageSent);
+ newQSess.commit();
+
+ logger.log(Logger.Level.TRACE, "Attempt to receive last message only");
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ if (messageReceived == null) {
+ throw new Exception("Fail: Should have received message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
+ logger.log(Logger.Level.TRACE, "Pass: last msg received, proper message was rolledback");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("transactionRollbackOnSendQTest");
+ }
+ }
+
+ /*
+ * @testName: transactionRollbackOnRecQTest
+ *
+ * @assertion_ids: JMS:SPEC:123;
+ *
+ * @test_Strategy: Use the default queue session, receiver and sender. Set up an
+ * additional queue session and sender. Send and receive a transacted message.
+ * Send another transacted message, but rollback the session after receive.
+ * Verify that the message is rolled back to the queue
+ */
+ @Test
+ public void transactionRollbackOnRecQTest() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TextMessage messageReceived2 = null;
+
+ // set up test tool for Queue for transacted session
+ tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
+ logger.log(Logger.Level.TRACE, "Start connection");
+ tool.getDefaultQueueConnection().start();
+
+ // send and receive message
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("transaction message test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "transactionRollbackOnRecQTest");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Call commit");
+ tool.getDefaultQueueSession().commit();
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Call commit");
+ tool.getDefaultQueueSession().commit();
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+ // Send another message
+ // Verify that now the message will not be received.
+ messageSent.setText("receive rollback");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+
+ // commit.
+ tool.getDefaultQueueSession().commit();
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "rollback session on receive");
+ tool.getDefaultQueueSession().rollback();
+ logger.log(Logger.Level.TRACE, "Message should have been recovered");
+ messageReceived2 = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ tool.getDefaultQueueSession().commit();
+ if (messageReceived2 == null) {
+ throw new Exception("Fail: message not recovered");
+ }
+ if (messageReceived.getText().equals(messageReceived2.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Message2 text: \"" + messageReceived2.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Pass: Message rolled back to the Q");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("transactionRollbackOnRecQTest");
+ }
+ }
+
+ /*
+ * @testName: txRollbackOnConnectionCloseRecQTest
+ *
+ * @assertion_ids: JMS:SPEC:104;
+ *
+ * @test_Strategy: Use the default queue session, receiver and sender. Set up an
+ * additional queue session and sender. Send and receive a transacted message.
+ * Send another transacted message, but close the connection after receive with
+ * no commit. Verify that the message is rolled back to the queue
+ */
+ @Test
+ public void txRollbackOnConnectionCloseRecQTest() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TextMessage messageReceived2 = null;
+
+ // set up test tool for Queue for transacted session
+ tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
+ logger.log(Logger.Level.TRACE, "Start connection");
+ tool.getDefaultQueueConnection().start();
+ tool.getDefaultQueueReceiver().close();
+ // open a new connection
+ logger.log(Logger.Level.TRACE, "Creating new Connection");
+ QueueConnection newQConn = (QueueConnection) tool.getNewConnection(JmsTool.QUEUE, user, password);
+ connections.add(newQConn);
+
+ // Create another Queue Session, queue receiver and queue sender
+ QueueSession newQSess = newQConn.createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
+ QueueSender qSender = newQSess.createSender(tool.getDefaultQueue());
+ QueueReceiver qReceiver = newQSess.createReceiver(tool.getDefaultQueue());
+
+ newQConn.start();
+
+ // send and receive message
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = newQSess.createTextMessage();
+ messageSent.setText("transaction message test");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "txRollbackOnConnectionCloseRecQTest");
+ qSender.send(messageSent);
+ logger.log(Logger.Level.TRACE, "Call commit");
+ newQSess.commit();
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) qReceiver.receive(timeout);
+ logger.log(Logger.Level.TRACE, "Call commit");
+ newQSess.commit();
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // Send another message
+ // Verify that now the message will not be received.
+ messageSent.setText("part 2");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ qSender.send(messageSent);
+
+ // commit.
+ newQSess.commit();
+ messageReceived = (TextMessage) qReceiver.receive(timeout);
+ logger.log(Logger.Level.TRACE, "close connection - don't do a commit on receive");
+ newQConn.close();
+ tool.getDefaultQueueConnection().start();
+
+ QueueReceiver qR = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue());
+ messageReceived2 = (TextMessage) qR.receive(timeout);
+ logger.log(Logger.Level.TRACE, "Receive was not commited, message should be restored");
+ tool.getDefaultQueueSession().commit();
+ if (messageReceived == null) {
+ throw new Exception("Fail:received message not rolled back to q on close session");
+ }
+ if (messageReceived.getText().equals(messageReceived2.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Message2 text: \"" + messageReceived2.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Pass: message restored to Q");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("txRollbackOnConnectionCloseRecQTest");
+ }
+ }
+
+ /*
+ * @testName: txCloseRolledBackSessionRecQTest
+ *
+ * @assertion_ids: JMS:SPEC:104;
+ *
+ * @test_Strategy: Use the default queue session, receiver and sender. Set up an
+ * additional queue session and sender. Send and receive a transacted message.
+ * Send another transacted message, do a rollback and close the sesion after
+ * receive with no commit. Verify that the message is rolled back to the queue.
+ */
+ @Test
+ public void txCloseRolledBackSessionRecQTest() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TextMessage messageReceived2 = null;
+
+ // set up test tool for Queue for transacted session
+ tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
+ logger.log(Logger.Level.TRACE, "Start connection");
+ tool.getDefaultQueueConnection().start();
+
+ // Create another Queue Session, queue receiver and queue sender
+ QueueSession newQSess = tool.getDefaultQueueConnection().createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
+ QueueSender qSender = newQSess.createSender(tool.getDefaultQueue());
+
+ tool.getDefaultQueueReceiver().close();
+ QueueReceiver qReceiver = newQSess.createReceiver(tool.getDefaultQueue());
+ // send and receive message
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = newQSess.createTextMessage();
+ messageSent.setText("transaction message test");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "txCloseRolledBackSessionRecQTest");
+ qSender.send(messageSent);
+ logger.log(Logger.Level.TRACE, "Call commit");
+ newQSess.commit();
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) qReceiver.receive(timeout);
+ logger.log(Logger.Level.TRACE, "Call commit");
+ newQSess.commit();
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // Send another message
+ // Verify that now the message will not be received.
+ messageSent.setText("part 2");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ qSender.send(messageSent);
+
+ // commit.
+ newQSess.commit();
+ messageReceived = (TextMessage) qReceiver.receive(timeout);
+ newQSess.rollback();
+ logger.log(Logger.Level.TRACE, "close session - don't do a commit on receive");
+ newQSess.close();
+ tool.getDefaultQueueConnection().start();
+ QueueReceiver qR = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue());
+ messageReceived2 = (TextMessage) qR.receive(timeout);
+
+ tool.getDefaultQueueSession().commit();
+ if (messageReceived.getText().equals(messageReceived2.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Message2 text: \"" + messageReceived2.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("received message not rolled back to q on close session");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("txCloseRolledBackSessionRecQTest");
+ }
+ }
+
+ /*
+ * @testName: txMultiQTest
+ *
+ * @assertion_ids: JMS:SPEC:125;
+ *
+ * @test_Strategy: Use 2 destination Queues - the default and create a new one.
+ * In the default session Send and commit a message to MY_QUEUE Create a new
+ * newQSess, qSender and qReceiver for Q2. Send a msg to Q2. - no commit yet
+ * Have qReceiver request a msg - expect none - send was not committed. Request
+ * a msg with the default receiver - expect a msg from MY_QUEUE commit the send
+ * form newQSess - for Q2. Verify qReceiver receives message from Q2.
+ *
+ */
+ @Test
+ public void txMultiQTest() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageSent2 = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Queue for transacted session
+ tool = new JmsTool(JmsTool.TX_QUEUE, user, password, mode);
+ logger.log(Logger.Level.TRACE, "Start connection");
+ tool.getDefaultQueueConnection().start();
+
+ // Create another Queue Session, queue receiver and queue sender
+ QueueSession newQSess = tool.getDefaultQueueConnection().createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
+ QueueSession newQSess1 = tool.getDefaultQueueConnection().createQueueSession(false,
+ Session.AUTO_ACKNOWLEDGE);
+ Queue newQueue = tool.createNewQueue("Q2");
+ QueueSender qSender = newQSess.createSender(newQueue);
+ QueueReceiver qReceiver = newQSess1.createReceiver(newQueue);
+ queues.add(newQueue);
+
+ // send and commit a message MY_QUEUE
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("This is from MY_QUEUE");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "txMultiQTest");
+ tool.getDefaultQueueSender().send(messageSent);
+ tool.getDefaultQueueSession().commit();
+
+ // send a message to Q2 without commit.
+ messageSent2 = newQSess.createTextMessage();
+ messageSent2.setText("This is from Q2");
+ messageSent2.setStringProperty("COM_SUN_JMS_TESTNAME", "txMultiQTest");
+ qSender.send(messageSent2);
+
+ // qReceiver is from NewQ session - it's Q is "Q2" -
+ logger.log(Logger.Level.TRACE, "Verify there is no msg to receive");
+ messageReceived = (TextMessage) qReceiver.receive(timeout);
+ if (messageReceived != null) {
+ throw new Exception("Error: Did not commit send - should not have received a msg!");
+ }
+
+ // commit new sessions send
+ newQSess.commit();
+
+ // Now look at the default Q - should be a committed msg to receive.
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Did not get the committed msg from MY_QUEUE!");
+ }
+ logger.log(Logger.Level.TRACE, " msg received for default q is: " + messageReceived.getText());
+
+ // Verify that this is the correct message
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ } else {
+ throw new Exception("This was not the expected message!!");
+ }
+
+ // commit the receive from MY_QUEUE
+ tool.getDefaultQueueSession().commit();
+
+ // now there should be a message to receive. from Q2
+ // qReceiver is from NewQ session - it's Queue is "Q2" -
+ logger.log(Logger.Level.TRACE, "Now there should be a message to receive");
+ messageReceived = (TextMessage) qReceiver.receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Error: Should have received a msg!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Msg recvd = " + messageReceived);
+ }
+ logger.log(Logger.Level.TRACE, " msg received for Q2 is: " + messageReceived.getText());
+
+ // Verify that this is the correct message
+ if (messageReceived.getText().equals(messageSent2.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ } else {
+ throw new Exception("This was not the expected message!!");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("txMultiQTest");
+ }
+ }
+
+ /*
+ * @testName: commitRollbackMultiMsgsTest
+ *
+ * @assertion_ids: JMS:JAVADOC:231; JMS:JAVADOC:221; JMS:JAVADOC:244;
+ * JMS:JAVADOC:242; JMS:JAVADOC:229; JMS:JAVADOC:504; JMS:JAVADOC:510;
+ * JMS:JAVADOC:597; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * ConnectionFactory.createConnection(String, String)
+ * Connection.createSession(boolean, int) Session.createTextMessage(String)
+ * Session.createConsumer(Destination) Session.createProducer(Destination)
+ * Session.commit() Session.rollback() MessageProducer.send(Message)
+ * MessagingConsumer.receive(long timeout)
+ *
+ * 1. Create Session with SESSION_TRANSACTED. This is done in the setup()
+ * routine. 2. Send x messages to a Queue. 3. Call rollback() to rollback the
+ * sent messages. 4. Create a MessageConsumer to consume the messages in the
+ * Queue. Should not receive any messages since the sent messages were rolled
+ * back. Verify that no messages are received. 5. Send x messages to a Queue. 6.
+ * Call commit() to commit the sent messages. 7. Create a MessageConsumer to
+ * consume the messages in the Queue. Should receive all the messages since the
+ * sent messages were committed. Verify that all messages are received.
+ */
+ @Test
+ public void commitRollbackMultiMsgsTest() throws Exception {
+ boolean pass = true;
+ int numMessages = 3;
+ try {
+ TextMessage tempMsg = null;
+
+ // set up JmsTool for COMMON_QTX setup
+ tool = new JmsTool(JmsTool.COMMON_QTX, user, password, mode);
+ Destination destination = tool.getDefaultDestination();
+ Session session = tool.getDefaultSession();
+ Connection connection = tool.getDefaultConnection();
+ MessageProducer producer = tool.getDefaultProducer();
+ MessageConsumer consumer = tool.getDefaultConsumer();
+ Queue queue = (Queue) destination;
+ connection.start();
+ queues.add(queue);
+
+ // Send "numMessages" messages to Queue and call rollback
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Queue and call rollback()");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "commitRollbackMultiMsgsTest" + i);
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ session.rollback();
+
+ logger.log(Logger.Level.INFO, "Should not consume any messages in Queue since rollback() was called");
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR,
+ "Received message " + tempMsg.getText() + ", expected NULL (NO MESSAGES)");
+ pass = false;
+ }
+
+ // Send "numMessages" messages to Queue and call commit
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Queue and call commit()");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "commitRollbackMultiMsgsTest" + i);
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ session.commit();
+
+ logger.log(Logger.Level.INFO, "Should consume all messages in Queue since commit() was called");
+ for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "MessageConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + msgCount + " missing from Queue");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + msgCount)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + msgCount + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message: " + tempMsg.getText());
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("commitRollbackMultiMsgsTest");
+ }
+
+ if (!pass) {
+ throw new Exception("commitRollbackMultiMsgsTest failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/txtopictests/TxTopicTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/txtopictests/TxTopicTests.java
deleted file mode 100644
index 6ab767ff79..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/txtopictests/TxTopicTests.java
+++ /dev/null
@@ -1,802 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.appclient.txtopictests;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.Connection;
-import jakarta.jms.Destination;
-import jakarta.jms.JMSException;
-import jakarta.jms.MessageConsumer;
-import jakarta.jms.MessageProducer;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicConnection;
-import jakarta.jms.TopicPublisher;
-import jakarta.jms.TopicSession;
-import jakarta.jms.TopicSubscriber;
-
-public class TxTopicTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.ee.ejbjspservlet.txtopictests.TxTopicTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // Harness req's
- private Properties props = null;
-
- // JMS object
- private transient JmsTool tool = null;
-
- // properties read from ts.jte file
- long timeout;
-
- private String jmsUser;
-
- private String jmsPassword;
-
- private String mode;
-
- public static final int TOPIC = 1;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- TxTopicTests theTests = new TxTopicTests();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout;user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- logTrace("In setup");
- // get props
- jmsUser = p.getProperty("user");
- jmsPassword = p.getProperty("password");
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- mode = p.getProperty("platform.mode");
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- connections = new ArrayList(5);
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: commitAckMsgTopicTest
- *
- * @assertion_ids: JMS:SPEC:130; JMS:SPEC:166;
- *
- * @test_Strategy: Create tx_session and receive one message from a topic.
- * Call commit() and close session. Create new non_tx session and receive
- * message. Should only receive the one message.
- */
- public void commitAckMsgTopicTest() throws Exception {
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- TextMessage mSent = null;
- TextMessage mReceived = null;
- TopicSession tSess = null;
- TopicPublisher tPub = null;
- TopicSubscriber tSub = null;
- String msg = "test message for commitAckMsgTest";
- String subscriptionName = "commitAckMsgTopicTestSubscription";
-
- // create tx session
- tool = new JmsTool(JmsTool.DURABLE_TX_TOPIC, jmsUser, jmsPassword, lookup,
- mode);
-
- tool.getDefaultTopicSubscriber().close();
- tSess = tool.getDefaultTopicSession();
- tPub = tool.getDefaultTopicPublisher();
- tSub = tSess.createDurableSubscriber(tool.getDefaultTopic(),
- subscriptionName);
- tool.getDefaultTopicConnection().start();
- // send message
- logTrace("Send first message");
- mSent = tSess.createTextMessage();
- mSent.setBooleanProperty("lastMessage", false);
- mSent.setText(msg);
- mSent.setStringProperty("COM_SUN_JMS_TESTNAME", "commitAckMsgTopicTest1");
- tPub.publish(mSent);
- tSess.commit();
-
- logTrace("Send second message");
- mSent.setBooleanProperty("lastMessage", true);
- tPub.publish(mSent);
- tSess.commit();
-
- logTrace("Message sent. Receive with tx session, do not acknowledge.");
- mReceived = (TextMessage) tSub.receive(timeout);
- if (mReceived == null) {
- logMsg("Did not receive message!");
- throw new Exception("Did not receive message first time");
- }
- logTrace("Received message: \"" + mReceived.getText() + "\"");
-
- // commit and close session
- logTrace("Call commit() without calling acknowledge().");
- tSess.commit();
- logTrace("Close session and create new one.");
- tSess.close();
-
- // create new (non-tx) session
- tSess = tool.getDefaultTopicConnection().createTopicSession(false,
- Session.AUTO_ACKNOWLEDGE);
- tSub = tSess.createDurableSubscriber(tool.getDefaultTopic(),
- subscriptionName);
-
- // check for messages; should receive second message
- mReceived = (TextMessage) tSub.receive(timeout);
- if (mReceived == null) {
- logMsg("Did not receive message!");
- throw new Exception("Did not receive expected message");
- } else if (mReceived.getBooleanProperty("lastMessage") == false) {
- logMsg(
- "Received orignal message again. Was not acknowledged by commit().");
- throw new Exception("Message not acknowledged by commit");
- } else if (mReceived.getBooleanProperty("lastMessage") == true) {
- logMsg("Pass: received proper message");
- }
- tSub.close();
- tSess.unsubscribe(subscriptionName);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("commitAckMsgTopicTest");
- }
- }
-
- /*
- * @testName: rollbackRecoverTopicTest
- *
- * @assertion_ids: JMS:SPEC:130;
- *
- * @test_Strategy: Create tx_session. Receive one message from a topic and
- * call rollback. Attempt to receive message again.
- */
- public void rollbackRecoverTopicTest() throws Exception {
- String lookup = "MyTopicConnectionFactory";
-
- try {
- TextMessage mSent = null;
- TextMessage mReceived = null;
- TopicSession tSess = null;
- TopicPublisher tPub = null;
- TopicSubscriber tSub = null;
- String msg = "test message for rollbackRecoverTest";
-
- // close default session and create tx AUTO_ACK session
- tool = new JmsTool(JmsTool.TX_TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicSession().close();
- tSess = tool.getDefaultTopicConnection().createTopicSession(true,
- Session.AUTO_ACKNOWLEDGE);
- tPub = tSess.createPublisher(tool.getDefaultTopic());
- tSub = tSess.createSubscriber(tool.getDefaultTopic());
- tool.getDefaultTopicConnection().start();
-
- // send message
- mSent = tSess.createTextMessage();
- mSent.setText(msg);
- mSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "rollbackRecoverTopicTest");
- tPub.publish(mSent);
- tSess.commit();
-
- // receive message
- logTrace("Message sent. Receive with tx session, do not acknowledge.");
- mReceived = (TextMessage) tSub.receive(timeout);
- if (mReceived == null) {
- logMsg("Did not receive message!");
- throw new Exception("Did not receive message first time");
- }
- logTrace("Received message: \"" + mReceived.getText() + "\"");
-
- // rollback session
- logTrace("Call rollback() without acknowledging message.");
- tSess.rollback();
-
- // check for messages; should receive one
- logTrace("Attempt to receive message again");
- mReceived = (TextMessage) tSub.receive(timeout);
- if (mReceived == null) {
- logMsg("Did not receive message!");
- throw new Exception("Did not receive expected message");
- }
- if (mReceived.getText().equals(msg)) {
- logMsg("Received orignal message again. Was not acknowledged.");
- } else {
- throw new Exception("Received unexpected message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("rollbackRecoverTopicTest");
- }
- }
-
- /*
- * @testName: redeliveredFlagTxTopicTest
- *
- * @assertion_ids: JMS:SPEC:129; JMS:JAVADOC:371; JMS:SPEC:13; JMS:SPEC:167;
- *
- * @test_Strategy: Send message to a topic and receive it with a AUTO_ACK
- * session. Check that the redelivered flag is FALSE. Call rollback and
- * receive the message again. Check that the flag is now TRUE.
- */
- public void redeliveredFlagTxTopicTest() throws Exception {
- String lookup = "MyTopicConnectionFactory";
-
- try {
- TextMessage sentMsg = null;
- TextMessage recMsg = null;
-
- // create topic setup with AUTO_ACK session for receiving
- tool = new JmsTool(JmsTool.TX_TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
-
- // create and publish message
- logTrace("publish and receive one message");
- sentMsg = tool.getDefaultTopicSession().createTextMessage();
- sentMsg.setText("test message for redelivered flag");
- sentMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "redeliveredFlagTxTopicTest");
- tool.getDefaultTopicPublisher().publish(sentMsg);
- tool.getDefaultTopicSession().commit();
-
- // receive message and check flag
- recMsg = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
- if (recMsg == null) {
- logMsg("Did not receive expected message!");
- throw new Exception("Did not receive message");
- }
- logTrace("Message received. Check redelivered flag.");
- boolean redelivered = recMsg.getJMSRedelivered();
-
- logTrace("redelivered = " + redelivered);
- if (redelivered == true) {
- throw new Exception("Message redelivered flag should be false");
- }
-
- // rollback, receive, check flag
- logTrace("calling rollback()");
- tool.getDefaultTopicSession().rollback();
- logTrace("receive message again");
- recMsg = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
- tool.getDefaultTopicSession().commit();
- redelivered = recMsg.getJMSRedelivered();
- logTrace("redelivered flag = " + redelivered);
- if (redelivered == false) {
- throw new Exception("Message redelivered flag should be true");
- }
- } catch (Exception e) {
- logMsg("Error: " + e);
- throw new Exception("redeliveredFlagTxTopicTest", e);
- }
- }
-
- /*
- * @testName: transactionRollbackOnSessionCloseReceiveTopicTest
- *
- * @assertion_ids: JMS:SPEC:104; JMS:SPEC:166; JMS:SPEC:167;
- *
- * @test_Strategy: Use the default topic session, subscriber and publisher.
- * Set up an additional tx topic session and subscriber. Send and receive a
- * transacted message. Send another transacted message, but close the session
- * after receive() with no commit. Verify that the message is not received by
- * receiving again with new session.
- */
- public void transactionRollbackOnSessionCloseReceiveTopicTest() throws Exception {
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- String subscriptionName = "TxTopicTestSubscription";
-
- // set up test tool for Topic for publishing session
- tool = new JmsTool(JmsTool.DURABLE_TX_TOPIC, jmsUser, jmsPassword, lookup,
- mode);
- // close default subscriber and create a durable one
- tool.getDefaultTopicSubscriber().close();
-
- // Create another topic session and subscriber
- TopicSession newTopicSess = tool.getDefaultTopicConnection()
- .createTopicSession(true, 0);
-
- TopicSubscriber newSubscriber = newTopicSess
- .createDurableSubscriber(tool.getDefaultTopic(), subscriptionName);
-
- logTrace("Start connection");
- tool.getDefaultTopicConnection().start();
-
- // send and receive message
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setBooleanProperty("lastMessage", false);
- messageSent.setText("transaction message test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "transactionRollbackOnSessionCloseReceiveTopicTest");
- tool.getDefaultTopicPublisher().publish(messageSent);
- tool.getDefaultTopicSession().commit();
-
- messageReceived = (TextMessage) newSubscriber.receive(timeout);
- newTopicSess.commit();
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // Send another message
- messageSent.setBooleanProperty("lastMessage", true);
- tool.getDefaultTopicPublisher().publish(messageSent);
- tool.getDefaultTopicSession().commit();
- // close the session without doing the commit.
- logTrace("Receive message and call close()");
- messageReceived = (TextMessage) newSubscriber.receive(timeout);
- newTopicSess.close();
-
- logTrace("Create new session and attempt to receive message");
- newTopicSess = tool.getDefaultTopicConnection().createTopicSession(true,
- 0);
- newSubscriber = newTopicSess
- .createDurableSubscriber(tool.getDefaultTopic(), subscriptionName);
- messageReceived = (TextMessage) newSubscriber.receive(timeout);
- newTopicSess.commit();
-
- newSubscriber.close();
- newTopicSess.unsubscribe(subscriptionName);
-
- // check message
- if (messageReceived == null) {
- throw new Exception("Fail: Should have received message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
- logTrace("Pass: received message again, previous tx was rolled back");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("transactionRollbackOnSessionCloseReceiveTopicTest");
- }
- }
-
- /*
- * @testName: transactionRollbackOnPublishTopicTest
- *
- * @assertion_ids: JMS:SPEC:123;
- *
- * @test_Strategy: Use the default topic session, subscriber and publisher.
- * Create durable subscriber to replace default Set up an additional tx topic
- * session and publisher. Send and receive a transacted message. Send another
- * transacted message, but rollback after publish() Send third message and
- * commit Verify that the second message is not received.
- */
- public void transactionRollbackOnPublishTopicTest() throws Exception {
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- String subscriptionName = "TxTopicTestSubscription";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.DURABLE_TX_TOPIC, jmsUser, jmsPassword, lookup,
- mode);
- tool.getDefaultTopicSubscriber().close();
- TopicSubscriber tSub = tool.getDefaultTopicSession()
- .createDurableSubscriber(tool.getDefaultTopic(), subscriptionName);
- logTrace("Start connection");
- tool.getDefaultTopicConnection().start();
-
- // Create another topic session and publisher
- TopicSession newTopicSess = tool.getDefaultTopicConnection()
- .createTopicSession(true, 0);
- TopicPublisher newPublisher = newTopicSess
- .createPublisher(tool.getDefaultTopic());
-
- // send and receive message
- logTrace("Creating 1 message");
- messageSent = newTopicSess.createTextMessage();
- messageSent.setBooleanProperty("lastMessage", false);
- messageSent.setText("transaction message test");
- logTrace("Publish the message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "transactionRollbackOnPublishTopicTest");
- newPublisher.publish(messageSent);
- logTrace("Call commit");
- newTopicSess.commit();
- logTrace("Receiving message");
- messageReceived = (TextMessage) tSub.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // Send another message, but then rollback.
- logTrace("Publish a message, but then rollback");
- newPublisher.publish(messageSent);
- newTopicSess.rollback();
-
- logTrace("Publish 3rd message");
- messageSent.setBooleanProperty("lastMessage", true);
- newPublisher.publish(messageSent);
- newTopicSess.commit();
-
- logTrace("Attempt to receive last message only");
- messageReceived = (TextMessage) tSub.receive(timeout);
- tool.getDefaultTopicSession().commit();
-
- if (messageReceived == null) {
- throw new Exception("Fail: Should have received message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
- logTrace("Pass: last msg received, proper message was rolledback");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("transactionRollbackOnPublishTopicTest");
- }
- }
-
- /*
- * @testName: transactionRollbackOnRecTopicTest
- *
- * @assertion_ids: JMS:SPEC:123;
- *
- * @test_Strategy: Use the default topic session, subscriber and publisher.
- * Set up an additional topic session, subscriber and pubisher. Send and
- * receive a transacted message. Send another transacted message, but rollback
- * after receive Verify that the message is rolled back to the topic
- */
- public void transactionRollbackOnRecTopicTest() throws Exception {
- String lookup = "MyTopicConnectionFactory";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TextMessage messageReceived2 = null;
- // set up test tool for Topic for transacted session
- tool = new JmsTool(JmsTool.TX_TOPIC, jmsUser, jmsPassword, lookup, mode);
- logTrace("Start connection");
- tool.getDefaultTopicConnection().start();
-
- // Create another topic Session, receiver and sender
- TopicSession newTopicSess = tool.getDefaultTopicConnection()
- .createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
- TopicPublisher newPublisher = newTopicSess
- .createPublisher(tool.getDefaultTopic());
-
- // send and receive message
- logTrace("Creating 1 message");
- messageSent = newTopicSess.createTextMessage();
- messageSent.setText("transaction message test");
- logTrace("Sending message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "transactionRollbackOnRecTopicTest");
- newPublisher.publish(messageSent);
- logTrace("Call commit");
- newTopicSess.commit();
- logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("Call commit");
- tool.getDefaultTopicSession().commit();
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
- logTrace("Publish the message and commit it");
- newPublisher.publish(messageSent);
- newTopicSess.commit();
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("Rollback after getting the message");
- tool.getDefaultTopicSession().rollback();
- logTrace("Doing a second receive - getting messageReceived2 ");
- messageReceived2 = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace(
- "Since the receive was not committed, I expect the message to still be there");
- if (messageReceived2 == null) {
- throw new Exception("Fail: message was not rolled back to the topic");
- }
- if (messageReceived.getText().equals(messageReceived2.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Message2 text: \"" + messageReceived2.getText() + "\"");
- logTrace("Pass: Message was recovered");
- } else {
- throw new Exception(
- "Did not receive expected message after not doing the commit");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("transactionRollbackOnRecTopicTest");
- }
- }
-
- /*
- * @testName: txRollbackOnConnectionCloseReceiveTopicTest
- *
- * @assertion_ids: JMS:SPEC:104; JMS:SPEC:166;
- *
- * @test_Strategy: Use the default topic session, subscriber and publisher.
- * Send and receive a transacted message. Send another transacted message, but
- * close the connection after receive() with no commit. Create new connection
- * and attempt to receive message.
- */
- public void txRollbackOnConnectionCloseReceiveTopicTest() throws Exception {
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- String subscriptionName = "TxTopicTestSubscription";
- String clientID = null;
-
- // set up test tool for Topic for transacted session
- tool = new JmsTool(JmsTool.DURABLE_TX_TOPIC, jmsUser, jmsPassword, lookup,
- mode);
- clientID = tool.getDefaultTopicConnection().getClientID();
- tool.getDefaultTopicSubscriber().close();
- TopicSubscriber tSub = tool.getDefaultTopicSession()
- .createDurableSubscriber(tool.getDefaultTopic(), subscriptionName);
- logTrace("Start connection");
- tool.getDefaultTopicConnection().start();
-
- // send and receive message
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setBooleanProperty("lastMessage", false);
- messageSent.setText("transaction message test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "txRollbackOnConnectionCloseReceiveTopicTest");
- tool.getDefaultTopicPublisher().publish(messageSent);
- tool.getDefaultTopicSession().commit();
- messageReceived = (TextMessage) tSub.receive(timeout);
- tool.getDefaultTopicSession().commit();
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- logTrace("Message text: \"" + messageReceived.getText() + "\"");
- logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // Send another message
- logTrace("send second message");
- messageSent.setBooleanProperty("lastMessage", true);
- tool.getDefaultTopicPublisher().publish(messageSent);
- tool.getDefaultTopicSession().commit();
-
- // receive and close the connection without doing the commit.
- logTrace("Receive message");
- messageReceived = (TextMessage) tSub.receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Should have received second message");
- }
- logTrace("Call connection.close()");
- tool.getDefaultTopicConnection().close();
-
- logTrace("Create new connection and attempt to receive message");
- TopicConnection newConn = (TopicConnection) tool.getNewConnection(
- JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup);
- connections.add(newConn);
-
- // must be same as first connection to use same durable subscription
- String newClientID = newConn.getClientID();
- if (newClientID == null || !newClientID.equals(clientID)) {
- try {
- newConn.setClientID(clientID);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- logMsg("Warning: cannot set client ID to match first connection.\n"
- + "Test may not be able to use same durable subscription");
- }
- }
-
- TopicSession newTopicSess = newConn.createTopicSession(true, 0);
- TopicSubscriber newSubscriber = newTopicSess
- .createDurableSubscriber(tool.getDefaultTopic(), subscriptionName);
-
- newConn.start();
-
- logTrace("receive message");
- messageReceived = (TextMessage) newSubscriber.receive(timeout);
- newTopicSess.commit();
-
- newSubscriber.close();
- newTopicSess.unsubscribe(subscriptionName);
- newConn.close();
-
- // check message
- if (messageReceived == null) {
- throw new Exception("Fail: Should have received message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
- logTrace("Pass: received message again, previous tx was rolled back");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("txRollbackOnConnectionCloseReceiveTopicTest");
- }
- }
-
- /*
- * @testName: commitRollbackMultiMsgsTest
- *
- * @assertion_ids: JMS:JAVADOC:231; JMS:JAVADOC:221; JMS:JAVADOC:244;
- * JMS:JAVADOC:242; JMS:JAVADOC:229; JMS:JAVADOC:504; JMS:JAVADOC:510;
- * JMS:JAVADOC:597; JMS:JAVADOC:334;
- *
- * @test_Strategy: Test the following APIs:
- *
- * ConnectionFactory.createConnection(String, String)
- * Connection.createSession(boolean, int) Session.createTextMessage(String)
- * Session.createConsumer(Destination) Session.createProducer(Destination)
- * Session.commit() Session.rollback() MessageProducer.send(Message)
- * MessagingConsumer.receive(long timeout)
- *
- * 1. Create Session with SESSION_TRANSACTED. This is done in the setup()
- * routine. 2. Send x messages to a Topic. 3. Call rollback() to rollback the
- * sent messages. 4. Create a MessageConsumer to consume the messages in the
- * Topic. Should not receive any messages since the sent messages were rolled
- * back. Verify that no messages are received. 5. Send x messages to a Topic.
- * 6. Call commit() to commit the sent messages. 7. Create a MessageConsumer
- * to consume the messages in the Topic. Should receive all the messages since
- * the sent messages were committed. Verify that all messages are received.
- */
- public void commitRollbackMultiMsgsTest() throws Exception {
- boolean pass = true;
- int numMessages = 3;
- try {
- TextMessage tempMsg = null;
-
- // set up JmsTool for COMMON_TTX setup
- tool = new JmsTool(JmsTool.COMMON_TTX, jmsUser, jmsPassword, mode);
- Destination destination = tool.getDefaultDestination();
- Session session = tool.getDefaultSession();
- Connection connection = tool.getDefaultConnection();
- MessageProducer producer = tool.getDefaultProducer();
- MessageConsumer consumer = tool.getDefaultConsumer();
- Topic topic = (Topic) destination;
- connection.start();
-
- // Send "numMessages" messages to Topic and call rollback
- TestUtil.logMsg(
- "Send " + numMessages + " messages to Topic and call rollback()");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "commitRollbackMultiMsgsTest" + i);
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- session.rollback();
-
- TestUtil.logMsg(
- "Should not consume any messages in Topic since rollback() was called");
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("Received message " + tempMsg.getText()
- + ", expected NULL (NO MESSAGES)");
- pass = false;
- }
-
- // Send "numMessages" messages to Topic and call commit
- TestUtil.logMsg(
- "Send " + numMessages + " messages to Topic and call commit()");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "commitRollbackMultiMsgsTest" + i);
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- session.commit();
-
- TestUtil.logMsg(
- "Should consume all messages in Topic since commit() was called");
- for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("MessageConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + msgCount + " missing from Topic");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + msgCount)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + msgCount + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received message: " + tempMsg.getText());
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("commitRollbackMultiMsgsTest");
- }
-
- if (!pass) {
- throw new Exception("commitRollbackMultiMsgsTest failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/txtopictests/TxTopicTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/txtopictests/TxTopicTestsIT.java
new file mode 100644
index 0000000000..eab526d4ee
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/appclient/txtopictests/TxTopicTestsIT.java
@@ -0,0 +1,777 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.appclient.txtopictests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.Connection;
+import jakarta.jms.Destination;
+import jakarta.jms.JMSException;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicConnection;
+import jakarta.jms.TopicPublisher;
+import jakarta.jms.TopicSession;
+import jakarta.jms.TopicSubscriber;
+
+
+public class TxTopicTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.ee.ejbjspservlet.txtopictests.TxTopicTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(TxTopicTestsIT.class.getName());
+
+ // Harness req's
+ private Properties props = null;
+
+ // JMS object
+ private transient JmsTool tool = null;
+
+ // properties read
+ long timeout;
+
+ private String jmsUser;
+
+ private String jmsPassword;
+
+ private String mode;
+
+ public static final int TOPIC = 1;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout;user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, "In setup");
+ // get props
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ mode = System.getProperty("platform.mode");
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ connections = new ArrayList(5);
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: commitAckMsgTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:130; JMS:SPEC:166;
+ *
+ * @test_Strategy: Create tx_session and receive one message from a topic. Call
+ * commit() and close session. Create new non_tx session and receive message.
+ * Should only receive the one message.
+ */
+ @Test
+ public void commitAckMsgTopicTest() throws Exception {
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ TextMessage mSent = null;
+ TextMessage mReceived = null;
+ TopicSession tSess = null;
+ TopicPublisher tPub = null;
+ TopicSubscriber tSub = null;
+ String msg = "test message for commitAckMsgTest";
+ String subscriptionName = "commitAckMsgTopicTestSubscription";
+
+ // create tx session
+ tool = new JmsTool(JmsTool.DURABLE_TX_TOPIC, jmsUser, jmsPassword, lookup, mode);
+
+ tool.getDefaultTopicSubscriber().close();
+ tSess = tool.getDefaultTopicSession();
+ tPub = tool.getDefaultTopicPublisher();
+ tSub = tSess.createDurableSubscriber(tool.getDefaultTopic(), subscriptionName);
+ tool.getDefaultTopicConnection().start();
+ // send message
+ logger.log(Logger.Level.TRACE, "Send first message");
+ mSent = tSess.createTextMessage();
+ mSent.setBooleanProperty("lastMessage", false);
+ mSent.setText(msg);
+ mSent.setStringProperty("COM_SUN_JMS_TESTNAME", "commitAckMsgTopicTest1");
+ tPub.publish(mSent);
+ tSess.commit();
+
+ logger.log(Logger.Level.TRACE, "Send second message");
+ mSent.setBooleanProperty("lastMessage", true);
+ tPub.publish(mSent);
+ tSess.commit();
+
+ logger.log(Logger.Level.TRACE, "Message sent. Receive with tx session, do not acknowledge.");
+ mReceived = (TextMessage) tSub.receive(timeout);
+ if (mReceived == null) {
+ logger.log(Logger.Level.INFO, "Did not receive message!");
+ throw new Exception("Did not receive message first time");
+ }
+ logger.log(Logger.Level.TRACE, "Received message: \"" + mReceived.getText() + "\"");
+
+ // commit and close session
+ logger.log(Logger.Level.TRACE, "Call commit() without calling acknowledge().");
+ tSess.commit();
+ logger.log(Logger.Level.TRACE, "Close session and create new one.");
+ tSess.close();
+
+ // create new (non-tx) session
+ tSess = tool.getDefaultTopicConnection().createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ tSub = tSess.createDurableSubscriber(tool.getDefaultTopic(), subscriptionName);
+
+ // check for messages; should receive second message
+ mReceived = (TextMessage) tSub.receive(timeout);
+ if (mReceived == null) {
+ logger.log(Logger.Level.INFO, "Did not receive message!");
+ throw new Exception("Did not receive expected message");
+ } else if (mReceived.getBooleanProperty("lastMessage") == false) {
+ logger.log(Logger.Level.INFO, "Received orignal message again. Was not acknowledged by commit().");
+ throw new Exception("Message not acknowledged by commit");
+ } else if (mReceived.getBooleanProperty("lastMessage") == true) {
+ logger.log(Logger.Level.INFO, "Pass: received proper message");
+ }
+ tSub.close();
+ tSess.unsubscribe(subscriptionName);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("commitAckMsgTopicTest");
+ }
+ }
+
+ /*
+ * @testName: rollbackRecoverTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:130;
+ *
+ * @test_Strategy: Create tx_session. Receive one message from a topic and call
+ * rollback. Attempt to receive message again.
+ */
+ @Test
+ public void rollbackRecoverTopicTest() throws Exception {
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+ TextMessage mSent = null;
+ TextMessage mReceived = null;
+ TopicSession tSess = null;
+ TopicPublisher tPub = null;
+ TopicSubscriber tSub = null;
+ String msg = "test message for rollbackRecoverTest";
+
+ // close default session and create tx AUTO_ACK session
+ tool = new JmsTool(JmsTool.TX_TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicSession().close();
+ tSess = tool.getDefaultTopicConnection().createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
+ tPub = tSess.createPublisher(tool.getDefaultTopic());
+ tSub = tSess.createSubscriber(tool.getDefaultTopic());
+ tool.getDefaultTopicConnection().start();
+
+ // send message
+ mSent = tSess.createTextMessage();
+ mSent.setText(msg);
+ mSent.setStringProperty("COM_SUN_JMS_TESTNAME", "rollbackRecoverTopicTest");
+ tPub.publish(mSent);
+ tSess.commit();
+
+ // receive message
+ logger.log(Logger.Level.TRACE, "Message sent. Receive with tx session, do not acknowledge.");
+ mReceived = (TextMessage) tSub.receive(timeout);
+ if (mReceived == null) {
+ logger.log(Logger.Level.INFO, "Did not receive message!");
+ throw new Exception("Did not receive message first time");
+ }
+ logger.log(Logger.Level.TRACE, "Received message: \"" + mReceived.getText() + "\"");
+
+ // rollback session
+ logger.log(Logger.Level.TRACE, "Call rollback() without acknowledging message.");
+ tSess.rollback();
+
+ // check for messages; should receive one
+ logger.log(Logger.Level.TRACE, "Attempt to receive message again");
+ mReceived = (TextMessage) tSub.receive(timeout);
+ if (mReceived == null) {
+ logger.log(Logger.Level.INFO, "Did not receive message!");
+ throw new Exception("Did not receive expected message");
+ }
+ if (mReceived.getText().equals(msg)) {
+ logger.log(Logger.Level.INFO, "Received orignal message again. Was not acknowledged.");
+ } else {
+ throw new Exception("Received unexpected message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("rollbackRecoverTopicTest");
+ }
+ }
+
+ /*
+ * @testName: redeliveredFlagTxTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:129; JMS:JAVADOC:371; JMS:SPEC:13; JMS:SPEC:167;
+ *
+ * @test_Strategy: Send message to a topic and receive it with a AUTO_ACK
+ * session. Check that the redelivered flag is FALSE. Call rollback and receive
+ * the message again. Check that the flag is now TRUE.
+ */
+ @Test
+ public void redeliveredFlagTxTopicTest() throws Exception {
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+ TextMessage sentMsg = null;
+ TextMessage recMsg = null;
+
+ // create topic setup with AUTO_ACK session for receiving
+ tool = new JmsTool(JmsTool.TX_TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+
+ // create and publish message
+ logger.log(Logger.Level.TRACE, "publish and receive one message");
+ sentMsg = tool.getDefaultTopicSession().createTextMessage();
+ sentMsg.setText("test message for redelivered flag");
+ sentMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "redeliveredFlagTxTopicTest");
+ tool.getDefaultTopicPublisher().publish(sentMsg);
+ tool.getDefaultTopicSession().commit();
+
+ // receive message and check flag
+ recMsg = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (recMsg == null) {
+ logger.log(Logger.Level.INFO, "Did not receive expected message!");
+ throw new Exception("Did not receive message");
+ }
+ logger.log(Logger.Level.TRACE, "Message received. Check redelivered flag.");
+ boolean redelivered = recMsg.getJMSRedelivered();
+
+ logger.log(Logger.Level.TRACE, "redelivered = " + redelivered);
+ if (redelivered == true) {
+ throw new Exception("Message redelivered flag should be false");
+ }
+
+ // rollback, receive, check flag
+ logger.log(Logger.Level.TRACE, "calling rollback()");
+ tool.getDefaultTopicSession().rollback();
+ logger.log(Logger.Level.TRACE, "receive message again");
+ recMsg = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ tool.getDefaultTopicSession().commit();
+ redelivered = recMsg.getJMSRedelivered();
+ logger.log(Logger.Level.TRACE, "redelivered flag = " + redelivered);
+ if (redelivered == false) {
+ throw new Exception("Message redelivered flag should be true");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Error: " + e);
+ throw new Exception("redeliveredFlagTxTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: transactionRollbackOnSessionCloseReceiveTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:104; JMS:SPEC:166; JMS:SPEC:167;
+ *
+ * @test_Strategy: Use the default topic session, subscriber and publisher. Set
+ * up an additional tx topic session and subscriber. Send and receive a
+ * transacted message. Send another transacted message, but close the session
+ * after receive() with no commit. Verify that the message is not received by
+ * receiving again with new session.
+ */
+ @Test
+ public void transactionRollbackOnSessionCloseReceiveTopicTest() throws Exception {
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ String subscriptionName = "TxTopicTestSubscription";
+
+ // set up test tool for Topic for publishing session
+ tool = new JmsTool(JmsTool.DURABLE_TX_TOPIC, jmsUser, jmsPassword, lookup, mode);
+ // close default subscriber and create a durable one
+ tool.getDefaultTopicSubscriber().close();
+
+ // Create another topic session and subscriber
+ TopicSession newTopicSess = tool.getDefaultTopicConnection().createTopicSession(true, 0);
+
+ TopicSubscriber newSubscriber = newTopicSess.createDurableSubscriber(tool.getDefaultTopic(),
+ subscriptionName);
+
+ logger.log(Logger.Level.TRACE, "Start connection");
+ tool.getDefaultTopicConnection().start();
+
+ // send and receive message
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setBooleanProperty("lastMessage", false);
+ messageSent.setText("transaction message test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "transactionRollbackOnSessionCloseReceiveTopicTest");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ tool.getDefaultTopicSession().commit();
+
+ messageReceived = (TextMessage) newSubscriber.receive(timeout);
+ newTopicSess.commit();
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // Send another message
+ messageSent.setBooleanProperty("lastMessage", true);
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ tool.getDefaultTopicSession().commit();
+ // close the session without doing the commit.
+ logger.log(Logger.Level.TRACE, "Receive message and call close()");
+ messageReceived = (TextMessage) newSubscriber.receive(timeout);
+ newTopicSess.close();
+
+ logger.log(Logger.Level.TRACE, "Create new session and attempt to receive message");
+ newTopicSess = tool.getDefaultTopicConnection().createTopicSession(true, 0);
+ newSubscriber = newTopicSess.createDurableSubscriber(tool.getDefaultTopic(), subscriptionName);
+ messageReceived = (TextMessage) newSubscriber.receive(timeout);
+ newTopicSess.commit();
+
+ newSubscriber.close();
+ newTopicSess.unsubscribe(subscriptionName);
+
+ // check message
+ if (messageReceived == null) {
+ throw new Exception("Fail: Should have received message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
+ logger.log(Logger.Level.TRACE, "Pass: received message again, previous tx was rolled back");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ e.printStackTrace();
+ throw new Exception("transactionRollbackOnSessionCloseReceiveTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: transactionRollbackOnPublishTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:123;
+ *
+ * @test_Strategy: Use the default topic session, subscriber and publisher.
+ * Create durable subscriber to replace default Set up an additional tx topic
+ * session and publisher. Send and receive a transacted message. Send another
+ * transacted message, but rollback after publish() Send third message and
+ * commit Verify that the second message is not received.
+ */
+ @Test
+ public void transactionRollbackOnPublishTopicTest() throws Exception {
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ String subscriptionName = "TxTopicTestSubscription";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.DURABLE_TX_TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicSubscriber().close();
+ TopicSubscriber tSub = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ subscriptionName);
+ logger.log(Logger.Level.TRACE, "Start connection");
+ tool.getDefaultTopicConnection().start();
+
+ // Create another topic session and publisher
+ TopicSession newTopicSess = tool.getDefaultTopicConnection().createTopicSession(true, 0);
+ TopicPublisher newPublisher = newTopicSess.createPublisher(tool.getDefaultTopic());
+
+ // send and receive message
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = newTopicSess.createTextMessage();
+ messageSent.setBooleanProperty("lastMessage", false);
+ messageSent.setText("transaction message test");
+ logger.log(Logger.Level.TRACE, "Publish the message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "transactionRollbackOnPublishTopicTest");
+ newPublisher.publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Call commit");
+ newTopicSess.commit();
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tSub.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // Send another message, but then rollback.
+ logger.log(Logger.Level.TRACE, "Publish a message, but then rollback");
+ newPublisher.publish(messageSent);
+ newTopicSess.rollback();
+
+ logger.log(Logger.Level.TRACE, "Publish 3rd message");
+ messageSent.setBooleanProperty("lastMessage", true);
+ newPublisher.publish(messageSent);
+ newTopicSess.commit();
+
+ logger.log(Logger.Level.TRACE, "Attempt to receive last message only");
+ messageReceived = (TextMessage) tSub.receive(timeout);
+ tool.getDefaultTopicSession().commit();
+
+ if (messageReceived == null) {
+ throw new Exception("Fail: Should have received message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
+ logger.log(Logger.Level.TRACE, "Pass: last msg received, proper message was rolledback");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ e.printStackTrace();
+ throw new Exception("transactionRollbackOnPublishTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: transactionRollbackOnRecTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:123;
+ *
+ * @test_Strategy: Use the default topic session, subscriber and publisher. Set
+ * up an additional topic session, subscriber and pubisher. Send and receive a
+ * transacted message. Send another transacted message, but rollback after
+ * receive Verify that the message is rolled back to the topic
+ */
+ @Test
+ public void transactionRollbackOnRecTopicTest() throws Exception {
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TextMessage messageReceived2 = null;
+ // set up test tool for Topic for transacted session
+ tool = new JmsTool(JmsTool.TX_TOPIC, jmsUser, jmsPassword, lookup, mode);
+ logger.log(Logger.Level.TRACE, "Start connection");
+ tool.getDefaultTopicConnection().start();
+
+ // Create another topic Session, receiver and sender
+ TopicSession newTopicSess = tool.getDefaultTopicConnection().createTopicSession(true,
+ Session.AUTO_ACKNOWLEDGE);
+ TopicPublisher newPublisher = newTopicSess.createPublisher(tool.getDefaultTopic());
+
+ // send and receive message
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = newTopicSess.createTextMessage();
+ messageSent.setText("transaction message test");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "transactionRollbackOnRecTopicTest");
+ newPublisher.publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Call commit");
+ newTopicSess.commit();
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Call commit");
+ tool.getDefaultTopicSession().commit();
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+ logger.log(Logger.Level.TRACE, "Publish the message and commit it");
+ newPublisher.publish(messageSent);
+ newTopicSess.commit();
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Rollback after getting the message");
+ tool.getDefaultTopicSession().rollback();
+ logger.log(Logger.Level.TRACE, "Doing a second receive - getting messageReceived2 ");
+ messageReceived2 = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE,
+ "Since the receive was not committed, I expect the message to still be there");
+ if (messageReceived2 == null) {
+ throw new Exception("Fail: message was not rolled back to the topic");
+ }
+ if (messageReceived.getText().equals(messageReceived2.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Message2 text: \"" + messageReceived2.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Pass: Message was recovered");
+ } else {
+ throw new Exception("Did not receive expected message after not doing the commit");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("transactionRollbackOnRecTopicTest");
+ }
+ }
+
+ /*
+ * @testName: txRollbackOnConnectionCloseReceiveTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:104; JMS:SPEC:166;
+ *
+ * @test_Strategy: Use the default topic session, subscriber and publisher. Send
+ * and receive a transacted message. Send another transacted message, but close
+ * the connection after receive() with no commit. Create new connection and
+ * attempt to receive message.
+ */
+ @Test
+ public void txRollbackOnConnectionCloseReceiveTopicTest() throws Exception {
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ String subscriptionName = "TxTopicTestSubscription";
+ String clientID = null;
+
+ // set up test tool for Topic for transacted session
+ tool = new JmsTool(JmsTool.DURABLE_TX_TOPIC, jmsUser, jmsPassword, lookup, mode);
+ clientID = tool.getDefaultTopicConnection().getClientID();
+ tool.getDefaultTopicSubscriber().close();
+ TopicSubscriber tSub = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ subscriptionName);
+ logger.log(Logger.Level.TRACE, "Start connection");
+ tool.getDefaultTopicConnection().start();
+
+ // send and receive message
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setBooleanProperty("lastMessage", false);
+ messageSent.setText("transaction message test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "txRollbackOnConnectionCloseReceiveTopicTest");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ tool.getDefaultTopicSession().commit();
+ messageReceived = (TextMessage) tSub.receive(timeout);
+ tool.getDefaultTopicSession().commit();
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // Send another message
+ logger.log(Logger.Level.TRACE, "send second message");
+ messageSent.setBooleanProperty("lastMessage", true);
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ tool.getDefaultTopicSession().commit();
+
+ // receive and close the connection without doing the commit.
+ logger.log(Logger.Level.TRACE, "Receive message");
+ messageReceived = (TextMessage) tSub.receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Should have received second message");
+ }
+ logger.log(Logger.Level.TRACE, "Call connection.close()");
+ tool.getDefaultTopicConnection().close();
+
+ logger.log(Logger.Level.TRACE, "Create new connection and attempt to receive message");
+ TopicConnection newConn = (TopicConnection) tool.getNewConnection(JmsTool.DURABLE_TOPIC, jmsUser,
+ jmsPassword, lookup);
+ connections.add(newConn);
+
+ // must be same as first connection to use same durable subscription
+ String newClientID = newConn.getClientID();
+ if (newClientID == null || !newClientID.equals(clientID)) {
+ try {
+ newConn.setClientID(clientID);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ logger.log(Logger.Level.INFO, "Warning: cannot set client ID to match first connection.\n"
+ + "Test may not be able to use same durable subscription");
+ }
+ }
+
+ TopicSession newTopicSess = newConn.createTopicSession(true, 0);
+ TopicSubscriber newSubscriber = newTopicSess.createDurableSubscriber(tool.getDefaultTopic(),
+ subscriptionName);
+
+ newConn.start();
+
+ logger.log(Logger.Level.TRACE, "receive message");
+ messageReceived = (TextMessage) newSubscriber.receive(timeout);
+ newTopicSess.commit();
+
+ newSubscriber.close();
+ newTopicSess.unsubscribe(subscriptionName);
+ newConn.close();
+
+ // check message
+ if (messageReceived == null) {
+ throw new Exception("Fail: Should have received message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
+ logger.log(Logger.Level.TRACE, "Pass: received message again, previous tx was rolled back");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ e.printStackTrace();
+ throw new Exception("txRollbackOnConnectionCloseReceiveTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: commitRollbackMultiMsgsTest
+ *
+ * @assertion_ids: JMS:JAVADOC:231; JMS:JAVADOC:221; JMS:JAVADOC:244;
+ * JMS:JAVADOC:242; JMS:JAVADOC:229; JMS:JAVADOC:504; JMS:JAVADOC:510;
+ * JMS:JAVADOC:597; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * ConnectionFactory.createConnection(String, String)
+ * Connection.createSession(boolean, int) Session.createTextMessage(String)
+ * Session.createConsumer(Destination) Session.createProducer(Destination)
+ * Session.commit() Session.rollback() MessageProducer.send(Message)
+ * MessagingConsumer.receive(long timeout)
+ *
+ * 1. Create Session with SESSION_TRANSACTED. This is done in the setup()
+ * routine. 2. Send x messages to a Topic. 3. Call rollback() to rollback the
+ * sent messages. 4. Create a MessageConsumer to consume the messages in the
+ * Topic. Should not receive any messages since the sent messages were rolled
+ * back. Verify that no messages are received. 5. Send x messages to a Topic. 6.
+ * Call commit() to commit the sent messages. 7. Create a MessageConsumer to
+ * consume the messages in the Topic. Should receive all the messages since the
+ * sent messages were committed. Verify that all messages are received.
+ */
+ @Test
+ public void commitRollbackMultiMsgsTest() throws Exception {
+ boolean pass = true;
+ int numMessages = 3;
+ try {
+ TextMessage tempMsg = null;
+
+ // set up JmsTool for COMMON_TTX setup
+ tool = new JmsTool(JmsTool.COMMON_TTX, jmsUser, jmsPassword, mode);
+ Destination destination = tool.getDefaultDestination();
+ Session session = tool.getDefaultSession();
+ Connection connection = tool.getDefaultConnection();
+ MessageProducer producer = tool.getDefaultProducer();
+ MessageConsumer consumer = tool.getDefaultConsumer();
+ Topic topic = (Topic) destination;
+ connection.start();
+
+ // Send "numMessages" messages to Topic and call rollback
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Topic and call rollback()");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "commitRollbackMultiMsgsTest" + i);
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ session.rollback();
+
+ logger.log(Logger.Level.INFO, "Should not consume any messages in Topic since rollback() was called");
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR,
+ "Received message " + tempMsg.getText() + ", expected NULL (NO MESSAGES)");
+ pass = false;
+ }
+
+ // Send "numMessages" messages to Topic and call commit
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Topic and call commit()");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "commitRollbackMultiMsgsTest" + i);
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ session.commit();
+
+ logger.log(Logger.Level.INFO, "Should consume all messages in Topic since commit() was called");
+ for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "MessageConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + msgCount + " missing from Topic");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + msgCount)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + msgCount + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message: " + tempMsg.getText());
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("commitRollbackMultiMsgsTest");
+ }
+
+ if (!pass) {
+ throw new Exception("commitRollbackMultiMsgsTest failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/bytesMsgQueue/BytesMsgQueueTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/bytesMsgQueue/BytesMsgQueueTests.java
deleted file mode 100644
index 3ae9edbb67..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/bytesMsgQueue/BytesMsgQueueTests.java
+++ /dev/null
@@ -1,652 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.bytesMsgQueue;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.MessageNotWriteableException;
-
-public class BytesMsgQueueTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.bytesMsgQueue.BytesMsgQueueTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- BytesMsgQueueTests theTests = new BytesMsgQueueTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(2);
- connections = new ArrayList(2);
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: bytesMsgNullStreamQTest
- *
- * @assertion_ids: JMS:SPEC:86.1; JMS:JAVADOC:714;
- *
- * @test_Strategy: create a byte message. Use writeObject to write a null.
- * verify a java.lang.NullPointerException is thrown.
- */
-
- public void bytesMsgNullStreamQTest() throws Exception {
- boolean pass = true;
- int nInt = 1000;
-
- try {
- BytesMessage messageSentBytesMessage = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- // BytesMessage
- try {
- logMsg(
- "Writing a null stream to byte message should throw a NullPointerException");
- messageSentBytesMessage = tool.getDefaultQueueSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "bytesMsgNullStreamQTest");
-
- // write a null to the message
- messageSentBytesMessage.writeObject(null);
- logMsg(
- "Fail: message did not throw NullPointerException exception as expected");
- pass = false;
- } catch (java.lang.NullPointerException np) {
- logTrace("Pass: NullPointerException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: bytesMsgNullStreamQTest test failure");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("bytesMsgNullStreamQTest");
- }
- }
-
- /*
- * @testName: bytesMessageQTestsFullMsg
- *
- * @assertion_ids: JMS:JAVADOC:560; JMS:JAVADOC:562; JMS:JAVADOC:564;
- * JMS:JAVADOC:566; JMS:JAVADOC:568; JMS:JAVADOC:570; JMS:JAVADOC:572;
- * JMS:JAVADOC:574; JMS:JAVADOC:576; JMS:JAVADOC:578; JMS:JAVADOC:580;
- * JMS:JAVADOC:582; JMS:JAVADOC:534; JMS:JAVADOC:536; JMS:JAVADOC:540;
- * JMS:JAVADOC:544; JMS:JAVADOC:546; JMS:JAVADOC:548; JMS:JAVADOC:550;
- * JMS:JAVADOC:552; JMS:JAVADOC:554; JMS:JAVADOC:556; JMS:JAVADOC:558;
- * JMS:JAVADOC:538; JMS:JAVADOC:542; JMS:JAVADOC:532;
- *
- * @test_Strategy: Create a BytesMessage -. write to the message using each
- * type of method and as an object. Send the message. Verify the data received
- * was as sent.
- *
- */
-
- public void bytesMessageQTestsFullMsg() throws Exception {
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = null;
- boolean pass = true;
- boolean booleanValue = false;
- byte byteValue = 127;
- byte byteValue1 = -12;
- int byteValue2 = 244;
- byte[] bytesValue = { 127, -127, 1, 0 };
- byte[] bytesValueRecvd = { 0, 0, 0, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- Integer nInteger = new Integer(-2147483648);
- short shortValue = -32768;
- short shortValue1 = -28679;
- int shortValue2 = 36857;
- String utfValue = "what";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createBytesMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "bytesMessageQTestsFullMsg");
-
- // -----------------------------------------------------------------------------
- logMsg("Writing one of each primitive type to the message");
-
- // -----------------------------------------------------------------------------
- messageSent.writeBoolean(booleanValue);
- messageSent.writeByte(byteValue);
- messageSent.writeByte(byteValue1);
- messageSent.writeChar(charValue);
- messageSent.writeDouble(doubleValue);
- messageSent.writeFloat(floatValue);
- messageSent.writeInt(intValue);
- messageSent.writeLong(longValue);
- messageSent.writeObject(nInteger);
- messageSent.writeShort(shortValue);
- messageSent.writeShort(shortValue1);
- messageSent.writeUTF(utfValue);
- messageSent.writeBytes(bytesValue);
- messageSent.writeBytes(bytesValue, 0, 1);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- try {
- if (messageReceived.readBoolean() == booleanValue) {
- logTrace("Pass: boolean returned ok");
- } else {
- logMsg("Fail: boolean not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readByte() == byteValue) {
- logTrace("Pass: Byte returned ok");
- } else {
- logMsg("Fail: Byte not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- int tmp = messageReceived.readUnsignedByte();
-
- if (tmp == byteValue2) {
- logTrace("Pass: Byte returned ok: " + byteValue2);
- } else {
- logMsg("Fail: readUnsignedByte not returned expected value: " + tmp);
- pass = false;
- }
- } catch (Exception e) {
- logErr("Error: unexpected exception" + "was thrown", e);
- pass = false;
- }
-
- try {
- if (messageReceived.readChar() == charValue) {
- logTrace("Pass: correct char");
- } else {
- logMsg("Fail: char not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readDouble() == doubleValue) {
- logTrace("Pass: correct double");
- } else {
- logMsg("Fail: double not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readFloat() == floatValue) {
- logTrace("Pass: correct float");
- } else {
- logMsg("Fail: float not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readInt() == intValue) {
- logTrace("Pass: correct int");
- } else {
- logMsg("Fail: int not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readLong() == longValue) {
- logTrace("Pass: correct long");
- } else {
- logMsg("Fail: long not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readInt() == nInteger.intValue()) {
- logTrace("Pass: correct Integer returned");
- } else {
- logMsg("Fail: Integer not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readShort() == shortValue) {
- logTrace("Pass: correct short");
- } else {
- logMsg("Fail: short not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- int tmps = messageReceived.readUnsignedShort();
- if (tmps == shortValue2) {
- logTrace("Pass: correct value returned by readUnsignedShort="
- + shortValue2);
- } else {
- logErr(
- "Fail: readUnsignedShort did not return expected value: " + tmps);
- pass = false;
- }
- } catch (Exception e) {
- logErr("Error: unexpected exception was thrown", e);
- pass = false;
- }
-
- try {
- if (messageReceived.readUTF().equals(utfValue)) {
- logTrace("Pass: correct UTF");
- } else {
- logMsg("Fail: UTF not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- int nCount = messageReceived.readBytes(bytesValueRecvd);
-
- for (int i = 0; i < nCount; i++) {
- if (bytesValueRecvd[i] != bytesValue[i]) {
- logMsg("Fail: bytes value incorrect");
- pass = false;
- } else {
- logTrace("Pass: byte value " + i + " ok");
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- int nCount = messageReceived.readBytes(bytesValueRecvd);
-
- logTrace("count returned " + nCount);
- if (bytesValueRecvd[0] != bytesValue[0]) {
- logMsg("Fail: bytes value incorrect");
- pass = false;
- } else {
- logTrace("Pass: byte value ok");
- }
- if (nCount == 1) {
- logTrace("Pass: correct count");
- } else {
- logMsg("Fail: count not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- long length = 37l;
- long tmpl = messageReceived.getBodyLength();
- if (tmpl < length) {
- logErr("getBodyLength test failed with incorrect length=" + tmpl);
- pass = false;
- }
- } catch (Exception e) {
- logErr("Error: getBodyLength test threw unexpected exception", e);
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("bytesMessageQTestsFullMsg", e);
- }
- }
-
- /*
- * @testName: bytesMessageQNotWriteable
- *
- * @assertion_ids: JMS:SPEC:73; JMS:JAVADOC:701; JMS:JAVADOC:702;
- * JMS:JAVADOC:703; JMS:JAVADOC:704; JMS:JAVADOC:705; JMS:JAVADOC:706;
- * JMS:JAVADOC:707; JMS:JAVADOC:708; JMS:JAVADOC:709; JMS:JAVADOC:710;
- * JMS:JAVADOC:711; JMS:JAVADOC:713;
- *
- * @test_Strategy: Create a BytesMessage - send it to a Queue. Write to the
- * received message using each type of method and as an object. Verify
- * MessageNotWriteableException thrown
- */
-
- public void bytesMessageQNotWriteable() throws Exception {
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = null;
- boolean pass = true;
- byte bValue = 127;
- byte[] bbValue = { 127, -127, 1, 0 };
- char cValue = 'Z';
- double dValue = 6.02e23;
- float fValue = 6.02e23f;
- int iValue = 2147483647;
- long lValue = 9223372036854775807L;
- short sValue = -32768;
- String ssValue = "what";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createBytesMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "bytesMessageQNotWriteable");
-
- messageSent.writeBytes(bbValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- logMsg("Writing a boolean ... ");
- try {
- messageReceived.writeBoolean(pass);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeBoolean");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeBoolean");
- }
-
- logMsg("Writing a byte ... ");
- try {
- messageReceived.writeByte(bValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeByte");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeByte");
- }
-
- logMsg("Writing a short ... ");
- try {
- messageReceived.writeShort(sValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeShort");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeShort");
- }
-
- logMsg("Writing a char ... ");
- try {
- messageReceived.writeChar(cValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeChar");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeChar");
- }
-
- logMsg("Writing a int ... ");
- try {
- messageReceived.writeInt(iValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeInt");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeInt");
- }
-
- logMsg("Writing a long ... ");
- try {
- messageReceived.writeLong(lValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeLong");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeLong");
- }
-
- logMsg("Writing a float ... ");
- try {
- messageReceived.writeFloat(fValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeFloat");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeFloat");
- }
-
- logMsg("Writing a double ... ");
- try {
- messageReceived.writeDouble(dValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeDouble");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeDouble");
- }
-
- logMsg("Writing a bytes... ");
- try {
- messageReceived.writeBytes(bbValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeBytes");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeBytes");
- }
-
- logMsg("Writing a bytes... ");
- try {
- messageReceived.writeBytes(bbValue, 0, 2);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeBytes");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeBytes");
- }
-
- logMsg("Writing a UTF ... ");
- try {
- messageReceived.writeUTF(ssValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeUTF");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeUTF");
- }
-
- logMsg("Writing a object ... ");
- try {
- messageReceived.writeObject(new Integer(iValue));
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeObject");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeObject");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("BytesMessageQueueNotWriteable", e);
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/bytesMsgQueue/BytesMsgQueueTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/bytesMsgQueue/BytesMsgQueueTestsIT.java
new file mode 100644
index 0000000000..451e0d4103
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/bytesMsgQueue/BytesMsgQueueTestsIT.java
@@ -0,0 +1,622 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.bytesMsgQueue;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.MessageNotWriteableException;
+
+
+public class BytesMsgQueueTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.bytesMsgQueue.BytesMsgQueueTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(BytesMsgQueueTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(2);
+ connections = new ArrayList(2);
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: bytesMsgNullStreamQTest
+ *
+ * @assertion_ids: JMS:SPEC:86.1; JMS:JAVADOC:714;
+ *
+ * @test_Strategy: create a byte message. Use writeObject to write a null.
+ * verify a java.lang.NullPointerException is thrown.
+ */
+ @Test
+ public void bytesMsgNullStreamQTest() throws Exception {
+ boolean pass = true;
+ int nInt = 1000;
+
+ try {
+ BytesMessage messageSentBytesMessage = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ // BytesMessage
+ try {
+ logger.log(Logger.Level.INFO,
+ "Writing a null stream to byte message should throw a NullPointerException");
+ messageSentBytesMessage = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "bytesMsgNullStreamQTest");
+
+ // write a null to the message
+ messageSentBytesMessage.writeObject(null);
+ logger.log(Logger.Level.INFO, "Fail: message did not throw NullPointerException exception as expected");
+ pass = false;
+ } catch (java.lang.NullPointerException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: bytesMsgNullStreamQTest test failure");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("bytesMsgNullStreamQTest");
+ }
+ }
+
+ /*
+ * @testName: bytesMessageQTestsFullMsg
+ *
+ * @assertion_ids: JMS:JAVADOC:560; JMS:JAVADOC:562; JMS:JAVADOC:564;
+ * JMS:JAVADOC:566; JMS:JAVADOC:568; JMS:JAVADOC:570; JMS:JAVADOC:572;
+ * JMS:JAVADOC:574; JMS:JAVADOC:576; JMS:JAVADOC:578; JMS:JAVADOC:580;
+ * JMS:JAVADOC:582; JMS:JAVADOC:534; JMS:JAVADOC:536; JMS:JAVADOC:540;
+ * JMS:JAVADOC:544; JMS:JAVADOC:546; JMS:JAVADOC:548; JMS:JAVADOC:550;
+ * JMS:JAVADOC:552; JMS:JAVADOC:554; JMS:JAVADOC:556; JMS:JAVADOC:558;
+ * JMS:JAVADOC:538; JMS:JAVADOC:542; JMS:JAVADOC:532;
+ *
+ * @test_Strategy: Create a BytesMessage -. write to the message using each type
+ * of method and as an object. Send the message. Verify the data received was as
+ * sent.
+ *
+ */
+ @Test
+ public void bytesMessageQTestsFullMsg() throws Exception {
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = null;
+ boolean pass = true;
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte byteValue1 = -12;
+ int byteValue2 = 244;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ byte[] bytesValueRecvd = { 0, 0, 0, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ Integer nInteger = new Integer(-2147483648);
+ short shortValue = -32768;
+ short shortValue1 = -28679;
+ int shortValue2 = 36857;
+ String utfValue = "what";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createBytesMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "bytesMessageQTestsFullMsg");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Writing one of each primitive type to the message");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeBoolean(booleanValue);
+ messageSent.writeByte(byteValue);
+ messageSent.writeByte(byteValue1);
+ messageSent.writeChar(charValue);
+ messageSent.writeDouble(doubleValue);
+ messageSent.writeFloat(floatValue);
+ messageSent.writeInt(intValue);
+ messageSent.writeLong(longValue);
+ messageSent.writeObject(nInteger);
+ messageSent.writeShort(shortValue);
+ messageSent.writeShort(shortValue1);
+ messageSent.writeUTF(utfValue);
+ messageSent.writeBytes(bytesValue);
+ messageSent.writeBytes(bytesValue, 0, 1);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ try {
+ if (messageReceived.readBoolean() == booleanValue) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean returned ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: boolean not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readByte() == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: Byte returned ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Byte not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ int tmp = messageReceived.readUnsignedByte();
+
+ if (tmp == byteValue2) {
+ logger.log(Logger.Level.TRACE, "Pass: Byte returned ok: " + byteValue2);
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: readUnsignedByte not returned expected value: " + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception" + "was thrown", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readChar() == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct char");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: char not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readDouble() == doubleValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct double");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: double not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readFloat() == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct float");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: float not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readInt() == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct int");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: int not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readLong() == longValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct long");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: long not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readInt() == nInteger.intValue()) {
+ logger.log(Logger.Level.TRACE, "Pass: correct Integer returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Integer not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readShort() == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct short");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: short not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ int tmps = messageReceived.readUnsignedShort();
+ if (tmps == shortValue2) {
+ logger.log(Logger.Level.TRACE, "Pass: correct value returned by readUnsignedShort=" + shortValue2);
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: readUnsignedShort did not return expected value: " + tmps);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readUTF().equals(utfValue)) {
+ logger.log(Logger.Level.TRACE, "Pass: correct UTF");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: UTF not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ int nCount = messageReceived.readBytes(bytesValueRecvd);
+
+ for (int i = 0; i < nCount; i++) {
+ if (bytesValueRecvd[i] != bytesValue[i]) {
+ logger.log(Logger.Level.INFO, "Fail: bytes value incorrect");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte value " + i + " ok");
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ int nCount = messageReceived.readBytes(bytesValueRecvd);
+
+ logger.log(Logger.Level.TRACE, "count returned " + nCount);
+ if (bytesValueRecvd[0] != bytesValue[0]) {
+ logger.log(Logger.Level.INFO, "Fail: bytes value incorrect");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte value ok");
+ }
+ if (nCount == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: correct count");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: count not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ long length = 37l;
+ long tmpl = messageReceived.getBodyLength();
+ if (tmpl < length) {
+ logger.log(Logger.Level.ERROR, "getBodyLength test failed with incorrect length=" + tmpl);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: getBodyLength test threw unexpected exception", e);
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("bytesMessageQTestsFullMsg", e);
+ }
+ }
+
+ /*
+ * @testName: bytesMessageQNotWriteable
+ *
+ * @assertion_ids: JMS:SPEC:73; JMS:JAVADOC:701; JMS:JAVADOC:702;
+ * JMS:JAVADOC:703; JMS:JAVADOC:704; JMS:JAVADOC:705; JMS:JAVADOC:706;
+ * JMS:JAVADOC:707; JMS:JAVADOC:708; JMS:JAVADOC:709; JMS:JAVADOC:710;
+ * JMS:JAVADOC:711; JMS:JAVADOC:713;
+ *
+ * @test_Strategy: Create a BytesMessage - send it to a Queue. Write to the
+ * received message using each type of method and as an object. Verify
+ * MessageNotWriteableException thrown
+ */
+ @Test
+ public void bytesMessageQNotWriteable() throws Exception {
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = null;
+ boolean pass = true;
+ byte bValue = 127;
+ byte[] bbValue = { 127, -127, 1, 0 };
+ char cValue = 'Z';
+ double dValue = 6.02e23;
+ float fValue = 6.02e23f;
+ int iValue = 2147483647;
+ long lValue = 9223372036854775807L;
+ short sValue = -32768;
+ String ssValue = "what";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createBytesMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "bytesMessageQNotWriteable");
+
+ messageSent.writeBytes(bbValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ logger.log(Logger.Level.INFO, "Writing a boolean ... ");
+ try {
+ messageReceived.writeBoolean(pass);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeBoolean");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeBoolean");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a byte ... ");
+ try {
+ messageReceived.writeByte(bValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeByte");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeByte");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a short ... ");
+ try {
+ messageReceived.writeShort(sValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeShort");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeShort");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a char ... ");
+ try {
+ messageReceived.writeChar(cValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeChar");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeChar");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a int ... ");
+ try {
+ messageReceived.writeInt(iValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeInt");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeInt");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a long ... ");
+ try {
+ messageReceived.writeLong(lValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeLong");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeLong");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a float ... ");
+ try {
+ messageReceived.writeFloat(fValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeFloat");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeFloat");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a double ... ");
+ try {
+ messageReceived.writeDouble(dValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeDouble");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeDouble");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageReceived.writeBytes(bbValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeBytes");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageReceived.writeBytes(bbValue, 0, 2);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeBytes");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a UTF ... ");
+ try {
+ messageReceived.writeUTF(ssValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeUTF");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeUTF");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a object ... ");
+ try {
+ messageReceived.writeObject(new Integer(iValue));
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeObject");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeObject");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("BytesMessageQueueNotWriteable", e);
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/bytesMsgTopic/BytesMsgTopicTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/bytesMsgTopic/BytesMsgTopicTests.java
deleted file mode 100644
index e638491c43..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/bytesMsgTopic/BytesMsgTopicTests.java
+++ /dev/null
@@ -1,596 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.bytesMsgTopic;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.MessageNotWriteableException;
-
-public class BytesMsgTopicTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.bytesMsgTopic.BytesMsgTopicTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- BytesMsgTopicTests theTests = new BytesMsgTopicTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
-
- // get ready for new test
- logMsg("Getting Administrator and deleting any leftover destinations.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: bytesMsgNullStreamTopicTest
- *
- * @assertion_ids: JMS:SPEC:86.1; JMS:JAVADOC:714;
- *
- * @test_Strategy: create a byte message. Use writeObject to write a null.
- * verify a java.lang.NullPointerException is thrown.
- */
-
- public void bytesMsgNullStreamTopicTest() throws Exception {
- boolean pass = true;
- int nInt = 1000;
-
- try {
- BytesMessage messageSentBytesMessage = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
-
- // BytesMessage
- try {
- logMsg(
- "Writing a null stream to byte message should throw a NullPointerException");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "bytesMsgNullStreamTopicTest");
-
- // write a null to the message
- messageSentBytesMessage.writeObject(null);
- logMsg(
- "Fail: message did not throw NullPointerException exception as expected");
- pass = false;
- } catch (java.lang.NullPointerException np) {
- logTrace("Pass: NullPointerException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: bytesMsgNullStreamTopicTest test failure");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("bytesMsgNullStreamTopicTest");
- }
- }
-
- /*
- * @testName: bytesMessageTopicTestsFullMsg
- *
- * @assertion_ids: JMS:JAVADOC:560; JMS:JAVADOC:562; JMS:JAVADOC:564;
- * JMS:JAVADOC:566; JMS:JAVADOC:568; JMS:JAVADOC:570; JMS:JAVADOC:572;
- * JMS:JAVADOC:574; JMS:JAVADOC:576; JMS:JAVADOC:578; JMS:JAVADOC:580;
- * JMS:JAVADOC:582; JMS:JAVADOC:534; JMS:JAVADOC:536; JMS:JAVADOC:540;
- * JMS:JAVADOC:544; JMS:JAVADOC:546; JMS:JAVADOC:548; JMS:JAVADOC:550;
- * JMS:JAVADOC:552; JMS:JAVADOC:554; JMS:JAVADOC:556; JMS:JAVADOC:558;
- *
- * @test_Strategy: Create a BytesMessage -. write to the message using each
- * type of method and as an object. Send the message. Verify the data received
- * was as sent.
- *
- */
-
- public void bytesMessageTopicTestsFullMsg() throws Exception {
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = null;
- boolean pass = true;
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- byte[] bytesValueRecvd = { 0, 0, 0, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- Integer nInteger = new Integer(-2147483648);
- short shortValue = -32768;
- String utfValue = "what";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createBytesMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "bytesMessageTopicTestsFullMsg");
-
- // -----------------------------------------------------------------------------
- logMsg("Writing one of each primitive type to the message");
-
- // -----------------------------------------------------------------------------
- messageSent.writeBoolean(booleanValue);
- messageSent.writeByte(byteValue);
- messageSent.writeChar(charValue);
- messageSent.writeDouble(doubleValue);
- messageSent.writeFloat(floatValue);
- messageSent.writeInt(intValue);
- messageSent.writeLong(longValue);
- messageSent.writeObject(nInteger);
- messageSent.writeShort(shortValue);
- messageSent.writeUTF(utfValue);
- messageSent.writeBytes(bytesValue);
- messageSent.writeBytes(bytesValue, 0, 1);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (BytesMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- try {
- if (messageReceived.readBoolean() == booleanValue) {
- logTrace("Pass: boolean returned ok");
- } else {
- logMsg("Fail: boolean not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readByte() == byteValue) {
- logTrace("Pass: Byte returned ok");
- } else {
- logMsg("Fail: Byte not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readChar() == charValue) {
- logTrace("Pass: correct char");
- } else {
- logMsg("Fail: char not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readDouble() == doubleValue) {
- logTrace("Pass: correct double");
- } else {
- logMsg("Fail: double not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readFloat() == floatValue) {
- logTrace("Pass: correct float");
- } else {
- logMsg("Fail: float not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readInt() == intValue) {
- logTrace("Pass: correct int");
- } else {
- logMsg("Fail: int not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readLong() == longValue) {
- logTrace("Pass: correct long");
- } else {
- logMsg("Fail: long not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readInt() == nInteger.intValue()) {
- logTrace("Pass: correct Integer returned");
- } else {
- logMsg("Fail: Integer not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readShort() == shortValue) {
- logTrace("Pass: correct short");
- } else {
- logMsg("Fail: short not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readUTF().equals(utfValue)) {
- logTrace("Pass: correct UTF");
- } else {
- logMsg("Fail: UTF not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- int nCount = messageReceived.readBytes(bytesValueRecvd);
-
- for (int i = 0; i < nCount; i++) {
- if (bytesValueRecvd[i] != bytesValue[i]) {
- logMsg("Fail: bytes value incorrect");
- pass = false;
- } else {
- logTrace("Pass: byte value " + i + " ok");
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- int nCount = messageReceived.readBytes(bytesValueRecvd);
-
- logTrace("count returned " + nCount);
- if (bytesValueRecvd[0] != bytesValue[0]) {
- logMsg("Fail: bytes value incorrect");
- pass = false;
- } else {
- logTrace("Pass: byte value ok");
- }
- if (nCount == 1) {
- logTrace("Pass: correct count");
- } else {
- logMsg("Fail: count not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("bytesMessageTopicTestsFullMsg", e);
- }
- }
-
- /*
- * @testName: bytesMessageTNotWriteable
- *
- * @assertion_ids: JMS:SPEC:73; JMS:JAVADOC:701; JMS:JAVADOC:702;
- * JMS:JAVADOC:703; JMS:JAVADOC:704; JMS:JAVADOC:705; JMS:JAVADOC:706;
- * JMS:JAVADOC:707; JMS:JAVADOC:708; JMS:JAVADOC:709; JMS:JAVADOC:710;
- * JMS:JAVADOC:711; JMS:JAVADOC:713;
- *
- * @test_Strategy: Create a BytesMessage - send it to a Topic. Write to the
- * received message using each type of method and as an object. Verify
- * MessageNotWriteableException thrown
- */
-
- public void bytesMessageTNotWriteable() throws Exception {
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = null;
- boolean pass = true;
- byte bValue = 127;
- byte[] bbValue = { 127, -127, 1, 0 };
- char cValue = 'Z';
- double dValue = 6.02e23;
- float fValue = 6.02e23f;
- int iValue = 2147483647;
- long lValue = 9223372036854775807L;
- short sValue = -32768;
- String ssValue = "what";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createBytesMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "bytesMessageTNotWriteable");
-
- messageSent.writeBytes(bbValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (BytesMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- logMsg("Writing a boolean ... ");
- try {
- messageReceived.writeBoolean(pass);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeBoolean");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeBoolean");
- }
-
- logMsg("Writing a byte ... ");
- try {
- messageReceived.writeByte(bValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeByte");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeByte");
- }
-
- logMsg("Writing a short ... ");
- try {
- messageReceived.writeShort(sValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeShort");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeShort");
- }
-
- logMsg("Writing a char ... ");
- try {
- messageReceived.writeChar(cValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeChar");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeChar");
- }
-
- logMsg("Writing a int ... ");
- try {
- messageReceived.writeInt(iValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeInt");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeInt");
- }
-
- logMsg("Writing a long ... ");
- try {
- messageReceived.writeLong(lValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeLong");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeLong");
- }
-
- logMsg("Writing a float ... ");
- try {
- messageReceived.writeFloat(fValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeFloat");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeFloat");
- }
-
- logMsg("Writing a double ... ");
- try {
- messageReceived.writeDouble(dValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeDouble");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeDouble");
- }
-
- logMsg("Writing a bytes... ");
- try {
- messageReceived.writeBytes(bbValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeBytes");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeBytes");
- }
-
- logMsg("Writing a bytes... ");
- try {
- messageReceived.writeBytes(bbValue, 0, 2);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeBytes");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeBytes");
- }
-
- logMsg("Writing a UTF ... ");
- try {
- messageReceived.writeUTF(ssValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeUTF");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeUTF");
- }
-
- logMsg("Writing a object ... ");
- try {
- messageReceived.writeObject(new Integer(iValue));
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeObject");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeObject");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("BytesMessageQueueNotWriteable", e);
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/bytesMsgTopic/BytesMsgTopicTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/bytesMsgTopic/BytesMsgTopicTestsIT.java
new file mode 100644
index 0000000000..318825ee06
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/bytesMsgTopic/BytesMsgTopicTestsIT.java
@@ -0,0 +1,568 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.bytesMsgTopic;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.MessageNotWriteableException;
+
+
+public class BytesMsgTopicTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.bytesMsgTopic.BytesMsgTopicTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(BytesMsgTopicTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+
+ // get ready for new test
+ logger.log(Logger.Level.INFO, "Getting Administrator and deleting any leftover destinations.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: bytesMsgNullStreamTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:86.1; JMS:JAVADOC:714;
+ *
+ * @test_Strategy: create a byte message. Use writeObject to write a null.
+ * verify a java.lang.NullPointerException is thrown.
+ */
+ @Test
+ public void bytesMsgNullStreamTopicTest() throws Exception {
+ boolean pass = true;
+ int nInt = 1000;
+
+ try {
+ BytesMessage messageSentBytesMessage = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+
+ // BytesMessage
+ try {
+ logger.log(Logger.Level.INFO,
+ "Writing a null stream to byte message should throw a NullPointerException");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "bytesMsgNullStreamTopicTest");
+
+ // write a null to the message
+ messageSentBytesMessage.writeObject(null);
+ logger.log(Logger.Level.INFO, "Fail: message did not throw NullPointerException exception as expected");
+ pass = false;
+ } catch (java.lang.NullPointerException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: bytesMsgNullStreamTopicTest test failure");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("bytesMsgNullStreamTopicTest");
+ }
+ }
+
+ /*
+ * @testName: bytesMessageTopicTestsFullMsg
+ *
+ * @assertion_ids: JMS:JAVADOC:560; JMS:JAVADOC:562; JMS:JAVADOC:564;
+ * JMS:JAVADOC:566; JMS:JAVADOC:568; JMS:JAVADOC:570; JMS:JAVADOC:572;
+ * JMS:JAVADOC:574; JMS:JAVADOC:576; JMS:JAVADOC:578; JMS:JAVADOC:580;
+ * JMS:JAVADOC:582; JMS:JAVADOC:534; JMS:JAVADOC:536; JMS:JAVADOC:540;
+ * JMS:JAVADOC:544; JMS:JAVADOC:546; JMS:JAVADOC:548; JMS:JAVADOC:550;
+ * JMS:JAVADOC:552; JMS:JAVADOC:554; JMS:JAVADOC:556; JMS:JAVADOC:558;
+ *
+ * @test_Strategy: Create a BytesMessage -. write to the message using each type
+ * of method and as an object. Send the message. Verify the data received was as
+ * sent.
+ *
+ */
+ @Test
+ public void bytesMessageTopicTestsFullMsg() throws Exception {
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = null;
+ boolean pass = true;
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ byte[] bytesValueRecvd = { 0, 0, 0, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ Integer nInteger = new Integer(-2147483648);
+ short shortValue = -32768;
+ String utfValue = "what";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createBytesMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "bytesMessageTopicTestsFullMsg");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Writing one of each primitive type to the message");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeBoolean(booleanValue);
+ messageSent.writeByte(byteValue);
+ messageSent.writeChar(charValue);
+ messageSent.writeDouble(doubleValue);
+ messageSent.writeFloat(floatValue);
+ messageSent.writeInt(intValue);
+ messageSent.writeLong(longValue);
+ messageSent.writeObject(nInteger);
+ messageSent.writeShort(shortValue);
+ messageSent.writeUTF(utfValue);
+ messageSent.writeBytes(bytesValue);
+ messageSent.writeBytes(bytesValue, 0, 1);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ try {
+ if (messageReceived.readBoolean() == booleanValue) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean returned ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: boolean not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readByte() == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: Byte returned ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Byte not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readChar() == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct char");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: char not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readDouble() == doubleValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct double");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: double not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readFloat() == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct float");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: float not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readInt() == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct int");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: int not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readLong() == longValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct long");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: long not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readInt() == nInteger.intValue()) {
+ logger.log(Logger.Level.TRACE, "Pass: correct Integer returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Integer not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readShort() == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct short");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: short not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readUTF().equals(utfValue)) {
+ logger.log(Logger.Level.TRACE, "Pass: correct UTF");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: UTF not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ int nCount = messageReceived.readBytes(bytesValueRecvd);
+
+ for (int i = 0; i < nCount; i++) {
+ if (bytesValueRecvd[i] != bytesValue[i]) {
+ logger.log(Logger.Level.INFO, "Fail: bytes value incorrect");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte value " + i + " ok");
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ int nCount = messageReceived.readBytes(bytesValueRecvd);
+
+ logger.log(Logger.Level.TRACE, "count returned " + nCount);
+ if (bytesValueRecvd[0] != bytesValue[0]) {
+ logger.log(Logger.Level.INFO, "Fail: bytes value incorrect");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte value ok");
+ }
+ if (nCount == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: correct count");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: count not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("bytesMessageTopicTestsFullMsg", e);
+ }
+ }
+
+ /*
+ * @testName: bytesMessageTNotWriteable
+ *
+ * @assertion_ids: JMS:SPEC:73; JMS:JAVADOC:701; JMS:JAVADOC:702;
+ * JMS:JAVADOC:703; JMS:JAVADOC:704; JMS:JAVADOC:705; JMS:JAVADOC:706;
+ * JMS:JAVADOC:707; JMS:JAVADOC:708; JMS:JAVADOC:709; JMS:JAVADOC:710;
+ * JMS:JAVADOC:711; JMS:JAVADOC:713;
+ *
+ * @test_Strategy: Create a BytesMessage - send it to a Topic. Write to the
+ * received message using each type of method and as an object. Verify
+ * MessageNotWriteableException thrown
+ */
+ @Test
+ public void bytesMessageTNotWriteable() throws Exception {
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = null;
+ boolean pass = true;
+ byte bValue = 127;
+ byte[] bbValue = { 127, -127, 1, 0 };
+ char cValue = 'Z';
+ double dValue = 6.02e23;
+ float fValue = 6.02e23f;
+ int iValue = 2147483647;
+ long lValue = 9223372036854775807L;
+ short sValue = -32768;
+ String ssValue = "what";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createBytesMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "bytesMessageTNotWriteable");
+
+ messageSent.writeBytes(bbValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ logger.log(Logger.Level.INFO, "Writing a boolean ... ");
+ try {
+ messageReceived.writeBoolean(pass);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeBoolean");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeBoolean");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a byte ... ");
+ try {
+ messageReceived.writeByte(bValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeByte");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeByte");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a short ... ");
+ try {
+ messageReceived.writeShort(sValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeShort");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeShort");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a char ... ");
+ try {
+ messageReceived.writeChar(cValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeChar");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeChar");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a int ... ");
+ try {
+ messageReceived.writeInt(iValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeInt");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeInt");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a long ... ");
+ try {
+ messageReceived.writeLong(lValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeLong");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeLong");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a float ... ");
+ try {
+ messageReceived.writeFloat(fValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeFloat");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeFloat");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a double ... ");
+ try {
+ messageReceived.writeDouble(dValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeDouble");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeDouble");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageReceived.writeBytes(bbValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeBytes");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageReceived.writeBytes(bbValue, 0, 2);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeBytes");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a UTF ... ");
+ try {
+ messageReceived.writeUTF(ssValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeUTF");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeUTF");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a object ... ");
+ try {
+ messageReceived.writeObject(new Integer(iValue));
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeObject");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeObject");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("BytesMessageQueueNotWriteable", e);
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueConnection/ClosedQueueConnectionTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueConnection/ClosedQueueConnectionTests.java
deleted file mode 100644
index bf95494852..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueConnection/ClosedQueueConnectionTests.java
+++ /dev/null
@@ -1,1815 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.closedQueueConnection;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.common.MessageTestImpl;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.ConnectionMetaData;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueBrowser;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueSender;
-import jakarta.jms.QueueSession;
-import jakarta.jms.Session;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TemporaryQueue;
-import jakarta.jms.TextMessage;
-
-/**
- * JMS TS tests. Testing method calls on closed QueueConnection objects.
- */
-public class ClosedQueueConnectionTests extends ServiceEETest {
- private static final String TestName = "com.sun.ts.tests.jms.core.closedQueueConnection.ClosedQueueConnectionTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- boolean jmsOptionalApisSupported;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ClosedQueueConnectionTests theTests = new ClosedQueueConnectionTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed connection for testing. Passes any
- * exceptions up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndCloseConnection(int type) throws Exception {
- if ((type == JmsTool.QUEUE) || (type == JmsTool.TX_QUEUE)) {
- tool = new JmsTool(type, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- logTrace("Closing queue Connection");
- tool.getDefaultQueueConnection().close();
- }
- logTrace("Connection closed");
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default
- * QueueConnection, as well as a default Queue. Tests that require multiple
- * Destinations create the extras within the test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'users' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(2);
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing QueueConnections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: closedQueueConnectionCommitTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:SPEC:113; JMS:JAVADOC:270;
- * JMS:JAVADOC:526; JMS:JAVADOC:274; JMS:JAVADOC:229;
- *
- * @test_Strategy: Close default connection and call the commit method on
- * session associated with it. Check for IllegalStateException.
- */
-
- public void closedQueueConnectionCommitTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TX_QUEUE);
- logTrace("Try to call commit with closed connection.");
- try {
- tool.getDefaultQueueSession().commit();
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueConnectionCommitTest");
- }
- }
-
- /*
- * @testName: closedQueueConnectionGetTransactedTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:SPEC:113; JMS:JAVADOC:270;
- * JMS:JAVADOC:526; JMS:JAVADOC:225; JMS:JAVADOC:274;
- *
- * @test_Strategy: Close default connection and call the getTransacted method
- * on a QueueSession associated with it. Check for IllegalStateException.
- */
-
- public void closedQueueConnectionGetTransactedTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getTransacted() with closed connection.");
- try {
- boolean b = tool.getDefaultQueueSession().getTransacted();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionGetTransactedTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionRollbackTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:SPEC:113; JMS:JAVADOC:270;
- * JMS:JAVADOC:526; JMS:JAVADOC:274; JMS:JAVADOC:231;
- *
- * @test_Strategy: Close default connection and call the rollback method on a
- * QueueSession associated with it. Check for IllegalStateException.
- */
-
- public void closedQueueConnectionRollbackTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call rollback() with closed connection.");
- try {
- tool.getDefaultQueueSession().rollback();
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionRollbackTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionRecoverTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:SPEC:113; JMS:JAVADOC:270;
- * JMS:JAVADOC:526; JMS:JAVADOC:274; JMS:JAVADOC:235;
- *
- * @test_Strategy: Close default connection and call the recover method on a
- * QueueSession associated with it. Check for IllegalStateException.
- */
-
- public void closedQueueConnectionRecoverTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call recover() with closed connection.");
- try {
- tool.getDefaultQueueSession().recover();
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionRecoverTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCloseTest
- *
- * @assertion_ids: JMS:SPEC:108; JMS:JAVADOC:274; JMS:JAVADOC:526;
- *
- * @test_Strategy: Close default Connection and call method on it.
- */
-
- public void closedQueueConnectionCloseTest() throws Exception {
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call close again");
- tool.getDefaultQueueConnection().close();
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCloseTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionGetClientIDTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:512;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionGetClientIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getClientID");
- try {
- String foo = tool.getDefaultQueueConnection().getClientID();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionGetClientIDTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionGetMetaDataTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:516;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionGetMetaDataTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getMetaData");
- try {
- ConnectionMetaData foo = tool.getDefaultQueueConnection().getMetaData();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionGetMetaDataTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionStartTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:522;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionStartTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call start");
- try {
- tool.getDefaultQueueConnection().start();
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionStartTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateQueueSessionTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateQueueSessionTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call createQueueSession");
- try {
- QueueSession foo = tool.getDefaultQueueConnection()
- .createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.logErr("Fail: wrong exception was returned", e);
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateQueueSessionTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSessionCloseTest
- *
- * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:SPEC:114;
- *
- * @test_Strategy: Close default connection and call method on it.
- */
-
- public void closedQueueConnectionSessionCloseTest() throws Exception {
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to close session again.");
- tool.getDefaultQueueSession().close();
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSessionCloseTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateBrowserTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:190;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateBrowserTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create QueueBrowser with closed connection.");
- try {
- QueueBrowser qB = tool.getDefaultQueueSession()
- .createBrowser(tool.getDefaultQueue());
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateBrowserTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateBrowserMsgSelectorTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:192;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateBrowserMsgSelectorTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create QueueBrowser with closed Connection.");
- try {
- QueueBrowser qB = tool.getDefaultQueueSession()
- .createBrowser(tool.getDefaultQueue(), "TEST = 'test'");
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateBrowserMsgSelectorTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateQueueTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:182;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateQueueTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create queue with closed Connection.");
- try {
- Queue q = tool.getDefaultQueueSession()
- .createQueue("closedQueueConnectionCreateQueueTest");
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateQueueTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateReceiverTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:184;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateReceiverTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create Receiver with closed Connection.");
- try {
- QueueReceiver qR = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue());
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateReceiverTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateReceiverMsgSelectorTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:186;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateReceiverMsgSelectorTest()
- throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create Receiver with closed Connection.");
- try {
- QueueReceiver qR = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue(), "TEST = 'test'");
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateReceiverMsgSelectorTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateSenderTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:188;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateSenderTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create Sender with closed Connection.");
- try {
- QueueSender qS = tool.getDefaultQueueSession()
- .createSender(tool.getDefaultQueue());
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateSenderTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateTempQueueTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:194;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateTempQueueTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create TemporaryQueue with closed connection.");
- try {
- TemporaryQueue tQ = tool.getDefaultQueueSession()
- .createTemporaryQueue();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateTempQueueTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateMessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:213;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create message with closed connection.");
- try {
- Message m = tool.getDefaultQueueSession().createMessage();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateMessageTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateBytesMessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:209;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateBytesMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create BytesMessage with closed connection.");
- try {
- BytesMessage m = tool.getDefaultQueueSession().createBytesMessage();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateBytesMessageTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateMapMessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:211;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateMapMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create MapMessage with closed connection.");
- try {
- MapMessage m = tool.getDefaultQueueSession().createMapMessage();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateMapMessageTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateObjectMessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:215;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateObjectMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create ObjectMessage with closed connection.");
- try {
- ObjectMessage m = tool.getDefaultQueueSession().createObjectMessage();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateObjectMessageTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateObject2MessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:217;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateObject2MessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create ObjectMessage(object) with closed connection.");
- try {
- String s = "Simple object";
- ObjectMessage m = tool.getDefaultQueueSession().createObjectMessage(s);
- if (m != null)
- logTrace("m=" + m);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateObject2MessageTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateStreamMessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:219;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateStreamMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create StreamMessage with closed connection.");
- try {
- StreamMessage m = tool.getDefaultQueueSession().createStreamMessage();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateStreamMessageTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateTextMessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:221;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateTextMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create TextMessage with closed connection.");
- try {
- TextMessage m = tool.getDefaultQueueSession().createTextMessage();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateTextMessageTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionCreateText2MessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:SPEC:113; JMS:JAVADOC:223;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionCreateText2MessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to create TextMessage with closed connection.");
- try {
- TextMessage m = tool.getDefaultQueueSession()
- .createTextMessage("test message");
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionCreateText2MessageTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionReceiverCloseTest
- *
- * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:338;
- *
- * @test_Strategy: Close default receiver and call method on it.
- */
-
- public void closedQueueConnectionReceiverCloseTest() throws Exception {
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call close again");
- tool.getDefaultQueueReceiver().close();
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionReceiverCloseTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionGetMessageSelectorTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:326;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionGetMessageSelectorTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getMessageSelector");
- try {
- String foo = tool.getDefaultQueueReceiver().getMessageSelector();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionGetMessageSelectorTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionReceiveTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:332;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionReceiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call receive");
- try {
- Message foo = tool.getDefaultQueueReceiver().receive();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionReceiveTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionReceiveTimeoutTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:334;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionReceiveTimeoutTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call receive(timeout)");
- try {
- Message foo = tool.getDefaultQueueReceiver().receive(timeout);
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionReceiveTimeoutTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionReceiveNoWaitTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:337;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionReceiveNoWaitTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call receiveNoWait");
- try {
- Message foo = tool.getDefaultQueueReceiver().receiveNoWait();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionReceiveNoWaitTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionReceiverGetQueueTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:268;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionReceiverGetQueueTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getQueue");
- try {
- Queue foo = tool.getDefaultQueueReceiver().getQueue();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionReceiverGetQueueTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSenderCloseTest
- *
- * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:315;
- *
- * @test_Strategy: Close default sender and call method on it.
- */
-
- public void closedQueueConnectionSenderCloseTest() throws Exception {
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call close again");
- tool.getDefaultQueueSender().close();
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSenderCloseTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionGetDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:303;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionGetDeliveryModeTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getDeliveryMode");
- try {
- int foo = tool.getDefaultQueueSender().getDeliveryMode();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionGetDeliveryModeTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionGetDisableMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:295;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionGetDisableMessageIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getDisableMessageID");
- try {
- boolean foo = tool.getDefaultQueueSender().getDisableMessageID();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionGetDisableMessageIDTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionGetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:299;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionGetDisableMessageTimestampTest()
- throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getDisableMessageTimestamp");
- try {
- boolean foo = tool.getDefaultQueueSender().getDisableMessageTimestamp();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionGetDisableMessageTimestampTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionGetPriorityTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:307;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionGetPriorityTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getPriority");
- try {
- int foo = tool.getDefaultQueueSender().getPriority();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionGetPriorityTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionGetTimeToLiveTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:311;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionGetTimeToLiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getTimeToLive");
- try {
- long foo = tool.getDefaultQueueSender().getTimeToLive();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionGetTimeToLiveTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSetDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:301;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionSetDeliveryModeTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call setDeliveryMode");
- try {
- tool.getDefaultQueueSender()
- .setDeliveryMode(Message.DEFAULT_DELIVERY_MODE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSetDeliveryModeTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSetDisableMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:293;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionSetDisableMessageIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call setDisableMessageID");
- try {
- tool.getDefaultQueueSender().setDisableMessageID(true);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSetDisableMessageIDTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:297;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionSetDisableMessageTimestampTest()
- throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call setDisableMessageTimestamp");
- try {
- tool.getDefaultQueueSender().setDisableMessageTimestamp(true);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSetDisableMessageTimestampTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSetPriorityTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:305;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionSetPriorityTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call setPriority");
- try {
- tool.getDefaultQueueSender().setPriority(Message.DEFAULT_PRIORITY);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSetPriorityTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSetTimeToLiveTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:309;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionSetTimeToLiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call setTimeToLive");
- try {
- tool.getDefaultQueueSender()
- .setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSetTimeToLiveTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSenderGetQueueTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:196;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionSenderGetQueueTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call getQueue");
- try {
- Queue foo = tool.getDefaultQueueSender().getQueue();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSenderGetQueueTest", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSend1Test
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:198;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionSend1Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call send(Message)");
- try {
- tool.getDefaultQueueSender().send(new MessageTestImpl());
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSend1Test", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSend2Test
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:200;
- *
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionSend2Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call send(Message,int,int,long)");
- try {
- tool.getDefaultQueueSender().send(new MessageTestImpl(),
- Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
- Message.DEFAULT_TIME_TO_LIVE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSend2Test", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSend3Test
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:202;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionSend3Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call send(Queue,Message)");
- try {
- tool.getDefaultQueueSender().send(new MessageTestImpl());
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSend3Test", e);
- }
- }
-
- /*
- * @testName: closedQueueConnectionSend4Test
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
- * JMS:JAVADOC:204;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueConnectionSend4Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.QUEUE);
- logTrace("Try to call send(Queue,Message,int,int,long)");
- try {
- tool.getDefaultQueueSender().send(new MessageTestImpl(),
- Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
- Message.DEFAULT_TIME_TO_LIVE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueConnectionSend4Test", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueConnection/ClosedQueueConnectionTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueConnection/ClosedQueueConnectionTestsIT.java
new file mode 100644
index 0000000000..d0852ef6f9
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueConnection/ClosedQueueConnectionTestsIT.java
@@ -0,0 +1,1748 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.closedQueueConnection;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.common.MessageTestImpl;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.ConnectionMetaData;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueBrowser;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueSender;
+import jakarta.jms.QueueSession;
+import jakarta.jms.Session;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TemporaryQueue;
+import jakarta.jms.TextMessage;
+
+/**
+ * JMS TS tests. Testing method calls on closed QueueConnection objects.
+ */
+
+public class ClosedQueueConnectionTestsIT {
+ private static final String TestName = "com.sun.ts.tests.jms.core.closedQueueConnection.ClosedQueueConnectionTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedQueueConnectionTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ boolean jmsOptionalApisSupported;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed connection for testing. Passes any
+ * exceptions up to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndCloseConnection(int type) throws Exception {
+ if ((type == JmsTool.QUEUE) || (type == JmsTool.TX_QUEUE)) {
+ tool = new JmsTool(type, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Closing queue Connection");
+ tool.getDefaultQueueConnection().close();
+ }
+ logger.log(Logger.Level.TRACE, "Connection closed");
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default QueueConnection,
+ * as well as a default Queue. Tests that require multiple Destinations create
+ * the extras within the test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'users' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(2);
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing QueueConnections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: closedQueueConnectionCommitTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:SPEC:113; JMS:JAVADOC:270; JMS:JAVADOC:526;
+ * JMS:JAVADOC:274; JMS:JAVADOC:229;
+ *
+ * @test_Strategy: Close default connection and call the commit method on
+ * session associated with it. Check for IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCommitTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TX_QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call commit with closed connection.");
+ try {
+ tool.getDefaultQueueSession().commit();
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueConnectionCommitTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionGetTransactedTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:SPEC:113; JMS:JAVADOC:270; JMS:JAVADOC:526;
+ * JMS:JAVADOC:225; JMS:JAVADOC:274;
+ *
+ * @test_Strategy: Close default connection and call the getTransacted method on
+ * a QueueSession associated with it. Check for IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionGetTransactedTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getTransacted() with closed connection.");
+ try {
+ boolean b = tool.getDefaultQueueSession().getTransacted();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionGetTransactedTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionRollbackTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:SPEC:113; JMS:JAVADOC:270; JMS:JAVADOC:526;
+ * JMS:JAVADOC:274; JMS:JAVADOC:231;
+ *
+ * @test_Strategy: Close default connection and call the rollback method on a
+ * QueueSession associated with it. Check for IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionRollbackTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call rollback() with closed connection.");
+ try {
+ tool.getDefaultQueueSession().rollback();
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionRollbackTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionRecoverTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:SPEC:113; JMS:JAVADOC:270; JMS:JAVADOC:526;
+ * JMS:JAVADOC:274; JMS:JAVADOC:235;
+ *
+ * @test_Strategy: Close default connection and call the recover method on a
+ * QueueSession associated with it. Check for IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionRecoverTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call recover() with closed connection.");
+ try {
+ tool.getDefaultQueueSession().recover();
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionRecoverTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:108; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ *
+ * @test_Strategy: Close default Connection and call method on it.
+ */
+ @Test
+ public void closedQueueConnectionCloseTest() throws Exception {
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultQueueConnection().close();
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionGetClientIDTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:512;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionGetClientIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getClientID");
+ try {
+ String foo = tool.getDefaultQueueConnection().getClientID();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionGetClientIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionGetMetaDataTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:516;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionGetMetaDataTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getMetaData");
+ try {
+ ConnectionMetaData foo = tool.getDefaultQueueConnection().getMetaData();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionGetMetaDataTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionStartTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:522;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionStartTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call start");
+ try {
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionStartTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateQueueSessionTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateQueueSessionTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call createQueueSession");
+ try {
+ QueueSession foo = tool.getDefaultQueueConnection().createQueueSession(true, Session.AUTO_ACKNOWLEDGE);
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: wrong exception was returned", e);
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateQueueSessionTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSessionCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:SPEC:114;
+ *
+ * @test_Strategy: Close default connection and call method on it.
+ */
+ @Test
+ public void closedQueueConnectionSessionCloseTest() throws Exception {
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to close session again.");
+ tool.getDefaultQueueSession().close();
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSessionCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateBrowserTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:190;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateBrowserTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create QueueBrowser with closed connection.");
+ try {
+ QueueBrowser qB = tool.getDefaultQueueSession().createBrowser(tool.getDefaultQueue());
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateBrowserTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateBrowserMsgSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:192;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateBrowserMsgSelectorTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create QueueBrowser with closed Connection.");
+ try {
+ QueueBrowser qB = tool.getDefaultQueueSession().createBrowser(tool.getDefaultQueue(), "TEST = 'test'");
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateBrowserMsgSelectorTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:182;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateQueueTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create queue with closed Connection.");
+ try {
+ Queue q = tool.getDefaultQueueSession().createQueue("closedQueueConnectionCreateQueueTest");
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateQueueTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateReceiverTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:184;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateReceiverTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create Receiver with closed Connection.");
+ try {
+ QueueReceiver qR = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue());
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateReceiverTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateReceiverMsgSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:186;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateReceiverMsgSelectorTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create Receiver with closed Connection.");
+ try {
+ QueueReceiver qR = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue(),
+ "TEST = 'test'");
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateReceiverMsgSelectorTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateSenderTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:188;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateSenderTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create Sender with closed Connection.");
+ try {
+ QueueSender qS = tool.getDefaultQueueSession().createSender(tool.getDefaultQueue());
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateSenderTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateTempQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:194;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateTempQueueTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create TemporaryQueue with closed connection.");
+ try {
+ TemporaryQueue tQ = tool.getDefaultQueueSession().createTemporaryQueue();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateTempQueueTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:213;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create message with closed connection.");
+ try {
+ Message m = tool.getDefaultQueueSession().createMessage();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateMessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateBytesMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:209;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateBytesMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create BytesMessage with closed connection.");
+ try {
+ BytesMessage m = tool.getDefaultQueueSession().createBytesMessage();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateBytesMessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateMapMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:211;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateMapMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create MapMessage with closed connection.");
+ try {
+ MapMessage m = tool.getDefaultQueueSession().createMapMessage();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateMapMessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateObjectMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:215;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateObjectMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create ObjectMessage with closed connection.");
+ try {
+ ObjectMessage m = tool.getDefaultQueueSession().createObjectMessage();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateObjectMessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateObject2MessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:217;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateObject2MessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create ObjectMessage(object) with closed connection.");
+ try {
+ String s = "Simple object";
+ ObjectMessage m = tool.getDefaultQueueSession().createObjectMessage(s);
+ if (m != null)
+ logger.log(Logger.Level.TRACE, "m=" + m);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateObject2MessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateStreamMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:219;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateStreamMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create StreamMessage with closed connection.");
+ try {
+ StreamMessage m = tool.getDefaultQueueSession().createStreamMessage();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateStreamMessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateTextMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:221;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateTextMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create TextMessage with closed connection.");
+ try {
+ TextMessage m = tool.getDefaultQueueSession().createTextMessage();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateTextMessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionCreateText2MessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526; JMS:SPEC:113;
+ * JMS:JAVADOC:223;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionCreateText2MessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to create TextMessage with closed connection.");
+ try {
+ TextMessage m = tool.getDefaultQueueSession().createTextMessage("test message");
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionCreateText2MessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionReceiverCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:338;
+ *
+ * @test_Strategy: Close default receiver and call method on it.
+ */
+ @Test
+ public void closedQueueConnectionReceiverCloseTest() throws Exception {
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultQueueReceiver().close();
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionReceiverCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionGetMessageSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:326;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionGetMessageSelectorTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getMessageSelector");
+ try {
+ String foo = tool.getDefaultQueueReceiver().getMessageSelector();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionGetMessageSelectorTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionReceiveTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:332;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionReceiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call receive");
+ try {
+ Message foo = tool.getDefaultQueueReceiver().receive();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionReceiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionReceiveTimeoutTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionReceiveTimeoutTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call receive(timeout)");
+ try {
+ Message foo = tool.getDefaultQueueReceiver().receive(timeout);
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionReceiveTimeoutTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionReceiveNoWaitTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:337;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionReceiveNoWaitTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call receiveNoWait");
+ try {
+ Message foo = tool.getDefaultQueueReceiver().receiveNoWait();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionReceiveNoWaitTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionReceiverGetQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:268;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionReceiverGetQueueTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getQueue");
+ try {
+ Queue foo = tool.getDefaultQueueReceiver().getQueue();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionReceiverGetQueueTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSenderCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:315;
+ *
+ * @test_Strategy: Close default sender and call method on it.
+ */
+ @Test
+ public void closedQueueConnectionSenderCloseTest() throws Exception {
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultQueueSender().close();
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSenderCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionGetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:303;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionGetDeliveryModeTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getDeliveryMode");
+ try {
+ int foo = tool.getDefaultQueueSender().getDeliveryMode();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionGetDeliveryModeTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionGetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:295;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionGetDisableMessageIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getDisableMessageID");
+ try {
+ boolean foo = tool.getDefaultQueueSender().getDisableMessageID();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionGetDisableMessageIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionGetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:299;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionGetDisableMessageTimestampTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getDisableMessageTimestamp");
+ try {
+ boolean foo = tool.getDefaultQueueSender().getDisableMessageTimestamp();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionGetDisableMessageTimestampTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionGetPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:307;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionGetPriorityTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getPriority");
+ try {
+ int foo = tool.getDefaultQueueSender().getPriority();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionGetPriorityTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionGetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:311;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionGetTimeToLiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getTimeToLive");
+ try {
+ long foo = tool.getDefaultQueueSender().getTimeToLive();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionGetTimeToLiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:301;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSetDeliveryModeTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call setDeliveryMode");
+ try {
+ tool.getDefaultQueueSender().setDeliveryMode(Message.DEFAULT_DELIVERY_MODE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSetDeliveryModeTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:293;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSetDisableMessageIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call setDisableMessageID");
+ try {
+ tool.getDefaultQueueSender().setDisableMessageID(true);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSetDisableMessageIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:297;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSetDisableMessageTimestampTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call setDisableMessageTimestamp");
+ try {
+ tool.getDefaultQueueSender().setDisableMessageTimestamp(true);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSetDisableMessageTimestampTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSetPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:305;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSetPriorityTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call setPriority");
+ try {
+ tool.getDefaultQueueSender().setPriority(Message.DEFAULT_PRIORITY);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSetPriorityTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:309;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSetTimeToLiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call setTimeToLive");
+ try {
+ tool.getDefaultQueueSender().setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSetTimeToLiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSenderGetQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:196;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSenderGetQueueTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call getQueue");
+ try {
+ Queue foo = tool.getDefaultQueueSender().getQueue();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSenderGetQueueTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSend1Test
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:198;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSend1Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call send(Message)");
+ try {
+ tool.getDefaultQueueSender().send(new MessageTestImpl());
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSend1Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSend2Test
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:200;
+ *
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSend2Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call send(Message,int,int,long)");
+ try {
+ tool.getDefaultQueueSender().send(new MessageTestImpl(), Message.DEFAULT_DELIVERY_MODE,
+ Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSend2Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSend3Test
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:202;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSend3Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call send(Queue,Message)");
+ try {
+ tool.getDefaultQueueSender().send(new MessageTestImpl());
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSend3Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueConnectionSend4Test
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:274; JMS:JAVADOC:526;
+ * JMS:JAVADOC:204;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueConnectionSend4Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.QUEUE);
+ logger.log(Logger.Level.TRACE, "Try to call send(Queue,Message,int,int,long)");
+ try {
+ tool.getDefaultQueueSender().send(new MessageTestImpl(), Message.DEFAULT_DELIVERY_MODE,
+ Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueConnectionSend4Test", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueReceiver/ClosedQueueReceiverTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueReceiver/ClosedQueueReceiverTests.java
deleted file mode 100644
index f7f524a365..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueReceiver/ClosedQueueReceiverTests.java
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.closedQueueReceiver;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.Message;
-import jakarta.jms.Queue;
-
-/**
- * JMS TS tests. Testing method calls on closed QueueReceiver objects.
- */
-public class ClosedQueueReceiverTests extends ServiceEETest {
- private static final String TestName = "com.sun.ts.tests.jms.core.closedQueueReceiver.ClosedQueueReceiverTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ClosedQueueReceiverTests theTests = new ClosedQueueReceiverTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed receiver for testing. Passes any
- * exceptions up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndCloseReceiver() throws Exception {
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- logTrace("Closing queue receiver");
- tool.getDefaultQueueReceiver().close();
- logTrace("Receiver closed");
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- /**
- * Method Declaration.
- *
- *
- * @param args
- * @param p
- *
- * @exception Fault
- *
- * @see
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(2);
-
- // get ready for new test
- logTrace("Getting Administrator and deleting any leftover destinations.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: closedQueueReceiverCloseTest
- *
- * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:338;
- *
- * @test_Strategy: Close default receiver and call method on it.
- */
-
- public void closedQueueReceiverCloseTest() throws Exception {
- try {
- createAndCloseReceiver();
- logTrace("Try to call close again");
- tool.getDefaultQueueReceiver().close();
- } catch (Exception e) {
- throw new Exception("closedQueueReceiverCloseTest", e);
- }
- }
-
- /*
- * @testName: closedQueueReceiverGetMessageSelectorTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:326;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueReceiverGetMessageSelectorTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseReceiver();
- logTrace("Try to call getMessageSelector");
- try {
- String foo = tool.getDefaultQueueReceiver().getMessageSelector();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueReceiverGetMessageSelectorTest", e);
- }
- }
-
- /*
- * @testName: closedQueueReceiverReceiveTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:332;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueReceiverReceiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseReceiver();
- logTrace("Try to call receive");
- try {
- Message foo = tool.getDefaultQueueReceiver().receive();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueReceiverReceiveTest", e);
- }
- }
-
- /*
- * @testName: closedQueueReceiverReceiveTimeoutTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:334;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueReceiverReceiveTimeoutTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseReceiver();
- logTrace("Try to call receive(timeout)");
- try {
- Message foo = tool.getDefaultQueueReceiver().receive(timeout);
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueReceiverReceiveTimeoutTest", e);
- }
- }
-
- /*
- * @testName: closedQueueReceiverReceiveNoWaitTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:336;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueReceiverReceiveNoWaitTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseReceiver();
- logTrace("Try to call receiveNoWait");
- try {
- Message foo = tool.getDefaultQueueReceiver().receiveNoWait();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueReceiverReceiveNoWaitTest", e);
- }
- }
-
- /*
- * @testName: closedQueueReceiverGetQueueTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:268;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueReceiverGetQueueTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseReceiver();
- logTrace("Try to call getQueue");
- try {
- Queue foo = tool.getDefaultQueueReceiver().getQueue();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueReceiverGetQueueTest", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueReceiver/ClosedQueueReceiverTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueReceiver/ClosedQueueReceiverTestsIT.java
new file mode 100644
index 0000000000..9a4bb088b2
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueReceiver/ClosedQueueReceiverTestsIT.java
@@ -0,0 +1,362 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.closedQueueReceiver;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.Message;
+import jakarta.jms.Queue;
+
+/**
+ * JMS TS tests. Testing method calls on closed QueueReceiver objects.
+ */
+
+public class ClosedQueueReceiverTestsIT {
+ private static final String TestName = "com.sun.ts.tests.jms.core.closedQueueReceiver.ClosedQueueReceiverTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedQueueReceiverTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed receiver for testing. Passes any exceptions
+ * up to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndCloseReceiver() throws Exception {
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Closing queue receiver");
+ tool.getDefaultQueueReceiver().close();
+ logger.log(Logger.Level.TRACE, "Receiver closed");
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ /**
+ * Method Declaration.
+ *
+ *
+ * @param args
+ * @param p
+ *
+ * @exception Fault
+ *
+ * @see
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(2);
+
+ // get ready for new test
+ logger.log(Logger.Level.TRACE, "Getting Administrator and deleting any leftover destinations.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: closedQueueReceiverCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:338;
+ *
+ * @test_Strategy: Close default receiver and call method on it.
+ */
+ @Test
+ public void closedQueueReceiverCloseTest() throws Exception {
+ try {
+ createAndCloseReceiver();
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultQueueReceiver().close();
+ } catch (Exception e) {
+ throw new Exception("closedQueueReceiverCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueReceiverGetMessageSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:326;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueReceiverGetMessageSelectorTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseReceiver();
+ logger.log(Logger.Level.TRACE, "Try to call getMessageSelector");
+ try {
+ String foo = tool.getDefaultQueueReceiver().getMessageSelector();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueReceiverGetMessageSelectorTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueReceiverReceiveTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:332;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueReceiverReceiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseReceiver();
+ logger.log(Logger.Level.TRACE, "Try to call receive");
+ try {
+ Message foo = tool.getDefaultQueueReceiver().receive();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueReceiverReceiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueReceiverReceiveTimeoutTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueReceiverReceiveTimeoutTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseReceiver();
+ logger.log(Logger.Level.TRACE, "Try to call receive(timeout)");
+ try {
+ Message foo = tool.getDefaultQueueReceiver().receive(timeout);
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueReceiverReceiveTimeoutTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueReceiverReceiveNoWaitTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:336;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueReceiverReceiveNoWaitTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseReceiver();
+ logger.log(Logger.Level.TRACE, "Try to call receiveNoWait");
+ try {
+ Message foo = tool.getDefaultQueueReceiver().receiveNoWait();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueReceiverReceiveNoWaitTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueReceiverGetQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:268;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueReceiverGetQueueTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseReceiver();
+ logger.log(Logger.Level.TRACE, "Try to call getQueue");
+ try {
+ Queue foo = tool.getDefaultQueueReceiver().getQueue();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueReceiverGetQueueTest", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueSender/ClosedQueueSenderTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueSender/ClosedQueueSenderTests.java
deleted file mode 100644
index 98667ae81b..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueSender/ClosedQueueSenderTests.java
+++ /dev/null
@@ -1,710 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.closedQueueSender;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.common.MessageTestImpl;
-
-import jakarta.jms.Message;
-import jakarta.jms.Queue;
-
-/**
- * JMS TS tests. Testing method calls on closed QueueSender objects.
- */
-public class ClosedQueueSenderTests extends ServiceEETest {
- private static final String TestName = "com.sun.ts.tests.jms.core.closedQueueSender.ClosedQueueSenderTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ClosedQueueSenderTests theTests = new ClosedQueueSenderTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed sender for testing. Passes any exceptions
- * up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndCloseSender() throws Exception {
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- logTrace("Closing queue sender");
- tool.getDefaultQueueSender().close();
- logTrace("Sender closed");
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the TestTools object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(2);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: closedQueueSenderCloseTest
- *
- * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:315;
- *
- * @test_Strategy: Close default sender and call method on it.
- */
-
- public void closedQueueSenderCloseTest() throws Exception {
- try {
- createAndCloseSender();
- logTrace("Try to call close again");
- tool.getDefaultQueueSender().close();
- } catch (Exception e) {
- throw new Exception("closedQueueSenderCloseTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderGetDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:303;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderGetDeliveryModeTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call getDeliveryMode");
- try {
- int foo = tool.getDefaultQueueSender().getDeliveryMode();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderGetDeliveryModeTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderGetDisableMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:295;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderGetDisableMessageIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call getDisableMessageID");
- try {
- boolean foo = tool.getDefaultQueueSender().getDisableMessageID();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderGetDisableMessageIDTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderGetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:299;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderGetDisableMessageTimestampTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call getDisableMessageTimestamp");
- try {
- boolean foo = tool.getDefaultQueueSender().getDisableMessageTimestamp();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderGetDisableMessageTimestampTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderGetPriorityTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:307;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderGetPriorityTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call getPriority");
- try {
- int foo = tool.getDefaultQueueSender().getPriority();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderGetPriorityTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderGetTimeToLiveTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:311;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderGetTimeToLiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call getTimeToLive");
- try {
- long foo = tool.getDefaultQueueSender().getTimeToLive();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderGetTimeToLiveTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderSetDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:301;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderSetDeliveryModeTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call setDeliveryMode");
- try {
- tool.getDefaultQueueSender()
- .setDeliveryMode(Message.DEFAULT_DELIVERY_MODE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderSetDeliveryModeTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderSetDisableMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:293;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderSetDisableMessageIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call setDisableMessageID");
- try {
- tool.getDefaultQueueSender().setDisableMessageID(true);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderSetDisableMessageIDTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderSetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:297;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderSetDisableMessageTimestampTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call setDisableMessageTimestamp");
- try {
- tool.getDefaultQueueSender().setDisableMessageTimestamp(true);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderSetDisableMessageTimestampTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderSetPriorityTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:305;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderSetPriorityTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call setPriority");
- try {
- tool.getDefaultQueueSender().setPriority(Message.DEFAULT_PRIORITY);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderSetPriorityTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderSetTimeToLiveTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:309;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderSetTimeToLiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call setTimeToLive");
- try {
- tool.getDefaultQueueSender()
- .setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderSetTimeToLiveTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderGetQueueTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:196;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderGetQueueTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call getQueue");
- try {
- Queue foo = tool.getDefaultQueueSender().getQueue();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderGetQueueTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderSend1Test
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:198;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderSend1Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call send(Message)");
- try {
- tool.getDefaultQueueSender().send(new MessageTestImpl());
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderSend1Test", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderSend2Test
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:200;
- *
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderSend2Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call send(Message,int,int,long)");
- try {
- tool.getDefaultQueueSender().send(new MessageTestImpl(),
- Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
- Message.DEFAULT_TIME_TO_LIVE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderSend2Test", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderSend3Test
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:202;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderSend3Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call send(Queue,Message)");
- try {
- tool.getDefaultQueueSender().send(new MessageTestImpl());
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderSend3Test", e);
- }
- }
-
- /*
- * @testName: closedQueueSenderSend4Test
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:204;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSenderSend4Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSender();
- logTrace("Try to call send(Queue,Message,int,int,long)");
- try {
- tool.getDefaultQueueSender().send(new MessageTestImpl(),
- Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
- Message.DEFAULT_TIME_TO_LIVE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedQueueSenderSend4Test", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueSender/ClosedQueueSenderTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueSender/ClosedQueueSenderTestsIT.java
new file mode 100644
index 0000000000..7f434f5554
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueSender/ClosedQueueSenderTestsIT.java
@@ -0,0 +1,683 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.closedQueueSender;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.common.MessageTestImpl;
+
+import jakarta.jms.Message;
+import jakarta.jms.Queue;
+
+/**
+ * JMS TS tests. Testing method calls on closed QueueSender objects.
+ */
+
+public class ClosedQueueSenderTestsIT {
+ private static final String TestName = "com.sun.ts.tests.jms.core.closedQueueSender.ClosedQueueSenderTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedQueueSenderTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed sender for testing. Passes any exceptions up
+ * to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndCloseSender() throws Exception {
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Closing queue sender");
+ tool.getDefaultQueueSender().close();
+ logger.log(Logger.Level.TRACE, "Sender closed");
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the TestTools object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(2);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: closedQueueSenderCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:315;
+ *
+ * @test_Strategy: Close default sender and call method on it.
+ */
+ @Test
+ public void closedQueueSenderCloseTest() throws Exception {
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultQueueSender().close();
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderGetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:303;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderGetDeliveryModeTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call getDeliveryMode");
+ try {
+ int foo = tool.getDefaultQueueSender().getDeliveryMode();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderGetDeliveryModeTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderGetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:295;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderGetDisableMessageIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call getDisableMessageID");
+ try {
+ boolean foo = tool.getDefaultQueueSender().getDisableMessageID();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderGetDisableMessageIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderGetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:299;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderGetDisableMessageTimestampTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call getDisableMessageTimestamp");
+ try {
+ boolean foo = tool.getDefaultQueueSender().getDisableMessageTimestamp();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderGetDisableMessageTimestampTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderGetPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:307;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderGetPriorityTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call getPriority");
+ try {
+ int foo = tool.getDefaultQueueSender().getPriority();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderGetPriorityTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderGetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:311;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderGetTimeToLiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call getTimeToLive");
+ try {
+ long foo = tool.getDefaultQueueSender().getTimeToLive();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderGetTimeToLiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderSetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:301;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderSetDeliveryModeTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call setDeliveryMode");
+ try {
+ tool.getDefaultQueueSender().setDeliveryMode(Message.DEFAULT_DELIVERY_MODE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderSetDeliveryModeTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderSetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:293;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderSetDisableMessageIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call setDisableMessageID");
+ try {
+ tool.getDefaultQueueSender().setDisableMessageID(true);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderSetDisableMessageIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderSetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:297;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderSetDisableMessageTimestampTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call setDisableMessageTimestamp");
+ try {
+ tool.getDefaultQueueSender().setDisableMessageTimestamp(true);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderSetDisableMessageTimestampTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderSetPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:305;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderSetPriorityTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call setPriority");
+ try {
+ tool.getDefaultQueueSender().setPriority(Message.DEFAULT_PRIORITY);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderSetPriorityTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderSetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:309;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderSetTimeToLiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call setTimeToLive");
+ try {
+ tool.getDefaultQueueSender().setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderSetTimeToLiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderGetQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:196;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderGetQueueTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call getQueue");
+ try {
+ Queue foo = tool.getDefaultQueueSender().getQueue();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderGetQueueTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderSend1Test
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:198;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderSend1Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call send(Message)");
+ try {
+ tool.getDefaultQueueSender().send(new MessageTestImpl());
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderSend1Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderSend2Test
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:200;
+ *
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderSend2Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call send(Message,int,int,long)");
+ try {
+ tool.getDefaultQueueSender().send(new MessageTestImpl(), Message.DEFAULT_DELIVERY_MODE,
+ Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderSend2Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderSend3Test
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:202;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderSend3Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call send(Queue,Message)");
+ try {
+ tool.getDefaultQueueSender().send(new MessageTestImpl());
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderSend3Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSenderSend4Test
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:204;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSenderSend4Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSender();
+ logger.log(Logger.Level.TRACE, "Try to call send(Queue,Message,int,int,long)");
+ try {
+ tool.getDefaultQueueSender().send(new MessageTestImpl(), Message.DEFAULT_DELIVERY_MODE,
+ Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedQueueSenderSend4Test", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueSession/ClosedQueueSessionTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueSession/ClosedQueueSessionTests.java
deleted file mode 100644
index 386f1c34a0..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueSession/ClosedQueueSessionTests.java
+++ /dev/null
@@ -1,1509 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.closedQueueSession;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.common.MessageTestImpl;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueBrowser;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueSender;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TemporaryQueue;
-import jakarta.jms.TextMessage;
-
-/**
- * JMS TS tests. Testing method calls on closed QueueSession objects.
- */
-public class ClosedQueueSessionTests extends ServiceEETest {
- private static final String TestName = "com.sun.ts.tests.jms.core.closedQueueSession.ClosedQueueSessionTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- */
- public static void main(String[] args) {
- ClosedQueueSessionTests theTests = new ClosedQueueSessionTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed session for testing. Passes any exceptions
- * up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndCloseSession(int type, String user, String password)
- throws Exception {
- if ((type == JmsTool.QUEUE) || (type == JmsTool.TX_QUEUE)) {
- tool = new JmsTool(type, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logMsg("Closing QueueSession");
- tool.getDefaultQueueSession().close();
-
- } else if (type == JmsTool.COMMON_QTX) {
- tool = new JmsTool(type, user, password, mode);
- tool.getDefaultConnection().start();
- logMsg("Closing Session");
- tool.getDefaultSession().close();
- } else {
- logErr("Unspecified type");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default
- * QueueConnection, as well as a default Queue. Tests that require multiple
- * Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(2);
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing QueueConnection");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: closedQueueSessionCloseTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:229;
- *
- * @test_Strategy: Close default session and call close method on it.
- */
-
- public void closedQueueSessionCloseTest() throws Exception {
- try {
- TestUtil.logTrace("Before create and close");
- createAndCloseSession(JmsTool.QUEUE, user, password);
-
- logMsg("Try to call close on closed session.");
- tool.getDefaultQueueSession().close();
- } catch (Exception e) {
- TestUtil.logTrace("fault " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCloseTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateBrowserTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:190;
- *
- * @test_Strategy: Close default session and call createBrowser on it. Check
- * for IllegalStateException.
- */
-
- public void closedQueueSessionCreateBrowserTest() throws Exception {
- String testName = "closedQueueSessionCreateBrowserTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create QueueBrowser with closed session.");
- try {
- QueueBrowser qB = tool.getDefaultQueueSession()
- .createBrowser(tool.getDefaultQueue());
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- throw new Exception("closedQueueSessionCreateBrowserTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateBrowserMsgSelectorTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:192;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateBrowserMsgSelectorTest() throws Exception {
- String testName = "closedQueueSessionCreateBrowserMsgSelectorTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create QueueBrowser with closed session.");
- try {
- QueueBrowser qB = tool.getDefaultQueueSession()
- .createBrowser(tool.getDefaultQueue(), "TEST = 'test'");
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateBrowserMsgSelectorTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateQueueTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:182;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateQueueTest() throws Exception {
- String testName = "closedQueueSessionCreateQueueTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create queue with closed session.");
- try {
- Queue q = tool.getDefaultQueueSession().createQueue(testName);
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateQueueTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateReceiverTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:184;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateReceiverTest() throws Exception {
- String testName = "closedQueueSessionCreateReceiverTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create Receiver with closed session.");
- try {
- QueueReceiver qR = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue());
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateReceiverTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateReceiverMsgSelectorTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:186;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateReceiverMsgSelectorTest() throws Exception {
- String testName = "closedQueueSessionCreateReceiverMsgSelectorTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create Receiver with closed session.");
- try {
- QueueReceiver qR = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue(), "TEST = 'test'");
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateReceiverMsgSelectorTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateSenderTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:188;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateSenderTest() throws Exception {
- String testName = "closedQueueSessionCreateSenderTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create Sender with closed session.");
- try {
- QueueSender qS = tool.getDefaultQueueSession()
- .createSender(tool.getDefaultQueue());
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateSenderTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateTempQueueTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:194;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateTempQueueTest() throws Exception {
- String testName = "closedQueueSessionCreateTempQueueTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create TemporaryQueue with closed session.");
- try {
- TemporaryQueue tQ = tool.getDefaultQueueSession()
- .createTemporaryQueue();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateTempQueueTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateMessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:213;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateMessageTest() throws Exception {
- String testName = "closedQueueSessionCreateMessageTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create message with closed session.");
- try {
- Message m = tool.getDefaultQueueSession().createMessage();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateMessageTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateBytesMessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:209;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateBytesMessageTest() throws Exception {
- String testName = "closedQueueSessionCreateBytesMessageTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create BytesMessage with closed session.");
- try {
- BytesMessage m = tool.getDefaultQueueSession().createBytesMessage();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateBytesMessageTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateMapMessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:211;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateMapMessageTest() throws Exception {
- String testName = "closedQueueSessionCreateMapMessageTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create MapMessage with closed session.");
- try {
- MapMessage m = tool.getDefaultQueueSession().createMapMessage();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateMapMessageTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateObjectMessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:215;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateObjectMessageTest() throws Exception {
- String testName = "closedQueueSessionCreateObjectMessageTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create ObjectMessage with closed session.");
- try {
- ObjectMessage m = tool.getDefaultQueueSession().createObjectMessage();
- if (m != null)
- TestUtil.logTrace("m=" + m);
- TestUtil.logTrace("FAIL: expected IllegalStateException");
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateObjectMessageTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateObject2MessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:217;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateObject2MessageTest() throws Exception {
- String testName = "closedQueueSessionCreateObject2MessageTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create ObjectMessage(object) with closed session.");
- try {
- String s = "Simple object";
- ObjectMessage m = tool.getDefaultQueueSession().createObjectMessage(s);
- if (m != null)
- TestUtil.logTrace("m=" + m);
- TestUtil.logTrace("FAIL: expected IllegalStateException");
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateObject2MessageTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateStreamMessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:219;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateStreamMessageTest() throws Exception {
- String testName = "closedQueueSessionCreateStreamMessageTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create StreamMessage with closed session.");
- try {
- StreamMessage m = tool.getDefaultQueueSession().createStreamMessage();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateStreamMessageTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateTextMessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:221;
- *
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateTextMessageTest() throws Exception {
- String testName = "closedQueueSessionCreateTextMessageTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create TextMessage with closed session.");
- try {
- TextMessage m = tool.getDefaultQueueSession().createTextMessage();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateTextMessageTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionCreateText2MessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:223;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCreateText2MessageTest() throws Exception {
- String testName = "closedQueueSessionCreateText2MessageTest";
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logMsg("Try to create TextMessage with closed session.");
- try {
- TextMessage m = tool.getDefaultQueueSession()
- .createTextMessage("test message");
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionCreateText2MessageTest");
- }
- }
-
- /*
- * @testName: closedQueueSessionReceiverCloseTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:338;
- *
- * @test_Strategy: Close default receiver and call method on it.
- */
-
- public void closedQueueSessionReceiverCloseTest() throws Exception {
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call close again");
- tool.getDefaultQueueReceiver().close();
- } catch (Exception e) {
- throw new Exception("closedQueueSessionReceiverCloseTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionGetMessageSelectorTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:326;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionGetMessageSelectorTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call getMessageSelector");
- try {
- String foo = tool.getDefaultQueueReceiver().getMessageSelector();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionGetMessageSelectorTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionReceiveTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:332;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionReceiveTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call receive");
- try {
- Message foo = tool.getDefaultQueueReceiver().receive();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionReceiveTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionReceiveTimeoutTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:334;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionReceiveTimeoutTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call receive(timeout)");
- try {
- Message foo = tool.getDefaultQueueReceiver().receive(timeout);
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionReceiveTimeoutTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionReceiveNoWaitTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:336;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionReceiveNoWaitTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call receiveNoWait");
- try {
- Message foo = tool.getDefaultQueueReceiver().receiveNoWait();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionReceiveNoWaitTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionReceiverGetQueueTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:268;
- *
- * @test_Strategy: Close default receiver and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionReceiverGetQueueTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call getQueue");
- try {
- Queue foo = tool.getDefaultQueueReceiver().getQueue();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionReceiverGetQueueTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionSenderCloseTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:315;
- *
- *
- * @test_Strategy: Close default sender and call method on it.
- */
-
- public void closedQueueSessionSenderCloseTest() throws Exception {
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call close again");
- tool.getDefaultQueueSender().close();
- } catch (Exception e) {
- throw new Exception("closedQueueSessionSenderCloseTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionGetDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:303;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionGetDeliveryModeTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call getDeliveryMode");
- try {
- int foo = tool.getDefaultQueueSender().getDeliveryMode();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionGetDeliveryModeTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionGetDisableMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:295;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionGetDisableMessageIDTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call getDisableMessageID");
- try {
- boolean foo = tool.getDefaultQueueSender().getDisableMessageID();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionGetDisableMessageIDTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionGetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:299;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionGetDisableMessageTimestampTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call getDisableMessageTimestamp");
- try {
- boolean foo = tool.getDefaultQueueSender().getDisableMessageTimestamp();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionGetDisableMessageTimestampTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionGetPriorityTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:307;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionGetPriorityTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call getPriority");
- try {
- int foo = tool.getDefaultQueueSender().getPriority();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionGetPriorityTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionGetTimeToLiveTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:311;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionGetTimeToLiveTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call getTimeToLive");
- try {
- long foo = tool.getDefaultQueueSender().getTimeToLive();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionGetTimeToLiveTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionSetDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:301;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionSetDeliveryModeTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call setDeliveryMode");
- try {
- tool.getDefaultQueueSender()
- .setDeliveryMode(Message.DEFAULT_DELIVERY_MODE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionSetDeliveryModeTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionSetDisableMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:293;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionSetDisableMessageIDTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call setDisableMessageID");
- try {
- tool.getDefaultQueueSender().setDisableMessageID(true);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionSetDisableMessageIDTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionSetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:297;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionSetDisableMessageTimestampTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call setDisableMessageTimestamp");
- try {
- tool.getDefaultQueueSender().setDisableMessageTimestamp(true);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionSetDisableMessageTimestampTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionSetPriorityTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:305;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionSetPriorityTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call setPriority");
- try {
- tool.getDefaultQueueSender().setPriority(Message.DEFAULT_PRIORITY);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionSetPriorityTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionSetTimeToLiveTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:309;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionSetTimeToLiveTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call setTimeToLive");
- try {
- tool.getDefaultQueueSender()
- .setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionSetTimeToLiveTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionSenderGetQueueTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:196;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionSenderGetQueueTest() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call getQueue");
- try {
- Queue foo = tool.getDefaultQueueSender().getQueue();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionSenderGetQueueTest", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionSend1Test
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:198;
- *
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionSend1Test() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call send(Message)");
- try {
- tool.getDefaultQueueSender().send(new MessageTestImpl());
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionSend1Test", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionSend2Test
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:200;
- *
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionSend2Test() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call send(Message,int,int,long)");
- try {
- tool.getDefaultQueueSender().send(new MessageTestImpl(),
- Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
- Message.DEFAULT_TIME_TO_LIVE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionSend2Test", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionSend3Test
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:202;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionSend3Test() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call send(Queue,Message)");
- try {
- tool.getDefaultQueueSender().send(new MessageTestImpl());
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
-
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionSend3Test", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionSend4Test
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:204;
- *
- * @test_Strategy: Close default sender and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedQueueSessionSend4Test() throws Exception {
-
- try {
- createAndCloseSession(JmsTool.QUEUE, user, password);
- logTrace("Try to call send(Queue,Message,int,int,long)");
- try {
- tool.getDefaultQueueSender().send(new MessageTestImpl(),
- Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
- Message.DEFAULT_TIME_TO_LIVE);
- logErr("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- return;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- throw new Exception("Error: failures occurred during tests");
-
- } catch (Exception e) {
- throw new Exception("closedQueueSessionSend4Test", e);
- }
- }
-
- /*
- * @testName: closedQueueSessionRecoverTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:235;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionRecoverTest() throws Exception {
- try {
- createAndCloseSession(JmsTool.TX_QUEUE, user, password);
- logMsg("Try to call recover() with closed session.");
- try {
- tool.getDefaultQueueSession().recover();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception("closedQueueSessionRecoverTest");
- } catch (Exception e) {
- TestUtil.logErr("closedQueueSessionRecoverTest failed: ", e);
- throw new Exception("closedQueueSessionRecoverTest", e);
- }
- }
-
- /*
- * @testName: closedSessionRecoverTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:636;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedSessionRecoverTest() throws Exception {
- String testName = "closedSessionRecoverTest";
-
- try {
- createAndCloseSession(JmsTool.COMMON_QTX, user, password);
- logMsg("Try to call recover() with closed session.");
- try {
- tool.getDefaultSession().recover();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logErr(testName + " failed: ", e);
- throw new Exception(testName);
- }
- }
-
- /*
- * @testName: closedQueueSessionCommitTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:229;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionCommitTest() throws Exception {
- String testName = "closedQueueSessionCommitTest";
-
- try {
- createAndCloseSession(JmsTool.TX_QUEUE, user, password);
- logMsg("Try to call commit with closed session.");
- try {
- tool.getDefaultQueueSession().commit();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logErr(testName + " failed: ", e);
- throw new Exception(testName);
- }
- }
-
- /*
- * @testName: closedQueueSessionGetTransactedTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:225;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionGetTransactedTest() throws Exception {
- String testName = "closedQueueSessionGetTransactedTest";
-
- try {
- createAndCloseSession(JmsTool.TX_QUEUE, user, password);
- logMsg("Try to call getTransacted() with closed session.");
- try {
- boolean b = tool.getDefaultQueueSession().getTransacted();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
-
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logErr(testName + " failed: ", e);
- throw new Exception(testName);
- }
- }
-
- /*
- * @testName: closedQueueSessionRollbackTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:231;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedQueueSessionRollbackTest() throws Exception {
- String testName = "closedQueueSessionRollbackTest";
-
- try {
- createAndCloseSession(JmsTool.TX_QUEUE, user, password);
- logMsg("Try to call rollback() with closed session.");
- try {
- tool.getDefaultQueueSession().rollback();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- return;
- }
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedQueueSessionRollbackTest");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueSession/ClosedQueueSessionTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueSession/ClosedQueueSessionTestsIT.java
new file mode 100644
index 0000000000..04b153b84b
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/closedQueueSession/ClosedQueueSessionTestsIT.java
@@ -0,0 +1,1472 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.closedQueueSession;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.common.MessageTestImpl;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueBrowser;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueSender;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TemporaryQueue;
+import jakarta.jms.TextMessage;
+
+/**
+ * JMS TS tests. Testing method calls on closed QueueSession objects.
+ */
+
+public class ClosedQueueSessionTestsIT {
+ private static final String TestName = "com.sun.ts.tests.jms.core.closedQueueSession.ClosedQueueSessionTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedQueueSessionTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed session for testing. Passes any exceptions
+ * up to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndCloseSession(int type, String user, String password) throws Exception {
+ if ((type == JmsTool.QUEUE) || (type == JmsTool.TX_QUEUE)) {
+ tool = new JmsTool(type, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.INFO, "Closing QueueSession");
+ tool.getDefaultQueueSession().close();
+
+ } else if (type == JmsTool.COMMON_QTX) {
+ tool = new JmsTool(type, user, password, mode);
+ tool.getDefaultConnection().start();
+ logger.log(Logger.Level.INFO, "Closing Session");
+ tool.getDefaultSession().close();
+ } else {
+ logger.log(Logger.Level.ERROR, "Unspecified type");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default QueueConnection,
+ * as well as a default Queue. Tests that require multiple Destinations create
+ * the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(2);
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing QueueConnection");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: closedQueueSessionCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:229;
+ *
+ * @test_Strategy: Close default session and call close method on it.
+ */
+ @Test
+ public void closedQueueSessionCloseTest() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, "Before create and close");
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+
+ logger.log(Logger.Level.INFO, "Try to call close on closed session.");
+ tool.getDefaultQueueSession().close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, "fault " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCloseTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateBrowserTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:190;
+ *
+ * @test_Strategy: Close default session and call createBrowser on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionCreateBrowserTest() throws Exception {
+ String testName = "closedQueueSessionCreateBrowserTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create QueueBrowser with closed session.");
+ try {
+ QueueBrowser qB = tool.getDefaultQueueSession().createBrowser(tool.getDefaultQueue());
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ throw new Exception("closedQueueSessionCreateBrowserTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateBrowserMsgSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:192;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateBrowserMsgSelectorTest() throws Exception {
+ String testName = "closedQueueSessionCreateBrowserMsgSelectorTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create QueueBrowser with closed session.");
+ try {
+ QueueBrowser qB = tool.getDefaultQueueSession().createBrowser(tool.getDefaultQueue(), "TEST = 'test'");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateBrowserMsgSelectorTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:182;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateQueueTest() throws Exception {
+ String testName = "closedQueueSessionCreateQueueTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create queue with closed session.");
+ try {
+ Queue q = tool.getDefaultQueueSession().createQueue(testName);
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateQueueTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateReceiverTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:184;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateReceiverTest() throws Exception {
+ String testName = "closedQueueSessionCreateReceiverTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create Receiver with closed session.");
+ try {
+ QueueReceiver qR = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue());
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateReceiverTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateReceiverMsgSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:186;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateReceiverMsgSelectorTest() throws Exception {
+ String testName = "closedQueueSessionCreateReceiverMsgSelectorTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create Receiver with closed session.");
+ try {
+ QueueReceiver qR = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue(),
+ "TEST = 'test'");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateReceiverMsgSelectorTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateSenderTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:188;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateSenderTest() throws Exception {
+ String testName = "closedQueueSessionCreateSenderTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create Sender with closed session.");
+ try {
+ QueueSender qS = tool.getDefaultQueueSession().createSender(tool.getDefaultQueue());
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateSenderTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateTempQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:194;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateTempQueueTest() throws Exception {
+ String testName = "closedQueueSessionCreateTempQueueTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create TemporaryQueue with closed session.");
+ try {
+ TemporaryQueue tQ = tool.getDefaultQueueSession().createTemporaryQueue();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateTempQueueTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:213;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateMessageTest() throws Exception {
+ String testName = "closedQueueSessionCreateMessageTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create message with closed session.");
+ try {
+ Message m = tool.getDefaultQueueSession().createMessage();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateMessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateBytesMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:209;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateBytesMessageTest() throws Exception {
+ String testName = "closedQueueSessionCreateBytesMessageTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create BytesMessage with closed session.");
+ try {
+ BytesMessage m = tool.getDefaultQueueSession().createBytesMessage();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateBytesMessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateMapMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:211;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateMapMessageTest() throws Exception {
+ String testName = "closedQueueSessionCreateMapMessageTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create MapMessage with closed session.");
+ try {
+ MapMessage m = tool.getDefaultQueueSession().createMapMessage();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateMapMessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateObjectMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:215;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateObjectMessageTest() throws Exception {
+ String testName = "closedQueueSessionCreateObjectMessageTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create ObjectMessage with closed session.");
+ try {
+ ObjectMessage m = tool.getDefaultQueueSession().createObjectMessage();
+ if (m != null)
+ logger.log(Logger.Level.TRACE, "m=" + m);
+ logger.log(Logger.Level.TRACE, "FAIL: expected IllegalStateException");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateObjectMessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateObject2MessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:217;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateObject2MessageTest() throws Exception {
+ String testName = "closedQueueSessionCreateObject2MessageTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create ObjectMessage(object) with closed session.");
+ try {
+ String s = "Simple object";
+ ObjectMessage m = tool.getDefaultQueueSession().createObjectMessage(s);
+ if (m != null)
+ logger.log(Logger.Level.TRACE, "m=" + m);
+ logger.log(Logger.Level.TRACE, "FAIL: expected IllegalStateException");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateObject2MessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateStreamMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:219;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateStreamMessageTest() throws Exception {
+ String testName = "closedQueueSessionCreateStreamMessageTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create StreamMessage with closed session.");
+ try {
+ StreamMessage m = tool.getDefaultQueueSession().createStreamMessage();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateStreamMessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateTextMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:221;
+ *
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateTextMessageTest() throws Exception {
+ String testName = "closedQueueSessionCreateTextMessageTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create TextMessage with closed session.");
+ try {
+ TextMessage m = tool.getDefaultQueueSession().createTextMessage();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateTextMessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCreateText2MessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:223;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCreateText2MessageTest() throws Exception {
+ String testName = "closedQueueSessionCreateText2MessageTest";
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to create TextMessage with closed session.");
+ try {
+ TextMessage m = tool.getDefaultQueueSession().createTextMessage("test message");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionCreateText2MessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionReceiverCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:338;
+ *
+ * @test_Strategy: Close default receiver and call method on it.
+ */
+ @Test
+ public void closedQueueSessionReceiverCloseTest() throws Exception {
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultQueueReceiver().close();
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionReceiverCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionGetMessageSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:326;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionGetMessageSelectorTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getMessageSelector");
+ try {
+ String foo = tool.getDefaultQueueReceiver().getMessageSelector();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionGetMessageSelectorTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionReceiveTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:332;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionReceiveTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call receive");
+ try {
+ Message foo = tool.getDefaultQueueReceiver().receive();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionReceiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionReceiveTimeoutTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionReceiveTimeoutTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call receive(timeout)");
+ try {
+ Message foo = tool.getDefaultQueueReceiver().receive(timeout);
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionReceiveTimeoutTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionReceiveNoWaitTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:336;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionReceiveNoWaitTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call receiveNoWait");
+ try {
+ Message foo = tool.getDefaultQueueReceiver().receiveNoWait();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionReceiveNoWaitTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionReceiverGetQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:268;
+ *
+ * @test_Strategy: Close default receiver and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionReceiverGetQueueTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getQueue");
+ try {
+ Queue foo = tool.getDefaultQueueReceiver().getQueue();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionReceiverGetQueueTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionSenderCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:315;
+ *
+ *
+ * @test_Strategy: Close default sender and call method on it.
+ */
+ @Test
+ public void closedQueueSessionSenderCloseTest() throws Exception {
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultQueueSender().close();
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionSenderCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionGetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:303;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionGetDeliveryModeTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getDeliveryMode");
+ try {
+ int foo = tool.getDefaultQueueSender().getDeliveryMode();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionGetDeliveryModeTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionGetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:295;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionGetDisableMessageIDTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getDisableMessageID");
+ try {
+ boolean foo = tool.getDefaultQueueSender().getDisableMessageID();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionGetDisableMessageIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionGetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:299;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionGetDisableMessageTimestampTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getDisableMessageTimestamp");
+ try {
+ boolean foo = tool.getDefaultQueueSender().getDisableMessageTimestamp();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionGetDisableMessageTimestampTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionGetPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:307;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionGetPriorityTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getPriority");
+ try {
+ int foo = tool.getDefaultQueueSender().getPriority();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionGetPriorityTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionGetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:311;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionGetTimeToLiveTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getTimeToLive");
+ try {
+ long foo = tool.getDefaultQueueSender().getTimeToLive();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionGetTimeToLiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionSetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:301;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionSetDeliveryModeTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setDeliveryMode");
+ try {
+ tool.getDefaultQueueSender().setDeliveryMode(Message.DEFAULT_DELIVERY_MODE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionSetDeliveryModeTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionSetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:293;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionSetDisableMessageIDTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setDisableMessageID");
+ try {
+ tool.getDefaultQueueSender().setDisableMessageID(true);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionSetDisableMessageIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionSetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:297;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionSetDisableMessageTimestampTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setDisableMessageTimestamp");
+ try {
+ tool.getDefaultQueueSender().setDisableMessageTimestamp(true);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionSetDisableMessageTimestampTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionSetPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:305;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionSetPriorityTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setPriority");
+ try {
+ tool.getDefaultQueueSender().setPriority(Message.DEFAULT_PRIORITY);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionSetPriorityTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionSetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:309;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionSetTimeToLiveTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setTimeToLive");
+ try {
+ tool.getDefaultQueueSender().setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionSetTimeToLiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionSenderGetQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:196;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionSenderGetQueueTest() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getQueue");
+ try {
+ Queue foo = tool.getDefaultQueueSender().getQueue();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionSenderGetQueueTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionSend1Test
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:198;
+ *
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionSend1Test() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call send(Message)");
+ try {
+ tool.getDefaultQueueSender().send(new MessageTestImpl());
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionSend1Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionSend2Test
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:200;
+ *
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionSend2Test() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call send(Message,int,int,long)");
+ try {
+ tool.getDefaultQueueSender().send(new MessageTestImpl(), Message.DEFAULT_DELIVERY_MODE,
+ Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionSend2Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionSend3Test
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:202;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionSend3Test() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call send(Queue,Message)");
+ try {
+ tool.getDefaultQueueSender().send(new MessageTestImpl());
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionSend3Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionSend4Test
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:204;
+ *
+ * @test_Strategy: Close default sender and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedQueueSessionSend4Test() throws Exception {
+
+ try {
+ createAndCloseSession(JmsTool.QUEUE, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call send(Queue,Message,int,int,long)");
+ try {
+ tool.getDefaultQueueSender().send(new MessageTestImpl(), Message.DEFAULT_DELIVERY_MODE,
+ Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.ERROR, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ return;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ throw new Exception("Error: failures occurred during tests");
+
+ } catch (Exception e) {
+ throw new Exception("closedQueueSessionSend4Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionRecoverTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:235;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionRecoverTest() throws Exception {
+ try {
+ createAndCloseSession(JmsTool.TX_QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to call recover() with closed session.");
+ try {
+ tool.getDefaultQueueSession().recover();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception("closedQueueSessionRecoverTest");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "closedQueueSessionRecoverTest failed: ", e);
+ throw new Exception("closedQueueSessionRecoverTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedSessionRecoverTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:636;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedSessionRecoverTest() throws Exception {
+ String testName = "closedSessionRecoverTest";
+
+ try {
+ createAndCloseSession(JmsTool.COMMON_QTX, user, password);
+ logger.log(Logger.Level.INFO, "Try to call recover() with closed session.");
+ try {
+ tool.getDefaultSession().recover();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, testName + " failed: ", e);
+ throw new Exception(testName);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionCommitTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:229;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionCommitTest() throws Exception {
+ String testName = "closedQueueSessionCommitTest";
+
+ try {
+ createAndCloseSession(JmsTool.TX_QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to call commit with closed session.");
+ try {
+ tool.getDefaultQueueSession().commit();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, testName + " failed: ", e);
+ throw new Exception(testName);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionGetTransactedTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:225;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionGetTransactedTest() throws Exception {
+ String testName = "closedQueueSessionGetTransactedTest";
+
+ try {
+ createAndCloseSession(JmsTool.TX_QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to call getTransacted() with closed session.");
+ try {
+ boolean b = tool.getDefaultQueueSession().getTransacted();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, testName + " failed: ", e);
+ throw new Exception(testName);
+ }
+ }
+
+ /*
+ * @testName: closedQueueSessionRollbackTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:231;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedQueueSessionRollbackTest() throws Exception {
+ String testName = "closedQueueSessionRollbackTest";
+
+ try {
+ createAndCloseSession(JmsTool.TX_QUEUE, user, password);
+ logger.log(Logger.Level.INFO, "Try to call rollback() with closed session.");
+ try {
+ tool.getDefaultQueueSession().rollback();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ return;
+ }
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedQueueSessionRollbackTest");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicConnection/ClosedTopicConnectionTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicConnection/ClosedTopicConnectionTests.java
deleted file mode 100644
index 38cdb1f97c..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicConnection/ClosedTopicConnectionTests.java
+++ /dev/null
@@ -1,1733 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.closedTopicConnection;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.common.MessageTestImpl;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.ConnectionMetaData;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.Session;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TemporaryTopic;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicPublisher;
-import jakarta.jms.TopicSession;
-import jakarta.jms.TopicSubscriber;
-
-/**
- * JMS product tests. Testing method calls on closed TopicConnection objects.
- */
-public class ClosedTopicConnectionTests extends ServiceEETest {
- private static final String TestName = "com.sun.ts.tests.jms.core.closedTopicConnection.ClosedTopicConnectionTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ClosedTopicConnectionTests theTests = new ClosedTopicConnectionTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed connection for testing. Passes any
- * exceptions up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndCloseConnection(int type, String user, String password)
- throws Exception {
- if ((type == JmsTool.TOPIC) || (type == JmsTool.TX_TOPIC)) {
- tool = new JmsTool(type, user, password, mode);
- tool.getDefaultTopicConnection().start();
-
- TestUtil.logTrace("Closing queue Connection");
- tool.getDefaultTopicConnection().close();
- }
- TestUtil.logTrace("Connection closed");
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Topic and/or
- * Topic Connection, as well as a default Topic and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- /**
- * Method Declaration.
- *
- *
- * @param args
- * @param p
- *
- * @exception Fault
- *
- * @see
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'numProducers' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
-
- // get ready for new test
- TestUtil.logTrace(
- "Getting Administrator and deleting any leftover destinations.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- TestUtil.logTrace("Cleanup: Closing Topic and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: closedTopicConnectionCommitTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:229;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCommitTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TX_TOPIC, user, password);
- TestUtil.logTrace("Try to call commit with closed connection.");
- try {
- tool.getDefaultTopicSession().commit();
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicConnectionCommitTest");
- }
- }
-
- /*
- * @testName: closedTopicConnectionRollbackTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:SPEC:111; JMS:JAVADOC:231;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionRollbackTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call rollback() with closed connection.");
- try {
- tool.getDefaultTopicSession().rollback();
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionRollbackTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionRecoverTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:235;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionRecoverTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call recover() with closed connection.");
- try {
- tool.getDefaultTopicSession().recover();
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionRecoverTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCloseTest
- *
- * @assertion_ids: JMS:SPEC:108; JMS:JAVADOC:107; JMS:JAVADOC:526;
- *
- * @test_Strategy: Close default Connection and call method on it.
- */
-
- public void closedTopicConnectionCloseTest() throws Exception {
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call close again");
- tool.getDefaultTopicConnection().close();
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCloseTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionGetClientIDTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:512;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionGetClientIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call getClientID");
- try {
- String foo = tool.getDefaultTopicConnection().getClientID();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionGetClientIDTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionGetMetaDataTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:516;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionGetMetaDataTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call getMetaData");
- try {
- ConnectionMetaData foo = tool.getDefaultTopicConnection().getMetaData();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionGetMetaDataTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionStartTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:522;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionStartTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call start");
- try {
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionStartTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateTopicSessionTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111;
- *
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateTopicSessionTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call createTopicSession");
- try {
- TopicSession foo = tool.getDefaultTopicConnection()
- .createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.logErr("Fail: wrong exception was returned:", e);
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateTopicSessionTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionSessionCloseTest
- *
- * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:233;
- *
- * @test_Strategy: Close default session and call method on it.
- */
-
- public void closedTopicConnectionSessionCloseTest() throws Exception {
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logMsg("Try to call close on closed session.");
- tool.getDefaultTopicSession().close();
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicConnectionSessionCloseTest");
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateTopicTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:81;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateTopicTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to create topic with closed Connection.");
- try {
- Topic t = tool.getDefaultTopicSession()
- .createTopic("closedTopicConnectionCreateTopicTest");
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateTopicTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateSubscriberTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:83;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateSubscriberTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to create Subscriber with closed Connection.");
- try {
- TopicSubscriber tS = tool.getDefaultTopicSession()
- .createSubscriber(tool.getDefaultTopic());
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateSubscriberTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateSubscriberMsgSelectorTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:85;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateSubscriberMsgSelectorTest()
- throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to create Receiver with closed Connection.");
- try {
- TopicSubscriber tS = tool.getDefaultTopicSession()
- .createSubscriber(tool.getDefaultTopic(), "TEST = 'test'", false);
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateSubscriberMsgSelectorTest",
- e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreatePublisherTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:91;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreatePublisherTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to create Publisher with closed Connection.");
- try {
- TopicPublisher tP = tool.getDefaultTopicSession()
- .createPublisher(tool.getDefaultTopic());
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreatePublisherTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateTempTopicTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:93;
- *
- * @test_Strategy: Close default Connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateTempTopicTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to create TemporaryTopic with closed connection.");
- try {
- TemporaryTopic tT = tool.getDefaultTopicSession()
- .createTemporaryTopic();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateTempTopicTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateMessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:213;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to create message with closed connection.");
- try {
- Message m = tool.getDefaultTopicSession().createMessage();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateMessageTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateBytesMessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:209;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateBytesMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to create BytesMessage with closed connection.");
- try {
- BytesMessage m = tool.getDefaultTopicSession().createBytesMessage();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateBytesMessageTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateMapMessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:211;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateMapMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to create MapMessage with closed connection.");
- try {
- MapMessage m = tool.getDefaultTopicSession().createMapMessage();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateMapMessageTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateObjectMessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:215;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateObjectMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to create ObjectMessage with closed connection.");
- try {
- ObjectMessage m = tool.getDefaultTopicSession().createObjectMessage();
- if (m != null)
- TestUtil.logTrace("m=" + m);
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateObjectMessageTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateObject2MessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:217;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateObject2MessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace(
- "Try to create ObjectMessage(object) with closed connection.");
- try {
- String s = "Simple object";
- ObjectMessage m = tool.getDefaultTopicSession().createObjectMessage(s);
- if (m != null)
- TestUtil.logTrace("m=" + m);
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateObject2MessageTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateStreamMessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:219;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateStreamMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to create StreamMessage with closed connection.");
- try {
- StreamMessage m = tool.getDefaultTopicSession().createStreamMessage();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateStreamMessageTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateTextMessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:221;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateTextMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to create TextMessage with closed connection.");
- try {
- TextMessage m = tool.getDefaultTopicSession().createTextMessage();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateTextMessageTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionCreateText2MessageTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:223;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionCreateText2MessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to create TextMessage with closed connection.");
- try {
- TextMessage m = tool.getDefaultTopicSession()
- .createTextMessage("test message");
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionCreateText2MessageTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionGetTransactedTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:111; JMS:JAVADOC:225;
- *
- * @test_Strategy: Close default connection and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionGetTransactedTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call getTransacted() with closed connection.");
- try {
- boolean b = tool.getDefaultTopicSession().getTransacted();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Caught expected exception");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionGetTransactedTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionSubscriberCloseTest
- *
- * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:338;
- *
- * @test_Strategy: Close default subscriber and call method on it.
- */
-
- public void closedTopicConnectionSubscriberCloseTest() throws Exception {
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call close again");
- tool.getDefaultTopicSubscriber().close();
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionSubscriberCloseTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionGetMessageSelectorTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:326;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionGetMessageSelectorTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call getMessageSelector");
- try {
- String foo = tool.getDefaultTopicSubscriber().getMessageSelector();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionGetMessageSelectorTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionReceiveTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:332;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionReceiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call receive");
- try {
- Message foo = tool.getDefaultTopicSubscriber().receive();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionReceiveTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionReceiveTimeoutTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:334;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionReceiveTimeoutTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call receive(timeout)");
- try {
- Message foo = tool.getDefaultTopicSubscriber().receive(timeout);
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionReceiveTimeoutTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionReceiveNoWaitTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:336;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionReceiveNoWaitTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call receiveNoWait");
- try {
- Message foo = tool.getDefaultTopicSubscriber().receiveNoWait();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionReceiveNoWaitTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionGetNoLocalTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:79;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionGetNoLocalTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call getNoLocal");
- try {
- boolean foo = tool.getDefaultTopicSubscriber().getNoLocal();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionGetNoLocalTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionSubscriberGetTopicTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:77;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionSubscriberGetTopicTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call getTopic");
- try {
- Topic foo = tool.getDefaultTopicSubscriber().getTopic();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionSubscriberGetTopicTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionPublisherCloseTest
- *
- * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:315;
- *
- * @test_Strategy: Close default publisher and call method on it.
- */
-
- public void closedTopicConnectionPublisherCloseTest() throws Exception {
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call close again");
- tool.getDefaultTopicPublisher().close();
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionPublisherCloseTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionGetDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:303;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionGetDeliveryModeTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call getDeliveryMode");
- try {
- int foo = tool.getDefaultTopicPublisher().getDeliveryMode();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionGetDeliveryModeTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionGetDisableMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:295;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionGetDisableMessageIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call getDisableMessageID");
- try {
- boolean foo = tool.getDefaultTopicPublisher().getDisableMessageID();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionGetDisableMessageIDTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionGetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:299;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionGetDisableMessageTimestampTest()
- throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call getDisableMessageTimestamp");
- try {
- boolean foo = tool.getDefaultTopicPublisher()
- .getDisableMessageTimestamp();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionGetDisableMessageTimestampTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionGetPriorityTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:307;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionGetPriorityTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call getPriority");
- try {
- int foo = tool.getDefaultTopicPublisher().getPriority();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionGetPriorityTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionGetTimeToLiveTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:311;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- /**
- * Method Declaration.
- *
- *
- * @exception Fault
- *
- * @see
- */
- public void closedTopicConnectionGetTimeToLiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call getTimeToLive");
- try {
- long foo = tool.getDefaultTopicPublisher().getTimeToLive();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionGetTimeToLiveTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionSetDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:301;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
- public void closedTopicConnectionSetDeliveryModeTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call setDeliveryMode");
- try {
- tool.getDefaultTopicPublisher()
- .setDeliveryMode(Message.DEFAULT_DELIVERY_MODE);
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionSetDeliveryModeTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionSetDisableMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:293;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- /**
- * Method Declaration.
- *
- *
- * @exception Fault
- *
- * @see
- */
- public void closedTopicConnectionSetDisableMessageIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call setDisableMessageID");
- try {
- tool.getDefaultTopicPublisher().setDisableMessageID(true);
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionSetDisableMessageIDTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionSetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:297;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionSetDisableMessageTimestampTest()
- throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call setDisableMessageTimestamp");
- try {
- tool.getDefaultTopicPublisher().setDisableMessageTimestamp(true);
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionSetDisableMessageTimestampTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionSetPriorityTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:305;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionSetPriorityTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call setPriority");
- try {
- tool.getDefaultTopicPublisher().setPriority(Message.DEFAULT_PRIORITY);
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionSetPriorityTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionSetTimeToLiveTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:309;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionSetTimeToLiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call setTimeToLive");
- try {
- tool.getDefaultTopicPublisher()
- .setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionSetTimeToLiveTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionPublisherGetTopicTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:97;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionPublisherGetTopicTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call getTopic");
- try {
- Topic foo = tool.getDefaultTopicPublisher().getTopic();
-
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionPublisherGetTopicTest", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionPublish1Test
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:99;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionPublish1Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call publish(Message)");
- try {
- tool.getDefaultTopicPublisher().publish(new MessageTestImpl());
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionPublish1Test", e);
- }
- }
-
- /*
- * @testName: closedTopicConnectionPublish2Test
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
- * JMS:JAVADOC:101;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicConnectionPublish2Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseConnection(JmsTool.TOPIC, user, password);
- TestUtil.logTrace("Try to call publish(Message,int,int,long)");
- try {
- tool.getDefaultTopicPublisher().publish(new MessageTestImpl(),
- Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
- Message.DEFAULT_TIME_TO_LIVE);
- TestUtil.logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- TestUtil.logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicConnectionPublish2Test", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicConnection/ClosedTopicConnectionTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicConnection/ClosedTopicConnectionTestsIT.java
new file mode 100644
index 0000000000..e4fe24f4fa
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicConnection/ClosedTopicConnectionTestsIT.java
@@ -0,0 +1,1672 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.closedTopicConnection;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.common.MessageTestImpl;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.ConnectionMetaData;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.Session;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TemporaryTopic;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicPublisher;
+import jakarta.jms.TopicSession;
+import jakarta.jms.TopicSubscriber;
+
+/**
+ * JMS product tests. Testing method calls on closed TopicConnection objects.
+ */
+
+public class ClosedTopicConnectionTestsIT {
+ private static final String TestName = "com.sun.ts.tests.jms.core.closedTopicConnection.ClosedTopicConnectionTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedTopicConnectionTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed connection for testing. Passes any
+ * exceptions up to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndCloseConnection(int type, String user, String password) throws Exception {
+ if ((type == JmsTool.TOPIC) || (type == JmsTool.TX_TOPIC)) {
+ tool = new JmsTool(type, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Closing queue Connection");
+ tool.getDefaultTopicConnection().close();
+ }
+ logger.log(Logger.Level.TRACE, "Connection closed");
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Topic and/or
+ * Topic Connection, as well as a default Topic and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ /**
+ * Method Declaration.
+ *
+ *
+ * @param args
+ * @param p
+ *
+ * @exception Fault
+ *
+ * @see
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'numProducers' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+
+ // get ready for new test
+ logger.log(Logger.Level.TRACE, "Getting Administrator and deleting any leftover destinations.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.TRACE, "Cleanup: Closing Topic and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: closedTopicConnectionCommitTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:229;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCommitTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TX_TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call commit with closed connection.");
+ try {
+ tool.getDefaultTopicSession().commit();
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicConnectionCommitTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionRollbackTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526; JMS:SPEC:111;
+ * JMS:JAVADOC:231;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionRollbackTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call rollback() with closed connection.");
+ try {
+ tool.getDefaultTopicSession().rollback();
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionRollbackTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionRecoverTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:235;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionRecoverTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call recover() with closed connection.");
+ try {
+ tool.getDefaultTopicSession().recover();
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionRecoverTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:108; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ *
+ * @test_Strategy: Close default Connection and call method on it.
+ */
+ @Test
+ public void closedTopicConnectionCloseTest() throws Exception {
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultTopicConnection().close();
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionGetClientIDTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:512;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionGetClientIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getClientID");
+ try {
+ String foo = tool.getDefaultTopicConnection().getClientID();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionGetClientIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionGetMetaDataTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:516;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionGetMetaDataTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getMetaData");
+ try {
+ ConnectionMetaData foo = tool.getDefaultTopicConnection().getMetaData();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionGetMetaDataTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionStartTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:522;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionStartTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call start");
+ try {
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionStartTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateTopicSessionTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111;
+ *
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateTopicSessionTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call createTopicSession");
+ try {
+ TopicSession foo = tool.getDefaultTopicConnection().createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: wrong exception was returned:", e);
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateTopicSessionTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionSessionCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:233;
+ *
+ * @test_Strategy: Close default session and call method on it.
+ */
+ @Test
+ public void closedTopicConnectionSessionCloseTest() throws Exception {
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.INFO, "Try to call close on closed session.");
+ tool.getDefaultTopicSession().close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicConnectionSessionCloseTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:81;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateTopicTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create topic with closed Connection.");
+ try {
+ Topic t = tool.getDefaultTopicSession().createTopic("closedTopicConnectionCreateTopicTest");
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateSubscriberTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:83;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateSubscriberTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create Subscriber with closed Connection.");
+ try {
+ TopicSubscriber tS = tool.getDefaultTopicSession().createSubscriber(tool.getDefaultTopic());
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateSubscriberTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateSubscriberMsgSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:85;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateSubscriberMsgSelectorTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create Receiver with closed Connection.");
+ try {
+ TopicSubscriber tS = tool.getDefaultTopicSession().createSubscriber(tool.getDefaultTopic(),
+ "TEST = 'test'", false);
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateSubscriberMsgSelectorTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreatePublisherTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:91;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreatePublisherTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create Publisher with closed Connection.");
+ try {
+ TopicPublisher tP = tool.getDefaultTopicSession().createPublisher(tool.getDefaultTopic());
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreatePublisherTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateTempTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:93;
+ *
+ * @test_Strategy: Close default Connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateTempTopicTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create TemporaryTopic with closed connection.");
+ try {
+ TemporaryTopic tT = tool.getDefaultTopicSession().createTemporaryTopic();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateTempTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:213;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create message with closed connection.");
+ try {
+ Message m = tool.getDefaultTopicSession().createMessage();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateMessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateBytesMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:209;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateBytesMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create BytesMessage with closed connection.");
+ try {
+ BytesMessage m = tool.getDefaultTopicSession().createBytesMessage();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateBytesMessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateMapMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:211;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateMapMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create MapMessage with closed connection.");
+ try {
+ MapMessage m = tool.getDefaultTopicSession().createMapMessage();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateMapMessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateObjectMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:215;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateObjectMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create ObjectMessage with closed connection.");
+ try {
+ ObjectMessage m = tool.getDefaultTopicSession().createObjectMessage();
+ if (m != null)
+ logger.log(Logger.Level.TRACE, "m=" + m);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateObjectMessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateObject2MessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:217;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateObject2MessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create ObjectMessage(object) with closed connection.");
+ try {
+ String s = "Simple object";
+ ObjectMessage m = tool.getDefaultTopicSession().createObjectMessage(s);
+ if (m != null)
+ logger.log(Logger.Level.TRACE, "m=" + m);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateObject2MessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateStreamMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:219;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateStreamMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create StreamMessage with closed connection.");
+ try {
+ StreamMessage m = tool.getDefaultTopicSession().createStreamMessage();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateStreamMessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateTextMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:221;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateTextMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create TextMessage with closed connection.");
+ try {
+ TextMessage m = tool.getDefaultTopicSession().createTextMessage();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateTextMessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionCreateText2MessageTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:223;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionCreateText2MessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to create TextMessage with closed connection.");
+ try {
+ TextMessage m = tool.getDefaultTopicSession().createTextMessage("test message");
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionCreateText2MessageTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionGetTransactedTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:111; JMS:JAVADOC:225;
+ *
+ * @test_Strategy: Close default connection and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionGetTransactedTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getTransacted() with closed connection.");
+ try {
+ boolean b = tool.getDefaultTopicSession().getTransacted();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionGetTransactedTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionSubscriberCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:338;
+ *
+ * @test_Strategy: Close default subscriber and call method on it.
+ */
+ @Test
+ public void closedTopicConnectionSubscriberCloseTest() throws Exception {
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultTopicSubscriber().close();
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionSubscriberCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionGetMessageSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:326;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionGetMessageSelectorTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getMessageSelector");
+ try {
+ String foo = tool.getDefaultTopicSubscriber().getMessageSelector();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionGetMessageSelectorTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionReceiveTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:332;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionReceiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call receive");
+ try {
+ Message foo = tool.getDefaultTopicSubscriber().receive();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionReceiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionReceiveTimeoutTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionReceiveTimeoutTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call receive(timeout)");
+ try {
+ Message foo = tool.getDefaultTopicSubscriber().receive(timeout);
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionReceiveTimeoutTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionReceiveNoWaitTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:336;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionReceiveNoWaitTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call receiveNoWait");
+ try {
+ Message foo = tool.getDefaultTopicSubscriber().receiveNoWait();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionReceiveNoWaitTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionGetNoLocalTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:79;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionGetNoLocalTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getNoLocal");
+ try {
+ boolean foo = tool.getDefaultTopicSubscriber().getNoLocal();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionGetNoLocalTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionSubscriberGetTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:77;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionSubscriberGetTopicTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getTopic");
+ try {
+ Topic foo = tool.getDefaultTopicSubscriber().getTopic();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionSubscriberGetTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionPublisherCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:315;
+ *
+ * @test_Strategy: Close default publisher and call method on it.
+ */
+ @Test
+ public void closedTopicConnectionPublisherCloseTest() throws Exception {
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultTopicPublisher().close();
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionPublisherCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionGetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:303;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionGetDeliveryModeTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getDeliveryMode");
+ try {
+ int foo = tool.getDefaultTopicPublisher().getDeliveryMode();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionGetDeliveryModeTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionGetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:295;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionGetDisableMessageIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getDisableMessageID");
+ try {
+ boolean foo = tool.getDefaultTopicPublisher().getDisableMessageID();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionGetDisableMessageIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionGetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:299;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionGetDisableMessageTimestampTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getDisableMessageTimestamp");
+ try {
+ boolean foo = tool.getDefaultTopicPublisher().getDisableMessageTimestamp();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionGetDisableMessageTimestampTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionGetPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:307;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionGetPriorityTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getPriority");
+ try {
+ int foo = tool.getDefaultTopicPublisher().getPriority();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionGetPriorityTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionGetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:311;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+
+ /**
+ * Method Declaration.
+ *
+ *
+ * @exception Fault
+ *
+ * @see
+ */
+ @Test
+ public void closedTopicConnectionGetTimeToLiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getTimeToLive");
+ try {
+ long foo = tool.getDefaultTopicPublisher().getTimeToLive();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionGetTimeToLiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionSetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:301;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionSetDeliveryModeTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setDeliveryMode");
+ try {
+ tool.getDefaultTopicPublisher().setDeliveryMode(Message.DEFAULT_DELIVERY_MODE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionSetDeliveryModeTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionSetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:293;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+
+ /**
+ * Method Declaration.
+ *
+ *
+ * @exception Fault
+ *
+ * @see
+ */
+ @Test
+ public void closedTopicConnectionSetDisableMessageIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setDisableMessageID");
+ try {
+ tool.getDefaultTopicPublisher().setDisableMessageID(true);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionSetDisableMessageIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionSetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:297;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionSetDisableMessageTimestampTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setDisableMessageTimestamp");
+ try {
+ tool.getDefaultTopicPublisher().setDisableMessageTimestamp(true);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionSetDisableMessageTimestampTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionSetPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:305;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionSetPriorityTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setPriority");
+ try {
+ tool.getDefaultTopicPublisher().setPriority(Message.DEFAULT_PRIORITY);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionSetPriorityTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionSetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:309;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionSetTimeToLiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call setTimeToLive");
+ try {
+ tool.getDefaultTopicPublisher().setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionSetTimeToLiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionPublisherGetTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:97;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionPublisherGetTopicTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call getTopic");
+ try {
+ Topic foo = tool.getDefaultTopicPublisher().getTopic();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionPublisherGetTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionPublish1Test
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:99;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionPublish1Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call publish(Message)");
+ try {
+ tool.getDefaultTopicPublisher().publish(new MessageTestImpl());
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionPublish1Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicConnectionPublish2Test
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:107; JMS:JAVADOC:526;
+ * JMS:JAVADOC:101;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicConnectionPublish2Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseConnection(JmsTool.TOPIC, user, password);
+ logger.log(Logger.Level.TRACE, "Try to call publish(Message,int,int,long)");
+ try {
+ tool.getDefaultTopicPublisher().publish(new MessageTestImpl(), Message.DEFAULT_DELIVERY_MODE,
+ Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicConnectionPublish2Test", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicPublisher/ClosedTopicPublisherTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicPublisher/ClosedTopicPublisherTests.java
deleted file mode 100644
index 824af0dd80..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicPublisher/ClosedTopicPublisherTests.java
+++ /dev/null
@@ -1,626 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.closedTopicPublisher;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.common.MessageTestImpl;
-
-import jakarta.jms.Message;
-import jakarta.jms.Topic;
-
-public class ClosedTopicPublisherTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.closedTopicPublisher.ClosedTopicPublisherTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // Harness req's
- private Properties props = null;
-
- // JMS object
- private transient JmsTool tool = null;
-
- // properties read from ts.jte file
- long timeout;
-
- private String jmsUser;
-
- private String jmsPassword;
-
- private String mode;
-
- ArrayList connections = null;
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ClosedTopicPublisherTests theTests = new ClosedTopicPublisherTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- logMsg("Didn't get expected exception");
- throw new Exception("Didn't catch expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- logTrace("In setup");
- // get props
- jmsUser = p.getProperty("user");
- jmsPassword = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed publisher for testing. Passes any
- * exceptions up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndClosePublisher() throws Exception {
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Closing topic publisher");
- tool.getDefaultTopicPublisher().close();
- logTrace("Publisher closed");
- }
-
- /* Tests */
- /*
- * @testName: closedTopicPublisherCloseTest
- *
- * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:315;
- *
- * @test_Strategy: Close default publisher and call method on it.
- */
-
- public void closedTopicPublisherCloseTest() throws Exception {
- try {
- createAndClosePublisher();
- logTrace("Try to call close again");
- tool.getDefaultTopicPublisher().close();
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherCloseTest", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherGetDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:303;
- *
- * @test_Strategy: Cannot call getDeliveryMode() on closed publishers Close
- * default publisher and call method on it. Check for IllegalStateException.
- */
-
- public void closedTopicPublisherGetDeliveryModeTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call getDeliveryMode");
- try {
- int foo = tool.getDefaultTopicPublisher().getDeliveryMode();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherGetDeliveryModeTest", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherGetDisableMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:295;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicPublisherGetDisableMessageIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call getDisableMessageID");
- try {
- boolean foo = tool.getDefaultTopicPublisher().getDisableMessageID();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherGetDisableMessageIDTest", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherGetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:299;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicPublisherGetDisableMessageTimestampTest()
- throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call getDisableMessageTimestamp");
- try {
- boolean foo = tool.getDefaultTopicPublisher()
- .getDisableMessageTimestamp();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherGetDisableMessageTimestampTest", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherGetPriorityTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:307;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicPublisherGetPriorityTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call getPriority");
- try {
- int foo = tool.getDefaultTopicPublisher().getPriority();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherGetPriorityTest", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherGetTimeToLiveTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:311;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicPublisherGetTimeToLiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call getTimeToLive");
- try {
- long foo = tool.getDefaultTopicPublisher().getTimeToLive();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherGetTimeToLiveTest", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherSetDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:301;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicPublisherSetDeliveryModeTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call setDeliveryMode");
- try {
- tool.getDefaultTopicPublisher()
- .setDeliveryMode(Message.DEFAULT_DELIVERY_MODE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherSetDeliveryModeTest", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherSetDisableMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:293;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicPublisherSetDisableMessageIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call setDisableMessageID");
- try {
- tool.getDefaultTopicPublisher().setDisableMessageID(true);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherSetDisableMessageIDTest", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherSetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:297;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicPublisherSetDisableMessageTimestampTest()
- throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call setDisableMessageTimestamp");
- try {
- tool.getDefaultTopicPublisher().setDisableMessageTimestamp(true);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherSetDisableMessageTimestampTest", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherSetPriorityTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:305;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicPublisherSetPriorityTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call setPriority");
- try {
- tool.getDefaultTopicPublisher().setPriority(Message.DEFAULT_PRIORITY);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherSetPriorityTest", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherSetTimeToLiveTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:309;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicPublisherSetTimeToLiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call setTimeToLive");
- try {
- tool.getDefaultTopicPublisher()
- .setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherSetTimeToLiveTest", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherGetTopicTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:97;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicPublisherGetTopicTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call getTopic");
- try {
- Topic foo = tool.getDefaultTopicPublisher().getTopic();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherGetTopicTest", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherPublish1Test
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:99;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicPublisherPublish1Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call publish(Message)");
- try {
- tool.getDefaultTopicPublisher().publish(new MessageTestImpl());
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherPublish1Test", e);
- }
- }
-
- /*
- * @testName: closedTopicPublisherPublish2Test
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:101;
- *
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
- public void closedTopicPublisherPublish2Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndClosePublisher();
- logTrace("Try to call publish(Message,int,int,long)");
- try {
- tool.getDefaultTopicPublisher().publish(new MessageTestImpl(),
- Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
- Message.DEFAULT_TIME_TO_LIVE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicPublisherPublish2Test", e);
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicPublisher/ClosedTopicPublisherTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicPublisher/ClosedTopicPublisherTestsIT.java
new file mode 100644
index 0000000000..26f160f7cf
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicPublisher/ClosedTopicPublisherTestsIT.java
@@ -0,0 +1,603 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.closedTopicPublisher;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.common.MessageTestImpl;
+
+import jakarta.jms.Message;
+import jakarta.jms.Topic;
+
+
+public class ClosedTopicPublisherTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.closedTopicPublisher.ClosedTopicPublisherIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedTopicPublisherTestsIT.class.getName());
+
+ // Harness req's
+ private Properties props = null;
+
+ // JMS object
+ private transient JmsTool tool = null;
+
+ // properties read
+ long timeout;
+
+ private String jmsUser;
+
+ private String jmsPassword;
+
+ private String mode;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't catch expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, "In setup");
+ // get props
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed publisher for testing. Passes any exceptions
+ * up to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndClosePublisher() throws Exception {
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Closing topic publisher");
+ tool.getDefaultTopicPublisher().close();
+ logger.log(Logger.Level.TRACE, "Publisher closed");
+ }
+
+ /* Tests */
+ /*
+ * @testName: closedTopicPublisherCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:315;
+ *
+ * @test_Strategy: Close default publisher and call method on it.
+ */
+ @Test
+ public void closedTopicPublisherCloseTest() throws Exception {
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultTopicPublisher().close();
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherGetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:303;
+ *
+ * @test_Strategy: Cannot call getDeliveryMode() on closed publishers Close
+ * default publisher and call method on it. Check for IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherGetDeliveryModeTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call getDeliveryMode");
+ try {
+ int foo = tool.getDefaultTopicPublisher().getDeliveryMode();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherGetDeliveryModeTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherGetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:295;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherGetDisableMessageIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call getDisableMessageID");
+ try {
+ boolean foo = tool.getDefaultTopicPublisher().getDisableMessageID();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherGetDisableMessageIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherGetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:299;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherGetDisableMessageTimestampTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call getDisableMessageTimestamp");
+ try {
+ boolean foo = tool.getDefaultTopicPublisher().getDisableMessageTimestamp();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherGetDisableMessageTimestampTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherGetPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:307;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherGetPriorityTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call getPriority");
+ try {
+ int foo = tool.getDefaultTopicPublisher().getPriority();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherGetPriorityTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherGetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:311;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherGetTimeToLiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call getTimeToLive");
+ try {
+ long foo = tool.getDefaultTopicPublisher().getTimeToLive();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherGetTimeToLiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherSetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:301;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherSetDeliveryModeTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call setDeliveryMode");
+ try {
+ tool.getDefaultTopicPublisher().setDeliveryMode(Message.DEFAULT_DELIVERY_MODE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherSetDeliveryModeTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherSetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:293;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherSetDisableMessageIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call setDisableMessageID");
+ try {
+ tool.getDefaultTopicPublisher().setDisableMessageID(true);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherSetDisableMessageIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherSetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:297;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherSetDisableMessageTimestampTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call setDisableMessageTimestamp");
+ try {
+ tool.getDefaultTopicPublisher().setDisableMessageTimestamp(true);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherSetDisableMessageTimestampTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherSetPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:305;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherSetPriorityTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call setPriority");
+ try {
+ tool.getDefaultTopicPublisher().setPriority(Message.DEFAULT_PRIORITY);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherSetPriorityTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherSetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:309;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherSetTimeToLiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call setTimeToLive");
+ try {
+ tool.getDefaultTopicPublisher().setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherSetTimeToLiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherGetTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:97;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherGetTopicTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call getTopic");
+ try {
+ Topic foo = tool.getDefaultTopicPublisher().getTopic();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherGetTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherPublish1Test
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:99;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherPublish1Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call publish(Message)");
+ try {
+ tool.getDefaultTopicPublisher().publish(new MessageTestImpl());
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherPublish1Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicPublisherPublish2Test
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:101;
+ *
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicPublisherPublish2Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndClosePublisher();
+ logger.log(Logger.Level.TRACE, "Try to call publish(Message,int,int,long)");
+ try {
+ tool.getDefaultTopicPublisher().publish(new MessageTestImpl(), Message.DEFAULT_DELIVERY_MODE,
+ Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicPublisherPublish2Test", e);
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicSession/ClosedTopicSessionTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicSession/ClosedTopicSessionTests.java
deleted file mode 100644
index fbf4fab461..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicSession/ClosedTopicSessionTests.java
+++ /dev/null
@@ -1,1486 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.closedTopicSession;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.common.MessageTestImpl;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TemporaryTopic;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicPublisher;
-import jakarta.jms.TopicSubscriber;
-
-public class ClosedTopicSessionTests extends ServiceEETest {
- private static final String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- private static final String testName = "com.sun.ts.tests.jms.core.closedTopicSession.ClosedTopicSessionTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // Harness req's
- private Properties props = null;
-
- // JMS object
- private transient JmsTool tool = null;
-
- // properties read from ts.jte file
- long timeout;
-
- private String jmsUser;
-
- private String jmsPassword;
-
- private String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ClosedTopicSessionTests theTests = new ClosedTopicSessionTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed session for testing. Passes any exceptions
- * up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndCloseSession(int type) throws Exception {
- if ((type == JmsTool.TOPIC) || (type == JmsTool.TX_TOPIC)) {
- tool = new JmsTool(type, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
- logMsg("Closing topic session");
- tool.getDefaultTopicSession().close();
- }
- logMsg("Session closed");
- }
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- logMsg("Didn't get expected exception");
- throw new Exception("Didn't catch expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- logTrace("In setup");
- // get props
- jmsUser = p.getProperty("user");
- jmsPassword = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: closedTopicSessionCommitTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:229;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
- public void closedTopicSessionCommitTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TX_TOPIC);
- logMsg("Try to call commit with closed session.");
- try {
- tool.getDefaultTopicSession().commit();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCommitTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCloseTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:SPEC:114; JMS:JAVADOC:233;
- *
- * @test_Strategy: Close default session and call method on it.
- */
-
- public void closedTopicSessionCloseTest() throws Exception {
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to call close on closed session.");
- tool.getDefaultTopicSession().close();
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCloseTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateDurableSubscriberTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:87;
- *
- * @test_Strategy: Close default session and call method on Cannot call
- * CreateDurableSubscriber() on closed session it. Check for proper
- * JMSException.
- */
-
- public void closedTopicSessionCreateDurableSubscriberTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create DurableSubscriber with closed session.");
- try {
- TopicSubscriber tS = tool.getDefaultTopicSession()
- .createDurableSubscriber(tool.getDefaultTopic(),
- "TestDurableSubscriber");
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateDurableSubscriberTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateDurableSubscriberMsgSelectorTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:89;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionCreateDurableSubscriberMsgSelectorTest()
- throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg(
- "Try to create DurableSubscriber with message selector using closed session.");
- try {
- TopicSubscriber tS = tool.getDefaultTopicSession()
- .createDurableSubscriber(tool.getDefaultTopic(),
- "TestDurableSubscriberMsgSelector", "TEST = 'test'", false);
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception(
- "closedTopicSessionCreateDurableSubscriberMsgSelectorTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateTopicTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:81;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionCreateTopicTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create topic with closed session.");
- try {
- Topic t = tool.getDefaultTopicSession()
- .createTopic("closedTopicSessionCreateTopicTest");
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateTopicTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateSubscriberTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:83;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
- public void closedTopicSessionCreateSubscriberTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create Subscriber with closed session.");
- try {
- TopicSubscriber tS = tool.getDefaultTopicSession()
- .createSubscriber(tool.getDefaultTopic());
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateSubscriberTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateSubscriberMsgSelectorTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:85;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionCreateSubscriberMsgSelectorTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create Subscriber with closed session.");
- try {
- TopicSubscriber tS = tool.getDefaultTopicSession()
- .createSubscriber(tool.getDefaultTopic(), "TEST = 'test'", false);
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateSubscriberMsgSelectorTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreatePublisherTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:91;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- /**
- * Method Declaration.
- *
- *
- * @exception Fault
- *
- * @see
- */
- public void closedTopicSessionCreatePublisherTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create Publisher with closed session.");
- try {
- TopicPublisher tP = tool.getDefaultTopicSession()
- .createPublisher(tool.getDefaultTopic());
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreatePublisherTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateTempTopicTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:93;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionCreateTempTopicTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create TemporaryTopic with closed session.");
- try {
- TemporaryTopic tT = tool.getDefaultTopicSession()
- .createTemporaryTopic();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateTempTopicTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionUnsubscribeTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:95;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionUnsubscribeTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to call unsubscribe with closed session.");
- try {
- tool.getDefaultTopicSession().unsubscribe("TestDurableSubscription");
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionUnsubscribeTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateMessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:213;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionCreateMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create message with closed session.");
- try {
- Message m = tool.getDefaultTopicSession().createMessage();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateMessageTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateBytesMessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:209;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionCreateBytesMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create BytesMessage with closed session.");
- try {
- BytesMessage m = tool.getDefaultTopicSession().createBytesMessage();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateBytesMessageTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateMapMessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:211;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionCreateMapMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create MapMessage with closed session.");
- try {
- MapMessage m = tool.getDefaultTopicSession().createMapMessage();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateMapMessageTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateObjectMessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:215;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
- public void closedTopicSessionCreateObjectMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create ObjectMessage with closed session.");
- try {
- ObjectMessage m = tool.getDefaultTopicSession().createObjectMessage();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateObjectMessageTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateObject2MessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:217;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionCreateObject2MessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create ObjectMessage(object) with closed session.");
- try {
- String s = "Simple object";
- ObjectMessage m = tool.getDefaultTopicSession().createObjectMessage(s);
- if (m != null)
- logMsg("ObjectMessage=" + m);
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateObject2MessageTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateStreamMessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:219;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionCreateStreamMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create StreamMessage with closed session.");
- try {
- StreamMessage m = tool.getDefaultTopicSession().createStreamMessage();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateStreamMessageTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateTextMessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:221;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionCreateTextMessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create TextMessage with closed session.");
- try {
- TextMessage m = tool.getDefaultTopicSession().createTextMessage();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateTextMessageTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionCreateText2MessageTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:223;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionCreateText2MessageTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to create TextMessage with closed session.");
- try {
- TextMessage m = tool.getDefaultTopicSession()
- .createTextMessage("test message");
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionCreateText2MessageTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionGetTransactedTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:225;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionGetTransactedTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to call getTransacted() with closed session.");
- try {
- boolean b = tool.getDefaultTopicSession().getTransacted();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionGetTransactedTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionRollbackTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:231;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionRollbackTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to call rollback() with closed session.");
- try {
- tool.getDefaultTopicSession().rollback();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionRollbackTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionRecoverTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:235;
- *
- * @test_Strategy: Close default session and call method on it. Check for
- * proper JMSException.
- */
-
- public void closedTopicSessionRecoverTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logMsg("Try to call recover() with closed session.");
- try {
- tool.getDefaultTopicSession().recover();
- } catch (jakarta.jms.IllegalStateException ise) {
- logMsg("Caught expected exception");
- passed = true;
- }
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.printStackTrace(e);
- throw new Exception("closedTopicSessionRecoverTest");
- }
- }
-
- /*
- * @testName: closedTopicSessionSubscriberCloseTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:338;
- *
- * @test_Strategy: Close default subscriber and call method on it.
- */
-
- public void closedTopicSessionSubscriberCloseTest() throws Exception {
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call close again");
- tool.getDefaultTopicSubscriber().close();
- } catch (Exception e) {
- throw new Exception("closedTopicSessionSubscriberCloseTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionGetMessageSelectorTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:326;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionGetMessageSelectorTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call getMessageSelector");
- try {
- String foo = tool.getDefaultTopicSubscriber().getMessageSelector();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionGetMessageSelectorTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionReceiveTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:332;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionReceiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call receive");
- try {
- Message foo = tool.getDefaultTopicSubscriber().receive();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionReceiveTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionReceiveTimeoutTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:334;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
- public void closedTopicSessionReceiveTimeoutTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call receive(timeout)");
- try {
- Message foo = tool.getDefaultTopicSubscriber().receive(timeout);
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionReceiveTimeoutTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionReceiveNoWaitTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:336;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionReceiveNoWaitTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call receiveNoWait");
- try {
- Message foo = tool.getDefaultTopicSubscriber().receiveNoWait();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionReceiveNoWaitTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionGetNoLocalTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:79;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
- public void closedTopicSessionGetNoLocalTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call getNoLocal");
- try {
- boolean foo = tool.getDefaultTopicSubscriber().getNoLocal();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionGetNoLocalTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionSubscriberGetTopicTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:77;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionSubscriberGetTopicTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call getTopic");
- try {
- Topic foo = tool.getDefaultTopicSubscriber().getTopic();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionSubscriberGetTopicTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionPublisherCloseTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:315;
- *
- * @test_Strategy: Close default publisher and call method on it.
- */
-
- public void closedTopicSessionPublisherCloseTest() throws Exception {
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call close again");
- tool.getDefaultTopicPublisher().close();
- } catch (Exception e) {
- throw new Exception("closedTopicSessionPublisherCloseTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionGetDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:303;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionGetDeliveryModeTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call getDeliveryMode");
- try {
- int foo = tool.getDefaultTopicPublisher().getDeliveryMode();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionGetDeliveryModeTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionGetDisableMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:295;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionGetDisableMessageIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call getDisableMessageID");
- try {
- boolean foo = tool.getDefaultTopicPublisher().getDisableMessageID();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionGetDisableMessageIDTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionGetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:299;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
- public void closedTopicSessionGetDisableMessageTimestampTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call getDisableMessageTimestamp");
- try {
- boolean foo = tool.getDefaultTopicPublisher()
- .getDisableMessageTimestamp();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionGetDisableMessageTimestampTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionGetPriorityTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:307;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionGetPriorityTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call getPriority");
- try {
- int foo = tool.getDefaultTopicPublisher().getPriority();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionGetPriorityTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionGetTimeToLiveTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:311;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionGetTimeToLiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call getTimeToLive");
- try {
- long foo = tool.getDefaultTopicPublisher().getTimeToLive();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionGetTimeToLiveTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionSetDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:301;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionSetDeliveryModeTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call setDeliveryMode");
- try {
- tool.getDefaultTopicPublisher()
- .setDeliveryMode(Message.DEFAULT_DELIVERY_MODE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionSetDeliveryModeTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionSetDisableMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:293;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionSetDisableMessageIDTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call setDisableMessageID");
- try {
- tool.getDefaultTopicPublisher().setDisableMessageID(true);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionSetDisableMessageIDTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionSetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:297;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionSetDisableMessageTimestampTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call setDisableMessageTimestamp");
- try {
- tool.getDefaultTopicPublisher().setDisableMessageTimestamp(true);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionSetDisableMessageTimestampTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionSetPriorityTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:305;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionSetPriorityTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call setPriority");
- try {
- tool.getDefaultTopicPublisher().setPriority(Message.DEFAULT_PRIORITY);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionSetPriorityTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionSetTimeToLiveTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:309;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionSetTimeToLiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call setTimeToLive");
- try {
- tool.getDefaultTopicPublisher()
- .setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionSetTimeToLiveTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionPublisherGetTopicTest
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:97;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionPublisherGetTopicTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call getTopic");
- try {
- Topic foo = tool.getDefaultTopicPublisher().getTopic();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionPublisherGetTopicTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionPublish1Test
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:99;
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionPublish1Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call publish(Message)");
- try {
- tool.getDefaultTopicPublisher().publish(new MessageTestImpl());
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionPublish1Test", e);
- }
- }
-
- /*
- * @testName: closedTopicSessionPublish2Test
- *
- * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:101;
- *
- *
- * @test_Strategy: Close default publisher and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSessionPublish2Test() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSession(JmsTool.TOPIC);
- logTrace("Try to call publish(Message,int,int,long)");
- try {
- tool.getDefaultTopicPublisher().publish(new MessageTestImpl(),
- Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
- Message.DEFAULT_TIME_TO_LIVE);
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSessionPublish2Test", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicSession/ClosedTopicSessionTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicSession/ClosedTopicSessionTestsIT.java
new file mode 100644
index 0000000000..f8fd306f0f
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicSession/ClosedTopicSessionTestsIT.java
@@ -0,0 +1,1454 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.closedTopicSession;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.common.MessageTestImpl;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TemporaryTopic;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicPublisher;
+import jakarta.jms.TopicSubscriber;
+
+
+public class ClosedTopicSessionTestsIT {
+ private static final String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ private static final String testName = "com.sun.ts.tests.jms.core.closedTopicSession.ClosedTopicSessionTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedTopicSessionTestsIT.class.getName());
+
+ // Harness req's
+ private Properties props = null;
+
+ // JMS object
+ private transient JmsTool tool = null;
+
+ // properties read
+ long timeout;
+
+ private String jmsUser;
+
+ private String jmsPassword;
+
+ private String mode;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed session for testing. Passes any exceptions
+ * up to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndCloseSession(int type) throws Exception {
+ if ((type == JmsTool.TOPIC) || (type == JmsTool.TX_TOPIC)) {
+ tool = new JmsTool(type, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "Closing topic session");
+ tool.getDefaultTopicSession().close();
+ }
+ logger.log(Logger.Level.INFO, "Session closed");
+ }
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't catch expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, "In setup");
+ // get props
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: closedTopicSessionCommitTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:229;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCommitTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TX_TOPIC);
+ logger.log(Logger.Level.INFO, "Try to call commit with closed session.");
+ try {
+ tool.getDefaultTopicSession().commit();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCommitTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:SPEC:114; JMS:JAVADOC:233;
+ *
+ * @test_Strategy: Close default session and call method on it.
+ */
+ @Test
+ public void closedTopicSessionCloseTest() throws Exception {
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to call close on closed session.");
+ tool.getDefaultTopicSession().close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCloseTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateDurableSubscriberTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:87;
+ *
+ * @test_Strategy: Close default session and call method on Cannot call
+ * CreateDurableSubscriber() on closed session it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateDurableSubscriberTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create DurableSubscriber with closed session.");
+ try {
+ TopicSubscriber tS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ "TestDurableSubscriber");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateDurableSubscriberTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateDurableSubscriberMsgSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:89;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateDurableSubscriberMsgSelectorTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO,
+ "Try to create DurableSubscriber with message selector using closed session.");
+ try {
+ TopicSubscriber tS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ "TestDurableSubscriberMsgSelector", "TEST = 'test'", false);
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateDurableSubscriberMsgSelectorTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:81;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateTopicTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create topic with closed session.");
+ try {
+ Topic t = tool.getDefaultTopicSession().createTopic("closedTopicSessionCreateTopicTest");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateTopicTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateSubscriberTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:83;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateSubscriberTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create Subscriber with closed session.");
+ try {
+ TopicSubscriber tS = tool.getDefaultTopicSession().createSubscriber(tool.getDefaultTopic());
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateSubscriberTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateSubscriberMsgSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:85;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateSubscriberMsgSelectorTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create Subscriber with closed session.");
+ try {
+ TopicSubscriber tS = tool.getDefaultTopicSession().createSubscriber(tool.getDefaultTopic(),
+ "TEST = 'test'", false);
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateSubscriberMsgSelectorTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreatePublisherTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:91;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+
+ /**
+ * Method Declaration.
+ *
+ *
+ * @exception Fault
+ *
+ * @see
+ */
+ @Test
+ public void closedTopicSessionCreatePublisherTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create Publisher with closed session.");
+ try {
+ TopicPublisher tP = tool.getDefaultTopicSession().createPublisher(tool.getDefaultTopic());
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreatePublisherTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateTempTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:93;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateTempTopicTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create TemporaryTopic with closed session.");
+ try {
+ TemporaryTopic tT = tool.getDefaultTopicSession().createTemporaryTopic();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateTempTopicTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionUnsubscribeTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:95;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionUnsubscribeTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to call unsubscribe with closed session.");
+ try {
+ tool.getDefaultTopicSession().unsubscribe("TestDurableSubscription");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionUnsubscribeTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:213;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create message with closed session.");
+ try {
+ Message m = tool.getDefaultTopicSession().createMessage();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateMessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateBytesMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:209;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateBytesMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create BytesMessage with closed session.");
+ try {
+ BytesMessage m = tool.getDefaultTopicSession().createBytesMessage();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateBytesMessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateMapMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:211;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateMapMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create MapMessage with closed session.");
+ try {
+ MapMessage m = tool.getDefaultTopicSession().createMapMessage();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateMapMessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateObjectMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:215;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateObjectMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create ObjectMessage with closed session.");
+ try {
+ ObjectMessage m = tool.getDefaultTopicSession().createObjectMessage();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateObjectMessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateObject2MessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:217;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateObject2MessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create ObjectMessage(object) with closed session.");
+ try {
+ String s = "Simple object";
+ ObjectMessage m = tool.getDefaultTopicSession().createObjectMessage(s);
+ if (m != null)
+ logger.log(Logger.Level.INFO, "ObjectMessage=" + m);
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateObject2MessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateStreamMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:219;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateStreamMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create StreamMessage with closed session.");
+ try {
+ StreamMessage m = tool.getDefaultTopicSession().createStreamMessage();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateStreamMessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateTextMessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:221;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateTextMessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create TextMessage with closed session.");
+ try {
+ TextMessage m = tool.getDefaultTopicSession().createTextMessage();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateTextMessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionCreateText2MessageTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:223;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionCreateText2MessageTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to create TextMessage with closed session.");
+ try {
+ TextMessage m = tool.getDefaultTopicSession().createTextMessage("test message");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionCreateText2MessageTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionGetTransactedTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:225;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionGetTransactedTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to call getTransacted() with closed session.");
+ try {
+ boolean b = tool.getDefaultTopicSession().getTransacted();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionGetTransactedTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionRollbackTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:231;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionRollbackTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to call rollback() with closed session.");
+ try {
+ tool.getDefaultTopicSession().rollback();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionRollbackTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionRecoverTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:235;
+ *
+ * @test_Strategy: Close default session and call method on it. Check for proper
+ * JMSException.
+ */
+ @Test
+ public void closedTopicSessionRecoverTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.INFO, "Try to call recover() with closed session.");
+ try {
+ tool.getDefaultTopicSession().recover();
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.INFO, "Caught expected exception");
+ passed = true;
+ }
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ TestUtil.printStackTrace(e);
+ throw new Exception("closedTopicSessionRecoverTest");
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionSubscriberCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:338;
+ *
+ * @test_Strategy: Close default subscriber and call method on it.
+ */
+ @Test
+ public void closedTopicSessionSubscriberCloseTest() throws Exception {
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultTopicSubscriber().close();
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionSubscriberCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionGetMessageSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:326;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionGetMessageSelectorTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call getMessageSelector");
+ try {
+ String foo = tool.getDefaultTopicSubscriber().getMessageSelector();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionGetMessageSelectorTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionReceiveTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:332;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionReceiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call receive");
+ try {
+ Message foo = tool.getDefaultTopicSubscriber().receive();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionReceiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionReceiveTimeoutTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionReceiveTimeoutTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call receive(timeout)");
+ try {
+ Message foo = tool.getDefaultTopicSubscriber().receive(timeout);
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionReceiveTimeoutTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionReceiveNoWaitTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:336;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionReceiveNoWaitTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call receiveNoWait");
+ try {
+ Message foo = tool.getDefaultTopicSubscriber().receiveNoWait();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionReceiveNoWaitTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionGetNoLocalTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:79;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionGetNoLocalTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call getNoLocal");
+ try {
+ boolean foo = tool.getDefaultTopicSubscriber().getNoLocal();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionGetNoLocalTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionSubscriberGetTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:77;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionSubscriberGetTopicTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call getTopic");
+ try {
+ Topic foo = tool.getDefaultTopicSubscriber().getTopic();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionSubscriberGetTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionPublisherCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:315;
+ *
+ * @test_Strategy: Close default publisher and call method on it.
+ */
+ @Test
+ public void closedTopicSessionPublisherCloseTest() throws Exception {
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultTopicPublisher().close();
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionPublisherCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionGetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:303;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionGetDeliveryModeTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call getDeliveryMode");
+ try {
+ int foo = tool.getDefaultTopicPublisher().getDeliveryMode();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionGetDeliveryModeTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionGetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:295;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionGetDisableMessageIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call getDisableMessageID");
+ try {
+ boolean foo = tool.getDefaultTopicPublisher().getDisableMessageID();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionGetDisableMessageIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionGetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:299;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionGetDisableMessageTimestampTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call getDisableMessageTimestamp");
+ try {
+ boolean foo = tool.getDefaultTopicPublisher().getDisableMessageTimestamp();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionGetDisableMessageTimestampTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionGetPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:307;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionGetPriorityTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call getPriority");
+ try {
+ int foo = tool.getDefaultTopicPublisher().getPriority();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionGetPriorityTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionGetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:311;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionGetTimeToLiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call getTimeToLive");
+ try {
+ long foo = tool.getDefaultTopicPublisher().getTimeToLive();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionGetTimeToLiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionSetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:301;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionSetDeliveryModeTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call setDeliveryMode");
+ try {
+ tool.getDefaultTopicPublisher().setDeliveryMode(Message.DEFAULT_DELIVERY_MODE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionSetDeliveryModeTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionSetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:293;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionSetDisableMessageIDTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call setDisableMessageID");
+ try {
+ tool.getDefaultTopicPublisher().setDisableMessageID(true);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionSetDisableMessageIDTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionSetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:297;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionSetDisableMessageTimestampTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call setDisableMessageTimestamp");
+ try {
+ tool.getDefaultTopicPublisher().setDisableMessageTimestamp(true);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionSetDisableMessageTimestampTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionSetPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:305;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionSetPriorityTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call setPriority");
+ try {
+ tool.getDefaultTopicPublisher().setPriority(Message.DEFAULT_PRIORITY);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionSetPriorityTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionSetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:309;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionSetTimeToLiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call setTimeToLive");
+ try {
+ tool.getDefaultTopicPublisher().setTimeToLive(Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionSetTimeToLiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionPublisherGetTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:97;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionPublisherGetTopicTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call getTopic");
+ try {
+ Topic foo = tool.getDefaultTopicPublisher().getTopic();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionPublisherGetTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionPublish1Test
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:99;
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionPublish1Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call publish(Message)");
+ try {
+ tool.getDefaultTopicPublisher().publish(new MessageTestImpl());
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionPublish1Test", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSessionPublish2Test
+ *
+ * @assertion_ids: JMS:SPEC:113; JMS:JAVADOC:101;
+ *
+ *
+ * @test_Strategy: Close default publisher and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSessionPublish2Test() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSession(JmsTool.TOPIC);
+ logger.log(Logger.Level.TRACE, "Try to call publish(Message,int,int,long)");
+ try {
+ tool.getDefaultTopicPublisher().publish(new MessageTestImpl(), Message.DEFAULT_DELIVERY_MODE,
+ Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSessionPublish2Test", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicSubscriber/ClosedTopicSubscriberTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicSubscriber/ClosedTopicSubscriberTests.java
deleted file mode 100644
index df7cfee1d2..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicSubscriber/ClosedTopicSubscriberTests.java
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.closedTopicSubscriber;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.Message;
-import jakarta.jms.Topic;
-
-public class ClosedTopicSubscriberTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.closedTopicSubscriber.ClosedTopicSubscriberTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // Harness req's
- private Properties props = null;
-
- // JMS object
- private transient JmsTool tool = null;
-
- // properties read from ts.jte file
- long timeout;
-
- private String jmsUser;
-
- private String jmsPassword;
-
- private String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ClosedTopicSubscriberTests theTests = new ClosedTopicSubscriberTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- logMsg("Didn't get expected exception");
- throw new Exception("Didn't catch expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- // get props
- jmsUser = p.getProperty("user");
- jmsPassword = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
- /* Utility methods for tests */
-
- /**
- * Used by tests that need a closed subscriber for testing. Passes any
- * exceptions up to caller.
- *
- * @param int
- * The type of session that needs to be created and closed
- */
- private void createAndCloseSubscriber() throws Exception {
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
- tool.getDefaultTopicConnection().start();
-
- logTrace("Closing topic subscriber");
- tool.getDefaultTopicSubscriber().close();
- logTrace("Subscriber closed");
- }
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: closedTopicSubscriberCloseTest
- *
- * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:338;
- *
- * @test_Strategy: Close default subscriber and call method on it.
- */
- public void closedTopicSubscriberCloseTest() throws Exception {
- try {
- createAndCloseSubscriber();
- logTrace("Try to call close again");
- tool.getDefaultTopicSubscriber().close();
- } catch (Exception e) {
- throw new Exception("closedTopicSubscriberCloseTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSubscriberGetMessageSelectorTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:326;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSubscriberGetMessageSelectorTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSubscriber();
- logTrace("Try to call getMessageSelector");
- try {
- String foo = tool.getDefaultTopicSubscriber().getMessageSelector();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSubscriberGetMessageSelectorTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSubscriberReceiveTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:332;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSubscriberReceiveTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSubscriber();
- logTrace("Try to call receive");
- try {
- Message foo = tool.getDefaultTopicSubscriber().receive();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSubscriberReceiveTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSubscriberReceiveTimeoutTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:334;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSubscriberReceiveTimeoutTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSubscriber();
- logTrace("Try to call receive(timeout)");
- try {
- Message foo = tool.getDefaultTopicSubscriber().receive(timeout);
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSubscriberReceiveTimeoutTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSubscriberReceiveNoWaitTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:336;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSubscriberReceiveNoWaitTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSubscriber();
- logTrace("Try to call receiveNoWait");
- try {
- Message foo = tool.getDefaultTopicSubscriber().receiveNoWait();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSubscriberReceiveNoWaitTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSubscriberGetNoLocalTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:79;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
- public void closedTopicSubscriberGetNoLocalTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSubscriber();
- logTrace("Try to call getNoLocal");
- try {
- boolean foo = tool.getDefaultTopicSubscriber().getNoLocal();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSubscriberGetNoLocalTest", e);
- }
- }
-
- /*
- * @testName: closedTopicSubscriberGetTopicTest
- *
- * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:77;
- *
- * @test_Strategy: Close default subscriber and call method on it. Check for
- * IllegalStateException.
- */
-
- public void closedTopicSubscriberGetTopicTest() throws Exception {
- boolean passed = false;
-
- try {
- createAndCloseSubscriber();
- logTrace("Try to call getTopic");
- try {
- Topic foo = tool.getDefaultTopicSubscriber().getTopic();
-
- logTrace("Fail: Exception was not thrown!");
- } catch (jakarta.jms.IllegalStateException ise) {
- logTrace("Pass: threw expected error");
- passed = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Fail: wrong exception: " + e.getClass().getName()
- + " was returned");
- }
- if (!passed) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("closedTopicSubscriberGetTopicTest", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicSubscriber/ClosedTopicSubscriberTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicSubscriber/ClosedTopicSubscriberTestsIT.java
new file mode 100644
index 0000000000..9de6799145
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/closedTopicSubscriber/ClosedTopicSubscriberTestsIT.java
@@ -0,0 +1,370 @@
+/*
+ * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.closedTopicSubscriber;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.Message;
+import jakarta.jms.Topic;
+
+
+public class ClosedTopicSubscriberTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.closedTopicSubscriber.ClosedTopicSubscriberTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClosedTopicSubscriberTestsIT.class.getName());
+
+ // Harness req's
+ private Properties props = null;
+
+ // JMS object
+ private transient JmsTool tool = null;
+
+ // properties read
+ long timeout;
+
+ private String jmsUser;
+
+ private String jmsPassword;
+
+ private String mode;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't catch expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ // get props
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+ /* Utility methods for tests */
+
+ /**
+ * Used by tests that need a closed subscriber for testing. Passes any
+ * exceptions up to caller.
+ *
+ * @param int The type of session that needs to be created and closed
+ */
+ private void createAndCloseSubscriber() throws Exception {
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
+ tool.getDefaultTopicConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Closing topic subscriber");
+ tool.getDefaultTopicSubscriber().close();
+ logger.log(Logger.Level.TRACE, "Subscriber closed");
+ }
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: closedTopicSubscriberCloseTest
+ *
+ * @assertion_ids: JMS:SPEC:201; JMS:JAVADOC:338;
+ *
+ * @test_Strategy: Close default subscriber and call method on it.
+ */
+ @Test
+ public void closedTopicSubscriberCloseTest() throws Exception {
+ try {
+ createAndCloseSubscriber();
+ logger.log(Logger.Level.TRACE, "Try to call close again");
+ tool.getDefaultTopicSubscriber().close();
+ } catch (Exception e) {
+ throw new Exception("closedTopicSubscriberCloseTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSubscriberGetMessageSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:326;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSubscriberGetMessageSelectorTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSubscriber();
+ logger.log(Logger.Level.TRACE, "Try to call getMessageSelector");
+ try {
+ String foo = tool.getDefaultTopicSubscriber().getMessageSelector();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSubscriberGetMessageSelectorTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSubscriberReceiveTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:332;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSubscriberReceiveTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSubscriber();
+ logger.log(Logger.Level.TRACE, "Try to call receive");
+ try {
+ Message foo = tool.getDefaultTopicSubscriber().receive();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSubscriberReceiveTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSubscriberReceiveTimeoutTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSubscriberReceiveTimeoutTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSubscriber();
+ logger.log(Logger.Level.TRACE, "Try to call receive(timeout)");
+ try {
+ Message foo = tool.getDefaultTopicSubscriber().receive(timeout);
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSubscriberReceiveTimeoutTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSubscriberReceiveNoWaitTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:336;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSubscriberReceiveNoWaitTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSubscriber();
+ logger.log(Logger.Level.TRACE, "Try to call receiveNoWait");
+ try {
+ Message foo = tool.getDefaultTopicSubscriber().receiveNoWait();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSubscriberReceiveNoWaitTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSubscriberGetNoLocalTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:79;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSubscriberGetNoLocalTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSubscriber();
+ logger.log(Logger.Level.TRACE, "Try to call getNoLocal");
+ try {
+ boolean foo = tool.getDefaultTopicSubscriber().getNoLocal();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSubscriberGetNoLocalTest", e);
+ }
+ }
+
+ /*
+ * @testName: closedTopicSubscriberGetTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:107; JMS:JAVADOC:77;
+ *
+ * @test_Strategy: Close default subscriber and call method on it. Check for
+ * IllegalStateException.
+ */
+ @Test
+ public void closedTopicSubscriberGetTopicTest() throws Exception {
+ boolean passed = false;
+
+ try {
+ createAndCloseSubscriber();
+ logger.log(Logger.Level.TRACE, "Try to call getTopic");
+ try {
+ Topic foo = tool.getDefaultTopicSubscriber().getTopic();
+
+ logger.log(Logger.Level.TRACE, "Fail: Exception was not thrown!");
+ } catch (jakarta.jms.IllegalStateException ise) {
+ logger.log(Logger.Level.TRACE, "Pass: threw expected error");
+ passed = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Fail: wrong exception: " + e.getClass().getName() + " was returned");
+ }
+ if (!passed) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("closedTopicSubscriberGetTopicTest", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/exceptionQueue/ExceptionQueueTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/exceptionQueue/ExceptionQueueTests.java
deleted file mode 100644
index b00c492253..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/exceptionQueue/ExceptionQueueTests.java
+++ /dev/null
@@ -1,1890 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.exceptionQueue;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.Destination;
-import jakarta.jms.InvalidDestinationException;
-import jakarta.jms.InvalidSelectorException;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.MessageEOFException;
-import jakarta.jms.MessageFormatException;
-import jakarta.jms.MessageNotReadableException;
-import jakarta.jms.MessageNotWriteableException;
-import jakarta.jms.MessageProducer;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueBrowser;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueSender;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-
-public class ExceptionQueueTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.exceptionQueue.ExceptionQueueTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ExceptionQueueTests theTests = new ExceptionQueueTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- queues = new ArrayList(2);
- connections = new ArrayList(2);
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- TestUtil.logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: xInvalidDestinationExceptionQTest
- *
- * @assertion_ids: JMS:SPEC:174; JMS:JAVADOC:190; JMS:JAVADOC:192;
- * JMS:JAVADOC:184; JMS:JAVADOC:186; JMS:JAVADOC:188; JMS:JAVADOC:622;
- * JMS:JAVADOC:623; JMS:JAVADOC:618; JMS:JAVADOC:619; JMS:JAVADOC:621;
- *
- * @test_Strategy: pass an invalid Queue object to createBrowser(null)
- * createBrowser(null,selector) createReceiver(null)
- * createReceiver(null,selector) createSender(null)This null is valid
- *
- */
-
- public void xInvalidDestinationExceptionQTest() throws Exception {
- boolean pass = true;
- QueueBrowser qBrowser = null;
- QueueSender qSender = null;
- QueueReceiver qReceiver = null;
-
- try {
-
- // create Queue Connection and QueueBrowser
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- TestUtil.logTrace("** Close default QueueReceiver **");
- tool.getDefaultQueueReceiver().close();
- tool.getDefaultQueueConnection().start();
-
- // create QueueBrowser
- TestUtil.logMsg("Test createBrowser(null)");
- Queue dummy = null;
-
- try {
- qBrowser = tool.getDefaultQueueSession().createBrowser(dummy);
- if (qBrowser != null)
- TestUtil.logTrace("qBrowser=" + qBrowser);
- TestUtil.logTrace("FAIL: expected InvalidDestinationException!");
- pass = false;
- } catch (Exception ee) {
- if (ee instanceof jakarta.jms.InvalidDestinationException) {
- logTrace("Pass: InvalidDestinationException thrown as expected");
- } else {
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
- }
- TestUtil.logMsg("Test createBrowser(null),selector");
- try {
- qBrowser = tool.getDefaultQueueSession().createBrowser(dummy, "TEST");
- if (qBrowser != null)
- TestUtil.logTrace("qBrowser=" + qBrowser);
- TestUtil.logTrace("FAIL: expected InvalidDestinationException!");
- pass = false;
- } catch (Exception ee) {
- if (ee instanceof jakarta.jms.InvalidDestinationException) {
- logTrace("Pass: InvalidDestinationException thrown as expected");
- } else {
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
- }
- TestUtil.logMsg("Test createReceiver(null)");
- try {
- qReceiver = tool.getDefaultQueueSession().createReceiver(dummy);
- if (qReceiver != null)
- TestUtil.logTrace("qReceiver=" + qReceiver);
- TestUtil.logTrace("FAIL: expected InvalidDestinationException!");
- pass = false;
- } catch (Exception ee) {
- if (ee instanceof jakarta.jms.InvalidDestinationException) {
- logTrace("Pass: InvalidDestinationException thrown as expected");
- } else {
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
- }
- TestUtil.logMsg("Test createReceiver(null,selector)");
- try {
- qReceiver = tool.getDefaultQueueSession().createReceiver(dummy, "TEST");
- if (qReceiver != null)
- TestUtil.logTrace("qReceiver=" + qReceiver);
- TestUtil.logTrace("FAIL: expected InvalidDestinationException!");
- pass = false;
- } catch (Exception ee) {
- if (ee instanceof jakarta.jms.InvalidDestinationException) {
- logTrace("Pass: InvalidDestinationException thrown as expected");
- } else {
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
- }
- TestUtil.logMsg("Test createSender(null) - null is valid here ");
- try {
- qSender = tool.getDefaultQueueSession().createSender(dummy);
- if (qSender != null)
- TestUtil.logTrace("qSender=" + qSender);
- TestUtil.logTrace("PASS: ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception(
- "Error: failures occurred during xInvalidDestinationExceptionQTest tests");
- }
- } catch (Exception e) {
- throw new Exception("xInvalidDestinationExceptionQTest", e);
- }
- }
-
- /*
- * @testName: xMessageNotReadableExceptionQueueTest
- *
- * @assertion_ids: JMS:SPEC:178; JMS:JAVADOC:680;
- *
- * @test_Strategy: create a BytesMessage, read it.
- */
-
- public void xMessageNotReadableExceptionQueueTest() throws Exception {
- try {
- BytesMessage msg = null;
-
- // create Queue Connection
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- // Create a BytesMessage
- msg = tool.getDefaultQueueSession().createBytesMessage();
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotReadableExceptionQueueTest");
- try {
- msg.readByte();
- TestUtil.logTrace("FAIL --- should not have gotten this far!");
- throw new Exception("Fail: Did not throw expected error!!!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace("Passed.\n");
- // TestUtil.printStackTrace(nr);
- TestUtil.logTrace("MessageNotReadableException occurred!");
- TestUtil.logTrace(" " + nr.getMessage());
- }
- } catch (Exception e) {
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.logTrace("Expected MessageNotReadableException did not occur!");
- throw new Exception("xMessageNotReadableExceptionQueueTest test failed", e);
- }
- }
-
- /*
- * @testName: xMessageNotWriteableExceptionQTestforTextMessage
- *
- * @assertion_ids: JMS:SPEC:179; JMS:SPEC:70; JMS:JAVADOC:766;
- *
- * @test_Strategy: When a client receives a text message it is in read-only
- * mode. Send a message and have the client attempt to write to it.
- */
-
- public void xMessageNotWriteableExceptionQTestforTextMessage() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotWriteableExceptionQTestforTextMessage");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- logTrace("Got message - OK");
- }
-
- // Received message should be read-only - verify proper exception is
- // thrown
- try {
- messageReceived.setText("testing...");
- } catch (MessageNotWriteableException nr) {
- TestUtil.logTrace("Passed.\n");
- // TestUtil.printStackTrace(nr);
- TestUtil.logTrace("MessageNotWriteableException occurred!");
- TestUtil.logTrace(" " + nr.getMessage());
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xMessageNotWriteableExceptionQTestforTextMessage");
- }
- }
-
- /*
- * @testName: xMessageNotWriteableExceptionQTestforBytesMessage
- *
- * @assertion_ids: JMS:SPEC:73; JMS:SPEC:179; JMS:SPEC:70; JMS:JAVADOC:702;
- *
- * @test_Strategy: When a client receives a Bytes message it is in read-only
- * mode. Send a message and have the client attempt to write to it.
- */
-
- public void xMessageNotWriteableExceptionQTestforBytesMessage() throws Exception {
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createBytesMessage();
- messageSent.writeByte(bValue);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotWriteableExceptionQTestforBytesMessage");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- logTrace("Got message - OK");
- }
-
- // Received message should be read-only - verify proper exception is
- // thrown
- try {
- messageReceived.writeByte(bValue);
- } catch (MessageNotWriteableException nr) {
- TestUtil.logTrace("Passed.\n");
- // TestUtil.printStackTrace(nr);
- TestUtil.logTrace("MessageNotWriteableException occurred!");
- TestUtil.logTrace(" " + nr.getMessage());
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xMessageNotWriteableExceptionQTestforBytesMessage", e);
- }
- }
-
- /*
- * @testName: xMessageNotWriteableExceptionQTestforStreamMessage
- *
- * @assertion_ids: JMS:SPEC:73; JMS:SPEC:179; JMS:JAVADOC:760;
- *
- * @test_Strategy: When a client receives a Stream message it is in read-only
- * mode. Send a message and have the client attempt to write to it.
- */
-
- public void xMessageNotWriteableExceptionQTestforStreamMessage()
- throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotWriteableExceptionQTestforStreamMessage");
-
- // Irene - what's this?
- // messageSent.writeByte(bValue);
- messageSent.writeString("Testing...");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- logTrace("Got message - OK");
- }
-
- // Received message should be read-only - verify proper exception is
- // thrown
- try {
- messageReceived.writeString("Testing...");
- } catch (MessageNotWriteableException nr) {
- TestUtil.logTrace("Passed.\n");
- // TestUtil.printStackTrace(nr);
- TestUtil.logTrace("MessageNotWriteableException occurred!");
- TestUtil.logTrace(" " + nr.getMessage());
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xMessageNotWriteableExceptionQTestforStreamMessage", e);
- }
- }
-
- /*
- * @testName: xMessageNotWriteableExceptionQTestforMapMessage
- *
- * @assertion_ids: JMS:SPEC:73; JMS:SPEC:179; JMS:JAVADOC:822;
- *
- * @test_Strategy: When a client receives a Map message it is in read-only
- * mode. Send a message and have the client attempt to write to it.
- */
-
- public void xMessageNotWriteableExceptionQTestforMapMessage() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotWriteableExceptionQTestforMapMessage");
-
- // messageSent.setByte("aByte",bValue);
- messageSent.setString("aString", "value");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- logTrace("Got message - OK");
- }
-
- // Received message should be read-only - verify proper exception is
- // thrown
- try {
-
- // messageReceived.setByte("aByte",bValue);
- messageReceived.setString("aString", "value");
- } catch (MessageNotWriteableException nr) {
- TestUtil.logTrace("Passed.\n");
- // TestUtil.printStackTrace(nr);
- TestUtil.logTrace("MessageNotWriteableException occurred!");
- TestUtil.logTrace(" " + nr.getMessage());
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xMessageNotWriteableExceptionQTestforMapMessage", e);
- }
- }
-
- /*
- * @testName: xNullPointerExceptionQueueTest
- *
- * @assertion_ids: JMS:SPEC:86.1;
- *
- * @test_Strategy: Create a bytes message. Attempt to write null to it. Verify
- * that a NullPointerException is thrown.
- *
- */
-
- public void xNullPointerExceptionQueueTest() throws Exception {
- try {
- BytesMessage msg = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- msg = tool.getDefaultQueueSession().createBytesMessage();
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xNullPointerExceptionQueueTest");
- msg.writeBytes(null);
- } catch (java.lang.NullPointerException nullp) {
- TestUtil.logTrace("Passed.\n");
- // TestUtil.printStackTrace(nullp);
- TestUtil.logTrace("NullPointerException occurred!");
- TestUtil.logTrace(" " + nullp.getMessage());
- } catch (Exception e) {
- e.printStackTrace();
- TestUtil.logTrace(" " + e.getMessage());
- TestUtil.logTrace("Expected NullPointerException did not occur!");
- throw new Exception("xNullPointerExceptionQueueTest");
- }
- }
-
- /*
- * @testName: xMessageEOFExceptionQTestforBytesMessage
- *
- * @assertion_ids: JMS:SPEC:176; JMS:JAVADOC:679;
- *
- * @test_Strategy: Send a message to the queue with one byte. Retreive message
- * from queue and read two bytes.
- *
- *
- */
-
- public void xMessageEOFExceptionQTestforBytesMessage() throws Exception {
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createBytesMessage();
- messageSent.writeByte(bValue);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageEOFExceptionQTestforBytesMessage");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- logTrace("Got message - OK");
- }
-
- // Received message should contain one byte
- // reading 2 bytes should throw the excpected exception
- messageReceived.readByte();
- try {
- messageReceived.readByte();
-
- // Should not reach here !!
- TestUtil.logTrace("Failed: expected MessageEOFException not thrown");
- throw new Exception("Fail: Did not throw expected error!!!");
- } catch (MessageEOFException end) {
- TestUtil.logTrace("Passed.\n");
- // TestUtil.printStackTrace(end);
- TestUtil.logTrace("MessageEOFException occurred!");
- TestUtil.logTrace(" " + end.getMessage());
- }
- } catch (Exception e) {
- throw new Exception("xMessageEOFExceptionQTestforBytesMessage", e);
- }
- }
-
- /*
- * @testName: xMessageEOFExceptionQTestforStreamMessage
- *
- * @assertion_ids: JMS:SPEC:176; JMS:JAVADOC:722;
- *
- * @test_Strategy: Send a message to the queue with one byte. Retreive message
- * from queue and read two bytes.
- *
- *
- */
-
- public void xMessageEOFExceptionQTestforStreamMessage() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.writeByte(bValue);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageEOFExceptionQTestforStreamMessage");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- logTrace("Got message - OK");
- }
-
- // Received message should contain one byte
- // reading 2 bytes should throw the excpected exception
- messageReceived.readByte();
- try {
- messageReceived.readByte();
-
- // Should not reach here !!
- TestUtil.logTrace("Failed: expected MessageEOFException not thrown");
- throw new Exception("Fail: Did not throw expected error!!!");
- } catch (MessageEOFException end) {
- TestUtil.logTrace("Passed.\n");
- // TestUtil.printStackTrace(end);
- TestUtil.logTrace("MessageEOFException occurred!");
- TestUtil.logTrace(" " + end.getMessage());
- }
- } catch (Exception e) {
- throw new Exception("xMessageEOFExceptionQTestforStreamMessage", e);
- }
- }
-
- /*
- * @testName: xMessageFormatExceptionQTestforBytesMessage
- *
- * @assertion_ids: JMS:SPEC:177;
- *
- * @test_Strategy: Call writeObject with a q session object
- */
-
- public void xMessageFormatExceptionQTestforBytesMessage() throws Exception {
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createBytesMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageFormatExceptionQTestforBytesMessage");
- logTrace("try to write an invalid object");
- try {
- messageSent.writeObject(tool.getDefaultQueueSession());
-
- // Should not reach here !!
- TestUtil.logTrace("Failed: expected MessageEOFException not thrown");
- throw new Exception("Fail: Did not throw expected error!!!");
- } catch (MessageFormatException fe) {
- TestUtil.logTrace("Passed.\n");
- // TestUtil.printStackTrace(fe);
- TestUtil.logTrace("MessageFormatException occurred!");
- TestUtil.logTrace(" " + fe.getMessage());
- }
- } catch (Exception e) {
- throw new Exception("xMessageFormatExceptionQTestforBytesMessage", e);
- }
- }
-
- /*
- * @testName: xMessageFormatExceptionQTestforStreamMessage
- *
- * @assertion_ids: JMS:SPEC:177; JMS:JAVADOC:744;
- *
- * @test_Strategy: Write a byte array, read it as a string.
- */
-
- public void xMessageFormatExceptionQTestforStreamMessage() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte[] bValues = { 127, 0, 3 };
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.writeBytes(bValues);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageFormatExceptionQTestforStreamMessage");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- logTrace("Got message - OK");
- }
-
- // Received message should contain a byte, read a string
- try {
- messageReceived.readString();
-
- // Should not reach here !!
- TestUtil
- .logTrace("Failed: expected MessageFormatException not thrown");
- throw new Exception("Fail: Did not throw expected error!!!");
- } catch (MessageFormatException fe) {
- TestUtil.logMsg("Passed.\n");
- TestUtil.logTrace("MessageFormatException occurred!");
- TestUtil.logTrace(" " + fe.getMessage());
- }
- } catch (Exception e) {
- throw new Exception("xMessageFormatExceptionQTestforStreamMessage", e);
- }
- }
-
- /*
- * @testName: xInvalidSelectorExceptionQueueTest
- *
- * @assertion_ids: JMS:SPEC:69; JMS:SPEC:175; JMS:JAVADOC:624;
- * JMS:JAVADOC:620;
- *
- * @test_Strategy: call createBrowser with an invalid selector string call
- * createReceiver with an invalid selector string
- */
-
- public void xInvalidSelectorExceptionQueueTest() throws Exception {
- try {
- QueueBrowser qBrowser = null;
- QueueReceiver qReceiver = null;
- boolean pass = true;
-
- // close default QueueReceiver
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- TestUtil.logTrace("** Close default QueueReceiver **");
- tool.getDefaultQueueReceiver().close();
- tool.getDefaultQueueConnection().start();
-
- // send message to Queue
- TestUtil.logTrace("Send message to Queue. Text = \"message 1\"");
- TextMessage msg1 = tool.getDefaultQueueSession().createTextMessage();
-
- msg1.setText("message 1");
- msg1.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xInvalidSelectorExceptionQueueTest");
- tool.getDefaultQueueSender().send(msg1);
-
- try {
- // create QueueBrowser
- TestUtil.logTrace("call createBrowser with incorrect selector.");
- qBrowser = tool.getDefaultQueueSession()
- .createBrowser(tool.getDefaultQueue(), "=TEST 'test'");
- TestUtil.logErr(
- "Error --- createBrowser didn't throw expected InvalidSelectorException!");
- pass = false;
- } catch (InvalidSelectorException es) {
- TestUtil
- .logTrace("createBrowser threw expected InvalidSelectorException!");
- } catch (Exception e) {
- pass = false;
- TestUtil.logErr("Error -- Incorrect Exception thrown by createBrowser.",
- e);
- } finally {
- if (qBrowser != null) {
- try {
- qBrowser.close();
- } catch (Exception ee) {
- TestUtil.logErr("Error -- failed to close qBrowser.", ee);
- }
- }
- }
-
- try {
- // create QueueReceiver
- TestUtil.logTrace("call createReceiver with incorrect selector.");
- qReceiver = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue(), "=TEST 'test'");
- if (qReceiver != null)
- TestUtil.logTrace("qReceiver=" + qReceiver);
- TestUtil.logErr(
- "Error --- createReceiver didn't throw expected InvalidSelectorException!");
- pass = false;
- } catch (InvalidSelectorException es) {
- TestUtil
- .logMsg("createReceiver threw expected InvalidSelectorException!");
- } catch (Exception e) {
- pass = false;
- TestUtil.logErr(
- "Error -- Incorrect Exception thrown by createReceiver.", e);
- } finally {
- if (qReceiver != null) {
- try {
- qReceiver.close();
- } catch (Exception ee) {
- TestUtil.logErr("Error -- failed to close qReceiver.", ee);
- }
- }
- }
-
- if (pass != true)
- throw new Exception("xInvalidSelectorExceptionQueueTest failed!!");
-
- } catch (Exception e) {
- throw new Exception("xInvalidSelectorExceptionQueueTest: ", e);
- }
-
- }
-
- /*
- * @testName: xIllegalStateExceptionQueueTest
- *
- * @assertion_ids: JMS:SPEC:171; JMS:JAVADOC:634;
- *
- * @test_Strategy: Call session.commit() when there is no transaction to be
- * committed. Verify that the proper exception is thrown.
- */
-
- public void xIllegalStateExceptionQueueTest() throws Exception {
- boolean passed = false;
-
- try {
-
- // create Queue Connection
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logMsg("Calling session.commit(), an illegal operation.");
- try {
- tool.getDefaultQueueSession().commit();
- } catch (jakarta.jms.IllegalStateException iStateE) {
- passed = true;
- TestUtil.logMsg("Received jakarta.jms.IllegalStateException -- GOOD");
- TestUtil.logTrace("Exception message: " + iStateE.getMessage());
- }
- if (passed == false) { // need case for no exception being thrown
- throw new Exception("Did not receive IllegalStateException");
- }
- } catch (Exception e) { // handles case of other exception being thrown
- TestUtil.printStackTrace(e);
- throw new Exception("xIllegalStateExceptionQueueTest");
- }
- }
-
- /*
- * @testName: xUnsupportedOperationExceptionQTest1
- *
- * @assertion_ids: JMS:JAVADOC:668; JMS:JAVADOC:671;
- *
- * @test_Strategy: Create a QueueSender with a null Queue. Verify that
- * UnsupportedOperationException is thrown when send is called without a valid
- * Queue.
- */
-
- public void xUnsupportedOperationExceptionQTest1() throws Exception {
- try {
- TextMessage messageSent = null;
- boolean pass = true;
- Queue myQueue = null;
- QueueSender qSender = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
-
- // Close default QueueSender and create a new one with null Queue
- tool.getDefaultQueueSender().close();
- qSender = tool.getDefaultQueueSession().createSender(myQueue);
-
- tool.getDefaultQueueConnection().start();
-
- try {
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xUnsupportedOperationExceptionQTest1");
-
- logTrace("sending a Text message");
- qSender.send(messageSent);
-
- pass = false;
- logErr(
- "Error: QueueSender.send(Message) didn't throw expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException ex) {
- logMsg(
- "Got expected UnsupportedOperationException from QueueSender.send(Message)");
- } catch (Exception e) {
- logErr("Error: QueueSender.send(Message) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xUnsupportedOperationExceptionQTest1");
-
- logTrace("sending a Text message");
- qSender.send(messageSent, Message.DEFAULT_DELIVERY_MODE,
- Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
-
- pass = false;
- logErr(
- "Error: QueueSender.send(Message, int, int, long) didn't throw expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException ex) {
- logMsg(
- "Got expected UnsupportedOperationException from QueueSender.send(Message, int, int, long)");
- } catch (Exception e) {
- logErr(
- "Error: QueueSender.send(Message, int, int, long) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("xUnsupportedOperationExceptionQTest1 Failed!");
- } catch (Exception e) {
- logErr("xUnsupportedOperationExceptionQTest1 Failed!", e);
- throw new Exception("xUnsupportedOperationExceptionQTest1 Failed!", e);
- } finally {
- try {
- if (tool.getDefaultQueueConnection() != null) {
- tool.flushQueue();
- tool.getDefaultQueueConnection().close();
- }
- } catch (Exception e) {
- TestUtil.logErr("Exception closing QueueConnection and cleanup", e);
- }
- }
- }
-
- /*
- * @testName: xUnsupportedOperationExceptionQTest2
- *
- * @assertion_ids: JMS:JAVADOC:599; JMS:JAVADOC:602;
- *
- * @test_Strategy: Create a MessageProducer with a null Destination. Verify
- * that UnsupportedOperationException is thrown when send is called without a
- * valid Destination.
- */
-
- public void xUnsupportedOperationExceptionQTest2() throws Exception {
- try {
- TextMessage messageSent = null;
- boolean pass = true;
- Destination myDest = null;
- MessageProducer mSender = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
-
- // Close default MessageProducer and create a new one with null
- // Destination
- tool.getDefaultProducer().close();
- mSender = tool.getDefaultSession().createProducer(myDest);
-
- tool.getDefaultConnection().start();
-
- try {
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xUnsupportedOperationExceptionQTest2");
-
- logTrace("sending a Text message");
- mSender.send(messageSent);
-
- pass = false;
- logErr(
- "Error: MessageProducer.send(Message) didn't throw expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException ex) {
- logMsg(
- "Got expected UnsupportedOperationException from MessageProducer.send(Message)");
- } catch (Exception e) {
- logErr(
- "Error: MessageProducer.send(Message) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xUnsupportedOperationExceptionQTest2");
-
- logTrace("sending a Text message");
- mSender.send(messageSent, Message.DEFAULT_DELIVERY_MODE,
- Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
-
- pass = false;
- logErr(
- "Error: MessageProducer.send(Message, int, int, long) didn't throw expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException ex) {
- logMsg(
- "Got expected UnsupportedOperationException from MessageProducer.send(Message, int, int, long)");
- } catch (Exception e) {
- logErr(
- "Error: MessageProducer.send(Message, int, int, long) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("xUnsupportedOperationExceptionQTest2 Failed!");
-
- } catch (Exception e) {
- logErr("xUnsupportedOperationExceptionQTest2 Failed!", e);
- throw new Exception("xUnsupportedOperationExceptionQTest2 Failed!", e);
- } finally {
- try {
- if (tool.getDefaultConnection() != null) {
- tool.flushDestination();
- tool.getDefaultConnection().close();
- }
- } catch (Exception e) {
- TestUtil.logErr("Exception closing Connection and cleanup", e);
- }
- }
- }
-
- /*
- * @testName: xUnsupportedOperationExceptionQTest3
- *
- * @assertion_ids: JMS:JAVADOC:605;
- *
- * @test_Strategy: Create a MessageProducer with a valid Destination. Verify
- * that UnsupportedOperationException is thrown when send is called with
- * another valid Destination.
- */
-
- public void xUnsupportedOperationExceptionQTest3() throws Exception {
- try {
- TextMessage messageSent = null;
- boolean pass = true;
- Destination myDest = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultConnection().start();
-
- try {
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xUnsupportedOperationExceptionQTest3");
-
- logTrace("get the second Destination");
- myDest = (Destination) tool.getQueueDestination("MY_QUEUE2");
-
- logTrace("sending a Text message");
- tool.getDefaultProducer().send(myDest, messageSent);
-
- pass = false;
- logErr(
- "Error: MessageProducer.send(Destination, Message) didn't throw expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException ex) {
- logMsg(
- "Got expected UnsupportedOperationException from MessageProducer.send(Destination, Message)");
- } catch (Exception e) {
- logErr(
- "Error: MessageProducer.send(Destination, Message) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("xUnsupportedOperationExceptionQTest3 Failed!");
-
- } catch (Exception e) {
- logErr("xUnsupportedOperationExceptionQTest3 Failed!", e);
- throw new Exception("xUnsupportedOperationExceptionQTest3 Failed!", e);
- } finally {
- try {
- if (tool.getDefaultConnection() != null) {
- tool.flushDestination();
- tool.getDefaultConnection().close();
- }
- } catch (Exception e) {
- TestUtil.logErr("Exception closing Connection and cleanup", e);
- }
- }
- }
-
- /*
- * @testName: xInvalidDestinationExceptionQTests
- *
- * @assertion_ids: JMS:JAVADOC:502; JMS:JAVADOC:504; JMS:JAVADOC:510;
- * JMS:JAVADOC:638; JMS:JAVADOC:639; JMS:JAVADOC:641; JMS:JAVADOC:643;
- * JMS:JAVADOC:644; JMS:JAVADOC:646; JMS:JAVADOC:647; JMS:JAVADOC:649;
- *
- * @test_Strategy: Create a Session with Queue Configuration, using a null
- * Destination/Queue to verify InvalidDestinationException is thrown with
- * various methods
- */
-
- public void xInvalidDestinationExceptionQTests() throws Exception {
-
- try {
- boolean pass = true;
- Destination dummy = null;
- Queue dummyQ = null;
-
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- tool.getDefaultConsumer().close();
-
- try {
- tool.getDefaultSession().createConsumer(dummy);
- logErr(
- "Error: createConsumer(null) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createConsumer(null)");
- } catch (Exception e) {
- logErr("Error: createConsumer(null) throw incorrect Exception: ", e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'");
- logErr(
- "Error: createConsumer(null, String) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createConsumer(null, String)");
- } catch (Exception e) {
- logErr(
- "Error: createConsumer(null, String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'", true);
- logErr(
- "Error: createConsumer(null, String, boolean) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createConsumer(null, String, true)");
- } catch (Exception e) {
- logErr(
- "Error: createConsumer(null, String, true) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createBrowser(dummyQ);
- logErr(
- "Error: createBrowser(null) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createBrowser(null)");
- } catch (Exception e) {
- logErr("Error: createBrowser(null) throw incorrect Exception: ", e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createBrowser(dummyQ, "TEST = 'test'");
- logErr(
- "Error: createBrowser(null, String) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createBrowser(null, String)");
- } catch (Exception e) {
- logErr("Error: createBrowser(null, String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing the default Connection", ex);
- }
-
- if (pass != true)
- throw new Exception("xInvalidDestinationExceptionQTests");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xInvalidDestinationExceptionQTests");
- } finally {
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: xMessageNotReadableExceptionQBytesMsgTest
- *
- * @assertion_ids: JMS:JAVADOC:676; JMS:JAVADOC:678; JMS:JAVADOC:682;
- * JMS:JAVADOC:684; JMS:JAVADOC:686; JMS:JAVADOC:688; JMS:JAVADOC:690;
- * JMS:JAVADOC:692; JMS:JAVADOC:694; JMS:JAVADOC:696; JMS:JAVADOC:698;
- * JMS:JAVADOC:699; JMS:JAVADOC:700;
- *
- * @test_Strategy: Create a BytesMessage, call various read methods on it
- * before sending. Verify that jakarta.jms.MessageNotReadableException is
- * thrown.
- */
-
- public void xMessageNotReadableExceptionQBytesMsgTest() throws Exception {
- try {
- BytesMessage messageSent = null;
- boolean pass = true;
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- byte[] bytesValueRecvd = { 0, 0, 0, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- Integer nInteger = new Integer(-2147483648);
- short shortValue = -32768;
- String utfValue = "what";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- tool.getDefaultConsumer().close();
-
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultSession().createBytesMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotReadableExceptionQBytesMsgTest");
-
- // -----------------------------------------------------------------------------
- logMsg("Writing one of each primitive type to the message");
-
- // -----------------------------------------------------------------------------
- messageSent.writeBoolean(booleanValue);
- messageSent.writeByte(byteValue);
- messageSent.writeChar(charValue);
- messageSent.writeDouble(doubleValue);
- messageSent.writeFloat(floatValue);
- messageSent.writeInt(intValue);
- messageSent.writeLong(longValue);
- messageSent.writeObject(nInteger);
- messageSent.writeShort(shortValue);
- messageSent.writeUTF(utfValue);
- messageSent.writeBytes(bytesValue);
- messageSent.writeBytes(bytesValue, 0, 1);
-
- try {
- messageSent.getBodyLength();
- pass = false;
- TestUtil.logErr(
- "Error: getBodyLength didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "getBodyLength threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("getBodyLength threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readBoolean();
- pass = false;
- TestUtil.logErr(
- "Error: readBoolean didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readBoolean threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readBoolean threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readByte();
- pass = false;
- TestUtil.logErr(
- "Error: readByte didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readByte threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readByte threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readUnsignedByte();
- pass = false;
- TestUtil.logErr(
- "Error: readUnsignedByte didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readUnsignedByte threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readUnsignedByte threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readShort();
- pass = false;
- TestUtil.logErr(
- "Error: readShort didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readShort threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readShort threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readUnsignedShort();
- pass = false;
- TestUtil.logErr(
- "Error: readUnsignedShort didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readUnsignedShort threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readUnsignedShort threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readChar();
- pass = false;
- TestUtil.logErr(
- "Error: readChar didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readChar threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readChar threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readInt();
- pass = false;
- TestUtil.logErr(
- "Error: readInt didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readInt threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readInt threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readLong();
- pass = false;
- TestUtil.logErr(
- "Error: readLong didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readLong threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readLong threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readFloat();
- pass = false;
- TestUtil.logErr(
- "Error: readFloat didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readFloat threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readFloat threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readDouble();
- pass = false;
- TestUtil.logErr(
- "Error: readDouble didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readDouble threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readDouble threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readUTF();
- pass = false;
- TestUtil.logErr(
- "Error: readUTF didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readUTF threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readUTF threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readBytes(bytesValueRecvd);
- pass = false;
- TestUtil.logErr(
- "Error: readBytes(byte[]) didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readBytes(byte[]) threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readBytes(byte[]) threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readBytes(bytesValueRecvd, 1);
- pass = false;
- TestUtil.logErr(
- "Error: readBytes(byte[], int) didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readBytes(byte[], int) threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readBytes(byte[],int) threw Wrong Exception!", e);
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("xMessageNotReadableExceptionQBytesMsgTest Failed!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xMessageNotReadableExceptionQBytesMsgTest:");
- } finally {
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: xMessageNotReadableExceptionQStreamMsgTest
- *
- * @assertion_ids: JMS:SPEC:73.1; JMS:JAVADOC:431; JMS:JAVADOC:721;
- * JMS:JAVADOC:724; JMS:JAVADOC:727; JMS:JAVADOC:730; JMS:JAVADOC:733;
- * JMS:JAVADOC:736; JMS:JAVADOC:739; JMS:JAVADOC:742; JMS:JAVADOC:745;
- * JMS:JAVADOC:748; JMS:JAVADOC:751;
- *
- * @test_Strategy: Create a StreamMessage, send and receive via a Topic; Call
- * clearBoldy right after receiving the message; Call various read methods on
- * received message; Verify jakarta.jms.MessageNotReadableException is thrown.
- */
-
- public void xMessageNotReadableExceptionQStreamMsgTest() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- boolean pass = true;
- byte bValue = 127;
- boolean abool = false;
- byte[] bValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
- byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
- byte[] bValuesReturned = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- char charValue = 'Z';
- short sValue = 32767;
- long lValue = 9223372036854775807L;
- double dValue = 6.02e23;
- float fValue = 6.02e23f;
- int iValue = 6;
- String myString = "text";
- String sTesting = "Testing StreamMessages";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultConnection().start();
-
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotReadableExceptionQStreamMsgTest");
-
- // -----------------------------------------------------------------------------
- logTrace("");
- logMsg("Writing one of each primitive type to the message");
- // -----------------------------------------------------------------------------
- messageSent.writeBytes(bValues2, 0, bValues.length);
- messageSent.writeBoolean(abool);
- messageSent.writeByte(bValue);
- messageSent.writeBytes(bValues);
- messageSent.writeChar(charValue);
- messageSent.writeDouble(dValue);
- messageSent.writeFloat(fValue);
- messageSent.writeInt(iValue);
- messageSent.writeLong(lValue);
- messageSent.writeObject(sTesting);
- messageSent.writeShort(sValue);
- messageSent.writeString(myString);
- messageSent.writeObject(null);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultProducer().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultConsumer()
- .receive(timeout);
-
- TestUtil.logTrace("call ClearBody()");
- messageReceived.clearBody();
-
- try {
- messageReceived.readBoolean();
- pass = false;
- TestUtil.logErr(
- "Error: readBoolean didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readBoolean threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readBoolean threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readByte();
- pass = false;
- TestUtil.logErr(
- "Error: readByte didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readByte threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readByte threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readShort();
- pass = false;
- TestUtil.logErr(
- "Error: readShort didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readShort threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readShort threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readChar();
- pass = false;
- TestUtil.logErr(
- "Error: readChar didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readChar threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readChar threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readInt();
- pass = false;
- TestUtil.logErr(
- "Error: readInt didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readInt threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readInt threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readLong();
- pass = false;
- TestUtil.logErr(
- "Error: readLong didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readLong threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readLong threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readFloat();
- pass = false;
- TestUtil.logErr(
- "Error: readFloat didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readFloat threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readFloat threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readDouble();
- pass = false;
- TestUtil.logErr(
- "Error: readDouble didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readDouble threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readDouble threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readString();
- pass = false;
- TestUtil.logErr(
- "Error: readString didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readString threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readString threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readBytes(bValuesReturned);
- pass = false;
- TestUtil.logErr(
- "Error: readBytes(byte[]) didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readBytes(byte[]) threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readBytes(byte[]) threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readObject();
- pass = false;
- TestUtil.logErr(
- "Error: readObject didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readObject threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readObject threw Wrong Exception!", e);
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("xMessageNotReadableExceptionQStreamMsgTest Failed!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xMessageNotReadableExceptionQStreamMsgTest:");
- } finally {
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: xIllegalStateExceptionTestTopicMethodsQ
- *
- * @assertion_ids: JMS:SPEC:185.2; JMS:SPEC:185.3; JMS:SPEC:185.4;
- * JMS:SPEC:185.5; JMS:SPEC:185;
- *
- * @test_Strategy: Create a QueueSession and call Topic specific methods
- * inherited from Session, and verify that jakarta.jms.IllegalStateException is
- * thrown.
- */
-
- public void xIllegalStateExceptionTestTopicMethodsQ() throws Exception {
-
- try {
- boolean pass = true;
- Topic myTopic = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- myTopic = tool.createNewTopic("MY_TOPIC");
-
- try {
- tool.getDefaultQueueSession().createDurableSubscriber(myTopic, "cts");
- pass = false;
- TestUtil.logErr(
- "Error: QueueSession.createDurableSubscriber(Topic, String) "
- + "didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg(
- "Got expected IllegalStateException from QueueSession.createDurableSubscriber(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: QueueSession.createDurableSubscriber(Topic, String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultQueueSession().createDurableSubscriber(myTopic, "cts",
- "TEST = 'test'", false);
- pass = false;
- TestUtil.logErr(
- "Error: QueueSession.createDurableSubscriber(Topic, String, String, boolean) "
- + "didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg("Got expected IllegalStateException from "
- + "QueueSession.createDurableSubscriber(Topic, String, String, boolean)");
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: QueueSession.createDurableSubscriber(Topic, String, String, boolean) "
- + "throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultQueueSession().createTemporaryTopic();
- pass = false;
- TestUtil.logErr(
- "Error: QueueSession.createTemporayTopic() didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg(
- "Got expected IllegalStateException from QueueSession.createTemporayTopic()");
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: QueueSession.createTemporayTopic() throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultQueueSession().createTopic("foo");
- pass = false;
- TestUtil.logErr(
- "Error: QueueSession.createTopic(String) didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg(
- "Got expected IllegalStateException from QueueSession.createTopic(String)");
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: QueueSession.createTopic(String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultQueueSession().unsubscribe("foo");
- pass = false;
- TestUtil.logErr(
- "Error: QueueSession.unsubscribe(String) didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg(
- "Got expected IllegalStateException from QueueSession.unsubscribe(String)");
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: QueueSession.unsubscribe(String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("xIllegalStateExceptionTestTopicMethodsQ Failed!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xIllegalStateExceptionTestTopicMethodsQ");
- } finally {
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- TestUtil.logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: xIllegalStateExceptionTestRollbackQ
- *
- * @assertion_ids: JMS:JAVADOC:502; JMS:JAVADOC:504; JMS:JAVADOC:510;
- * JMS:JAVADOC:242; JMS:JAVADOC:635; JMS:JAVADOC:317;
- *
- * @test_Strategy: 1. Create a TextMessages, send use a MessageProducer 2.
- * Then rollback on the non-transacted session Verify that
- * IllegalStateException is thrown
- */
-
- public void xIllegalStateExceptionTestRollbackQ() throws Exception {
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- boolean pass = true;
-
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultConnection().start();
-
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xIllegalStateExceptionTestRollbackQ");
-
- // send the message and then get it back
- logTrace("Sending message to a Queue");
- tool.getDefaultProducer().send(messageSent);
-
- try {
- logTrace(
- "Rolling back a non-transacted session must throw IllegalStateException");
- tool.getDefaultSession().rollback();
- pass = false;
- TestUtil.logErr(
- "Error: QueueSession.rollback() didn't throw expected IllegalStateException");
- } catch (jakarta.jms.IllegalStateException en) {
- TestUtil.logMsg(
- "Got expected IllegalStateException from QueueSession.rollback()");
- }
-
- if (pass != true)
- throw new Exception("xIllegalStateExceptionTestRollbackQ");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xIllegalStateExceptionTestRollbackQ");
- } finally {
- try {
- tool.closeDefaultConnections();
- tool.flushDestination();
- } catch (Exception ex) {
- TestUtil.logErr("Error closing Connection", ex);
- }
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/exceptionQueue/ExceptionQueueTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/exceptionQueue/ExceptionQueueTestsIT.java
new file mode 100644
index 0000000000..f3108cf125
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/exceptionQueue/ExceptionQueueTestsIT.java
@@ -0,0 +1,1778 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.exceptionQueue;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.Destination;
+import jakarta.jms.InvalidDestinationException;
+import jakarta.jms.InvalidSelectorException;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.MessageEOFException;
+import jakarta.jms.MessageFormatException;
+import jakarta.jms.MessageNotReadableException;
+import jakarta.jms.MessageNotWriteableException;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueBrowser;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueSender;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+
+
+public class ExceptionQueueTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.exceptionQueue.ExceptionQueueTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ExceptionQueueTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ queues = new ArrayList(2);
+ connections = new ArrayList(2);
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: xInvalidDestinationExceptionQTest
+ *
+ * @assertion_ids: JMS:SPEC:174; JMS:JAVADOC:190; JMS:JAVADOC:192;
+ * JMS:JAVADOC:184; JMS:JAVADOC:186; JMS:JAVADOC:188; JMS:JAVADOC:622;
+ * JMS:JAVADOC:623; JMS:JAVADOC:618; JMS:JAVADOC:619; JMS:JAVADOC:621;
+ *
+ * @test_Strategy: pass an invalid Queue object to createBrowser(null)
+ * createBrowser(null,selector) createReceiver(null)
+ * createReceiver(null,selector) createSender(null)This null is valid
+ *
+ */
+ @Test
+ public void xInvalidDestinationExceptionQTest() throws Exception {
+ boolean pass = true;
+ QueueBrowser qBrowser = null;
+ QueueSender qSender = null;
+ QueueReceiver qReceiver = null;
+
+ try {
+
+ // create Queue Connection and QueueBrowser
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ logger.log(Logger.Level.TRACE, "** Close default QueueReceiver **");
+ tool.getDefaultQueueReceiver().close();
+ tool.getDefaultQueueConnection().start();
+
+ // create QueueBrowser
+ logger.log(Logger.Level.INFO, "Test createBrowser(null)");
+ Queue dummy = null;
+
+ try {
+ qBrowser = tool.getDefaultQueueSession().createBrowser(dummy);
+ if (qBrowser != null)
+ logger.log(Logger.Level.TRACE, "qBrowser=" + qBrowser);
+ logger.log(Logger.Level.TRACE, "FAIL: expected InvalidDestinationException!");
+ pass = false;
+ } catch (Exception ee) {
+ if (ee instanceof jakarta.jms.InvalidDestinationException) {
+ logger.log(Logger.Level.TRACE, "Pass: InvalidDestinationException thrown as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Test createBrowser(null),selector");
+ try {
+ qBrowser = tool.getDefaultQueueSession().createBrowser(dummy, "TEST");
+ if (qBrowser != null)
+ logger.log(Logger.Level.TRACE, "qBrowser=" + qBrowser);
+ logger.log(Logger.Level.TRACE, "FAIL: expected InvalidDestinationException!");
+ pass = false;
+ } catch (Exception ee) {
+ if (ee instanceof jakarta.jms.InvalidDestinationException) {
+ logger.log(Logger.Level.TRACE, "Pass: InvalidDestinationException thrown as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Test createReceiver(null)");
+ try {
+ qReceiver = tool.getDefaultQueueSession().createReceiver(dummy);
+ if (qReceiver != null)
+ logger.log(Logger.Level.TRACE, "qReceiver=" + qReceiver);
+ logger.log(Logger.Level.TRACE, "FAIL: expected InvalidDestinationException!");
+ pass = false;
+ } catch (Exception ee) {
+ if (ee instanceof jakarta.jms.InvalidDestinationException) {
+ logger.log(Logger.Level.TRACE, "Pass: InvalidDestinationException thrown as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Test createReceiver(null,selector)");
+ try {
+ qReceiver = tool.getDefaultQueueSession().createReceiver(dummy, "TEST");
+ if (qReceiver != null)
+ logger.log(Logger.Level.TRACE, "qReceiver=" + qReceiver);
+ logger.log(Logger.Level.TRACE, "FAIL: expected InvalidDestinationException!");
+ pass = false;
+ } catch (Exception ee) {
+ if (ee instanceof jakarta.jms.InvalidDestinationException) {
+ logger.log(Logger.Level.TRACE, "Pass: InvalidDestinationException thrown as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Test createSender(null) - null is valid here ");
+ try {
+ qSender = tool.getDefaultQueueSession().createSender(dummy);
+ if (qSender != null)
+ logger.log(Logger.Level.TRACE, "qSender=" + qSender);
+ logger.log(Logger.Level.TRACE, "PASS: ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during xInvalidDestinationExceptionQTest tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("xInvalidDestinationExceptionQTest", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageNotReadableExceptionQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:178; JMS:JAVADOC:680;
+ *
+ * @test_Strategy: create a BytesMessage, read it.
+ */
+ @Test
+ public void xMessageNotReadableExceptionQueueTest() throws Exception {
+ try {
+ BytesMessage msg = null;
+
+ // create Queue Connection
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ // Create a BytesMessage
+ msg = tool.getDefaultQueueSession().createBytesMessage();
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotReadableExceptionQueueTest");
+ try {
+ msg.readByte();
+ logger.log(Logger.Level.TRACE, "FAIL --- should not have gotten this far!");
+ throw new Exception("Fail: Did not throw expected error!!!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ // TestUtil.printStackTrace(nr);
+ logger.log(Logger.Level.TRACE, "MessageNotReadableException occurred!");
+ logger.log(Logger.Level.TRACE, " " + nr.getMessage());
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ logger.log(Logger.Level.TRACE, "Expected MessageNotReadableException did not occur!");
+ throw new Exception("xMessageNotReadableExceptionQueueTest test failed", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageNotWriteableExceptionQTestforTextMessage
+ *
+ * @assertion_ids: JMS:SPEC:179; JMS:SPEC:70; JMS:JAVADOC:766;
+ *
+ * @test_Strategy: When a client receives a text message it is in read-only
+ * mode. Send a message and have the client attempt to write to it.
+ */
+ @Test
+ public void xMessageNotWriteableExceptionQTestforTextMessage() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotWriteableExceptionQTestforTextMessage");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should be read-only - verify proper exception is
+ // thrown
+ try {
+ messageReceived.setText("testing...");
+ } catch (MessageNotWriteableException nr) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ // TestUtil.printStackTrace(nr);
+ logger.log(Logger.Level.TRACE, "MessageNotWriteableException occurred!");
+ logger.log(Logger.Level.TRACE, " " + nr.getMessage());
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xMessageNotWriteableExceptionQTestforTextMessage");
+ }
+ }
+
+ /*
+ * @testName: xMessageNotWriteableExceptionQTestforBytesMessage
+ *
+ * @assertion_ids: JMS:SPEC:73; JMS:SPEC:179; JMS:SPEC:70; JMS:JAVADOC:702;
+ *
+ * @test_Strategy: When a client receives a Bytes message it is in read-only
+ * mode. Send a message and have the client attempt to write to it.
+ */
+ @Test
+ public void xMessageNotWriteableExceptionQTestforBytesMessage() throws Exception {
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createBytesMessage();
+ messageSent.writeByte(bValue);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotWriteableExceptionQTestforBytesMessage");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should be read-only - verify proper exception is
+ // thrown
+ try {
+ messageReceived.writeByte(bValue);
+ } catch (MessageNotWriteableException nr) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ // TestUtil.printStackTrace(nr);
+ logger.log(Logger.Level.TRACE, "MessageNotWriteableException occurred!");
+ logger.log(Logger.Level.TRACE, " " + nr.getMessage());
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xMessageNotWriteableExceptionQTestforBytesMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageNotWriteableExceptionQTestforStreamMessage
+ *
+ * @assertion_ids: JMS:SPEC:73; JMS:SPEC:179; JMS:JAVADOC:760;
+ *
+ * @test_Strategy: When a client receives a Stream message it is in read-only
+ * mode. Send a message and have the client attempt to write to it.
+ */
+ @Test
+ public void xMessageNotWriteableExceptionQTestforStreamMessage() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotWriteableExceptionQTestforStreamMessage");
+
+ // Irene - what's this?
+ // messageSent.writeByte(bValue);
+ messageSent.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should be read-only - verify proper exception is
+ // thrown
+ try {
+ messageReceived.writeString("Testing...");
+ } catch (MessageNotWriteableException nr) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ // TestUtil.printStackTrace(nr);
+ logger.log(Logger.Level.TRACE, "MessageNotWriteableException occurred!");
+ logger.log(Logger.Level.TRACE, " " + nr.getMessage());
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xMessageNotWriteableExceptionQTestforStreamMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageNotWriteableExceptionQTestforMapMessage
+ *
+ * @assertion_ids: JMS:SPEC:73; JMS:SPEC:179; JMS:JAVADOC:822;
+ *
+ * @test_Strategy: When a client receives a Map message it is in read-only mode.
+ * Send a message and have the client attempt to write to it.
+ */
+ @Test
+ public void xMessageNotWriteableExceptionQTestforMapMessage() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotWriteableExceptionQTestforMapMessage");
+
+ // messageSent.setByte("aByte",bValue);
+ messageSent.setString("aString", "value");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should be read-only - verify proper exception is
+ // thrown
+ try {
+
+ // messageReceived.setByte("aByte",bValue);
+ messageReceived.setString("aString", "value");
+ } catch (MessageNotWriteableException nr) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ // TestUtil.printStackTrace(nr);
+ logger.log(Logger.Level.TRACE, "MessageNotWriteableException occurred!");
+ logger.log(Logger.Level.TRACE, " " + nr.getMessage());
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xMessageNotWriteableExceptionQTestforMapMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xNullPointerExceptionQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:86.1;
+ *
+ * @test_Strategy: Create a bytes message. Attempt to write null to it. Verify
+ * that a NullPointerException is thrown.
+ *
+ */
+ @Test
+ public void xNullPointerExceptionQueueTest() throws Exception {
+ try {
+ BytesMessage msg = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ msg = tool.getDefaultQueueSession().createBytesMessage();
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "xNullPointerExceptionQueueTest");
+ msg.writeBytes(null);
+ } catch (java.lang.NullPointerException nullp) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ // TestUtil.printStackTrace(nullp);
+ logger.log(Logger.Level.TRACE, "NullPointerException occurred!");
+ logger.log(Logger.Level.TRACE, " " + nullp.getMessage());
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.log(Logger.Level.TRACE, " " + e.getMessage());
+ logger.log(Logger.Level.TRACE, "Expected NullPointerException did not occur!");
+ throw new Exception("xNullPointerExceptionQueueTest");
+ }
+ }
+
+ /*
+ * @testName: xMessageEOFExceptionQTestforBytesMessage
+ *
+ * @assertion_ids: JMS:SPEC:176; JMS:JAVADOC:679;
+ *
+ * @test_Strategy: Send a message to the queue with one byte. Retreive message
+ * from queue and read two bytes.
+ *
+ *
+ */
+ @Test
+ public void xMessageEOFExceptionQTestforBytesMessage() throws Exception {
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createBytesMessage();
+ messageSent.writeByte(bValue);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageEOFExceptionQTestforBytesMessage");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should contain one byte
+ // reading 2 bytes should throw the excpected exception
+ messageReceived.readByte();
+ try {
+ messageReceived.readByte();
+
+ // Should not reach here !!
+ logger.log(Logger.Level.TRACE, "Failed: expected MessageEOFException not thrown");
+ throw new Exception("Fail: Did not throw expected error!!!");
+ } catch (MessageEOFException end) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ // TestUtil.printStackTrace(end);
+ logger.log(Logger.Level.TRACE, "MessageEOFException occurred!");
+ logger.log(Logger.Level.TRACE, " " + end.getMessage());
+ }
+ } catch (Exception e) {
+ throw new Exception("xMessageEOFExceptionQTestforBytesMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageEOFExceptionQTestforStreamMessage
+ *
+ * @assertion_ids: JMS:SPEC:176; JMS:JAVADOC:722;
+ *
+ * @test_Strategy: Send a message to the queue with one byte. Retreive message
+ * from queue and read two bytes.
+ *
+ *
+ */
+ @Test
+ public void xMessageEOFExceptionQTestforStreamMessage() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.writeByte(bValue);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageEOFExceptionQTestforStreamMessage");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should contain one byte
+ // reading 2 bytes should throw the excpected exception
+ messageReceived.readByte();
+ try {
+ messageReceived.readByte();
+
+ // Should not reach here !!
+ logger.log(Logger.Level.TRACE, "Failed: expected MessageEOFException not thrown");
+ throw new Exception("Fail: Did not throw expected error!!!");
+ } catch (MessageEOFException end) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ // TestUtil.printStackTrace(end);
+ logger.log(Logger.Level.TRACE, "MessageEOFException occurred!");
+ logger.log(Logger.Level.TRACE, " " + end.getMessage());
+ }
+ } catch (Exception e) {
+ throw new Exception("xMessageEOFExceptionQTestforStreamMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageFormatExceptionQTestforBytesMessage
+ *
+ * @assertion_ids: JMS:SPEC:177;
+ *
+ * @test_Strategy: Call writeObject with a q session object
+ */
+ @Test
+ public void xMessageFormatExceptionQTestforBytesMessage() throws Exception {
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createBytesMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageFormatExceptionQTestforBytesMessage");
+ logger.log(Logger.Level.TRACE, "try to write an invalid object");
+ try {
+ messageSent.writeObject(tool.getDefaultQueueSession());
+
+ // Should not reach here !!
+ logger.log(Logger.Level.TRACE, "Failed: expected MessageEOFException not thrown");
+ throw new Exception("Fail: Did not throw expected error!!!");
+ } catch (MessageFormatException fe) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ // TestUtil.printStackTrace(fe);
+ logger.log(Logger.Level.TRACE, "MessageFormatException occurred!");
+ logger.log(Logger.Level.TRACE, " " + fe.getMessage());
+ }
+ } catch (Exception e) {
+ throw new Exception("xMessageFormatExceptionQTestforBytesMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageFormatExceptionQTestforStreamMessage
+ *
+ * @assertion_ids: JMS:SPEC:177; JMS:JAVADOC:744;
+ *
+ * @test_Strategy: Write a byte array, read it as a string.
+ */
+ @Test
+ public void xMessageFormatExceptionQTestforStreamMessage() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte[] bValues = { 127, 0, 3 };
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.writeBytes(bValues);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageFormatExceptionQTestforStreamMessage");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should contain a byte, read a string
+ try {
+ messageReceived.readString();
+
+ // Should not reach here !!
+ logger.log(Logger.Level.TRACE, "Failed: expected MessageFormatException not thrown");
+ throw new Exception("Fail: Did not throw expected error!!!");
+ } catch (MessageFormatException fe) {
+ logger.log(Logger.Level.INFO, "Passed.\n");
+ logger.log(Logger.Level.TRACE, "MessageFormatException occurred!");
+ logger.log(Logger.Level.TRACE, " " + fe.getMessage());
+ }
+ } catch (Exception e) {
+ throw new Exception("xMessageFormatExceptionQTestforStreamMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xInvalidSelectorExceptionQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:69; JMS:SPEC:175; JMS:JAVADOC:624; JMS:JAVADOC:620;
+ *
+ * @test_Strategy: call createBrowser with an invalid selector string call
+ * createReceiver with an invalid selector string
+ */
+ @Test
+ public void xInvalidSelectorExceptionQueueTest() throws Exception {
+ try {
+ QueueBrowser qBrowser = null;
+ QueueReceiver qReceiver = null;
+ boolean pass = true;
+
+ // close default QueueReceiver
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ logger.log(Logger.Level.TRACE, "** Close default QueueReceiver **");
+ tool.getDefaultQueueReceiver().close();
+ tool.getDefaultQueueConnection().start();
+
+ // send message to Queue
+ logger.log(Logger.Level.TRACE, "Send message to Queue. Text = \"message 1\"");
+ TextMessage msg1 = tool.getDefaultQueueSession().createTextMessage();
+
+ msg1.setText("message 1");
+ msg1.setStringProperty("COM_SUN_JMS_TESTNAME", "xInvalidSelectorExceptionQueueTest");
+ tool.getDefaultQueueSender().send(msg1);
+
+ try {
+ // create QueueBrowser
+ logger.log(Logger.Level.TRACE, "call createBrowser with incorrect selector.");
+ qBrowser = tool.getDefaultQueueSession().createBrowser(tool.getDefaultQueue(), "=TEST 'test'");
+ logger.log(Logger.Level.ERROR,
+ "Error --- createBrowser didn't throw expected InvalidSelectorException!");
+ pass = false;
+ } catch (InvalidSelectorException es) {
+ logger.log(Logger.Level.TRACE, "createBrowser threw expected InvalidSelectorException!");
+ } catch (Exception e) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error -- Incorrect Exception thrown by createBrowser.", e);
+ } finally {
+ if (qBrowser != null) {
+ try {
+ qBrowser.close();
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error -- failed to close qBrowser.", ee);
+ }
+ }
+ }
+
+ try {
+ // create QueueReceiver
+ logger.log(Logger.Level.TRACE, "call createReceiver with incorrect selector.");
+ qReceiver = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue(), "=TEST 'test'");
+ if (qReceiver != null)
+ logger.log(Logger.Level.TRACE, "qReceiver=" + qReceiver);
+ logger.log(Logger.Level.ERROR,
+ "Error --- createReceiver didn't throw expected InvalidSelectorException!");
+ pass = false;
+ } catch (InvalidSelectorException es) {
+ logger.log(Logger.Level.INFO, "createReceiver threw expected InvalidSelectorException!");
+ } catch (Exception e) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error -- Incorrect Exception thrown by createReceiver.", e);
+ } finally {
+ if (qReceiver != null) {
+ try {
+ qReceiver.close();
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error -- failed to close qReceiver.", ee);
+ }
+ }
+ }
+
+ if (pass != true)
+ throw new Exception("xInvalidSelectorExceptionQueueTest failed!!");
+
+ } catch (Exception e) {
+ throw new Exception("xInvalidSelectorExceptionQueueTest: ", e);
+ }
+
+ }
+
+ /*
+ * @testName: xIllegalStateExceptionQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:171; JMS:JAVADOC:634;
+ *
+ * @test_Strategy: Call session.commit() when there is no transaction to be
+ * committed. Verify that the proper exception is thrown.
+ */
+ @Test
+ public void xIllegalStateExceptionQueueTest() throws Exception {
+ boolean passed = false;
+
+ try {
+
+ // create Queue Connection
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.INFO, "Calling session.commit(), an illegal operation.");
+ try {
+ tool.getDefaultQueueSession().commit();
+ } catch (jakarta.jms.IllegalStateException iStateE) {
+ passed = true;
+ logger.log(Logger.Level.INFO, "Received jakarta.jms.IllegalStateException -- GOOD");
+ logger.log(Logger.Level.TRACE, "Exception message: " + iStateE.getMessage());
+ }
+ if (passed == false) { // need case for no exception being thrown
+ throw new Exception("Did not receive IllegalStateException");
+ }
+ } catch (Exception e) { // handles case of other exception being thrown
+ TestUtil.printStackTrace(e);
+ throw new Exception("xIllegalStateExceptionQueueTest");
+ }
+ }
+
+ /*
+ * @testName: xUnsupportedOperationExceptionQTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:668; JMS:JAVADOC:671;
+ *
+ * @test_Strategy: Create a QueueSender with a null Queue. Verify that
+ * UnsupportedOperationException is thrown when send is called without a valid
+ * Queue.
+ */
+ @Test
+ public void xUnsupportedOperationExceptionQTest1() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ boolean pass = true;
+ Queue myQueue = null;
+ QueueSender qSender = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+
+ // Close default QueueSender and create a new one with null Queue
+ tool.getDefaultQueueSender().close();
+ qSender = tool.getDefaultQueueSession().createSender(myQueue);
+
+ tool.getDefaultQueueConnection().start();
+
+ try {
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xUnsupportedOperationExceptionQTest1");
+
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+ qSender.send(messageSent);
+
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: QueueSender.send(Message) didn't throw expected UnsupportedOperationException.");
+ } catch (UnsupportedOperationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected UnsupportedOperationException from QueueSender.send(Message)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: QueueSender.send(Message) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xUnsupportedOperationExceptionQTest1");
+
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+ qSender.send(messageSent, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
+ Message.DEFAULT_TIME_TO_LIVE);
+
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: QueueSender.send(Message, int, int, long) didn't throw expected UnsupportedOperationException.");
+ } catch (UnsupportedOperationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected UnsupportedOperationException from QueueSender.send(Message, int, int, long)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error: QueueSender.send(Message, int, int, long) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("xUnsupportedOperationExceptionQTest1 Failed!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "xUnsupportedOperationExceptionQTest1 Failed!", e);
+ throw new Exception("xUnsupportedOperationExceptionQTest1 Failed!", e);
+ } finally {
+ try {
+ if (tool.getDefaultQueueConnection() != null) {
+ tool.flushQueue();
+ tool.getDefaultQueueConnection().close();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception closing QueueConnection and cleanup", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: xUnsupportedOperationExceptionQTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:599; JMS:JAVADOC:602;
+ *
+ * @test_Strategy: Create a MessageProducer with a null Destination. Verify that
+ * UnsupportedOperationException is thrown when send is called without a valid
+ * Destination.
+ */
+ @Test
+ public void xUnsupportedOperationExceptionQTest2() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ boolean pass = true;
+ Destination myDest = null;
+ MessageProducer mSender = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+
+ // Close default MessageProducer and create a new one with null
+ // Destination
+ tool.getDefaultProducer().close();
+ mSender = tool.getDefaultSession().createProducer(myDest);
+
+ tool.getDefaultConnection().start();
+
+ try {
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xUnsupportedOperationExceptionQTest2");
+
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+ mSender.send(messageSent);
+
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: MessageProducer.send(Message) didn't throw expected UnsupportedOperationException.");
+ } catch (UnsupportedOperationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected UnsupportedOperationException from MessageProducer.send(Message)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: MessageProducer.send(Message) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xUnsupportedOperationExceptionQTest2");
+
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+ mSender.send(messageSent, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
+ Message.DEFAULT_TIME_TO_LIVE);
+
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: MessageProducer.send(Message, int, int, long) didn't throw expected UnsupportedOperationException.");
+ } catch (UnsupportedOperationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected UnsupportedOperationException from MessageProducer.send(Message, int, int, long)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error: MessageProducer.send(Message, int, int, long) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("xUnsupportedOperationExceptionQTest2 Failed!");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "xUnsupportedOperationExceptionQTest2 Failed!", e);
+ throw new Exception("xUnsupportedOperationExceptionQTest2 Failed!", e);
+ } finally {
+ try {
+ if (tool.getDefaultConnection() != null) {
+ tool.flushDestination();
+ tool.getDefaultConnection().close();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception closing Connection and cleanup", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: xUnsupportedOperationExceptionQTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:605;
+ *
+ * @test_Strategy: Create a MessageProducer with a valid Destination. Verify
+ * that UnsupportedOperationException is thrown when send is called with another
+ * valid Destination.
+ */
+ @Test
+ public void xUnsupportedOperationExceptionQTest3() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ boolean pass = true;
+ Destination myDest = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultConnection().start();
+
+ try {
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xUnsupportedOperationExceptionQTest3");
+
+ logger.log(Logger.Level.TRACE, "get the second Destination");
+ myDest = (Destination) tool.getQueueDestination("MY_QUEUE2");
+
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+ tool.getDefaultProducer().send(myDest, messageSent);
+
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: MessageProducer.send(Destination, Message) didn't throw expected UnsupportedOperationException.");
+ } catch (UnsupportedOperationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected UnsupportedOperationException from MessageProducer.send(Destination, Message)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error: MessageProducer.send(Destination, Message) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("xUnsupportedOperationExceptionQTest3 Failed!");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "xUnsupportedOperationExceptionQTest3 Failed!", e);
+ throw new Exception("xUnsupportedOperationExceptionQTest3 Failed!", e);
+ } finally {
+ try {
+ if (tool.getDefaultConnection() != null) {
+ tool.flushDestination();
+ tool.getDefaultConnection().close();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception closing Connection and cleanup", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: xInvalidDestinationExceptionQTests
+ *
+ * @assertion_ids: JMS:JAVADOC:502; JMS:JAVADOC:504; JMS:JAVADOC:510;
+ * JMS:JAVADOC:638; JMS:JAVADOC:639; JMS:JAVADOC:641; JMS:JAVADOC:643;
+ * JMS:JAVADOC:644; JMS:JAVADOC:646; JMS:JAVADOC:647; JMS:JAVADOC:649;
+ *
+ * @test_Strategy: Create a Session with Queue Configuration, using a null
+ * Destination/Queue to verify InvalidDestinationException is thrown with
+ * various methods
+ */
+ @Test
+ public void xInvalidDestinationExceptionQTests() throws Exception {
+
+ try {
+ boolean pass = true;
+ Destination dummy = null;
+ Queue dummyQ = null;
+
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ tool.getDefaultConsumer().close();
+
+ try {
+ tool.getDefaultSession().createConsumer(dummy);
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(null) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO, "Got expected InvalidDestinationException from createConsumer(null)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(null) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'");
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(null, String) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createConsumer(null, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(null, String) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'", true);
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(null, String, boolean) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createConsumer(null, String, true)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(null, String, true) throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createBrowser(dummyQ);
+ logger.log(Logger.Level.ERROR,
+ "Error: createBrowser(null) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO, "Got expected InvalidDestinationException from createBrowser(null)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createBrowser(null) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createBrowser(dummyQ, "TEST = 'test'");
+ logger.log(Logger.Level.ERROR,
+ "Error: createBrowser(null, String) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createBrowser(null, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createBrowser(null, String) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing the default Connection", ex);
+ }
+
+ if (pass != true)
+ throw new Exception("xInvalidDestinationExceptionQTests");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xInvalidDestinationExceptionQTests");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: xMessageNotReadableExceptionQBytesMsgTest
+ *
+ * @assertion_ids: JMS:JAVADOC:676; JMS:JAVADOC:678; JMS:JAVADOC:682;
+ * JMS:JAVADOC:684; JMS:JAVADOC:686; JMS:JAVADOC:688; JMS:JAVADOC:690;
+ * JMS:JAVADOC:692; JMS:JAVADOC:694; JMS:JAVADOC:696; JMS:JAVADOC:698;
+ * JMS:JAVADOC:699; JMS:JAVADOC:700;
+ *
+ * @test_Strategy: Create a BytesMessage, call various read methods on it before
+ * sending. Verify that jakarta.jms.MessageNotReadableException is thrown.
+ */
+ @Test
+ public void xMessageNotReadableExceptionQBytesMsgTest() throws Exception {
+ try {
+ BytesMessage messageSent = null;
+ boolean pass = true;
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ byte[] bytesValueRecvd = { 0, 0, 0, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ Integer nInteger = new Integer(-2147483648);
+ short shortValue = -32768;
+ String utfValue = "what";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ tool.getDefaultConsumer().close();
+
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultSession().createBytesMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotReadableExceptionQBytesMsgTest");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Writing one of each primitive type to the message");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeBoolean(booleanValue);
+ messageSent.writeByte(byteValue);
+ messageSent.writeChar(charValue);
+ messageSent.writeDouble(doubleValue);
+ messageSent.writeFloat(floatValue);
+ messageSent.writeInt(intValue);
+ messageSent.writeLong(longValue);
+ messageSent.writeObject(nInteger);
+ messageSent.writeShort(shortValue);
+ messageSent.writeUTF(utfValue);
+ messageSent.writeBytes(bytesValue);
+ messageSent.writeBytes(bytesValue, 0, 1);
+
+ try {
+ messageSent.getBodyLength();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: getBodyLength didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "getBodyLength threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "getBodyLength threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readBoolean();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readBoolean didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readBoolean threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readBoolean threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readByte();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readByte didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readByte threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readByte threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readUnsignedByte();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: readUnsignedByte didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readUnsignedByte threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readUnsignedByte threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readShort();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readShort didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readShort threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readShort threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readUnsignedShort();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: readUnsignedShort didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readUnsignedShort threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readUnsignedShort threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readChar();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readChar didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readChar threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readChar threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readInt();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readInt didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readInt threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readInt threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readLong();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readLong didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readLong threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readLong threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readFloat();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readFloat didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readFloat threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readFloat threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readDouble();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readDouble didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readDouble threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readDouble threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readUTF();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readUTF didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readUTF threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readUTF threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readBytes(bytesValueRecvd);
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: readBytes(byte[]) didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readBytes(byte[]) threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readBytes(byte[]) threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readBytes(bytesValueRecvd, 1);
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: readBytes(byte[], int) didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readBytes(byte[], int) threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readBytes(byte[],int) threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("xMessageNotReadableExceptionQBytesMsgTest Failed!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xMessageNotReadableExceptionQBytesMsgTest:");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: xMessageNotReadableExceptionQStreamMsgTest
+ *
+ * @assertion_ids: JMS:SPEC:73.1; JMS:JAVADOC:431; JMS:JAVADOC:721;
+ * JMS:JAVADOC:724; JMS:JAVADOC:727; JMS:JAVADOC:730; JMS:JAVADOC:733;
+ * JMS:JAVADOC:736; JMS:JAVADOC:739; JMS:JAVADOC:742; JMS:JAVADOC:745;
+ * JMS:JAVADOC:748; JMS:JAVADOC:751;
+ *
+ * @test_Strategy: Create a StreamMessage, send and receive via a Topic; Call
+ * clearBoldy right after receiving the message; Call various read methods on
+ * received message; Verify jakarta.jms.MessageNotReadableException is thrown.
+ */
+ @Test
+ public void xMessageNotReadableExceptionQStreamMsgTest() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ boolean pass = true;
+ byte bValue = 127;
+ boolean abool = false;
+ byte[] bValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+ byte[] bValuesReturned = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ char charValue = 'Z';
+ short sValue = 32767;
+ long lValue = 9223372036854775807L;
+ double dValue = 6.02e23;
+ float fValue = 6.02e23f;
+ int iValue = 6;
+ String myString = "text";
+ String sTesting = "Testing StreamMessages";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotReadableExceptionQStreamMsgTest");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "");
+ logger.log(Logger.Level.INFO, "Writing one of each primitive type to the message");
+ // -----------------------------------------------------------------------------
+ messageSent.writeBytes(bValues2, 0, bValues.length);
+ messageSent.writeBoolean(abool);
+ messageSent.writeByte(bValue);
+ messageSent.writeBytes(bValues);
+ messageSent.writeChar(charValue);
+ messageSent.writeDouble(dValue);
+ messageSent.writeFloat(fValue);
+ messageSent.writeInt(iValue);
+ messageSent.writeLong(lValue);
+ messageSent.writeObject(sTesting);
+ messageSent.writeShort(sValue);
+ messageSent.writeString(myString);
+ messageSent.writeObject(null);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultProducer().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultConsumer().receive(timeout);
+
+ logger.log(Logger.Level.TRACE, "call ClearBody()");
+ messageReceived.clearBody();
+
+ try {
+ messageReceived.readBoolean();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readBoolean didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readBoolean threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readBoolean threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readByte();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readByte didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readByte threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readByte threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readShort();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readShort didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readShort threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readShort threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readChar();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readChar didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readChar threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readChar threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readInt();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readInt didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readInt threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readInt threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readLong();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readLong didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readLong threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readLong threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readFloat();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readFloat didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readFloat threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readFloat threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readDouble();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readDouble didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readDouble threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readDouble threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readString();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readString didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readString threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readString threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readBytes(bValuesReturned);
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: readBytes(byte[]) didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readBytes(byte[]) threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readBytes(byte[]) threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readObject();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readObject didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readObject threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readObject threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("xMessageNotReadableExceptionQStreamMsgTest Failed!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xMessageNotReadableExceptionQStreamMsgTest:");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: xIllegalStateExceptionTestTopicMethodsQ
+ *
+ * @assertion_ids: JMS:SPEC:185.2; JMS:SPEC:185.3; JMS:SPEC:185.4;
+ * JMS:SPEC:185.5; JMS:SPEC:185;
+ *
+ * @test_Strategy: Create a QueueSession and call Topic specific methods
+ * inherited from Session, and verify that jakarta.jms.IllegalStateException is
+ * thrown.
+ */
+ @Test
+ public void xIllegalStateExceptionTestTopicMethodsQ() throws Exception {
+
+ try {
+ boolean pass = true;
+ Topic myTopic = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ myTopic = tool.createNewTopic("MY_TOPIC");
+
+ try {
+ tool.getDefaultQueueSession().createDurableSubscriber(myTopic, "cts");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: QueueSession.createDurableSubscriber(Topic, String) "
+ + "didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateException from QueueSession.createDurableSubscriber(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error: QueueSession.createDurableSubscriber(Topic, String) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultQueueSession().createDurableSubscriber(myTopic, "cts", "TEST = 'test'", false);
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: QueueSession.createDurableSubscriber(Topic, String, String, boolean) "
+ + "didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateException from "
+ + "QueueSession.createDurableSubscriber(Topic, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error: QueueSession.createDurableSubscriber(Topic, String, String, boolean) "
+ + "throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultQueueSession().createTemporaryTopic();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: QueueSession.createTemporayTopic() didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateException from QueueSession.createTemporayTopic()");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: QueueSession.createTemporayTopic() throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultQueueSession().createTopic("foo");
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: QueueSession.createTopic(String) didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateException from QueueSession.createTopic(String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: QueueSession.createTopic(String) throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultQueueSession().unsubscribe("foo");
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: QueueSession.unsubscribe(String) didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateException from QueueSession.unsubscribe(String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: QueueSession.unsubscribe(String) throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("xIllegalStateExceptionTestTopicMethodsQ Failed!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xIllegalStateExceptionTestTopicMethodsQ");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: xIllegalStateExceptionTestRollbackQ
+ *
+ * @assertion_ids: JMS:JAVADOC:502; JMS:JAVADOC:504; JMS:JAVADOC:510;
+ * JMS:JAVADOC:242; JMS:JAVADOC:635; JMS:JAVADOC:317;
+ *
+ * @test_Strategy: 1. Create a TextMessages, send use a MessageProducer 2. Then
+ * rollback on the non-transacted session Verify that IllegalStateException is
+ * thrown
+ */
+ @Test
+ public void xIllegalStateExceptionTestRollbackQ() throws Exception {
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ boolean pass = true;
+
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultConnection().start();
+
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xIllegalStateExceptionTestRollbackQ");
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message to a Queue");
+ tool.getDefaultProducer().send(messageSent);
+
+ try {
+ logger.log(Logger.Level.TRACE,
+ "Rolling back a non-transacted session must throw IllegalStateException");
+ tool.getDefaultSession().rollback();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: QueueSession.rollback() didn't throw expected IllegalStateException");
+ } catch (jakarta.jms.IllegalStateException en) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateException from QueueSession.rollback()");
+ }
+
+ if (pass != true)
+ throw new Exception("xIllegalStateExceptionTestRollbackQ");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xIllegalStateExceptionTestRollbackQ");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ tool.flushDestination();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/exceptionTopic/ExceptionTopicTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/exceptionTopic/ExceptionTopicTests.java
deleted file mode 100644
index 4681b45baa..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/exceptionTopic/ExceptionTopicTests.java
+++ /dev/null
@@ -1,1553 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.exceptionTopic;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.Destination;
-import jakarta.jms.InvalidDestinationException;
-import jakarta.jms.InvalidSelectorException;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.MessageEOFException;
-import jakarta.jms.MessageFormatException;
-import jakarta.jms.MessageNotReadableException;
-import jakarta.jms.MessageNotWriteableException;
-import jakarta.jms.Queue;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicPublisher;
-import jakarta.jms.TopicSubscriber;
-
-public class ExceptionTopicTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.exceptionTopic.ExceptionTopicTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // Harness req's
- private Properties props = null;
-
- // JMS object
- private transient JmsTool tool = null;
-
- // properties read from ts.jte file
- long timeout;
-
- private String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- private String jmsUser;
-
- private String jmsPassword;
-
- private String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ExceptionTopicTests theTests = new ExceptionTopicTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- logMsg("Didn't get expected exception");
- throw new Exception("Didn't catch expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- TestUtil.logTrace("In setup");
- // get props
- jmsUser = p.getProperty("user");
- jmsPassword = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- connections = new ArrayList(2);
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: xInvalidDestinationExceptionTopicTest
- *
- * @assertion_ids: JMS:SPEC:174; JMS:JAVADOC:83; JMS:JAVADOC:85;
- * JMS:JAVADOC:87; JMS:JAVADOC:89; JMS:JAVADOC:91; JMS:JAVADOC:95;
- * JMS:JAVADOC:625; JMS:JAVADOC:626; JMS:JAVADOC:628; JMS:JAVADOC:629;
- * JMS:JAVADOC:631; JMS:JAVADOC:632;
- *
- * @test_Strategy: pass an invalid Topic object to createSubscriber(null)
- * createSubscriber(null,selector,nolocal)
- * createDurableSubscriber(null,subscriber)
- * createDurableSubscriber(null,String,selector,nolocal) createPublisher(null)
- * - null is valid here. unsubscribe(invalidSubscriptionName)
- */
-
- public void xInvalidDestinationExceptionTopicTest() throws Exception {
- boolean pass = true;
- TopicPublisher tPublisher = null;
- TopicSubscriber tSubscriber = null;
- Topic dummy = null;
-
- try {
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- TestUtil.logTrace("** Close default TopicSubscriber **");
- tool.getDefaultTopicSubscriber().close();
- tool.getDefaultTopicConnection().start();
- logMsg("Test unsubscribe(invalidSubscriptionName)");
- try {
- tool.getDefaultTopicSession().unsubscribe("invalidSubscriptionName");
- TestUtil.logTrace("FAIL: expected InvalidDestinationException!");
- pass = false;
- } catch (Exception ee) {
- if (ee instanceof jakarta.jms.InvalidDestinationException) {
- TestUtil
- .logTrace("Pass: InvalidDestinationException thrown as expected");
- } else {
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
- }
- logMsg("Test createSubscriber(null)");
- try {
- tSubscriber = tool.getDefaultTopicSession().createSubscriber(dummy);
- TestUtil.logTrace("FAIL: expected InvalidDestinationException!");
- pass = false;
- } catch (Exception ee) {
- if (ee instanceof jakarta.jms.InvalidDestinationException) {
- TestUtil
- .logTrace("Pass: InvalidDestinationException thrown as expected");
- } else {
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
- }
- logMsg("Test createSubscriber(null,selector,nolocal)");
- try {
- tSubscriber = tool.getDefaultTopicSession().createSubscriber(dummy,
- "TEST", true);
- TestUtil.logTrace("FAIL: expected InvalidDestinationException!");
- pass = false;
- } catch (Exception ee) {
- if (ee instanceof jakarta.jms.InvalidDestinationException) {
- TestUtil
- .logTrace("Pass: InvalidDestinationException thrown as expected");
- } else {
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
- }
- logMsg("Test createDurableSubscriber(null,String)");
- try {
- tSubscriber = tool.getDefaultTopicSession()
- .createDurableSubscriber(dummy, "durable");
- TestUtil.logTrace("FAIL: expected InvalidDestinationException!");
- pass = false;
- } catch (Exception ee) {
- if (ee instanceof jakarta.jms.InvalidDestinationException) {
- TestUtil
- .logTrace("Pass: InvalidDestinationException thrown as expected");
- } else {
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
- }
- logMsg("Test createDurableSubscriber(null,String,selector,nolocal)");
- try {
- tSubscriber = tool.getDefaultTopicSession()
- .createDurableSubscriber(dummy, "durable", "TEST", true);
- TestUtil.logTrace("FAIL: expected InvalidDestinationException!");
- pass = false;
- } catch (Exception ee) {
- if (ee instanceof jakarta.jms.InvalidDestinationException) {
- TestUtil
- .logTrace("Pass: InvalidDestinationException thrown as expected");
- } else {
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
- }
- logMsg("Test createPublisher(null) - This is valid");
- try {
- tPublisher = tool.getDefaultTopicSession().createPublisher(dummy);
- if (tPublisher != null)
- logMsg("tPublisher=" + tPublisher);
- TestUtil.logTrace("PASS: null allowed for unidentified producer");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logErr("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception(
- "Error: failures occurred during xInvalidDestinationExceptionQTest tests");
- }
- } catch (Exception e) {
- throw new Exception("xInvalidDestinationExceptionTopicTest", e);
- }
- }
-
- /*
- * @testName: xMessageNotReadableExceptionTopicTest
- *
- * @assertion_ids: JMS:SPEC:178; JMS:JAVADOC:680;
- *
- * @test_Strategy: create a BytesMessage, read it.
- */
-
- public void xMessageNotReadableExceptionTopicTest() throws Exception {
- try {
- BytesMessage msg = null;
-
- // create Topic Connection
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
-
- // Create a BytesMessage
- msg = tool.getDefaultTopicSession().createBytesMessage();
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotReadableExceptionTopicTest");
- try {
- msg.readByte();
- TestUtil.logErr("FAIL --- should not have gotten this far!");
- throw new Exception("Fail: Did not throw expected error!!!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logMsg("Passed with expected MessageNotReadableException.");
- }
- } catch (Exception e) {
- TestUtil.logErr("Expected MessageNotReadableException did not occur:", e);
- throw new Exception("xMessageNotReadableExceptionTopicTest test failed", e);
- }
- }
-
- /*
- * @testName: xMessageNotWriteableExceptionTTestforTextMessage
- *
- * @assertion_ids: JMS:SPEC:179; JMS:SPEC:70; JMS:JAVADOC:766;
- *
- * @test_Strategy: When a client receives a text message it is in read-only
- * mode. Publish a message and have the client attempt to write to it.
- */
-
- public void xMessageNotWriteableExceptionTTestforTextMessage() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotWriteableExceptionTTestforTextMessage");
- TestUtil.logTrace("Publishing message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- TestUtil.logTrace("Got message - OK");
- }
-
- // Received message should be read-only - verify proper exception is
- // thrown
- try {
- messageReceived.setText("testing...");
- } catch (MessageNotWriteableException nr) {
- TestUtil.logMsg("Passed with expected MessageNotWriteableException");
- }
- } catch (Exception e) {
- TestUtil.logErr(
- "xMessageNotWriteableExceptionTTestforTextMessage failed:", e);
- throw new Exception("xMessageNotWriteableExceptionTTestforTextMessage", e);
- }
- }
-
- /*
- * @testName: xMessageNotWriteableExceptionTestforBytesMessage
- *
- * @assertion_ids: JMS:SPEC:73; JMS:SPEC:179; JMS:JAVADOC:702;
- *
- * @test_Strategy: When a client receives a Bytes message it is in read-only
- * mode. Publish a message and have the client attempt to write to it.
- */
-
- public void xMessageNotWriteableExceptionTestforBytesMessage() throws Exception {
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createBytesMessage();
- messageSent.writeByte(bValue);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotWriteableExceptionTestforBytesMessage");
- TestUtil.logTrace("Publishing message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (BytesMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- TestUtil.logTrace("Got message - OK");
- }
-
- // Received message should be read-only - verify proper exception is
- // thrown
- try {
- messageReceived.writeByte(bValue);
- } catch (MessageNotWriteableException nr) {
- TestUtil.logMsg("Passed with expected MessageNotWriteableException.");
- }
- } catch (Exception e) {
- TestUtil.logErr(
- "xMessageNotWriteableExceptionTestforBytesMessage failed: ", e);
- throw new Exception("xMessageNotWriteableExceptionTestforBytesMessage", e);
- }
- }
-
- /*
- * @testName: xMessageNotWriteableExceptionTTestforStreamMessage
- *
- * @assertion_ids: JMS:SPEC:73; JMS:SPEC:179; JMS:JAVADOC:760;
- *
- * @test_Strategy: When a client receives a Stream message it is in read-only
- * mode. Publish a message and have the client attempt to write to it.
- */
-
- public void xMessageNotWriteableExceptionTTestforStreamMessage()
- throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotWriteableExceptionTTestforStreamMessage");
-
- messageSent.writeString("Testing...");
- TestUtil.logTrace("Publishing message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- TestUtil.logTrace("Got message - OK");
- }
-
- // Received message should be read-only - verify proper exception is
- // thrown
- try {
- messageReceived.writeString("Testing...");
- } catch (MessageNotWriteableException nr) {
- TestUtil.logTrace("Passed with expected MessageNotWriteableException");
- }
- } catch (Exception e) {
- TestUtil.logErr(
- "xMessageNotWriteableExceptionTTestforStreamMessage failed: ", e);
- throw new Exception("xMessageNotWriteableExceptionTTestforStreamMessage", e);
- }
- }
-
- /*
- * @testName: xMessageNotWriteableExceptionTTestforMapMessage
- *
- * @assertion_ids: JMS:SPEC:73; JMS:SPEC:179; JMS:JAVADOC:822;
- *
- * @test_Strategy: When a client receives a Map message it is in read-only
- * mode. Publish a message and have the client attempt to write to it.
- */
- public void xMessageNotWriteableExceptionTTestforMapMessage() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotWriteableExceptionTTestforMapMessage");
- messageSent.setString("aString", "value");
- TestUtil.logTrace("Publishing message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- TestUtil.logTrace("Got message - OK");
- }
-
- // Received message should be read-only - verify proper exception is
- // thrown
- try {
- messageReceived.setString("aString", "value");
- } catch (MessageNotWriteableException nr) {
- TestUtil.logMsg(
- "Passed with expected MessageNotWriteableException occurred.");
- }
- } catch (Exception e) {
- TestUtil.logErr(
- "xMessageNotWriteableExceptionTTestforMapMessage failed: ", e);
- throw new Exception("xMessageNotWriteableExceptionTTestforMapMessage", e);
- }
- }
-
- /*
- * @testName: xNullPointerExceptionTopicTest
- *
- * @assertion_ids: JMS:SPEC:86.1;
- *
- * @test_Strategy: Create a bytes message. Attempt to write null to it. Verify
- * that a NullPointerException is thrown.
- *
- */
-
- public void xNullPointerExceptionTopicTest() throws Exception {
- try {
- BytesMessage msg = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
- msg = tool.getDefaultTopicSession().createBytesMessage();
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xNullPointerExceptionTopicTest");
- msg.writeBytes(null);
- } catch (java.lang.NullPointerException nullp) {
- TestUtil.logMsg("Passed with expected NullPointerException.");
- } catch (Exception e) {
- TestUtil.logErr("Expected NullPointerException did not occur!", e);
- throw new Exception("xNullPointerExceptionTopicTest");
- }
- }
-
- /*
- * @testName: xMessageEOFExceptionTTestforBytesMessage
- *
- * @assertion_ids: JMS:SPEC:176;
- *
- * @test_Strategy: Publish a bytes message to a topic with one byte. Retreive
- * message from the topic and read two bytes.
- */
-
- public void xMessageEOFExceptionTTestforBytesMessage() throws Exception {
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createBytesMessage();
- messageSent.writeByte(bValue);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageEOFExceptionTTestforBytesMessage");
- TestUtil.logTrace("Publishing message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (BytesMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- TestUtil.logTrace("Got message - OK");
- }
-
- // Received message should contain one byte
- // reading 2 bytes should throw the excpected exception
- messageReceived.readByte();
- try {
- messageReceived.readByte();
-
- // Should not reach here !!
- TestUtil.logTrace("Failed: expected MessageEOFException not thrown");
- throw new Exception("Fail: Did not throw expected error!!!");
- } catch (MessageEOFException end) {
- TestUtil.logTrace("Passed.\n");
- TestUtil.logTrace("MessageEOFException occurred!");
- TestUtil.logTrace(" " + end.getMessage());
- }
- } catch (Exception e) {
- throw new Exception("xMessageEOFExceptionTTestforBytesMessage", e);
- }
- }
-
- /*
- * @testName: xMessageEOFExceptionTTestforStreamMessage
- *
- * @assertion_ids: JMS:SPEC:176;
- *
- * @test_Strategy: Publish a Stream message to a topic with one byte. Retreive
- * message from the topic and read two bytes.
- */
-
- public void xMessageEOFExceptionTTestforStreamMessage() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.writeByte(bValue);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageEOFExceptionTTestforStreamMessage");
- TestUtil.logTrace("Publishing message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- TestUtil.logTrace("Got message - OK");
- }
-
- // Received message should contain one byte
- // reading 2 bytes should throw the excpected exception
- messageReceived.readByte();
- try {
- messageReceived.readByte();
-
- // Should not reach here !!
- TestUtil.logTrace("Failed: expected MessageEOFException not thrown");
- throw new Exception("Fail: Did not throw expected error!!!");
- } catch (MessageEOFException end) {
- TestUtil.logTrace("Passed.\n");
- TestUtil.logTrace("MessageEOFException occurred!");
- TestUtil.logTrace(" " + end.getMessage());
- }
- } catch (Exception e) {
- throw new Exception("xMessageEOFExceptionTTestforStreamMessage", e);
- }
- }
-
- /*
- * @testName: xMessageFormatExceptionTTestforBytesMessage
- *
- * @assertion_ids: JMS:SPEC:177;
- *
- *
- * @test_Strategy: Call writeObject with a topic session object
- */
-
- public void xMessageFormatExceptionTTestforBytesMessage() throws Exception {
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = null;
- byte bValue = 127;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createBytesMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageFormatExceptionTTestforBytesMessage");
- TestUtil.logTrace("try to write an invalid object");
- try {
- messageSent.writeObject(tool.getDefaultTopicSession());
-
- // Should not reach here !!
- TestUtil
- .logTrace("Failed: expected MessageFormatException not thrown");
- throw new Exception("Fail: Did not throw expected error!!!");
- } catch (MessageFormatException fe) {
- TestUtil.logTrace("Passed.\n");
- TestUtil.logTrace("MessageFormatException occurred!");
- TestUtil.logTrace(" " + fe.getMessage());
- }
- } catch (Exception e) {
- throw new Exception("xMessageFormatExceptionTTestforBytesMessage", e);
- }
- }
-
- /*
- * @testName: xMessageFormatExceptionTTestforStreamMessage
- *
- * @assertion_ids: JMS:SPEC:177; JMS:JAVADOC:744;
- *
- * @test_Strategy: Write a byte array, read it as a string.
- */
-
- public void xMessageFormatExceptionTTestforStreamMessage() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte[] bValues = { 127, 0, 3 };
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.writeBytes(bValues);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageFormatExceptionTTestforStreamMessage");
- TestUtil.logTrace("Publishing message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("getMessage returned null!! - test did not run!");
- } else {
- TestUtil.logTrace("Got message - OK");
- }
-
- // Received message should contain a byte, read a string
- try {
- messageReceived.readString();
-
- // Should not reach here !!
- TestUtil
- .logTrace("Failed: expected MessageFormatException not thrown");
- throw new Exception("Fail: Did not throw expected error!!!");
- } catch (MessageFormatException fe) {
- TestUtil.logTrace("Passed.\n");
- TestUtil.logTrace("MessageFormatException occurred!");
- TestUtil.logTrace(" " + fe.getMessage());
- }
- } catch (Exception e) {
- throw new Exception("xMessageFormatExceptionTTestforStreamMessage", e);
- }
- }
-
- /*
- * @testName: xInvalidSelectorExceptionTopicTest
- *
- * @assertion_ids: JMS:SPEC:69; JMS:SPEC:175; JMS:JAVADOC:627;
- * JMS:JAVADOC:630;
- *
- * @test_Strategy: Call createSubscriber/createDurableSubscriber with an
- * invalid selector string
- */
-
- public void xInvalidSelectorExceptionTopicTest() throws Exception {
- try {
- TopicSubscriber tSub = null;
-
- // create Topic Connection and TopicSubscriber
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- TestUtil.logTrace("** Close default TopicSubscriber **");
- tool.getDefaultTopicSubscriber().close();
- tool.getDefaultTopicConnection().start();
-
- // create TopicSubscriber
- tSub = tool.getDefaultTopicSession()
- .createSubscriber(tool.getDefaultTopic(), "=TEST 'test'", false);
- TestUtil.logTrace("FAIL --- should not have gotten this far!");
- throw new Exception("xInvalidSelectorException test Failed!");
- } catch (InvalidSelectorException es) {
- TestUtil.logTrace("Passed.\n");
- TestUtil.logMsg("InvalidSelectorException occurred!");
- } catch (Exception e) {
- TestUtil.logErr("Got Exception instead: ", e);
- TestUtil.logTrace("Expected InvalidSelectorException did not occur!");
- throw new Exception("xInvalidSelectorExceptionTopicTest eee", e);
- }
- }
-
- /*
- * @testName: xIllegalStateExceptionTopicTest
- *
- * @assertion_ids: JMS:SPEC:171; JMS:JAVADOC:634;
- *
- * @test_Strategy: Call session.commit() when there is no transaction to be
- * committed. Verify that the proper exception is thrown.
- */
-
- public void xIllegalStateExceptionTopicTest() throws Exception {
- boolean passed = false;
-
- try {
-
- // create Topic Connection
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultTopicConnection().start();
- logMsg("Calling session.commit(), an illegal operation.");
- try {
- tool.getDefaultTopicSession().commit();
- } catch (jakarta.jms.IllegalStateException iStateE) {
- logMsg("Received jakarta.jms.IllegalStateException -- GOOD");
- passed = true;
- }
- if (passed == false) { // need case for no exception being thrown
- throw new Exception("Did not receive IllegalStateException");
- }
- } catch (Exception e) { // handles case of other exception being thrown
- TestUtil.printStackTrace(e);
- throw new Exception("xIllegalStateExceptionTopicTest");
- }
- }
-
- /*
- * @testName: xUnsupportedOperationExceptionTTest1
- *
- * @assertion_ids: JMS:JAVADOC:658; JMS:JAVADOC:661;
- *
- * @test_Strategy: Create a TopicPublisher with a null Topic. Verify that
- * UnsupportedOperationException is thrown when publish is called without a
- * valid Topic.
- */
-
- public void xUnsupportedOperationExceptionTTest1() throws Exception {
- try {
- TextMessage messageSent = null;
- boolean pass = true;
- Topic myTopic = null;
- TopicPublisher tPub = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
-
- // Close default TopicPublisher and create a new one with null Topic
- tool.getDefaultTopicPublisher().close();
- tPub = tool.getDefaultTopicSession().createPublisher(myTopic);
-
- tool.getDefaultTopicConnection().start();
-
- try {
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xUnsupportedOperationExceptionTTest1");
-
- logTrace("sending a Text message");
- tPub.publish(messageSent);
-
- pass = false;
- logErr(
- "Error: TopicPublisher.publish(Message) didn't throw expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException ex) {
- logMsg(
- "Got expected UnsupportedOperationException from TopicPublisher.publish(Message)");
- } catch (Exception e) {
- logErr(
- "Error: TopicPublisher.publish(Message) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xUnsupportedOperationExceptionTTest1");
-
- logTrace("sending a Text message");
- tPub.publish(messageSent, Message.DEFAULT_DELIVERY_MODE,
- Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
-
- pass = false;
- logErr(
- "Error: TopicPublisher.publish(Message, int, int, long) didn't throw expected UnsupportedOperationException.");
- } catch (UnsupportedOperationException ex) {
- logMsg(
- "Got expected UnsupportedOperationException from TopicPublisher.publish(Message, int, int, long)");
- } catch (Exception e) {
- logErr(
- "Error: TopicPublisher.publish(Message, int, int, long) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("xUnsupportedOperationExceptionTTest1 Failed!");
-
- } catch (Exception e) {
- logErr("xUnsupportedOperationExceptionTTest1 Failed!", e);
- throw new Exception("xUnsupportedOperationExceptionTTest1 Failed!", e);
- } finally {
- try {
- if (tool.getDefaultTopicConnection() != null) {
- tool.getDefaultTopicConnection().close();
- }
- } catch (Exception e) {
- TestUtil.logErr("Exception closing TopicConnection and cleanup", e);
- }
- }
- }
-
- /*
- * @testName: xInvalidDestinationExceptionTTests
- *
- * @assertion_ids: JMS:JAVADOC:502; JMS:JAVADOC:504; JMS:JAVADOC:510;
- * JMS:JAVADOC:638; JMS:JAVADOC:639; JMS:JAVADOC:641; JMS:JAVADOC:643;
- * JMS:JAVADOC:644; JMS:JAVADOC:646; JMS:JAVADOC:647; JMS:JAVADOC:649;
- *
- * @test_Strategy: Create a Session with Topic Configuration, using a null
- * Destination/Topic to verify InvalidDestinationException is thrown with
- * various methods
- */
-
- public void xInvalidDestinationExceptionTTests() throws Exception {
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- boolean pass = true;
- Destination dummy = null;
- Topic dummyT = null;
-
- tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultProducer().close();
- tool.getDefaultConsumer().close();
-
- try {
- tool.getDefaultSession().createConsumer(dummy);
- logErr(
- "Error: createConsumer(null) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createConsumer(null)");
- } catch (Exception e) {
- logErr("Error: createConsumer(null) throw incorrect Exception: ", e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'");
- logErr(
- "Error: createConsumer(null, String) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createConsumer(null, String)");
- } catch (Exception e) {
- logErr(
- "Error: createConsumer(null, String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'", true);
- logErr(
- "Error: createConsumer(null, String, boolean) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createConsumer(null, String, true)");
- } catch (Exception e) {
- logErr(
- "Error: createConsumer(null, String, true) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing default Connection", ex);
- }
-
- if (pass != true)
- throw new Exception("xInvalidDestinationExceptionTTests");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xInvalidDestinationExceptionTTests");
- } finally {
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: xMessageNotReadableExceptionTBytesMsgTest
- *
- * @assertion_ids: JMS:JAVADOC:676; JMS:JAVADOC:678; JMS:JAVADOC:682;
- * JMS:JAVADOC:684; JMS:JAVADOC:686; JMS:JAVADOC:688; JMS:JAVADOC:690;
- * JMS:JAVADOC:692; JMS:JAVADOC:694; JMS:JAVADOC:696; JMS:JAVADOC:698;
- * JMS:JAVADOC:699; JMS:JAVADOC:700;
- *
- * @test_Strategy: Create a BytesMessage, call various read methods on it
- * before sending. Verify that jakarta.jms.MessageNotReadableException is
- * thrown.
- */
-
- public void xMessageNotReadableExceptionTBytesMsgTest() throws Exception {
- try {
- BytesMessage messageSent = null;
- boolean pass = true;
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- byte[] bytesValueRecvd = { 0, 0, 0, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- Integer nInteger = new Integer(-2147483648);
- short shortValue = -32768;
- String utfValue = "what";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultProducer().close();
- tool.getDefaultConsumer().close();
-
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultSession().createBytesMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotReadableExceptionTBytesMsgTest");
-
- // -----------------------------------------------------------------------------
- logMsg("Writing one of each primitive type to the message");
-
- // -----------------------------------------------------------------------------
- messageSent.writeBoolean(booleanValue);
- messageSent.writeByte(byteValue);
- messageSent.writeChar(charValue);
- messageSent.writeDouble(doubleValue);
- messageSent.writeFloat(floatValue);
- messageSent.writeInt(intValue);
- messageSent.writeLong(longValue);
- messageSent.writeObject(nInteger);
- messageSent.writeShort(shortValue);
- messageSent.writeUTF(utfValue);
- messageSent.writeBytes(bytesValue);
- messageSent.writeBytes(bytesValue, 0, 1);
-
- try {
- messageSent.getBodyLength();
- pass = false;
- TestUtil.logErr(
- "Error: getBodyLength didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "getBodyLength threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("getBodyLength threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readBoolean();
- pass = false;
- TestUtil.logErr(
- "Error: readBoolean didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readBoolean threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readBoolean threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readByte();
- pass = false;
- TestUtil.logErr(
- "Error: readByte didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readByte threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readByte threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readUnsignedByte();
- pass = false;
- TestUtil.logErr(
- "Error: readUnsignedByte didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readUnsignedByte threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readUnsignedByte threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readShort();
- pass = false;
- TestUtil.logErr(
- "Error: readShort didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readShort threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readShort threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readUnsignedShort();
- pass = false;
- TestUtil.logErr(
- "Error: readUnsignedShort didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readUnsignedShort threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readUnsignedShort threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readChar();
- pass = false;
- TestUtil.logErr(
- "Error: readChar didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readChar threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readChar threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readInt();
- pass = false;
- TestUtil.logErr(
- "Error: readInt didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readInt threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readInt threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readLong();
- pass = false;
- TestUtil.logErr(
- "Error: readLong didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readLong threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readLong threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readFloat();
- pass = false;
- TestUtil.logErr(
- "Error: readFloat didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readFloat threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readFloat threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readDouble();
- pass = false;
- TestUtil.logErr(
- "Error: readDouble didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readDouble threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readDouble threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readUTF();
- pass = false;
- TestUtil.logErr(
- "Error: readUTF didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readUTF threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readUTF threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readBytes(bytesValueRecvd);
- pass = false;
- TestUtil.logErr(
- "Error: readBytes(byte[]) didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readBytes(byte[]) threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readBytes(byte[]) threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageSent.readBytes(bytesValueRecvd, 1);
- pass = false;
- TestUtil.logErr(
- "Error: readBytes(byte[], int) didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readBytes(byte[], int) threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readBytes(byte[],int) threw Wrong Exception!", e);
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("xMessageNotReadableExceptionTBytesMsgTest Failed!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xMessageNotReadableExceptionTBytesMsgTest:");
- } finally {
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: xMessageNotReadableExceptionTStreamMsgTest
- *
- * @assertion_ids: JMS:SPEC:73.1; JMS:JAVADOC:431; JMS:JAVADOC:721;
- * JMS:JAVADOC:724; JMS:JAVADOC:727; JMS:JAVADOC:730; JMS:JAVADOC:733;
- * JMS:JAVADOC:736; JMS:JAVADOC:739; JMS:JAVADOC:742; JMS:JAVADOC:745;
- * JMS:JAVADOC:748; JMS:JAVADOC:751;
- *
- * @test_Strategy: Create a StreamMessage, send and receive via a Topic; Call
- * clearBoldy right after receiving the message; Call various read methods on
- * received message; Verify jakarta.jms.MessageNotReadableException is thrown.
- */
-
- public void xMessageNotReadableExceptionTStreamMsgTest() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- boolean pass = true;
- byte bValue = 127;
- boolean abool = false;
- byte[] bValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
- byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
- byte[] bValuesReturned = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- char charValue = 'Z';
- short sValue = 32767;
- long lValue = 9223372036854775807L;
- double dValue = 6.02e23;
- float fValue = 6.02e23f;
- int iValue = 6;
- String myString = "text";
- String sTesting = "Testing StreamMessages";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, lookup, mode);
- tool.getDefaultConnection().start();
-
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "xMessageNotReadableExceptionTStreamMsgTest");
-
- // -----------------------------------------------------------------------------
- logTrace("");
- logMsg("Writing one of each primitive type to the message");
- // -----------------------------------------------------------------------------
- messageSent.writeBytes(bValues2, 0, bValues.length);
- messageSent.writeBoolean(abool);
- messageSent.writeByte(bValue);
- messageSent.writeBytes(bValues);
- messageSent.writeChar(charValue);
- messageSent.writeDouble(dValue);
- messageSent.writeFloat(fValue);
- messageSent.writeInt(iValue);
- messageSent.writeLong(lValue);
- messageSent.writeObject(sTesting);
- messageSent.writeShort(sValue);
- messageSent.writeString(myString);
- messageSent.writeObject(null);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultProducer().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultConsumer()
- .receive(timeout);
-
- TestUtil.logTrace("call ClearBody()");
- messageReceived.clearBody();
-
- try {
- messageReceived.readBoolean();
- pass = false;
- TestUtil.logErr(
- "Error: readBoolean didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readBoolean threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readBoolean threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readByte();
- pass = false;
- TestUtil.logErr(
- "Error: readByte didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readByte threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readByte threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readShort();
- pass = false;
- TestUtil.logErr(
- "Error: readShort didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readShort threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readShort threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readChar();
- pass = false;
- TestUtil.logErr(
- "Error: readChar didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readChar threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readChar threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readInt();
- pass = false;
- TestUtil.logErr(
- "Error: readInt didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readInt threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readInt threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readLong();
- pass = false;
- TestUtil.logErr(
- "Error: readLong didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readLong threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readLong threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readFloat();
- pass = false;
- TestUtil.logErr(
- "Error: readFloat didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readFloat threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readFloat threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readDouble();
- pass = false;
- TestUtil.logErr(
- "Error: readDouble didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readDouble threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readDouble threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readString();
- pass = false;
- TestUtil.logErr(
- "Error: readString didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readString threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readString threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readBytes(bValuesReturned);
- pass = false;
- TestUtil.logErr(
- "Error: readBytes(byte[]) didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil.logTrace(
- "readBytes(byte[]) threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readBytes(byte[]) threw Wrong Exception!", e);
- pass = false;
- }
-
- try {
- messageReceived.readObject();
- pass = false;
- TestUtil.logErr(
- "Error: readObject didn't throw Expected MessageNotReadableException!");
- } catch (MessageNotReadableException nr) {
- TestUtil
- .logTrace("readObject threw Expected MessageNotReadableException!");
- } catch (Exception e) {
- TestUtil.logErr("readObject threw Wrong Exception!", e);
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("xMessageNotReadableExceptionTStreamMsgTest Failed!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xMessageNotReadableExceptionTStreamMsgTest:");
- } finally {
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: xIllegalStateExceptionTestQueueMethodsT
- *
- * @assertion_ids: JMS:SPEC:185.6; JMS:SPEC:185.7; JMS:SPEC:185.8;
- * JMS:SPEC:185;
- *
- * @test_Strategy: Create a TopicSession and call Queue specific methods
- * inherited from Session, and verify that jakarta.jms.IllegalStateException is
- * thrown.
- */
-
- public void xIllegalStateExceptionTestQueueMethodsT() throws Exception {
-
- try {
- boolean pass = true;
- Queue myQueue = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
- myQueue = tool.createNewQueue("MY_QUEUE");
-
- try {
- tool.getDefaultTopicSession().createBrowser(myQueue);
- pass = false;
- TestUtil.logErr(
- "Error: TopicSession.createBrowser(Queue) didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg(
- "Got expected IllegalStateException from TopicSession.createBrowser(Queue)");
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: TopicSession.createBrowser(Queue) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultTopicSession().createBrowser(myQueue, "TEST = 'test'");
- pass = false;
- TestUtil.logErr(
- "Error: TopicSession.createBrowser(Queue, String) didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg(
- "Got expected IllegalStateException from TopicSession.createBrowser(Queue, String)");
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: TopicSession.createBrowser(Queue, String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultTopicSession().createTemporaryQueue();
- pass = false;
- TestUtil.logErr(
- "Error: TopicSession.createTemporayQueue() didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg(
- "Got expected IllegalStateException from TopicSession.createTemporayQueue()");
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: TopicSession.createTemporayQueue() throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultTopicSession().createQueue("foo");
- pass = false;
- TestUtil.logErr(
- "Error: TopicSession.createQueue(String) didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg(
- "Got expected IllegalStateException from TopicSession.createQueue(String)");
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: TopicSession.createQueue(String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("xIllegalStateExceptionTestQueueMethodsT Failed!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("xIllegalStateExceptionTestQueueMethodsT");
- } finally {
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- TestUtil.logErr("Error closing Connection", ex);
- }
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/exceptionTopic/ExceptionTopicTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/exceptionTopic/ExceptionTopicTestsIT.java
new file mode 100644
index 0000000000..8302943588
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/exceptionTopic/ExceptionTopicTestsIT.java
@@ -0,0 +1,1445 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.exceptionTopic;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.Destination;
+import jakarta.jms.InvalidDestinationException;
+import jakarta.jms.InvalidSelectorException;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.MessageEOFException;
+import jakarta.jms.MessageFormatException;
+import jakarta.jms.MessageNotReadableException;
+import jakarta.jms.MessageNotWriteableException;
+import jakarta.jms.Queue;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicPublisher;
+import jakarta.jms.TopicSubscriber;
+
+
+public class ExceptionTopicTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.exceptionTopic.ExceptionTopicTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ExceptionTopicTestsIT.class.getName());
+
+ // Harness req's
+ private Properties props = null;
+
+ // JMS object
+ private transient JmsTool tool = null;
+
+ // properties read
+ long timeout;
+
+ private String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ private String jmsUser;
+
+ private String jmsPassword;
+
+ private String mode;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't catch expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, "In setup");
+ // get props
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ connections = new ArrayList(2);
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: xInvalidDestinationExceptionTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:174; JMS:JAVADOC:83; JMS:JAVADOC:85; JMS:JAVADOC:87;
+ * JMS:JAVADOC:89; JMS:JAVADOC:91; JMS:JAVADOC:95; JMS:JAVADOC:625;
+ * JMS:JAVADOC:626; JMS:JAVADOC:628; JMS:JAVADOC:629; JMS:JAVADOC:631;
+ * JMS:JAVADOC:632;
+ *
+ * @test_Strategy: pass an invalid Topic object to createSubscriber(null)
+ * createSubscriber(null,selector,nolocal)
+ * createDurableSubscriber(null,subscriber)
+ * createDurableSubscriber(null,String,selector,nolocal) createPublisher(null) -
+ * null is valid here. unsubscribe(invalidSubscriptionName)
+ */
+ @Test
+ public void xInvalidDestinationExceptionTopicTest() throws Exception {
+ boolean pass = true;
+ TopicPublisher tPublisher = null;
+ TopicSubscriber tSubscriber = null;
+ Topic dummy = null;
+
+ try {
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ logger.log(Logger.Level.TRACE, "** Close default TopicSubscriber **");
+ tool.getDefaultTopicSubscriber().close();
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "Test unsubscribe(invalidSubscriptionName)");
+ try {
+ tool.getDefaultTopicSession().unsubscribe("invalidSubscriptionName");
+ logger.log(Logger.Level.TRACE, "FAIL: expected InvalidDestinationException!");
+ pass = false;
+ } catch (Exception ee) {
+ if (ee instanceof jakarta.jms.InvalidDestinationException) {
+ logger.log(Logger.Level.TRACE, "Pass: InvalidDestinationException thrown as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Test createSubscriber(null)");
+ try {
+ tSubscriber = tool.getDefaultTopicSession().createSubscriber(dummy);
+ logger.log(Logger.Level.TRACE, "FAIL: expected InvalidDestinationException!");
+ pass = false;
+ } catch (Exception ee) {
+ if (ee instanceof jakarta.jms.InvalidDestinationException) {
+ logger.log(Logger.Level.TRACE, "Pass: InvalidDestinationException thrown as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Test createSubscriber(null,selector,nolocal)");
+ try {
+ tSubscriber = tool.getDefaultTopicSession().createSubscriber(dummy, "TEST", true);
+ logger.log(Logger.Level.TRACE, "FAIL: expected InvalidDestinationException!");
+ pass = false;
+ } catch (Exception ee) {
+ if (ee instanceof jakarta.jms.InvalidDestinationException) {
+ logger.log(Logger.Level.TRACE, "Pass: InvalidDestinationException thrown as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Test createDurableSubscriber(null,String)");
+ try {
+ tSubscriber = tool.getDefaultTopicSession().createDurableSubscriber(dummy, "durable");
+ logger.log(Logger.Level.TRACE, "FAIL: expected InvalidDestinationException!");
+ pass = false;
+ } catch (Exception ee) {
+ if (ee instanceof jakarta.jms.InvalidDestinationException) {
+ logger.log(Logger.Level.TRACE, "Pass: InvalidDestinationException thrown as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Test createDurableSubscriber(null,String,selector,nolocal)");
+ try {
+ tSubscriber = tool.getDefaultTopicSession().createDurableSubscriber(dummy, "durable", "TEST", true);
+ logger.log(Logger.Level.TRACE, "FAIL: expected InvalidDestinationException!");
+ pass = false;
+ } catch (Exception ee) {
+ if (ee instanceof jakarta.jms.InvalidDestinationException) {
+ logger.log(Logger.Level.TRACE, "Pass: InvalidDestinationException thrown as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Test createPublisher(null) - This is valid");
+ try {
+ tPublisher = tool.getDefaultTopicSession().createPublisher(dummy);
+ if (tPublisher != null)
+ logger.log(Logger.Level.INFO, "tPublisher=" + tPublisher);
+ logger.log(Logger.Level.TRACE, "PASS: null allowed for unidentified producer");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.ERROR, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during xInvalidDestinationExceptionQTest tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("xInvalidDestinationExceptionTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageNotReadableExceptionTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:178; JMS:JAVADOC:680;
+ *
+ * @test_Strategy: create a BytesMessage, read it.
+ */
+ @Test
+ public void xMessageNotReadableExceptionTopicTest() throws Exception {
+ try {
+ BytesMessage msg = null;
+
+ // create Topic Connection
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+
+ // Create a BytesMessage
+ msg = tool.getDefaultTopicSession().createBytesMessage();
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotReadableExceptionTopicTest");
+ try {
+ msg.readByte();
+ logger.log(Logger.Level.ERROR, "FAIL --- should not have gotten this far!");
+ throw new Exception("Fail: Did not throw expected error!!!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.INFO, "Passed with expected MessageNotReadableException.");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageNotReadableException did not occur:", e);
+ throw new Exception("xMessageNotReadableExceptionTopicTest test failed", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageNotWriteableExceptionTTestforTextMessage
+ *
+ * @assertion_ids: JMS:SPEC:179; JMS:SPEC:70; JMS:JAVADOC:766;
+ *
+ * @test_Strategy: When a client receives a text message it is in read-only
+ * mode. Publish a message and have the client attempt to write to it.
+ */
+ @Test
+ public void xMessageNotWriteableExceptionTTestforTextMessage() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotWriteableExceptionTTestforTextMessage");
+ logger.log(Logger.Level.TRACE, "Publishing message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should be read-only - verify proper exception is
+ // thrown
+ try {
+ messageReceived.setText("testing...");
+ } catch (MessageNotWriteableException nr) {
+ logger.log(Logger.Level.INFO, "Passed with expected MessageNotWriteableException");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "xMessageNotWriteableExceptionTTestforTextMessage failed:", e);
+ throw new Exception("xMessageNotWriteableExceptionTTestforTextMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageNotWriteableExceptionTestforBytesMessage
+ *
+ * @assertion_ids: JMS:SPEC:73; JMS:SPEC:179; JMS:JAVADOC:702;
+ *
+ * @test_Strategy: When a client receives a Bytes message it is in read-only
+ * mode. Publish a message and have the client attempt to write to it.
+ */
+ @Test
+ public void xMessageNotWriteableExceptionTestforBytesMessage() throws Exception {
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createBytesMessage();
+ messageSent.writeByte(bValue);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotWriteableExceptionTestforBytesMessage");
+ logger.log(Logger.Level.TRACE, "Publishing message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should be read-only - verify proper exception is
+ // thrown
+ try {
+ messageReceived.writeByte(bValue);
+ } catch (MessageNotWriteableException nr) {
+ logger.log(Logger.Level.INFO, "Passed with expected MessageNotWriteableException.");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "xMessageNotWriteableExceptionTestforBytesMessage failed: ", e);
+ throw new Exception("xMessageNotWriteableExceptionTestforBytesMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageNotWriteableExceptionTTestforStreamMessage
+ *
+ * @assertion_ids: JMS:SPEC:73; JMS:SPEC:179; JMS:JAVADOC:760;
+ *
+ * @test_Strategy: When a client receives a Stream message it is in read-only
+ * mode. Publish a message and have the client attempt to write to it.
+ */
+ @Test
+ public void xMessageNotWriteableExceptionTTestforStreamMessage() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotWriteableExceptionTTestforStreamMessage");
+
+ messageSent.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Publishing message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should be read-only - verify proper exception is
+ // thrown
+ try {
+ messageReceived.writeString("Testing...");
+ } catch (MessageNotWriteableException nr) {
+ logger.log(Logger.Level.TRACE, "Passed with expected MessageNotWriteableException");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "xMessageNotWriteableExceptionTTestforStreamMessage failed: ", e);
+ throw new Exception("xMessageNotWriteableExceptionTTestforStreamMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageNotWriteableExceptionTTestforMapMessage
+ *
+ * @assertion_ids: JMS:SPEC:73; JMS:SPEC:179; JMS:JAVADOC:822;
+ *
+ * @test_Strategy: When a client receives a Map message it is in read-only mode.
+ * Publish a message and have the client attempt to write to it.
+ */
+ @Test
+ public void xMessageNotWriteableExceptionTTestforMapMessage() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotWriteableExceptionTTestforMapMessage");
+ messageSent.setString("aString", "value");
+ logger.log(Logger.Level.TRACE, "Publishing message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should be read-only - verify proper exception is
+ // thrown
+ try {
+ messageReceived.setString("aString", "value");
+ } catch (MessageNotWriteableException nr) {
+ logger.log(Logger.Level.INFO, "Passed with expected MessageNotWriteableException occurred.");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "xMessageNotWriteableExceptionTTestforMapMessage failed: ", e);
+ throw new Exception("xMessageNotWriteableExceptionTTestforMapMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xNullPointerExceptionTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:86.1;
+ *
+ * @test_Strategy: Create a bytes message. Attempt to write null to it. Verify
+ * that a NullPointerException is thrown.
+ *
+ */
+ @Test
+ public void xNullPointerExceptionTopicTest() throws Exception {
+ try {
+ BytesMessage msg = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+ msg = tool.getDefaultTopicSession().createBytesMessage();
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "xNullPointerExceptionTopicTest");
+ msg.writeBytes(null);
+ } catch (java.lang.NullPointerException nullp) {
+ logger.log(Logger.Level.INFO, "Passed with expected NullPointerException.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected NullPointerException did not occur!", e);
+ throw new Exception("xNullPointerExceptionTopicTest");
+ }
+ }
+
+ /*
+ * @testName: xMessageEOFExceptionTTestforBytesMessage
+ *
+ * @assertion_ids: JMS:SPEC:176;
+ *
+ * @test_Strategy: Publish a bytes message to a topic with one byte. Retreive
+ * message from the topic and read two bytes.
+ */
+ @Test
+ public void xMessageEOFExceptionTTestforBytesMessage() throws Exception {
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createBytesMessage();
+ messageSent.writeByte(bValue);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageEOFExceptionTTestforBytesMessage");
+ logger.log(Logger.Level.TRACE, "Publishing message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should contain one byte
+ // reading 2 bytes should throw the excpected exception
+ messageReceived.readByte();
+ try {
+ messageReceived.readByte();
+
+ // Should not reach here !!
+ logger.log(Logger.Level.TRACE, "Failed: expected MessageEOFException not thrown");
+ throw new Exception("Fail: Did not throw expected error!!!");
+ } catch (MessageEOFException end) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ logger.log(Logger.Level.TRACE, "MessageEOFException occurred!");
+ logger.log(Logger.Level.TRACE, " " + end.getMessage());
+ }
+ } catch (Exception e) {
+ throw new Exception("xMessageEOFExceptionTTestforBytesMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageEOFExceptionTTestforStreamMessage
+ *
+ * @assertion_ids: JMS:SPEC:176;
+ *
+ * @test_Strategy: Publish a Stream message to a topic with one byte. Retreive
+ * message from the topic and read two bytes.
+ */
+ @Test
+ public void xMessageEOFExceptionTTestforStreamMessage() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.writeByte(bValue);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageEOFExceptionTTestforStreamMessage");
+ logger.log(Logger.Level.TRACE, "Publishing message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should contain one byte
+ // reading 2 bytes should throw the excpected exception
+ messageReceived.readByte();
+ try {
+ messageReceived.readByte();
+
+ // Should not reach here !!
+ logger.log(Logger.Level.TRACE, "Failed: expected MessageEOFException not thrown");
+ throw new Exception("Fail: Did not throw expected error!!!");
+ } catch (MessageEOFException end) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ logger.log(Logger.Level.TRACE, "MessageEOFException occurred!");
+ logger.log(Logger.Level.TRACE, " " + end.getMessage());
+ }
+ } catch (Exception e) {
+ throw new Exception("xMessageEOFExceptionTTestforStreamMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageFormatExceptionTTestforBytesMessage
+ *
+ * @assertion_ids: JMS:SPEC:177;
+ *
+ *
+ * @test_Strategy: Call writeObject with a topic session object
+ */
+ @Test
+ public void xMessageFormatExceptionTTestforBytesMessage() throws Exception {
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = null;
+ byte bValue = 127;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createBytesMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageFormatExceptionTTestforBytesMessage");
+ logger.log(Logger.Level.TRACE, "try to write an invalid object");
+ try {
+ messageSent.writeObject(tool.getDefaultTopicSession());
+
+ // Should not reach here !!
+ logger.log(Logger.Level.TRACE, "Failed: expected MessageFormatException not thrown");
+ throw new Exception("Fail: Did not throw expected error!!!");
+ } catch (MessageFormatException fe) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ logger.log(Logger.Level.TRACE, "MessageFormatException occurred!");
+ logger.log(Logger.Level.TRACE, " " + fe.getMessage());
+ }
+ } catch (Exception e) {
+ throw new Exception("xMessageFormatExceptionTTestforBytesMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xMessageFormatExceptionTTestforStreamMessage
+ *
+ * @assertion_ids: JMS:SPEC:177; JMS:JAVADOC:744;
+ *
+ * @test_Strategy: Write a byte array, read it as a string.
+ */
+ @Test
+ public void xMessageFormatExceptionTTestforStreamMessage() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte[] bValues = { 127, 0, 3 };
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.writeBytes(bValues);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageFormatExceptionTTestforStreamMessage");
+ logger.log(Logger.Level.TRACE, "Publishing message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("getMessage returned null!! - test did not run!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+
+ // Received message should contain a byte, read a string
+ try {
+ messageReceived.readString();
+
+ // Should not reach here !!
+ logger.log(Logger.Level.TRACE, "Failed: expected MessageFormatException not thrown");
+ throw new Exception("Fail: Did not throw expected error!!!");
+ } catch (MessageFormatException fe) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ logger.log(Logger.Level.TRACE, "MessageFormatException occurred!");
+ logger.log(Logger.Level.TRACE, " " + fe.getMessage());
+ }
+ } catch (Exception e) {
+ throw new Exception("xMessageFormatExceptionTTestforStreamMessage", e);
+ }
+ }
+
+ /*
+ * @testName: xInvalidSelectorExceptionTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:69; JMS:SPEC:175; JMS:JAVADOC:627; JMS:JAVADOC:630;
+ *
+ * @test_Strategy: Call createSubscriber/createDurableSubscriber with an invalid
+ * selector string
+ */
+ @Test
+ public void xInvalidSelectorExceptionTopicTest() throws Exception {
+ try {
+ TopicSubscriber tSub = null;
+
+ // create Topic Connection and TopicSubscriber
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ logger.log(Logger.Level.TRACE, "** Close default TopicSubscriber **");
+ tool.getDefaultTopicSubscriber().close();
+ tool.getDefaultTopicConnection().start();
+
+ // create TopicSubscriber
+ tSub = tool.getDefaultTopicSession().createSubscriber(tool.getDefaultTopic(), "=TEST 'test'", false);
+ logger.log(Logger.Level.TRACE, "FAIL --- should not have gotten this far!");
+ throw new Exception("xInvalidSelectorException test Failed!");
+ } catch (InvalidSelectorException es) {
+ logger.log(Logger.Level.TRACE, "Passed.\n");
+ logger.log(Logger.Level.INFO, "InvalidSelectorException occurred!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Got Exception instead: ", e);
+ logger.log(Logger.Level.TRACE, "Expected InvalidSelectorException did not occur!");
+ throw new Exception("xInvalidSelectorExceptionTopicTest eee", e);
+ }
+ }
+
+ /*
+ * @testName: xIllegalStateExceptionTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:171; JMS:JAVADOC:634;
+ *
+ * @test_Strategy: Call session.commit() when there is no transaction to be
+ * committed. Verify that the proper exception is thrown.
+ */
+ @Test
+ public void xIllegalStateExceptionTopicTest() throws Exception {
+ boolean passed = false;
+
+ try {
+
+ // create Topic Connection
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "Calling session.commit(), an illegal operation.");
+ try {
+ tool.getDefaultTopicSession().commit();
+ } catch (jakarta.jms.IllegalStateException iStateE) {
+ logger.log(Logger.Level.INFO, "Received jakarta.jms.IllegalStateException -- GOOD");
+ passed = true;
+ }
+ if (passed == false) { // need case for no exception being thrown
+ throw new Exception("Did not receive IllegalStateException");
+ }
+ } catch (Exception e) { // handles case of other exception being thrown
+ TestUtil.printStackTrace(e);
+ throw new Exception("xIllegalStateExceptionTopicTest");
+ }
+ }
+
+ /*
+ * @testName: xUnsupportedOperationExceptionTTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:658; JMS:JAVADOC:661;
+ *
+ * @test_Strategy: Create a TopicPublisher with a null Topic. Verify that
+ * UnsupportedOperationException is thrown when publish is called without a
+ * valid Topic.
+ */
+ @Test
+ public void xUnsupportedOperationExceptionTTest1() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ boolean pass = true;
+ Topic myTopic = null;
+ TopicPublisher tPub = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+
+ // Close default TopicPublisher and create a new one with null Topic
+ tool.getDefaultTopicPublisher().close();
+ tPub = tool.getDefaultTopicSession().createPublisher(myTopic);
+
+ tool.getDefaultTopicConnection().start();
+
+ try {
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xUnsupportedOperationExceptionTTest1");
+
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+ tPub.publish(messageSent);
+
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: TopicPublisher.publish(Message) didn't throw expected UnsupportedOperationException.");
+ } catch (UnsupportedOperationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected UnsupportedOperationException from TopicPublisher.publish(Message)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: TopicPublisher.publish(Message) throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ try {
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xUnsupportedOperationExceptionTTest1");
+
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+ tPub.publish(messageSent, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
+ Message.DEFAULT_TIME_TO_LIVE);
+
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: TopicPublisher.publish(Message, int, int, long) didn't throw expected UnsupportedOperationException.");
+ } catch (UnsupportedOperationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected UnsupportedOperationException from TopicPublisher.publish(Message, int, int, long)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error: TopicPublisher.publish(Message, int, int, long) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("xUnsupportedOperationExceptionTTest1 Failed!");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "xUnsupportedOperationExceptionTTest1 Failed!", e);
+ throw new Exception("xUnsupportedOperationExceptionTTest1 Failed!", e);
+ } finally {
+ try {
+ if (tool.getDefaultTopicConnection() != null) {
+ tool.getDefaultTopicConnection().close();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception closing TopicConnection and cleanup", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: xInvalidDestinationExceptionTTests
+ *
+ * @assertion_ids: JMS:JAVADOC:502; JMS:JAVADOC:504; JMS:JAVADOC:510;
+ * JMS:JAVADOC:638; JMS:JAVADOC:639; JMS:JAVADOC:641; JMS:JAVADOC:643;
+ * JMS:JAVADOC:644; JMS:JAVADOC:646; JMS:JAVADOC:647; JMS:JAVADOC:649;
+ *
+ * @test_Strategy: Create a Session with Topic Configuration, using a null
+ * Destination/Topic to verify InvalidDestinationException is thrown with
+ * various methods
+ */
+ @Test
+ public void xInvalidDestinationExceptionTTests() throws Exception {
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ boolean pass = true;
+ Destination dummy = null;
+ Topic dummyT = null;
+
+ tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultProducer().close();
+ tool.getDefaultConsumer().close();
+
+ try {
+ tool.getDefaultSession().createConsumer(dummy);
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(null) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO, "Got expected InvalidDestinationException from createConsumer(null)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(null) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'");
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(null, String) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createConsumer(null, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(null, String) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'", true);
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(null, String, boolean) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createConsumer(null, String, true)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(null, String, true) throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing default Connection", ex);
+ }
+
+ if (pass != true)
+ throw new Exception("xInvalidDestinationExceptionTTests");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xInvalidDestinationExceptionTTests");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: xMessageNotReadableExceptionTBytesMsgTest
+ *
+ * @assertion_ids: JMS:JAVADOC:676; JMS:JAVADOC:678; JMS:JAVADOC:682;
+ * JMS:JAVADOC:684; JMS:JAVADOC:686; JMS:JAVADOC:688; JMS:JAVADOC:690;
+ * JMS:JAVADOC:692; JMS:JAVADOC:694; JMS:JAVADOC:696; JMS:JAVADOC:698;
+ * JMS:JAVADOC:699; JMS:JAVADOC:700;
+ *
+ * @test_Strategy: Create a BytesMessage, call various read methods on it before
+ * sending. Verify that jakarta.jms.MessageNotReadableException is thrown.
+ */
+ @Test
+ public void xMessageNotReadableExceptionTBytesMsgTest() throws Exception {
+ try {
+ BytesMessage messageSent = null;
+ boolean pass = true;
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ byte[] bytesValueRecvd = { 0, 0, 0, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ Integer nInteger = new Integer(-2147483648);
+ short shortValue = -32768;
+ String utfValue = "what";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultProducer().close();
+ tool.getDefaultConsumer().close();
+
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultSession().createBytesMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotReadableExceptionTBytesMsgTest");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Writing one of each primitive type to the message");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeBoolean(booleanValue);
+ messageSent.writeByte(byteValue);
+ messageSent.writeChar(charValue);
+ messageSent.writeDouble(doubleValue);
+ messageSent.writeFloat(floatValue);
+ messageSent.writeInt(intValue);
+ messageSent.writeLong(longValue);
+ messageSent.writeObject(nInteger);
+ messageSent.writeShort(shortValue);
+ messageSent.writeUTF(utfValue);
+ messageSent.writeBytes(bytesValue);
+ messageSent.writeBytes(bytesValue, 0, 1);
+
+ try {
+ messageSent.getBodyLength();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: getBodyLength didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "getBodyLength threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "getBodyLength threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readBoolean();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readBoolean didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readBoolean threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readBoolean threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readByte();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readByte didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readByte threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readByte threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readUnsignedByte();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: readUnsignedByte didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readUnsignedByte threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readUnsignedByte threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readShort();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readShort didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readShort threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readShort threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readUnsignedShort();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: readUnsignedShort didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readUnsignedShort threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readUnsignedShort threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readChar();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readChar didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readChar threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readChar threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readInt();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readInt didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readInt threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readInt threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readLong();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readLong didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readLong threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readLong threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readFloat();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readFloat didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readFloat threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readFloat threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readDouble();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readDouble didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readDouble threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readDouble threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readUTF();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readUTF didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readUTF threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readUTF threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readBytes(bytesValueRecvd);
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: readBytes(byte[]) didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readBytes(byte[]) threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readBytes(byte[]) threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageSent.readBytes(bytesValueRecvd, 1);
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: readBytes(byte[], int) didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readBytes(byte[], int) threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readBytes(byte[],int) threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("xMessageNotReadableExceptionTBytesMsgTest Failed!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xMessageNotReadableExceptionTBytesMsgTest:");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: xMessageNotReadableExceptionTStreamMsgTest
+ *
+ * @assertion_ids: JMS:SPEC:73.1; JMS:JAVADOC:431; JMS:JAVADOC:721;
+ * JMS:JAVADOC:724; JMS:JAVADOC:727; JMS:JAVADOC:730; JMS:JAVADOC:733;
+ * JMS:JAVADOC:736; JMS:JAVADOC:739; JMS:JAVADOC:742; JMS:JAVADOC:745;
+ * JMS:JAVADOC:748; JMS:JAVADOC:751;
+ *
+ * @test_Strategy: Create a StreamMessage, send and receive via a Topic; Call
+ * clearBoldy right after receiving the message; Call various read methods on
+ * received message; Verify jakarta.jms.MessageNotReadableException is thrown.
+ */
+ @Test
+ public void xMessageNotReadableExceptionTStreamMsgTest() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ boolean pass = true;
+ byte bValue = 127;
+ boolean abool = false;
+ byte[] bValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+ byte[] bValuesReturned = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ char charValue = 'Z';
+ short sValue = 32767;
+ long lValue = 9223372036854775807L;
+ double dValue = 6.02e23;
+ float fValue = 6.02e23f;
+ int iValue = 6;
+ String myString = "text";
+ String sTesting = "Testing StreamMessages";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, lookup, mode);
+ tool.getDefaultConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "xMessageNotReadableExceptionTStreamMsgTest");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "");
+ logger.log(Logger.Level.INFO, "Writing one of each primitive type to the message");
+ // -----------------------------------------------------------------------------
+ messageSent.writeBytes(bValues2, 0, bValues.length);
+ messageSent.writeBoolean(abool);
+ messageSent.writeByte(bValue);
+ messageSent.writeBytes(bValues);
+ messageSent.writeChar(charValue);
+ messageSent.writeDouble(dValue);
+ messageSent.writeFloat(fValue);
+ messageSent.writeInt(iValue);
+ messageSent.writeLong(lValue);
+ messageSent.writeObject(sTesting);
+ messageSent.writeShort(sValue);
+ messageSent.writeString(myString);
+ messageSent.writeObject(null);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultProducer().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultConsumer().receive(timeout);
+
+ logger.log(Logger.Level.TRACE, "call ClearBody()");
+ messageReceived.clearBody();
+
+ try {
+ messageReceived.readBoolean();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readBoolean didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readBoolean threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readBoolean threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readByte();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readByte didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readByte threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readByte threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readShort();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readShort didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readShort threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readShort threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readChar();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readChar didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readChar threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readChar threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readInt();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readInt didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readInt threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readInt threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readLong();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readLong didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readLong threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readLong threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readFloat();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readFloat didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readFloat threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readFloat threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readDouble();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readDouble didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readDouble threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readDouble threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readString();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readString didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readString threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readString threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readBytes(bValuesReturned);
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: readBytes(byte[]) didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readBytes(byte[]) threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readBytes(byte[]) threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ try {
+ messageReceived.readObject();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: readObject didn't throw Expected MessageNotReadableException!");
+ } catch (MessageNotReadableException nr) {
+ logger.log(Logger.Level.TRACE, "readObject threw Expected MessageNotReadableException!");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "readObject threw Wrong Exception!", e);
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("xMessageNotReadableExceptionTStreamMsgTest Failed!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xMessageNotReadableExceptionTStreamMsgTest:");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: xIllegalStateExceptionTestQueueMethodsT
+ *
+ * @assertion_ids: JMS:SPEC:185.6; JMS:SPEC:185.7; JMS:SPEC:185.8; JMS:SPEC:185;
+ *
+ * @test_Strategy: Create a TopicSession and call Queue specific methods
+ * inherited from Session, and verify that jakarta.jms.IllegalStateException is
+ * thrown.
+ */
+ @Test
+ public void xIllegalStateExceptionTestQueueMethodsT() throws Exception {
+
+ try {
+ boolean pass = true;
+ Queue myQueue = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+ myQueue = tool.createNewQueue("MY_QUEUE");
+
+ try {
+ tool.getDefaultTopicSession().createBrowser(myQueue);
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: TopicSession.createBrowser(Queue) didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateException from TopicSession.createBrowser(Queue)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: TopicSession.createBrowser(Queue) throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultTopicSession().createBrowser(myQueue, "TEST = 'test'");
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: TopicSession.createBrowser(Queue, String) didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateException from TopicSession.createBrowser(Queue, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error: TopicSession.createBrowser(Queue, String) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultTopicSession().createTemporaryQueue();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: TopicSession.createTemporayQueue() didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateException from TopicSession.createTemporayQueue()");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: TopicSession.createTemporayQueue() throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultTopicSession().createQueue("foo");
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: TopicSession.createQueue(String) didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateException from TopicSession.createQueue(String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: TopicSession.createQueue(String) throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("xIllegalStateExceptionTestQueueMethodsT Failed!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("xIllegalStateExceptionTestQueueMethodsT");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/exceptiontests/ExceptionTest.java b/jms/src/main/java/com/sun/ts/tests/jms/core/exceptiontests/ExceptionTest.java
deleted file mode 100644
index 8e642d7590..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/exceptiontests/ExceptionTest.java
+++ /dev/null
@@ -1,784 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.exceptiontests;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-
-import jakarta.jms.InvalidClientIDException;
-import jakarta.jms.InvalidDestinationException;
-import jakarta.jms.InvalidSelectorException;
-import jakarta.jms.JMSException;
-import jakarta.jms.JMSSecurityException;
-import jakarta.jms.MessageEOFException;
-import jakarta.jms.MessageFormatException;
-import jakarta.jms.MessageNotReadableException;
-import jakarta.jms.MessageNotWriteableException;
-import jakarta.jms.ResourceAllocationException;
-import jakarta.jms.TransactionInProgressException;
-import jakarta.jms.TransactionRolledBackException;
-
-public class ExceptionTest extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.exceptiontests.ExceptionTest";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ExceptionTest theTests = new ExceptionTest();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props:
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- }
-
- /* Tests */
- /*
- * @testName: transactionRolledBackExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:1;
- *
- * @test_Strategy: Construct TransactionRolledBackException(String, String)
- * the correct message in it.
- */
-
- public void transactionRolledBackExceptionTest1() throws Exception {
-
- try {
- String errorCode = "Serious";
- String cause = "Rollback operation not allowed.";
-
- jakarta.jms.TransactionRolledBackException exceptionToTest = new TransactionRolledBackException(
- cause, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (TransactionRolledBackException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("TransactionRolledBackExceptionTest1 Failed: ");
- }
- }
-
- /*
- * @testName: transactionRolledBackExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:2;
- *
- * @test_Strategy: Construct TransactionRolledBackException(String)
- */
-
- public void transactionRolledBackExceptionTest2() throws Exception {
- try {
- jakarta.jms.TransactionRolledBackException exceptionToTest = new TransactionRolledBackException(
- "Rollback operation not allowed.");
- try {
- throw exceptionToTest;
- } catch (TransactionRolledBackException e) {
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("TransactionRolledBackExceptionTest2 Failed: ");
- }
- }
-
- /*
- * @testName: testTransactionInProgressException1
- *
- * @assertion_ids: JMS:JAVADOC:3;
- *
- * @test_Strategy: Construct TransactionInProgressException(String, String)
- */
-
- public void testTransactionInProgressException1() throws Exception {
- try {
- String errorCode = "Warning";
- String cause = "Transaction is still in progress.";
-
- jakarta.jms.TransactionInProgressException exceptionToTest = new TransactionInProgressException(
- cause, errorCode);
- try {
- throw exceptionToTest;
- } catch (TransactionInProgressException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("TransactionInProgressExceptionTest1 Failed: ");
- }
- }
-
- /*
- * @testName: testTransactionInProgressException2
- *
- * @assertion_ids: JMS:JAVADOC:4;
- *
- * @test_Strategy: Construct TransactionInProgressException(String)
- */
-
- public void testTransactionInProgressException2() throws Exception {
- try {
- jakarta.jms.TransactionInProgressException exceptionToTest = new TransactionInProgressException(
- "Transaction is still in progress.");
- try {
- throw exceptionToTest;
- } catch (TransactionInProgressException e) {
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("TransactionInProgressExceptionTest2 Failed: ");
- }
- }
-
- /*
- * @testName: testResourceAllocationException1
- *
- * @assertion_ids: JMS:JAVADOC:10;
- *
- * @test_Strategy: Construct ResourceAllocationException(String, String)
- */
-
- public void testResourceAllocationException1() throws Exception {
-
- try {
- String errorCode = "Urgent";
- String cause = "Cannot get the resource, not enough heap space.";
-
- jakarta.jms.ResourceAllocationException exceptionToTest = new ResourceAllocationException(
- cause, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (ResourceAllocationException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("ResourceAllocationException1 Failed: ");
- }
- }
-
- /*
- * @testName: resourceAllocationExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:11;
- *
- * @test_Strategy: Construct ResourceAllocationException(String)
- */
-
- public void resourceAllocationExceptionTest2() throws Exception {
- try {
- jakarta.jms.ResourceAllocationException exceptionToTest = new ResourceAllocationException(
- "Cannot get the resource, " + "not enough heap space.");
- try {
- throw exceptionToTest;
- } catch (ResourceAllocationException e) {
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("ResourceAllocationException2 Failed: ");
- }
- }
-
- /*
- * @testName: testMessageNotWriteableException1
- *
- * @assertion_ids: JMS:JAVADOC:17;
- *
- * @test_Strategy: Construct MessageNotWriteableException(String, String)
- */
-
- public void testMessageNotWriteableException1() throws Exception {
-
- try {
- String errorCode = "Urgent";
- String cause = "Message just received";
-
- jakarta.jms.MessageNotWriteableException exceptionToTest = new MessageNotWriteableException(
- cause, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (MessageNotWriteableException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MessageNotWriteableExceptionTest1 Failed: ");
- }
- }
-
- /*
- * @testName: testMessageNotWriteableException2
- *
- * @assertion_ids: JMS:JAVADOC:18;
- *
- * @test_Strategy: Construct MessageNotWriteableException(String)
- */
-
- public void testMessageNotWriteableException2() throws Exception {
- try {
- jakarta.jms.MessageNotWriteableException exceptionToTest = new MessageNotWriteableException(
- "Message just received");
- try {
- throw exceptionToTest;
- } catch (MessageNotWriteableException e) {
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MessageNotWriteableExceptionTest2 Failed: ");
- }
- }
-
- /*
- * @testName: testMessageNotReadableException1
- *
- * @assertion_ids: JMS:JAVADOC:19;
- *
- * @test_Strategy: Construct MessageNotReadableException(String, String)
- */
-
- public void testMessageNotReadableException1() throws Exception {
-
- try {
- String errorCode = "Urgent";
- String cause = "Message is empty";
-
- jakarta.jms.MessageNotReadableException exceptionToTest = new MessageNotReadableException(
- cause, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (MessageNotReadableException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MessageNotReadableExceptionTest1 Failed: ");
- }
- }
-
- /*
- * @testName: testMessageNotReadableException2
- *
- * @assertion_ids: JMS:JAVADOC:20;
- *
- * @test_Strategy: Construct MessageNotReadableException(String)
- */
-
- public void testMessageNotReadableException2() throws Exception {
- try {
- jakarta.jms.MessageNotReadableException exceptionToTest = new MessageNotReadableException(
- "Message is empty");
- try {
- throw exceptionToTest;
- } catch (MessageNotReadableException e) {
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MessageNotReadableExceptionTest2 Failed: ");
- }
- }
-
- /*
- * @testName: testMessageFormatException1
- *
- * @assertion_ids: JMS:JAVADOC:21;
- *
- * @test_Strategy: Construct MessageFormatException(String, String)
- */
-
- public void testMessageFormatException1() throws Exception {
-
- try {
- String errorCode = "Urgent";
- String cause = "Cannot convert from int to char";
-
- jakarta.jms.MessageFormatException exceptionToTest = new MessageFormatException(
- cause, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (MessageFormatException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MessageFormatExceptionTest1 Failed: ");
- }
- }
-
- /*
- * @testName: testMessageFormatException2
- *
- * @assertion_ids: JMS:JAVADOC:22;
- *
- * @test_Strategy: Construct MessageFormatException(String)
- */
-
- public void testMessageFormatException2() throws Exception {
- try {
- jakarta.jms.MessageFormatException exceptionToTest = new MessageFormatException(
- "Cannot convert from int to char");
- try {
- throw exceptionToTest;
- } catch (MessageFormatException e) {
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MessageFormatExceptionTest2 Failed: ");
- }
- }
-
- /*
- * @testName: testMessageEOFException1
- *
- * @assertion_ids: JMS:JAVADOC:23;
- *
- * @test_Strategy: Construct MessageEOFException(String, String)
- */
-
- public void testMessageEOFException1() throws Exception {
-
- try {
- String errorCode = "Urgent";
- String cause = "It is a byte, not an int.";
-
- jakarta.jms.MessageEOFException exceptionToTest = new MessageEOFException(
- cause, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (MessageEOFException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MessageEOFExceptionTest1 Failed: ");
- }
- }
-
- /*
- * @testName: testMessageEOFException2
- *
- * @assertion_ids: JMS:JAVADOC:24;
- *
- * @test_Strategy: Construct MessageEOFException(String)
- */
-
- public void testMessageEOFException2() throws Exception {
- try {
- jakarta.jms.MessageEOFException exceptionToTest = new MessageEOFException(
- "It is a byte, not an int.");
- try {
- throw exceptionToTest;
- } catch (MessageEOFException e) {
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MessageEOFExceptionTest2 Failed: ");
- }
- }
-
- /*
- * @testName: testJMSSecurityException1
- *
- * @assertion_ids: JMS:JAVADOC:25;
- *
- * @test_Strategy: Construct JMSSecurityException(String, String)
- */
-
- public void testJMSSecurityException1() throws Exception {
-
- try {
- String errorCode = "Urgent";
- String cause = "Cannot find the user.";
-
- jakarta.jms.JMSSecurityException exceptionToTest = new JMSSecurityException(
- cause, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (JMSSecurityException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("JMSSecurityExceptionTest1 Failed: ");
- }
- }
-
- /*
- * @testName: testJMSSecurityException2
- *
- * @assertion_ids: JMS:JAVADOC:26;
- *
- * @test_Strategy: Construct JMSSecurityException(String)
- */
-
- public void testJMSSecurityException2() throws Exception {
- try {
- jakarta.jms.JMSSecurityException exceptionToTest = new JMSSecurityException(
- "Cannot find the user.");
- try {
- throw exceptionToTest;
- } catch (JMSSecurityException e) {
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("JMSSecurityExceptionTest2 Failed: ");
- }
- }
-
- /*
- * @testName: testJMSException1
- *
- * @assertion_ids: JMS:JAVADOC:27; JMS:JAVADOC:29;
- *
- * @test_Strategy: Construct JMSException(String, String)
- */
-
- public void testJMSException1() throws Exception {
-
- try {
- String errorCode = "Warning";
- String cause = "Not a JMS operation";
-
- jakarta.jms.JMSException exceptionToTest = new JMSException(cause,
- errorCode);
-
- try {
- throw exceptionToTest;
- } catch (JMSException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("JMSExceptionTest1 Failed: ");
- }
- }
-
- /*
- * @testName: testJMSException2
- *
- * @assertion_ids: JMS:JAVADOC:28; JMS:JAVADOC:30; JMS:JAVADOC:31;
- *
- * @test_Strategy: Construct JMSException(String)
- */
-
- public void testJMSException2() throws Exception {
-
- try {
- String cause = "Not a JMS operation";
- String cause1 = "Deprecated since v1.1";
-
- jakarta.jms.JMSException exceptionToTest = new JMSException(cause);
- jakarta.jms.JMSException exceptionToTest1 = new JMSException(cause1);
-
- exceptionToTest.setLinkedException(exceptionToTest1);
-
- if (!exceptionToTest.getLinkedException().getMessage()
- .equals(exceptionToTest1.getMessage()))
- throw new Exception("Linked Exception does not return correct message "
- + exceptionToTest.getLinkedException().getMessage());
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("JMSExceptionTest2 Failed: ");
- }
- }
-
- /*
- * @testName: invalidSelectorExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:32;
- *
- * @test_Strategy: Construct InvalidSelectorException(String, String)
- */
-
- public void invalidSelectorExceptionTest1() throws Exception {
-
- try {
- String errorCode = "Urgent";
- String cause = "unknown variable";
-
- jakarta.jms.InvalidSelectorException exceptionToTest = new InvalidSelectorException(
- cause, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (InvalidSelectorException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("InvalidSelectorExceptionTest1 Failed: ");
- }
- }
-
- /*
- * @testName: invalidSelectorExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:33;
- *
- * @test_Strategy: Construct InvalidSelectorException(String)
- */
-
- public void invalidSelectorExceptionTest2() throws Exception {
- try {
- jakarta.jms.InvalidSelectorException exceptionToTest = new InvalidSelectorException(
- "unknown variable");
- try {
- throw exceptionToTest;
- } catch (InvalidSelectorException e) {
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("InvalidSelectorExceptionTest2 Failed: ");
- }
- }
-
- /*
- * @testName: invalidDestinationExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:34;
- *
- * @test_Strategy: Construct InvalidDestinationException(String, String)
- */
-
- public void invalidDestinationExceptionTest1() throws Exception {
-
- try {
- String errorCode = "Urgent";
- String cause = "Destination is Null";
-
- jakarta.jms.InvalidDestinationException exceptionToTest = new InvalidDestinationException(
- cause, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (InvalidDestinationException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("InvalidDestinationExceptionTest1 Failed: ");
- }
- }
-
- /*
- * @testName: invalidDestinationExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:35;
- *
- * @test_Strategy: Construct InvalidDestinationException(String)
- */
-
- public void invalidDestinationExceptionTest2() throws Exception {
- try {
- jakarta.jms.InvalidDestinationException exceptionToTest = new InvalidDestinationException(
- "Destination is Null");
- try {
- throw exceptionToTest;
- } catch (InvalidDestinationException e) {
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("InvalidDestinationExceptionTest2 Failed: ");
- }
- }
-
- /*
- * @testName: invalidClientIDExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:36;
- *
- * @test_Strategy: Construct InvalidClientIDException(String, String)
- */
-
- public void invalidClientIDExceptionTest1() throws Exception {
-
- try {
- String errorCode = "Urgent";
- String cause = "Duplicate Client ID";
-
- jakarta.jms.InvalidClientIDException exceptionToTest = new InvalidClientIDException(
- cause, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (InvalidClientIDException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("InvalidClientIDExceptionTest1 Failed: ");
- }
- }
-
- /*
- * @testName: invalidClientIDExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:37;
- *
- * @test_Strategy: Construct InvalidClientIDException(String)
- */
-
- public void invalidClientIDExceptionTest2() throws Exception {
- try {
- jakarta.jms.InvalidClientIDException exceptionToTest = new InvalidClientIDException(
- "Duplicate Client ID");
- try {
- throw exceptionToTest;
- } catch (InvalidClientIDException e) {
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("InvalidClientIDExceptionTest2 Failed: ");
- }
- }
-
- /*
- * @testName: illegalStateExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:38;
- *
- * @test_Strategy: Construct IllegalStateException(String, String)
- */
-
- public void illegalStateExceptionTest1() throws Exception {
-
- try {
- String errorCode = "Urgent";
- String cause = "The operation is intended for Queue Configuration only.";
-
- jakarta.jms.IllegalStateException exceptionToTest = new jakarta.jms.IllegalStateException(
- cause, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.IllegalStateException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode))
- throw new Exception(
- "Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("IllegalStateExceptionTest1 Failed: ");
- }
- }
-
- /*
- * @testName: illegalStateExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:39;
- *
- * @test_Strategy: Construct IllegalStateException(String)
- */
-
- public void illegalStateExceptionTest2() throws Exception {
-
- try {
- jakarta.jms.IllegalStateException exceptionToTest = new jakarta.jms.IllegalStateException(
- "The operation is intended for Queue Configuration only.");
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.IllegalStateException e) {
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Failed to construct IllegalStateException: ");
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/exceptiontests/ExceptionTestIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/exceptiontests/ExceptionTestIT.java
new file mode 100644
index 0000000000..49058932e3
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/exceptiontests/ExceptionTestIT.java
@@ -0,0 +1,751 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.exceptiontests;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+
+import jakarta.jms.InvalidClientIDException;
+import jakarta.jms.InvalidDestinationException;
+import jakarta.jms.InvalidSelectorException;
+import jakarta.jms.JMSException;
+import jakarta.jms.JMSSecurityException;
+import jakarta.jms.MessageEOFException;
+import jakarta.jms.MessageFormatException;
+import jakarta.jms.MessageNotReadableException;
+import jakarta.jms.MessageNotWriteableException;
+import jakarta.jms.ResourceAllocationException;
+import jakarta.jms.TransactionInProgressException;
+import jakarta.jms.TransactionRolledBackException;
+
+
+public class ExceptionTestIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.exceptiontests.ExceptionTestIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ExceptionTestIT.class.getName());
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props:
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ }
+
+ /* Tests */
+ /*
+ * @testName: transactionRolledBackExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1;
+ *
+ * @test_Strategy: Construct TransactionRolledBackException(String, String) the
+ * correct message in it.
+ */
+ @Test
+ public void transactionRolledBackExceptionTest1() throws Exception {
+
+ try {
+ String errorCode = "Serious";
+ String cause = "Rollback operation not allowed.";
+
+ jakarta.jms.TransactionRolledBackException exceptionToTest = new TransactionRolledBackException(cause,
+ errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (TransactionRolledBackException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("TransactionRolledBackExceptionTest1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: transactionRolledBackExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:2;
+ *
+ * @test_Strategy: Construct TransactionRolledBackException(String)
+ */
+ @Test
+ public void transactionRolledBackExceptionTest2() throws Exception {
+ try {
+ jakarta.jms.TransactionRolledBackException exceptionToTest = new TransactionRolledBackException(
+ "Rollback operation not allowed.");
+ try {
+ throw exceptionToTest;
+ } catch (TransactionRolledBackException e) {
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("TransactionRolledBackExceptionTest2 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testTransactionInProgressException1
+ *
+ * @assertion_ids: JMS:JAVADOC:3;
+ *
+ * @test_Strategy: Construct TransactionInProgressException(String, String)
+ */
+ @Test
+ public void testTransactionInProgressException1() throws Exception {
+ try {
+ String errorCode = "Warning";
+ String cause = "Transaction is still in progress.";
+
+ jakarta.jms.TransactionInProgressException exceptionToTest = new TransactionInProgressException(cause,
+ errorCode);
+ try {
+ throw exceptionToTest;
+ } catch (TransactionInProgressException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("TransactionInProgressExceptionTest1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testTransactionInProgressException2
+ *
+ * @assertion_ids: JMS:JAVADOC:4;
+ *
+ * @test_Strategy: Construct TransactionInProgressException(String)
+ */
+ @Test
+ public void testTransactionInProgressException2() throws Exception {
+ try {
+ jakarta.jms.TransactionInProgressException exceptionToTest = new TransactionInProgressException(
+ "Transaction is still in progress.");
+ try {
+ throw exceptionToTest;
+ } catch (TransactionInProgressException e) {
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("TransactionInProgressExceptionTest2 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testResourceAllocationException1
+ *
+ * @assertion_ids: JMS:JAVADOC:10;
+ *
+ * @test_Strategy: Construct ResourceAllocationException(String, String)
+ */
+ @Test
+ public void testResourceAllocationException1() throws Exception {
+
+ try {
+ String errorCode = "Urgent";
+ String cause = "Cannot get the resource, not enough heap space.";
+
+ jakarta.jms.ResourceAllocationException exceptionToTest = new ResourceAllocationException(cause, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (ResourceAllocationException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("ResourceAllocationException1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: resourceAllocationExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:11;
+ *
+ * @test_Strategy: Construct ResourceAllocationException(String)
+ */
+ @Test
+ public void resourceAllocationExceptionTest2() throws Exception {
+ try {
+ jakarta.jms.ResourceAllocationException exceptionToTest = new ResourceAllocationException(
+ "Cannot get the resource, " + "not enough heap space.");
+ try {
+ throw exceptionToTest;
+ } catch (ResourceAllocationException e) {
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("ResourceAllocationException2 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testMessageNotWriteableException1
+ *
+ * @assertion_ids: JMS:JAVADOC:17;
+ *
+ * @test_Strategy: Construct MessageNotWriteableException(String, String)
+ */
+ @Test
+ public void testMessageNotWriteableException1() throws Exception {
+
+ try {
+ String errorCode = "Urgent";
+ String cause = "Message just received";
+
+ jakarta.jms.MessageNotWriteableException exceptionToTest = new MessageNotWriteableException(cause,
+ errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (MessageNotWriteableException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MessageNotWriteableExceptionTest1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testMessageNotWriteableException2
+ *
+ * @assertion_ids: JMS:JAVADOC:18;
+ *
+ * @test_Strategy: Construct MessageNotWriteableException(String)
+ */
+ @Test
+ public void testMessageNotWriteableException2() throws Exception {
+ try {
+ jakarta.jms.MessageNotWriteableException exceptionToTest = new MessageNotWriteableException(
+ "Message just received");
+ try {
+ throw exceptionToTest;
+ } catch (MessageNotWriteableException e) {
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MessageNotWriteableExceptionTest2 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testMessageNotReadableException1
+ *
+ * @assertion_ids: JMS:JAVADOC:19;
+ *
+ * @test_Strategy: Construct MessageNotReadableException(String, String)
+ */
+ @Test
+ public void testMessageNotReadableException1() throws Exception {
+
+ try {
+ String errorCode = "Urgent";
+ String cause = "Message is empty";
+
+ jakarta.jms.MessageNotReadableException exceptionToTest = new MessageNotReadableException(cause, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (MessageNotReadableException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MessageNotReadableExceptionTest1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testMessageNotReadableException2
+ *
+ * @assertion_ids: JMS:JAVADOC:20;
+ *
+ * @test_Strategy: Construct MessageNotReadableException(String)
+ */
+ @Test
+ public void testMessageNotReadableException2() throws Exception {
+ try {
+ jakarta.jms.MessageNotReadableException exceptionToTest = new MessageNotReadableException(
+ "Message is empty");
+ try {
+ throw exceptionToTest;
+ } catch (MessageNotReadableException e) {
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MessageNotReadableExceptionTest2 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testMessageFormatException1
+ *
+ * @assertion_ids: JMS:JAVADOC:21;
+ *
+ * @test_Strategy: Construct MessageFormatException(String, String)
+ */
+ @Test
+ public void testMessageFormatException1() throws Exception {
+
+ try {
+ String errorCode = "Urgent";
+ String cause = "Cannot convert from int to char";
+
+ jakarta.jms.MessageFormatException exceptionToTest = new MessageFormatException(cause, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (MessageFormatException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MessageFormatExceptionTest1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testMessageFormatException2
+ *
+ * @assertion_ids: JMS:JAVADOC:22;
+ *
+ * @test_Strategy: Construct MessageFormatException(String)
+ */
+ @Test
+ public void testMessageFormatException2() throws Exception {
+ try {
+ jakarta.jms.MessageFormatException exceptionToTest = new MessageFormatException(
+ "Cannot convert from int to char");
+ try {
+ throw exceptionToTest;
+ } catch (MessageFormatException e) {
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MessageFormatExceptionTest2 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testMessageEOFException1
+ *
+ * @assertion_ids: JMS:JAVADOC:23;
+ *
+ * @test_Strategy: Construct MessageEOFException(String, String)
+ */
+ @Test
+ public void testMessageEOFException1() throws Exception {
+
+ try {
+ String errorCode = "Urgent";
+ String cause = "It is a byte, not an int.";
+
+ jakarta.jms.MessageEOFException exceptionToTest = new MessageEOFException(cause, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (MessageEOFException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MessageEOFExceptionTest1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testMessageEOFException2
+ *
+ * @assertion_ids: JMS:JAVADOC:24;
+ *
+ * @test_Strategy: Construct MessageEOFException(String)
+ */
+ @Test
+ public void testMessageEOFException2() throws Exception {
+ try {
+ jakarta.jms.MessageEOFException exceptionToTest = new MessageEOFException("It is a byte, not an int.");
+ try {
+ throw exceptionToTest;
+ } catch (MessageEOFException e) {
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MessageEOFExceptionTest2 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testJMSSecurityException1
+ *
+ * @assertion_ids: JMS:JAVADOC:25;
+ *
+ * @test_Strategy: Construct JMSSecurityException(String, String)
+ */
+ @Test
+ public void testJMSSecurityException1() throws Exception {
+
+ try {
+ String errorCode = "Urgent";
+ String cause = "Cannot find the user.";
+
+ jakarta.jms.JMSSecurityException exceptionToTest = new JMSSecurityException(cause, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (JMSSecurityException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("JMSSecurityExceptionTest1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testJMSSecurityException2
+ *
+ * @assertion_ids: JMS:JAVADOC:26;
+ *
+ * @test_Strategy: Construct JMSSecurityException(String)
+ */
+ @Test
+ public void testJMSSecurityException2() throws Exception {
+ try {
+ jakarta.jms.JMSSecurityException exceptionToTest = new JMSSecurityException("Cannot find the user.");
+ try {
+ throw exceptionToTest;
+ } catch (JMSSecurityException e) {
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("JMSSecurityExceptionTest2 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testJMSException1
+ *
+ * @assertion_ids: JMS:JAVADOC:27; JMS:JAVADOC:29;
+ *
+ * @test_Strategy: Construct JMSException(String, String)
+ */
+ @Test
+ public void testJMSException1() throws Exception {
+
+ try {
+ String errorCode = "Warning";
+ String cause = "Not a JMS operation";
+
+ jakarta.jms.JMSException exceptionToTest = new JMSException(cause, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (JMSException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("JMSExceptionTest1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: testJMSException2
+ *
+ * @assertion_ids: JMS:JAVADOC:28; JMS:JAVADOC:30; JMS:JAVADOC:31;
+ *
+ * @test_Strategy: Construct JMSException(String)
+ */
+ @Test
+ public void testJMSException2() throws Exception {
+
+ try {
+ String cause = "Not a JMS operation";
+ String cause1 = "Deprecated since v1.1";
+
+ jakarta.jms.JMSException exceptionToTest = new JMSException(cause);
+ jakarta.jms.JMSException exceptionToTest1 = new JMSException(cause1);
+
+ exceptionToTest.setLinkedException(exceptionToTest1);
+
+ if (!exceptionToTest.getLinkedException().getMessage().equals(exceptionToTest1.getMessage()))
+ throw new Exception("Linked Exception does not return correct message "
+ + exceptionToTest.getLinkedException().getMessage());
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("JMSExceptionTest2 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: invalidSelectorExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:32;
+ *
+ * @test_Strategy: Construct InvalidSelectorException(String, String)
+ */
+ @Test
+ public void invalidSelectorExceptionTest1() throws Exception {
+
+ try {
+ String errorCode = "Urgent";
+ String cause = "unknown variable";
+
+ jakarta.jms.InvalidSelectorException exceptionToTest = new InvalidSelectorException(cause, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (InvalidSelectorException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("InvalidSelectorExceptionTest1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: invalidSelectorExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:33;
+ *
+ * @test_Strategy: Construct InvalidSelectorException(String)
+ */
+ @Test
+ public void invalidSelectorExceptionTest2() throws Exception {
+ try {
+ jakarta.jms.InvalidSelectorException exceptionToTest = new InvalidSelectorException("unknown variable");
+ try {
+ throw exceptionToTest;
+ } catch (InvalidSelectorException e) {
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("InvalidSelectorExceptionTest2 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: invalidDestinationExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:34;
+ *
+ * @test_Strategy: Construct InvalidDestinationException(String, String)
+ */
+ @Test
+ public void invalidDestinationExceptionTest1() throws Exception {
+
+ try {
+ String errorCode = "Urgent";
+ String cause = "Destination is Null";
+
+ jakarta.jms.InvalidDestinationException exceptionToTest = new InvalidDestinationException(cause, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (InvalidDestinationException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("InvalidDestinationExceptionTest1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: invalidDestinationExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:35;
+ *
+ * @test_Strategy: Construct InvalidDestinationException(String)
+ */
+ @Test
+ public void invalidDestinationExceptionTest2() throws Exception {
+ try {
+ jakarta.jms.InvalidDestinationException exceptionToTest = new InvalidDestinationException(
+ "Destination is Null");
+ try {
+ throw exceptionToTest;
+ } catch (InvalidDestinationException e) {
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("InvalidDestinationExceptionTest2 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: invalidClientIDExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:36;
+ *
+ * @test_Strategy: Construct InvalidClientIDException(String, String)
+ */
+ @Test
+ public void invalidClientIDExceptionTest1() throws Exception {
+
+ try {
+ String errorCode = "Urgent";
+ String cause = "Duplicate Client ID";
+
+ jakarta.jms.InvalidClientIDException exceptionToTest = new InvalidClientIDException(cause, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (InvalidClientIDException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("InvalidClientIDExceptionTest1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: invalidClientIDExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:37;
+ *
+ * @test_Strategy: Construct InvalidClientIDException(String)
+ */
+ @Test
+ public void invalidClientIDExceptionTest2() throws Exception {
+ try {
+ jakarta.jms.InvalidClientIDException exceptionToTest = new InvalidClientIDException("Duplicate Client ID");
+ try {
+ throw exceptionToTest;
+ } catch (InvalidClientIDException e) {
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("InvalidClientIDExceptionTest2 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: illegalStateExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:38;
+ *
+ * @test_Strategy: Construct IllegalStateException(String, String)
+ */
+ @Test
+ public void illegalStateExceptionTest1() throws Exception {
+
+ try {
+ String errorCode = "Urgent";
+ String cause = "The operation is intended for Queue Configuration only.";
+
+ jakarta.jms.IllegalStateException exceptionToTest = new jakarta.jms.IllegalStateException(cause, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.IllegalStateException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode))
+ throw new Exception("Incorrect ErrorCode " + exceptionToTest.getErrorCode(), e);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("IllegalStateExceptionTest1 Failed: ");
+ }
+ }
+
+ /*
+ * @testName: illegalStateExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:39;
+ *
+ * @test_Strategy: Construct IllegalStateException(String)
+ */
+ @Test
+ public void illegalStateExceptionTest2() throws Exception {
+
+ try {
+ jakarta.jms.IllegalStateException exceptionToTest = new jakarta.jms.IllegalStateException(
+ "The operation is intended for Queue Configuration only.");
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.IllegalStateException e) {
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Failed to construct IllegalStateException: ");
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/foreignMsgQueue/ForeignMsgQueueTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/foreignMsgQueue/ForeignMsgQueueTests.java
deleted file mode 100644
index e701f73967..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/foreignMsgQueue/ForeignMsgQueueTests.java
+++ /dev/null
@@ -1,751 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.foreignMsgQueue;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.BytesMessageTestImpl;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.common.MapMessageTestImpl;
-import com.sun.ts.tests.jms.common.MessageTestImpl;
-import com.sun.ts.tests.jms.common.ObjectMessageTestImpl;
-import com.sun.ts.tests.jms.common.StreamMessageTestImpl;
-import com.sun.ts.tests.jms.common.TextMessageTestImpl;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.Queue;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-
-public class ForeignMsgQueueTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.foreignMsgQueue.ForeignMsgQueueTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- // values to pass into/read from messages
- boolean testBoolean = true;
-
- byte testByte = 100;
-
- char testChar = 'a';
-
- int testInt = 10;
-
- Object testObject = new Double(3.141);
-
- String testString = "java";
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ForeignMsgQueueTests theTests = new ForeignMsgQueueTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- queues = new ArrayList(2);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: sendReceiveBytesMsgQueueTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
- *
- * @test_Strategy: Send message with appropriate data Receive message and
- * check data
- */
-
- public void sendReceiveBytesMsgQueueTest() throws Exception {
- boolean pass = true;
-
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = new BytesMessageTestImpl();
- logTrace("Setting test values in MessageTestImpl.javaessage");
- long bodyLength = 22L;
- BytesMessageTestImpl messageSentImpl = (BytesMessageTestImpl) messageSent;
- messageSentImpl.setBodyLength(bodyLength);
- messageSent.writeBoolean(testBoolean);
- messageSent.writeByte(testByte);
- messageSent.writeChar(testChar);
- messageSent.writeInt(testInt);
- messageSent.writeObject(testObject);
- messageSent.writeUTF(testString);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendReceiveBytesMsgQueueTest");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Did not receive message");
- }
- logTrace("Check received message");
- if (messageReceived.readBoolean() == testBoolean) {
- logTrace("Received correct boolean value");
- } else {
- logMsg("incorrect boolean value -- BAD");
- pass = false;
- }
- if (messageReceived.readByte() == testByte) {
- logTrace("Received correct byte value");
- } else {
- logMsg("incorrect byte value -- BAD");
- pass = false;
- }
- if (messageReceived.readChar() == testChar) {
- logTrace("Received correct char value");
- } else {
- logMsg("incorrect char value -- BAD");
- pass = false;
- }
- if (messageReceived.readInt() == testInt) {
- logTrace("Received correct int value");
- } else {
- logMsg("incorrect int value -- BAD");
- pass = false;
- }
- if (messageReceived.readDouble() == ((Double) testObject).doubleValue()) {
- logTrace("Received correct object");
- } else {
- logMsg("incorrect object -- BAD");
- pass = false;
- }
- if (messageReceived.readUTF().equals(testString)) {
- logTrace("Received correct String");
- } else {
- logMsg("incorrect string -- BAD");
- pass = false;
- }
- if (pass == false) {
- logMsg("Test failed -- see above");
- throw new Exception();
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendReceiveBytesMsgQueueTest");
- }
- }
-
- /*
- * @testName: sendReceiveMsgQueueTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
- *
- * @test_Strategy: Send message with appropriate data Receive message and
- * check data
- */
-
- public void sendReceiveMsgQueueTest() throws Exception {
- try {
- Message messageSent = null;
- Message messageReceived = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logMsg("Creating 1 message");
- messageSent = new MessageTestImpl();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendReceiveMsgQueueTest");
- logMsg("sending: " + messageSent);
- logMsg("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logMsg("Receiving message");
- messageReceived = tool.getDefaultQueueReceiver().receive(timeout);
- logMsg("received: " + messageReceived);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendReceiveMsgQueueTest");
- }
- }
-
- /*
- * @testName: sendReceiveMapMsgQueueTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
- *
- * @test_Strategy: Send message with appropriate data Receive message and
- * check data
- */
-
- public void sendReceiveMapMsgQueueTest() throws Exception {
- boolean pass = true;
-
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = new MapMessageTestImpl();
- logTrace("Setting test values in message");
- messageSent.setBoolean("TestBoolean", testBoolean);
- messageSent.setByte("TestByte", testByte);
- messageSent.setChar("TestChar", testChar);
- messageSent.setInt("TestInt", testInt);
- messageSent.setObject("TestDouble", testObject);
- messageSent.setString("TestString", testString);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendReceiveMapMsgQueueTest");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Did not receive message");
- }
- logTrace("Check received message");
- if (messageReceived.getBoolean("TestBoolean") == testBoolean) {
- logTrace("Received correct boolean value");
- } else {
- logMsg("incorrect boolean value -- BAD");
- pass = false;
- }
- if (messageReceived.getByte("TestByte") == testByte) {
- logTrace("Received correct byte value");
- } else {
- logMsg("incorrect byte value -- BAD");
- pass = false;
- }
- if (messageReceived.getChar("TestChar") == testChar) {
- logTrace("Received correct char value");
- } else {
- logMsg("incorrect char value -- BAD");
- pass = false;
- }
- if (messageReceived.getInt("TestInt") == testInt) {
- logTrace("Received correct int value");
- } else {
- logMsg("incorrect int value -- BAD");
- pass = false;
- }
- if (messageReceived.getDouble("TestDouble") == ((Double) testObject)
- .doubleValue()) {
- logTrace("Received correct object");
- } else {
- logMsg("incorrect object -- BAD");
- pass = false;
- }
- if (messageReceived.getString("TestString").equals(testString)) {
- logTrace("Received correct String");
- } else {
- logMsg("incorrect string -- BAD");
- pass = false;
- }
- if (pass == false) {
- logMsg("Test failed -- see above");
- throw new Exception();
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendReceiveMapMsgQueueTest");
- }
- }
-
- /*
- * @testName: sendReceiveObjectMsgQueueTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
- *
- * @test_Strategy: Send message with appropriate data Receive message and
- * check data
- */
-
- public void sendReceiveObjectMsgQueueTest() throws Exception {
- try {
- ObjectMessage messageSent = null;
- ObjectMessage messageReceived = null;
- String text = "test";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logMsg("Creating 1 message");
- messageSent = new ObjectMessageTestImpl();
- messageSent.setObject(text);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendReceiveObjectMsgQueueTest");
- logMsg("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logMsg("Receiving message");
- messageReceived = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Did not receive message");
- }
- if (((String) messageReceived.getObject()).equals(text)) {
- logMsg("Received correct object");
- } else {
- throw new Exception("Did not receive correct message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendReceiveObjectMsgQueueTest");
- }
- }
-
- /*
- * @testName: sendReceiveStreamMsgQueueTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
- *
- * @test_Strategy: Send message with appropriate data Receive message and
- * check data
- */
-
- public void sendReceiveStreamMsgQueueTest() throws Exception {
- boolean pass = true;
-
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logMsg("Creating 1 message");
- messageSent = new StreamMessageTestImpl();
- logTrace("Setting test values in message");
- messageSent.writeBoolean(testBoolean);
- messageSent.writeByte(testByte);
- messageSent.writeChar(testChar);
- messageSent.writeInt(testInt);
- messageSent.writeObject(testObject);
- messageSent.writeString(testString);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendReceiveStreamMsgQueueTest");
- logMsg("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logMsg("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Did not receive message");
- }
- logTrace("Check received message");
- if (messageReceived.readBoolean() == testBoolean) {
- logTrace("Received correct boolean value");
- } else {
- logMsg("incorrect boolean value -- BAD");
- pass = false;
- }
- if (messageReceived.readByte() == testByte) {
- logTrace("Received correct byte value");
- } else {
- logMsg("incorrect byte value -- BAD");
- pass = false;
- }
- if (messageReceived.readChar() == testChar) {
- logTrace("Received correct char value");
- } else {
- logMsg("incorrect char value -- BAD");
- pass = false;
- }
- if (messageReceived.readInt() == testInt) {
- logTrace("Received correct int value");
- } else {
- logMsg("incorrect int value -- BAD");
- pass = false;
- }
- if (messageReceived.readDouble() == ((Double) testObject).doubleValue()) {
- logTrace("Received correct object");
- } else {
- logMsg("incorrect object -- BAD");
- pass = false;
- }
- if (messageReceived.readString().equals(testString)) {
- logTrace("Received correct String");
- } else {
- logMsg("incorrect string -- BAD");
- pass = false;
- }
- if (pass == false) {
- logMsg("Test failed -- see above");
- throw new Exception();
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendReceiveStreamMsgQueueTest");
- }
- }
-
- /*
- * @testName: sendReceiveTextMsgQueueTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:77;
- *
- * @test_Strategy: Send message with appropriate data Receive message and
- * check data
- */
-
- public void sendReceiveTextMsgQueueTest() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- String text = "test";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logMsg("Creating 1 message");
- messageSent = new TextMessageTestImpl();
- messageSent.setText(text);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendReceiveTextMsgQueueTest");
- logMsg("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logMsg("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Did not receive message");
- }
- if (messageReceived.getText().equals(text)) {
- logMsg("Received correct text");
- } else {
- throw new Exception("Did not receive correct message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendReceiveTextMsgQueueTest");
- }
- }
-
- /*
- * @testName: sendSetsJMSDestinationQueueTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.1; JMS:SPEC:246;
- * JMS:JAVADOC:365; JMS:JAVADOC:363;
- *
- * @test_Strategy: Send message verify that JMSDestination was set
- */
-
- public void sendSetsJMSDestinationQueueTest() throws Exception {
- try {
- Message message;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- logMsg("Creating 1 message");
- message = new MessageTestImpl();
- message.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendSetsJMSDestinationQueueTest");
-
- // set header value
- message.setJMSDestination(null);
- logMsg("Sending message");
- tool.getDefaultQueueSender().send(message);
-
- // check again
- logTrace("Check header value");
- if (!((Queue) message.getJMSDestination()).getQueueName()
- .equals(tool.getDefaultQueue().getQueueName())) {
- throw new Exception("Header not set correctly");
- } else {
- logTrace("Header set correctly");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendSetsJMSDestinationQueueTest");
- }
- }
-
- /*
- * @testName: sendSetsJMSExpirationQueueTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.3; JMS:SPEC:246;
- * JMS:JAVADOC:381; JMS:JAVADOC:379;
- *
- * @test_Strategy: Send message verify that JMSExpiration was set
- */
-
- public void sendSetsJMSExpirationQueueTest() throws Exception {
- try {
- Message message;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- logMsg("Creating 1 message");
- message = new MessageTestImpl();
- message.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendSetsJMSExpirationQueueTest");
-
- // set header value
- logTrace("Set JMSExpiration to 9999");
- message.setJMSExpiration(9999);
- logMsg("Sending message");
- tool.getDefaultQueueSender().send(message);
-
- // check header
- long mode = message.getJMSExpiration();
-
- logTrace("Check header value");
- if (mode == 9999) {
- logTrace("JMSExpiration for message is " + mode);
- throw new Exception("Header not set correctly");
- } else {
- logTrace("Header set correctly");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendSetsJMSExpirationQueueTest");
- }
- }
-
- /*
- * @testName: sendSetsJMSPriorityQueueTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.4; JMS:SPEC:246;
- * JMS:JAVADOC:385; JMS:JAVADOC:383;
- *
- * @test_Strategy: Send message verify that JMSPriority was set
- */
-
- public void sendSetsJMSPriorityQueueTest() throws Exception {
- try {
- Message message;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- logMsg("Creating 1 message");
- message = new MessageTestImpl();
- message.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendSetsJMSPriorityQueueTest");
-
- // set header value
- logTrace("Set JMSPriority to 9999");
- message.setJMSPriority(9999);
- logMsg("Sending message");
- tool.getDefaultQueueSender().send(message);
-
- // check header value
- int mode = message.getJMSPriority();
-
- logTrace("Check header value");
- if (mode == 9999) {
- logTrace("JMSPriority for message is " + mode);
- throw new Exception("Header not set correctly");
- } else {
- logTrace("Header set correctly: " + mode);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendSetsJMSPriorityQueueTest");
- }
- }
-
- /*
- * @testName: sendSetsJMSMessageIDQueueTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.5; JMS:SPEC:246;
- * JMS:JAVADOC:345; JMS:JAVADOC:343;
- *
- * @test_Strategy: Send message verify that JMSMessageID was set
- */
-
- public void sendSetsJMSMessageIDQueueTest() throws Exception {
- try {
- Message message;
- String id0 = "foo";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- logMsg("Creating 1 message");
- message = new MessageTestImpl();
- message.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendSetsJMSMessageIDQueueTest");
-
- // set header value
- logTrace("Set JMSMessageID to \"" + id0 + "\"");
- message.setJMSMessageID(id0);
- logMsg("Sending message");
- tool.getDefaultQueueSender().send(message);
-
- // check header value
- String id1 = message.getJMSMessageID();
-
- logTrace("Check header value");
- if (id1.equals(id0)) {
- logTrace("JMSMessageID for message is " + id1);
- throw new Exception("Header not set correctly");
- } else {
- logTrace("Header set correctly: " + id1);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendSetsJMSMessageIDQueueTest");
- }
- }
-
- /*
- * @testName: sendSetsJMSTimestampQueueTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.6; JMS:SPEC:246;
- * JMS:JAVADOC:349; JMS:JAVADOC:347;
- *
- * @test_Strategy: Send message verify that JMSTimestamp was set
- */
-
- public void sendSetsJMSTimestampQueueTest() throws Exception {
- try {
- Message message;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- logMsg("Creating 1 message");
- message = new MessageTestImpl();
- message.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendSetsJMSTimestampQueueTest");
-
- // set header value
- logTrace("Set JMSTimestamp to 9999");
- message.setJMSTimestamp(9999);
- logMsg("Sending message");
- tool.getDefaultQueueSender().send(message);
-
- // check header value
- long mode = message.getJMSTimestamp();
-
- logTrace("Check header value");
- if (mode == 9999) {
- logTrace("JMSTimestamp for message is " + mode);
- throw new Exception("Header not set correctly");
- } else {
- logTrace("Header set correctly: " + mode);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendSetsJMSTimestampQueueTest");
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/foreignMsgQueue/ForeignMsgQueueTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/foreignMsgQueue/ForeignMsgQueueTestsIT.java
new file mode 100644
index 0000000000..349f44b879
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/foreignMsgQueue/ForeignMsgQueueTestsIT.java
@@ -0,0 +1,727 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.foreignMsgQueue;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.BytesMessageTestImpl;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.common.MapMessageTestImpl;
+import com.sun.ts.tests.jms.common.MessageTestImpl;
+import com.sun.ts.tests.jms.common.ObjectMessageTestImpl;
+import com.sun.ts.tests.jms.common.StreamMessageTestImpl;
+import com.sun.ts.tests.jms.common.TextMessageTestImpl;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.Queue;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+
+
+public class ForeignMsgQueueTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.foreignMsgQueue.ForeignMsgQueueTests";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ForeignMsgQueueTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ // values to pass into/read from messages
+ boolean testBoolean = true;
+
+ byte testByte = 100;
+
+ char testChar = 'a';
+
+ int testInt = 10;
+
+ Object testObject = new Double(3.141);
+
+ String testString = "java";
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ queues = new ArrayList(2);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: sendReceiveBytesMsgQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
+ *
+ * @test_Strategy: Send message with appropriate data Receive message and check
+ * data
+ */
+ @Test
+ public void sendReceiveBytesMsgQueueTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = new BytesMessageTestImpl();
+ logger.log(Logger.Level.TRACE, "Setting test values in MessageTestImpl.javaessage");
+ long bodyLength = 22L;
+ BytesMessageTestImpl messageSentImpl = (BytesMessageTestImpl) messageSent;
+ messageSentImpl.setBodyLength(bodyLength);
+ messageSent.writeBoolean(testBoolean);
+ messageSent.writeByte(testByte);
+ messageSent.writeChar(testChar);
+ messageSent.writeInt(testInt);
+ messageSent.writeObject(testObject);
+ messageSent.writeUTF(testString);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendReceiveBytesMsgQueueTest");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Did not receive message");
+ }
+ logger.log(Logger.Level.TRACE, "Check received message");
+ if (messageReceived.readBoolean() == testBoolean) {
+ logger.log(Logger.Level.TRACE, "Received correct boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect boolean value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readByte() == testByte) {
+ logger.log(Logger.Level.TRACE, "Received correct byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect byte value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readChar() == testChar) {
+ logger.log(Logger.Level.TRACE, "Received correct char value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect char value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readInt() == testInt) {
+ logger.log(Logger.Level.TRACE, "Received correct int value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect int value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readDouble() == ((Double) testObject).doubleValue()) {
+ logger.log(Logger.Level.TRACE, "Received correct object");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect object -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readUTF().equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Received correct String");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect string -- BAD");
+ pass = false;
+ }
+ if (pass == false) {
+ logger.log(Logger.Level.INFO, "Test failed -- see above");
+ throw new Exception();
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendReceiveBytesMsgQueueTest");
+ }
+ }
+
+ /*
+ * @testName: sendReceiveMsgQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
+ *
+ * @test_Strategy: Send message with appropriate data Receive message and check
+ * data
+ */
+ @Test
+ public void sendReceiveMsgQueueTest() throws Exception {
+ try {
+ Message messageSent = null;
+ Message messageReceived = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = new MessageTestImpl();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendReceiveMsgQueueTest");
+ logger.log(Logger.Level.INFO, "sending: " + messageSent);
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.INFO, "received: " + messageReceived);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendReceiveMsgQueueTest");
+ }
+ }
+
+ /*
+ * @testName: sendReceiveMapMsgQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
+ *
+ * @test_Strategy: Send message with appropriate data Receive message and check
+ * data
+ */
+ @Test
+ public void sendReceiveMapMsgQueueTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = new MapMessageTestImpl();
+ logger.log(Logger.Level.TRACE, "Setting test values in message");
+ messageSent.setBoolean("TestBoolean", testBoolean);
+ messageSent.setByte("TestByte", testByte);
+ messageSent.setChar("TestChar", testChar);
+ messageSent.setInt("TestInt", testInt);
+ messageSent.setObject("TestDouble", testObject);
+ messageSent.setString("TestString", testString);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendReceiveMapMsgQueueTest");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Did not receive message");
+ }
+ logger.log(Logger.Level.TRACE, "Check received message");
+ if (messageReceived.getBoolean("TestBoolean") == testBoolean) {
+ logger.log(Logger.Level.TRACE, "Received correct boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect boolean value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.getByte("TestByte") == testByte) {
+ logger.log(Logger.Level.TRACE, "Received correct byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect byte value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.getChar("TestChar") == testChar) {
+ logger.log(Logger.Level.TRACE, "Received correct char value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect char value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.getInt("TestInt") == testInt) {
+ logger.log(Logger.Level.TRACE, "Received correct int value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect int value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.getDouble("TestDouble") == ((Double) testObject).doubleValue()) {
+ logger.log(Logger.Level.TRACE, "Received correct object");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect object -- BAD");
+ pass = false;
+ }
+ if (messageReceived.getString("TestString").equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Received correct String");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect string -- BAD");
+ pass = false;
+ }
+ if (pass == false) {
+ logger.log(Logger.Level.INFO, "Test failed -- see above");
+ throw new Exception();
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendReceiveMapMsgQueueTest");
+ }
+ }
+
+ /*
+ * @testName: sendReceiveObjectMsgQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
+ *
+ * @test_Strategy: Send message with appropriate data Receive message and check
+ * data
+ */
+ @Test
+ public void sendReceiveObjectMsgQueueTest() throws Exception {
+ try {
+ ObjectMessage messageSent = null;
+ ObjectMessage messageReceived = null;
+ String text = "test";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = new ObjectMessageTestImpl();
+ messageSent.setObject(text);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendReceiveObjectMsgQueueTest");
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Did not receive message");
+ }
+ if (((String) messageReceived.getObject()).equals(text)) {
+ logger.log(Logger.Level.INFO, "Received correct object");
+ } else {
+ throw new Exception("Did not receive correct message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendReceiveObjectMsgQueueTest");
+ }
+ }
+
+ /*
+ * @testName: sendReceiveStreamMsgQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
+ *
+ * @test_Strategy: Send message with appropriate data Receive message and check
+ * data
+ */
+ @Test
+ public void sendReceiveStreamMsgQueueTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = new StreamMessageTestImpl();
+ logger.log(Logger.Level.TRACE, "Setting test values in message");
+ messageSent.writeBoolean(testBoolean);
+ messageSent.writeByte(testByte);
+ messageSent.writeChar(testChar);
+ messageSent.writeInt(testInt);
+ messageSent.writeObject(testObject);
+ messageSent.writeString(testString);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendReceiveStreamMsgQueueTest");
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Did not receive message");
+ }
+ logger.log(Logger.Level.TRACE, "Check received message");
+ if (messageReceived.readBoolean() == testBoolean) {
+ logger.log(Logger.Level.TRACE, "Received correct boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect boolean value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readByte() == testByte) {
+ logger.log(Logger.Level.TRACE, "Received correct byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect byte value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readChar() == testChar) {
+ logger.log(Logger.Level.TRACE, "Received correct char value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect char value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readInt() == testInt) {
+ logger.log(Logger.Level.TRACE, "Received correct int value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect int value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readDouble() == ((Double) testObject).doubleValue()) {
+ logger.log(Logger.Level.TRACE, "Received correct object");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect object -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readString().equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Received correct String");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect string -- BAD");
+ pass = false;
+ }
+ if (pass == false) {
+ logger.log(Logger.Level.INFO, "Test failed -- see above");
+ throw new Exception();
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendReceiveStreamMsgQueueTest");
+ }
+ }
+
+ /*
+ * @testName: sendReceiveTextMsgQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:77;
+ *
+ * @test_Strategy: Send message with appropriate data Receive message and check
+ * data
+ */
+ @Test
+ public void sendReceiveTextMsgQueueTest() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ String text = "test";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = new TextMessageTestImpl();
+ messageSent.setText(text);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendReceiveTextMsgQueueTest");
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Did not receive message");
+ }
+ if (messageReceived.getText().equals(text)) {
+ logger.log(Logger.Level.INFO, "Received correct text");
+ } else {
+ throw new Exception("Did not receive correct message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendReceiveTextMsgQueueTest");
+ }
+ }
+
+ /*
+ * @testName: sendSetsJMSDestinationQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.1; JMS:SPEC:246;
+ * JMS:JAVADOC:365; JMS:JAVADOC:363;
+ *
+ * @test_Strategy: Send message verify that JMSDestination was set
+ */
+ @Test
+ public void sendSetsJMSDestinationQueueTest() throws Exception {
+ try {
+ Message message;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ message = new MessageTestImpl();
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "sendSetsJMSDestinationQueueTest");
+
+ // set header value
+ message.setJMSDestination(null);
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultQueueSender().send(message);
+
+ // check again
+ logger.log(Logger.Level.TRACE, "Check header value");
+ if (!((Queue) message.getJMSDestination()).getQueueName().equals(tool.getDefaultQueue().getQueueName())) {
+ throw new Exception("Header not set correctly");
+ } else {
+ logger.log(Logger.Level.TRACE, "Header set correctly");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendSetsJMSDestinationQueueTest");
+ }
+ }
+
+ /*
+ * @testName: sendSetsJMSExpirationQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.3; JMS:SPEC:246;
+ * JMS:JAVADOC:381; JMS:JAVADOC:379;
+ *
+ * @test_Strategy: Send message verify that JMSExpiration was set
+ */
+ @Test
+ public void sendSetsJMSExpirationQueueTest() throws Exception {
+ try {
+ Message message;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ message = new MessageTestImpl();
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "sendSetsJMSExpirationQueueTest");
+
+ // set header value
+ logger.log(Logger.Level.TRACE, "Set JMSExpiration to 9999");
+ message.setJMSExpiration(9999);
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultQueueSender().send(message);
+
+ // check header
+ long mode = message.getJMSExpiration();
+
+ logger.log(Logger.Level.TRACE, "Check header value");
+ if (mode == 9999) {
+ logger.log(Logger.Level.TRACE, "JMSExpiration for message is " + mode);
+ throw new Exception("Header not set correctly");
+ } else {
+ logger.log(Logger.Level.TRACE, "Header set correctly");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendSetsJMSExpirationQueueTest");
+ }
+ }
+
+ /*
+ * @testName: sendSetsJMSPriorityQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.4; JMS:SPEC:246;
+ * JMS:JAVADOC:385; JMS:JAVADOC:383;
+ *
+ * @test_Strategy: Send message verify that JMSPriority was set
+ */
+ @Test
+ public void sendSetsJMSPriorityQueueTest() throws Exception {
+ try {
+ Message message;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ message = new MessageTestImpl();
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "sendSetsJMSPriorityQueueTest");
+
+ // set header value
+ logger.log(Logger.Level.TRACE, "Set JMSPriority to 9999");
+ message.setJMSPriority(9999);
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultQueueSender().send(message);
+
+ // check header value
+ int mode = message.getJMSPriority();
+
+ logger.log(Logger.Level.TRACE, "Check header value");
+ if (mode == 9999) {
+ logger.log(Logger.Level.TRACE, "JMSPriority for message is " + mode);
+ throw new Exception("Header not set correctly");
+ } else {
+ logger.log(Logger.Level.TRACE, "Header set correctly: " + mode);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendSetsJMSPriorityQueueTest");
+ }
+ }
+
+ /*
+ * @testName: sendSetsJMSMessageIDQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.5; JMS:SPEC:246;
+ * JMS:JAVADOC:345; JMS:JAVADOC:343;
+ *
+ * @test_Strategy: Send message verify that JMSMessageID was set
+ */
+ @Test
+ public void sendSetsJMSMessageIDQueueTest() throws Exception {
+ try {
+ Message message;
+ String id0 = "foo";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ message = new MessageTestImpl();
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "sendSetsJMSMessageIDQueueTest");
+
+ // set header value
+ logger.log(Logger.Level.TRACE, "Set JMSMessageID to \"" + id0 + "\"");
+ message.setJMSMessageID(id0);
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultQueueSender().send(message);
+
+ // check header value
+ String id1 = message.getJMSMessageID();
+
+ logger.log(Logger.Level.TRACE, "Check header value");
+ if (id1.equals(id0)) {
+ logger.log(Logger.Level.TRACE, "JMSMessageID for message is " + id1);
+ throw new Exception("Header not set correctly");
+ } else {
+ logger.log(Logger.Level.TRACE, "Header set correctly: " + id1);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendSetsJMSMessageIDQueueTest");
+ }
+ }
+
+ /*
+ * @testName: sendSetsJMSTimestampQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.6; JMS:SPEC:246;
+ * JMS:JAVADOC:349; JMS:JAVADOC:347;
+ *
+ * @test_Strategy: Send message verify that JMSTimestamp was set
+ */
+ @Test
+ public void sendSetsJMSTimestampQueueTest() throws Exception {
+ try {
+ Message message;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ message = new MessageTestImpl();
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "sendSetsJMSTimestampQueueTest");
+
+ // set header value
+ logger.log(Logger.Level.TRACE, "Set JMSTimestamp to 9999");
+ message.setJMSTimestamp(9999);
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultQueueSender().send(message);
+
+ // check header value
+ long mode = message.getJMSTimestamp();
+
+ logger.log(Logger.Level.TRACE, "Check header value");
+ if (mode == 9999) {
+ logger.log(Logger.Level.TRACE, "JMSTimestamp for message is " + mode);
+ throw new Exception("Header not set correctly");
+ } else {
+ logger.log(Logger.Level.TRACE, "Header set correctly: " + mode);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendSetsJMSTimestampQueueTest");
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/foreignMsgTopic/ForeignMsgTopicTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/foreignMsgTopic/ForeignMsgTopicTests.java
deleted file mode 100644
index d4db21e5c8..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/foreignMsgTopic/ForeignMsgTopicTests.java
+++ /dev/null
@@ -1,748 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.foreignMsgTopic;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.BytesMessageTestImpl;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.common.MapMessageTestImpl;
-import com.sun.ts.tests.jms.common.MessageTestImpl;
-import com.sun.ts.tests.jms.common.ObjectMessageTestImpl;
-import com.sun.ts.tests.jms.common.StreamMessageTestImpl;
-import com.sun.ts.tests.jms.common.TextMessageTestImpl;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-
-public class ForeignMsgTopicTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.foreignMsgTopic.ForeignMsgTopicTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList connections = null;
-
- // values to pass into/read from messages
- boolean testBoolean = true;
-
- byte testByte = 100;
-
- char testChar = 'a';
-
- int testInt = 10;
-
- Object testObject = new Double(3.141);
-
- String testString = "java";
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ForeignMsgTopicTests theTests = new ForeignMsgTopicTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: sendReceiveBytesMsgTopicTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
- *
- * @test_Strategy: Send message with appropriate data Receive message and
- * check data
- */
-
- public void sendReceiveBytesMsgTopicTest() throws Exception {
- boolean pass = true;
-
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = new BytesMessageTestImpl();
- logTrace("Setting test values in message");
- long bodyLength = 22L;
- BytesMessageTestImpl messageSentImpl = (BytesMessageTestImpl) messageSent;
- messageSentImpl.setBodyLength(bodyLength);
- messageSent.writeBoolean(testBoolean);
- messageSent.writeByte(testByte);
- messageSent.writeChar(testChar);
- messageSent.writeInt(testInt);
- messageSent.writeObject(testObject);
- messageSent.writeUTF(testString);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendReceiveBytesMsgTopicTest");
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (BytesMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Did not receive message");
- }
- logTrace("Check received message");
- if (messageReceived.readBoolean() == testBoolean) {
- logTrace("Received correct boolean value");
- } else {
- logMsg("incorrect boolean value -- BAD");
- pass = false;
- }
- if (messageReceived.readByte() == testByte) {
- logTrace("Received correct byte value");
- } else {
- logMsg("incorrect byte value -- BAD");
- pass = false;
- }
- if (messageReceived.readChar() == testChar) {
- logTrace("Received correct char value");
- } else {
- logMsg("incorrect char value -- BAD");
- pass = false;
- }
- if (messageReceived.readInt() == testInt) {
- logTrace("Received correct int value");
- } else {
- logMsg("incorrect int value -- BAD");
- pass = false;
- }
- if (messageReceived.readDouble() == ((Double) testObject).doubleValue()) {
- logTrace("Received correct object");
- } else {
- logMsg("incorrect object -- BAD");
- pass = false;
- }
- if (messageReceived.readUTF().equals(testString)) {
- logTrace("Received correct String");
- } else {
- logMsg("incorrect string -- BAD");
- pass = false;
- }
- if (pass == false) {
- logMsg("Test failed -- see above");
- throw new Exception();
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendReceiveBytesMsgTopicTest");
- }
- }
-
- /*
- * @testName: sendReceiveMsgTopicTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
- *
- * @test_Strategy: Send message with appropriate data Receive message and
- * check data
- */
-
- public void sendReceiveMsgTopicTest() throws Exception {
- try {
- Message messageSent = null;
- Message messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logMsg("Creating 1 message");
- messageSent = new MessageTestImpl();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendReceiveMsgTopicTest");
- logMsg("sending: " + messageSent);
- logMsg("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logMsg("Receiving message");
- messageReceived = tool.getDefaultTopicSubscriber().receive(timeout);
- logMsg("received: " + messageReceived);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendReceiveMsgTopicTest");
- }
- }
-
- /*
- * @testName: sendReceiveMapMsgTopicTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
- *
- * @test_Strategy: Send message with appropriate data Receive message and
- * check data
- */
-
- public void sendReceiveMapMsgTopicTest() throws Exception {
- boolean pass = true;
-
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = new MapMessageTestImpl();
- logTrace("Setting test values in message");
- messageSent.setBoolean("TestBoolean", testBoolean);
- messageSent.setByte("TestByte", testByte);
- messageSent.setChar("TestChar", testChar);
- messageSent.setInt("TestInt", testInt);
- messageSent.setObject("TestDouble", testObject);
- messageSent.setString("TestString", testString);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendReceiveMapMsgTopicTest");
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Did not receive message");
- }
- logTrace("Check received message");
- if (messageReceived.getBoolean("TestBoolean") == testBoolean) {
- logTrace("Received correct boolean value");
- } else {
- logMsg("incorrect boolean value -- BAD");
- pass = false;
- }
- if (messageReceived.getByte("TestByte") == testByte) {
- logTrace("Received correct byte value");
- } else {
- logMsg("incorrect byte value -- BAD");
- pass = false;
- }
- if (messageReceived.getChar("TestChar") == testChar) {
- logTrace("Received correct char value");
- } else {
- logMsg("incorrect char value -- BAD");
- pass = false;
- }
- if (messageReceived.getInt("TestInt") == testInt) {
- logTrace("Received correct int value");
- } else {
- logMsg("incorrect int value -- BAD");
- pass = false;
- }
- if (messageReceived.getDouble("TestDouble") == ((Double) testObject)
- .doubleValue()) {
- logTrace("Received correct object");
- } else {
- logMsg("incorrect object -- BAD");
- pass = false;
- }
- if (messageReceived.getString("TestString").equals(testString)) {
- logTrace("Received correct String");
- } else {
- logMsg("incorrect string -- BAD");
- pass = false;
- }
- if (pass == false) {
- logMsg("Test failed -- see above");
- throw new Exception();
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendReceiveMapMsgTopicTest");
- }
- }
-
- /*
- * @testName: sendReceiveObjectMsgTopicTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
- *
- * @test_Strategy: Send message with appropriate data Receive message and
- * check data
- */
-
- public void sendReceiveObjectMsgTopicTest() throws Exception {
- try {
- ObjectMessage messageSent = null;
- ObjectMessage messageReceived = null;
- String text = "test";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logMsg("Creating 1 message");
- messageSent = new ObjectMessageTestImpl();
- messageSent.setObject(text);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendReceiveObjectMsgTopicTest");
- logMsg("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logMsg("Receiving message");
- messageReceived = (ObjectMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Did not receive message");
- }
- if (((String) messageReceived.getObject()).equals(text)) {
- logMsg("Received correct object");
- } else {
- throw new Exception("Did not receive correct message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendReceiveObjectMsgTopicTest");
- }
- }
-
- /*
- * @testName: sendReceiveStreamMsgTopicTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
- *
- * @test_Strategy: Send message with appropriate data Receive message and
- * check data
- */
-
- public void sendReceiveStreamMsgTopicTest() throws Exception {
- boolean pass = true;
-
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logMsg("Creating 1 message");
- messageSent = new StreamMessageTestImpl();
- logTrace("Setting test values in message");
- messageSent.writeBoolean(testBoolean);
- messageSent.writeByte(testByte);
- messageSent.writeChar(testChar);
- messageSent.writeInt(testInt);
- messageSent.writeObject(testObject);
- messageSent.writeString(testString);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendReceiveStreamMsgTopicTest");
- logMsg("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logMsg("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Did not receive message");
- }
- logTrace("Check received message");
- if (messageReceived.readBoolean() == testBoolean) {
- logTrace("Received correct boolean value");
- } else {
- logMsg("incorrect boolean value -- BAD");
- pass = false;
- }
- if (messageReceived.readByte() == testByte) {
- logTrace("Received correct byte value");
- } else {
- logMsg("incorrect byte value -- BAD");
- pass = false;
- }
- if (messageReceived.readChar() == testChar) {
- logTrace("Received correct char value");
- } else {
- logMsg("incorrect char value -- BAD");
- pass = false;
- }
- if (messageReceived.readInt() == testInt) {
- logTrace("Received correct int value");
- } else {
- logMsg("incorrect int value -- BAD");
- pass = false;
- }
- if (messageReceived.readDouble() == ((Double) testObject).doubleValue()) {
- logTrace("Received correct object");
- } else {
- logMsg("incorrect object -- BAD");
- pass = false;
- }
- if (messageReceived.readString().equals(testString)) {
- logTrace("Received correct String");
- } else {
- logMsg("incorrect string -- BAD");
- pass = false;
- }
- if (pass == false) {
- logMsg("Test failed -- see above");
- throw new Exception();
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendReceiveStreamMsgTopicTest");
- }
- }
-
- /*
- * @testName: sendReceiveTextMsgTopicTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
- *
- * @test_Strategy: Send message with appropriate data Receive message and
- * check data
- */
-
- public void sendReceiveTextMsgTopicTest() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- String text = "test";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logMsg("Creating 1 message");
- messageSent = new TextMessageTestImpl();
- messageSent.setText(text);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendReceiveTextMsgTopicTest");
- logMsg("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logMsg("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Did not receive message");
- }
- if (messageReceived.getText().equals(text)) {
- logMsg("Received correct text");
- } else {
- throw new Exception("Did not receive correct message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendReceiveTextMsgTopicTest");
- }
- }
-
- /*
- * @testName: sendSetsJMSDestinationTopicTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.1; JMS:SPEC:246;
- * JMS:JAVADOC:365; JMS:JAVADOC:363;
- *
- * @test_Strategy: Send message verify that JMSDestination was set
- */
-
- public void sendSetsJMSDestinationTopicTest() throws Exception {
- try {
- Message message;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- logMsg("Creating 1 message");
- message = new MessageTestImpl();
- message.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendSetsJMSDestinationTopicTest");
-
- // set header value
- message.setJMSDestination(null);
- logMsg("Publishing message");
- tool.getDefaultTopicPublisher().publish(message);
-
- // check again
- logTrace("Check header value");
- if (!((Topic) message.getJMSDestination()).getTopicName()
- .equals(tool.getDefaultTopic().getTopicName())) {
- throw new Exception("Header not set correctly");
- } else {
- logTrace("Header set correctly");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendSetsJMSDestinationTopicTest");
- }
- }
-
- /*
- * @testName: sendSetsJMSExpirationTopicTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.3; JMS:SPEC:246;
- * JMS:JAVADOC:381; JMS:JAVADOC:379;
- *
- * @test_Strategy: Send message verify that JMSExpiration was set
- */
-
- public void sendSetsJMSExpirationTopicTest() throws Exception {
- try {
- Message message;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- logMsg("Creating 1 message");
- message = new MessageTestImpl();
- message.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendSetsJMSExpirationTopicTest");
-
- // set header value
- logTrace("Set JMSExpiration to 9999");
- message.setJMSExpiration(9999);
- logMsg("Publishing message");
- tool.getDefaultTopicPublisher().publish(message);
-
- // check header
- long mode = message.getJMSExpiration();
-
- logTrace("Check header value");
- if (mode == 9999) {
- logTrace("JMSExpiration for message is " + mode);
- throw new Exception("Header not set correctly");
- } else {
- logTrace("Header set correctly");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendSetsJMSExpirationTopicTest");
- }
- }
-
- /*
- * @testName: sendSetsJMSPriorityTopicTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.4; JMS:SPEC:246;
- * JMS:JAVADOC:385; JMS:JAVADOC:383;
- *
- * @test_Strategy: Send message verify that JMSPriority was set
- */
-
- public void sendSetsJMSPriorityTopicTest() throws Exception {
- try {
- Message message;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- logMsg("Creating 1 message");
- message = new MessageTestImpl();
- message.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendSetsJMSPriorityTopicTest");
-
- // set header value
- logTrace("Set JMSPriority to 9999");
- message.setJMSPriority(9999);
- logMsg("Publishing message");
- tool.getDefaultTopicPublisher().publish(message);
-
- // check header value
- int mode = message.getJMSPriority();
-
- logTrace("Check header value");
- if (mode == 9999) {
- logTrace("JMSPriority for message is " + mode);
- throw new Exception("Header not set correctly");
- } else {
- logTrace("Header set correctly: " + mode);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendSetsJMSPriorityTopicTest");
- }
- }
-
- /*
- * @testName: sendSetsJMSMessageIDTopicTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.5; JMS:SPEC:246;
- * JMS:JAVADOC:345; JMS:JAVADOC:343;
- *
- * @test_Strategy: Send message verify that JMSMessageID was set
- */
-
- public void sendSetsJMSMessageIDTopicTest() throws Exception {
- try {
- Message message;
- String id0 = "foo";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- logMsg("Creating 1 message");
- message = new MessageTestImpl();
- message.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendSetsJMSMessageIDTopicTest");
-
- // set header value
- logTrace("Set JMSMessageID to \"" + id0 + "\"");
- message.setJMSMessageID(id0);
- logMsg("Publishing message");
- tool.getDefaultTopicPublisher().publish(message);
-
- // check header value
- String id1 = message.getJMSMessageID();
-
- logTrace("Check header value");
- if (id1.equals(id0)) {
- logTrace("JMSMessageID for message is " + id1);
- throw new Exception("Header not set correctly");
- } else {
- logTrace("Header set correctly: " + id1);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendSetsJMSMessageIDTopicTest");
- }
- }
-
- /*
- * @testName: sendSetsJMSTimestampTopicTest
- *
- * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.6; JMS:SPEC:246;
- * JMS:JAVADOC:349; JMS:JAVADOC:347;
- *
- * @test_Strategy: Send message verify that JMSTimestamp was set
- */
-
- public void sendSetsJMSTimestampTopicTest() throws Exception {
- try {
- Message message;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- logMsg("Creating 1 message");
- message = new MessageTestImpl();
- message.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendSetsJMSTimestampTopicTest");
-
- // set header value
- logTrace("Set JMSTimestamp to 9999");
- message.setJMSTimestamp(9999);
- logMsg("Publishing message");
- tool.getDefaultTopicPublisher().publish(message);
-
- // check header value
- long mode = message.getJMSTimestamp();
-
- logTrace("Check header value");
- if (mode == 9999) {
- logTrace("JMSTimestamp for message is " + mode);
- throw new Exception("Header not set correctly");
- } else {
- logTrace("Header set correctly: " + mode);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("sendSetsJMSTimestampTopicTest");
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/foreignMsgTopic/ForeignMsgTopicTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/foreignMsgTopic/ForeignMsgTopicTestsIT.java
new file mode 100644
index 0000000000..3994709d18
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/foreignMsgTopic/ForeignMsgTopicTestsIT.java
@@ -0,0 +1,724 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.foreignMsgTopic;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.BytesMessageTestImpl;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.common.MapMessageTestImpl;
+import com.sun.ts.tests.jms.common.MessageTestImpl;
+import com.sun.ts.tests.jms.common.ObjectMessageTestImpl;
+import com.sun.ts.tests.jms.common.StreamMessageTestImpl;
+import com.sun.ts.tests.jms.common.TextMessageTestImpl;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+
+
+public class ForeignMsgTopicTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.foreignMsgTopic.ForeignMsgTopicTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ForeignMsgTopicTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList connections = null;
+
+ // values to pass into/read from messages
+ boolean testBoolean = true;
+
+ byte testByte = 100;
+
+ char testChar = 'a';
+
+ int testInt = 10;
+
+ Object testObject = new Double(3.141);
+
+ String testString = "java";
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: sendReceiveBytesMsgTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
+ *
+ * @test_Strategy: Send message with appropriate data Receive message and check
+ * data
+ */
+ @Test
+ public void sendReceiveBytesMsgTopicTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = new BytesMessageTestImpl();
+ logger.log(Logger.Level.TRACE, "Setting test values in message");
+ long bodyLength = 22L;
+ BytesMessageTestImpl messageSentImpl = (BytesMessageTestImpl) messageSent;
+ messageSentImpl.setBodyLength(bodyLength);
+ messageSent.writeBoolean(testBoolean);
+ messageSent.writeByte(testByte);
+ messageSent.writeChar(testChar);
+ messageSent.writeInt(testInt);
+ messageSent.writeObject(testObject);
+ messageSent.writeUTF(testString);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendReceiveBytesMsgTopicTest");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Did not receive message");
+ }
+ logger.log(Logger.Level.TRACE, "Check received message");
+ if (messageReceived.readBoolean() == testBoolean) {
+ logger.log(Logger.Level.TRACE, "Received correct boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect boolean value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readByte() == testByte) {
+ logger.log(Logger.Level.TRACE, "Received correct byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect byte value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readChar() == testChar) {
+ logger.log(Logger.Level.TRACE, "Received correct char value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect char value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readInt() == testInt) {
+ logger.log(Logger.Level.TRACE, "Received correct int value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect int value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readDouble() == ((Double) testObject).doubleValue()) {
+ logger.log(Logger.Level.TRACE, "Received correct object");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect object -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readUTF().equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Received correct String");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect string -- BAD");
+ pass = false;
+ }
+ if (pass == false) {
+ logger.log(Logger.Level.INFO, "Test failed -- see above");
+ throw new Exception();
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendReceiveBytesMsgTopicTest");
+ }
+ }
+
+ /*
+ * @testName: sendReceiveMsgTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
+ *
+ * @test_Strategy: Send message with appropriate data Receive message and check
+ * data
+ */
+ @Test
+ public void sendReceiveMsgTopicTest() throws Exception {
+ try {
+ Message messageSent = null;
+ Message messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = new MessageTestImpl();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendReceiveMsgTopicTest");
+ logger.log(Logger.Level.INFO, "sending: " + messageSent);
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.INFO, "received: " + messageReceived);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendReceiveMsgTopicTest");
+ }
+ }
+
+ /*
+ * @testName: sendReceiveMapMsgTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
+ *
+ * @test_Strategy: Send message with appropriate data Receive message and check
+ * data
+ */
+ @Test
+ public void sendReceiveMapMsgTopicTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = new MapMessageTestImpl();
+ logger.log(Logger.Level.TRACE, "Setting test values in message");
+ messageSent.setBoolean("TestBoolean", testBoolean);
+ messageSent.setByte("TestByte", testByte);
+ messageSent.setChar("TestChar", testChar);
+ messageSent.setInt("TestInt", testInt);
+ messageSent.setObject("TestDouble", testObject);
+ messageSent.setString("TestString", testString);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendReceiveMapMsgTopicTest");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Did not receive message");
+ }
+ logger.log(Logger.Level.TRACE, "Check received message");
+ if (messageReceived.getBoolean("TestBoolean") == testBoolean) {
+ logger.log(Logger.Level.TRACE, "Received correct boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect boolean value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.getByte("TestByte") == testByte) {
+ logger.log(Logger.Level.TRACE, "Received correct byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect byte value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.getChar("TestChar") == testChar) {
+ logger.log(Logger.Level.TRACE, "Received correct char value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect char value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.getInt("TestInt") == testInt) {
+ logger.log(Logger.Level.TRACE, "Received correct int value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect int value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.getDouble("TestDouble") == ((Double) testObject).doubleValue()) {
+ logger.log(Logger.Level.TRACE, "Received correct object");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect object -- BAD");
+ pass = false;
+ }
+ if (messageReceived.getString("TestString").equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Received correct String");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect string -- BAD");
+ pass = false;
+ }
+ if (pass == false) {
+ logger.log(Logger.Level.INFO, "Test failed -- see above");
+ throw new Exception();
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendReceiveMapMsgTopicTest");
+ }
+ }
+
+ /*
+ * @testName: sendReceiveObjectMsgTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
+ *
+ * @test_Strategy: Send message with appropriate data Receive message and check
+ * data
+ */
+ @Test
+ public void sendReceiveObjectMsgTopicTest() throws Exception {
+ try {
+ ObjectMessage messageSent = null;
+ ObjectMessage messageReceived = null;
+ String text = "test";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = new ObjectMessageTestImpl();
+ messageSent.setObject(text);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendReceiveObjectMsgTopicTest");
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Did not receive message");
+ }
+ if (((String) messageReceived.getObject()).equals(text)) {
+ logger.log(Logger.Level.INFO, "Received correct object");
+ } else {
+ throw new Exception("Did not receive correct message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendReceiveObjectMsgTopicTest");
+ }
+ }
+
+ /*
+ * @testName: sendReceiveStreamMsgTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
+ *
+ * @test_Strategy: Send message with appropriate data Receive message and check
+ * data
+ */
+ @Test
+ public void sendReceiveStreamMsgTopicTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = new StreamMessageTestImpl();
+ logger.log(Logger.Level.TRACE, "Setting test values in message");
+ messageSent.writeBoolean(testBoolean);
+ messageSent.writeByte(testByte);
+ messageSent.writeChar(testChar);
+ messageSent.writeInt(testInt);
+ messageSent.writeObject(testObject);
+ messageSent.writeString(testString);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendReceiveStreamMsgTopicTest");
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Did not receive message");
+ }
+ logger.log(Logger.Level.TRACE, "Check received message");
+ if (messageReceived.readBoolean() == testBoolean) {
+ logger.log(Logger.Level.TRACE, "Received correct boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect boolean value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readByte() == testByte) {
+ logger.log(Logger.Level.TRACE, "Received correct byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect byte value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readChar() == testChar) {
+ logger.log(Logger.Level.TRACE, "Received correct char value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect char value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readInt() == testInt) {
+ logger.log(Logger.Level.TRACE, "Received correct int value");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect int value -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readDouble() == ((Double) testObject).doubleValue()) {
+ logger.log(Logger.Level.TRACE, "Received correct object");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect object -- BAD");
+ pass = false;
+ }
+ if (messageReceived.readString().equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Received correct String");
+ } else {
+ logger.log(Logger.Level.INFO, "incorrect string -- BAD");
+ pass = false;
+ }
+ if (pass == false) {
+ logger.log(Logger.Level.INFO, "Test failed -- see above");
+ throw new Exception();
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendReceiveStreamMsgTopicTest");
+ }
+ }
+
+ /*
+ * @testName: sendReceiveTextMsgTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88;
+ *
+ * @test_Strategy: Send message with appropriate data Receive message and check
+ * data
+ */
+ @Test
+ public void sendReceiveTextMsgTopicTest() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ String text = "test";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = new TextMessageTestImpl();
+ messageSent.setText(text);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendReceiveTextMsgTopicTest");
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Did not receive message");
+ }
+ if (messageReceived.getText().equals(text)) {
+ logger.log(Logger.Level.INFO, "Received correct text");
+ } else {
+ throw new Exception("Did not receive correct message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendReceiveTextMsgTopicTest");
+ }
+ }
+
+ /*
+ * @testName: sendSetsJMSDestinationTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.1; JMS:SPEC:246;
+ * JMS:JAVADOC:365; JMS:JAVADOC:363;
+ *
+ * @test_Strategy: Send message verify that JMSDestination was set
+ */
+ @Test
+ public void sendSetsJMSDestinationTopicTest() throws Exception {
+ try {
+ Message message;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ message = new MessageTestImpl();
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "sendSetsJMSDestinationTopicTest");
+
+ // set header value
+ message.setJMSDestination(null);
+ logger.log(Logger.Level.INFO, "Publishing message");
+ tool.getDefaultTopicPublisher().publish(message);
+
+ // check again
+ logger.log(Logger.Level.TRACE, "Check header value");
+ if (!((Topic) message.getJMSDestination()).getTopicName().equals(tool.getDefaultTopic().getTopicName())) {
+ throw new Exception("Header not set correctly");
+ } else {
+ logger.log(Logger.Level.TRACE, "Header set correctly");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendSetsJMSDestinationTopicTest");
+ }
+ }
+
+ /*
+ * @testName: sendSetsJMSExpirationTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.3; JMS:SPEC:246;
+ * JMS:JAVADOC:381; JMS:JAVADOC:379;
+ *
+ * @test_Strategy: Send message verify that JMSExpiration was set
+ */
+ @Test
+ public void sendSetsJMSExpirationTopicTest() throws Exception {
+ try {
+ Message message;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ message = new MessageTestImpl();
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "sendSetsJMSExpirationTopicTest");
+
+ // set header value
+ logger.log(Logger.Level.TRACE, "Set JMSExpiration to 9999");
+ message.setJMSExpiration(9999);
+ logger.log(Logger.Level.INFO, "Publishing message");
+ tool.getDefaultTopicPublisher().publish(message);
+
+ // check header
+ long mode = message.getJMSExpiration();
+
+ logger.log(Logger.Level.TRACE, "Check header value");
+ if (mode == 9999) {
+ logger.log(Logger.Level.TRACE, "JMSExpiration for message is " + mode);
+ throw new Exception("Header not set correctly");
+ } else {
+ logger.log(Logger.Level.TRACE, "Header set correctly");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendSetsJMSExpirationTopicTest");
+ }
+ }
+
+ /*
+ * @testName: sendSetsJMSPriorityTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.4; JMS:SPEC:246;
+ * JMS:JAVADOC:385; JMS:JAVADOC:383;
+ *
+ * @test_Strategy: Send message verify that JMSPriority was set
+ */
+ @Test
+ public void sendSetsJMSPriorityTopicTest() throws Exception {
+ try {
+ Message message;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ message = new MessageTestImpl();
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "sendSetsJMSPriorityTopicTest");
+
+ // set header value
+ logger.log(Logger.Level.TRACE, "Set JMSPriority to 9999");
+ message.setJMSPriority(9999);
+ logger.log(Logger.Level.INFO, "Publishing message");
+ tool.getDefaultTopicPublisher().publish(message);
+
+ // check header value
+ int mode = message.getJMSPriority();
+
+ logger.log(Logger.Level.TRACE, "Check header value");
+ if (mode == 9999) {
+ logger.log(Logger.Level.TRACE, "JMSPriority for message is " + mode);
+ throw new Exception("Header not set correctly");
+ } else {
+ logger.log(Logger.Level.TRACE, "Header set correctly: " + mode);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendSetsJMSPriorityTopicTest");
+ }
+ }
+
+ /*
+ * @testName: sendSetsJMSMessageIDTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.5; JMS:SPEC:246;
+ * JMS:JAVADOC:345; JMS:JAVADOC:343;
+ *
+ * @test_Strategy: Send message verify that JMSMessageID was set
+ */
+ @Test
+ public void sendSetsJMSMessageIDTopicTest() throws Exception {
+ try {
+ Message message;
+ String id0 = "foo";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ message = new MessageTestImpl();
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "sendSetsJMSMessageIDTopicTest");
+
+ // set header value
+ logger.log(Logger.Level.TRACE, "Set JMSMessageID to \"" + id0 + "\"");
+ message.setJMSMessageID(id0);
+ logger.log(Logger.Level.INFO, "Publishing message");
+ tool.getDefaultTopicPublisher().publish(message);
+
+ // check header value
+ String id1 = message.getJMSMessageID();
+
+ logger.log(Logger.Level.TRACE, "Check header value");
+ if (id1.equals(id0)) {
+ logger.log(Logger.Level.TRACE, "JMSMessageID for message is " + id1);
+ throw new Exception("Header not set correctly");
+ } else {
+ logger.log(Logger.Level.TRACE, "Header set correctly: " + id1);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendSetsJMSMessageIDTopicTest");
+ }
+ }
+
+ /*
+ * @testName: sendSetsJMSTimestampTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:84; JMS:SPEC:88; JMS:SPEC:246.6; JMS:SPEC:246;
+ * JMS:JAVADOC:349; JMS:JAVADOC:347;
+ *
+ * @test_Strategy: Send message verify that JMSTimestamp was set
+ */
+ @Test
+ public void sendSetsJMSTimestampTopicTest() throws Exception {
+ try {
+ Message message;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ message = new MessageTestImpl();
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "sendSetsJMSTimestampTopicTest");
+
+ // set header value
+ logger.log(Logger.Level.TRACE, "Set JMSTimestamp to 9999");
+ message.setJMSTimestamp(9999);
+ logger.log(Logger.Level.INFO, "Publishing message");
+ tool.getDefaultTopicPublisher().publish(message);
+
+ // check header value
+ long mode = message.getJMSTimestamp();
+
+ logger.log(Logger.Level.TRACE, "Check header value");
+ if (mode == 9999) {
+ logger.log(Logger.Level.TRACE, "JMSTimestamp for message is " + mode);
+ throw new Exception("Header not set correctly");
+ } else {
+ logger.log(Logger.Level.TRACE, "Header set correctly: " + mode);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendSetsJMSTimestampTopicTest");
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/mapMsgQueue/MapMsgQueueTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/mapMsgQueue/MapMsgQueueTests.java
deleted file mode 100644
index 4bafaaf1cc..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/mapMsgQueue/MapMsgQueueTests.java
+++ /dev/null
@@ -1,3260 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.mapMsgQueue;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.MapMessage;
-import jakarta.jms.MessageFormatException;
-import jakarta.jms.MessageNotWriteableException;
-
-public class MapMsgQueueTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.mapMsgQueue.MapMsgQueueTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String password;
-
- String mode;
-
- String user;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- MapMsgQueueTests theTests = new MapMsgQueueTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
-
- queues = new ArrayList(2);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- TestUtil.logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.logErr("An error occurred while cleaning: ", e);
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: mapMessageFullMsgQTest
- *
- * @assertion_ids: JMS:SPEC:74; JMS:SPEC:80; JMS:JAVADOC:211; JMS:JAVADOC:457;
- * JMS:JAVADOC:459; JMS:JAVADOC:475; JMS:JAVADOC:477; JMS:JAVADOC:479;
- * JMS:JAVADOC:461; JMS:JAVADOC:463; JMS:JAVADOC:465; JMS:JAVADOC:467;
- * JMS:JAVADOC:469; JMS:JAVADOC:471; JMS:JAVADOC:473; JMS:JAVADOC:433;
- * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:439; JMS:JAVADOC:441;
- * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
- * JMS:JAVADOC:451; JMS:JAVADOC:453; JMS:JAVADOC:455; JMS:JAVADOC:481;
- *
- * @test_Strategy: Create a MapMessage write to the message using each type of
- * methods: setBoolean/Byte/Bytes/Bytes/Char/Double/Float and
- * setInt/Long/Object/Short/String/String. Send the message. Verify on receive
- * tha all data was received correctly using: 1. getMapNames that all fields
- * are intact; 2. ItemExists that all fields are intact; 3.
- * getBoolean/Byte/Bytes/Bytes/Char/Double/Float and
- * getInt/Long/Object/Short/String/String that that all fields contain correct
- * values; 4. an unset field is treated as null field.
- */
-
- public void mapMessageFullMsgQTest() throws Exception {
- boolean pass = true;
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- byte[] bytesValueRecvd = { 0, 0, 0, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- short shortValue = 32767;
- String stringValue = "Map Message Test";
- Integer integerValue = Integer.valueOf(100);
- String initial = "spring is here!";
- Enumeration list;
-
- try {
- MapMessage messageSentMapMessage = null;
- MapMessage messageReceivedMapMessage = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- // send and receive map message to Queue
- TestUtil.logTrace("Send MapMessage to Queue.");
- messageSentMapMessage = tool.getDefaultQueueSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageFullMsgQTest");
- messageSentMapMessage.setBoolean("booleanValue", booleanValue);
- messageSentMapMessage.setByte("byteValue", byteValue);
- messageSentMapMessage.setBytes("bytesValue", bytesValue);
- messageSentMapMessage.setBytes("bytesValue2", bytesValue, 0, 1);
- messageSentMapMessage.setChar("charValue", charValue);
- messageSentMapMessage.setDouble("doubleValue", doubleValue);
- messageSentMapMessage.setFloat("floatValue", floatValue);
- messageSentMapMessage.setInt("intValue", intValue);
- messageSentMapMessage.setLong("longValue", longValue);
- messageSentMapMessage.setObject("integerValue", integerValue);
- messageSentMapMessage.setShort("shortValue", shortValue);
- messageSentMapMessage.setString("stringValue", stringValue);
- messageSentMapMessage.setString("nullTest", null);
- tool.getDefaultQueueSender().send(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- list = messageReceivedMapMessage.getMapNames();
- String name = null;
- int it = 0;
- int j = 0;
- while (list.hasMoreElements()) {
- name = (String) list.nextElement();
- TestUtil.logTrace("Object with name: " + name);
- it++;
- if (name.equals("booleanValue"))
- j++;
- else if (name.equals("byteValue"))
- j++;
- else if (name.equals("bytesValue"))
- j++;
- else if (name.equals("bytesValue2"))
- j++;
- else if (name.equals("charValue"))
- j++;
- else if (name.equals("doubleValue"))
- j++;
- else if (name.equals("floatValue"))
- j++;
- else if (name.equals("intValue"))
- j++;
- else if (name.equals("longValue"))
- j++;
- else if (name.equals("integerValue"))
- j++;
- else if (name.equals("shortValue"))
- j++;
- else if (name.equals("stringValue"))
- j++;
- else if (name.equals("nullTest"))
- j++;
- else
- TestUtil
- .logTrace("Object not created by the test with name: " + name);
- }
-
- if ((it < 13) || (j < 13))
- TestUtil.logErr("Incorrect number of of Objects." + " Total number = "
- + it + " Total created by the test = " + j);
-
- try {
- if (messageReceivedMapMessage.itemExists("booleanValue")) {
- if (messageReceivedMapMessage
- .getBoolean("booleanValue") != booleanValue) {
- TestUtil.logErr("Error: Invalid boolean returned="
- + messageReceivedMapMessage.getBoolean("booleanValue"));
- pass = false;
- }
- } else {
- TestUtil.logErr("Error: No Object with name booleanValue exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception was returned: ", e);
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.itemExists("byteValue")) {
- if (messageReceivedMapMessage.getByte("byteValue") != byteValue) {
- TestUtil.logErr("Fail: invalid byte returned");
- pass = false;
- }
- } else {
- TestUtil.logErr("Error: No Object with name byteValue exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception was returned: ", e);
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.itemExists("bytesValue")) {
- byte[] b = messageReceivedMapMessage.getBytes("bytesValue");
-
- for (int i = 0; i < b.length; i++) {
- if (b[i] != bytesValue[i]) {
- TestUtil.logErr("Fail: byte array " + i + " not valid");
- pass = false;
- }
- }
- } else {
- TestUtil.logErr("Error: No Object with name bytesValue exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.itemExists("bytesValue2")) {
- byte[] b = messageReceivedMapMessage.getBytes("bytesValue2");
- if (b[0] != bytesValue[0]) {
- TestUtil.logErr("Fail: byte array not valid");
- pass = false;
- }
- } else {
- TestUtil.logErr("Error: No Object with name bytesValue2 exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.itemExists("charValue")) {
- if (messageReceivedMapMessage.getChar("charValue") != charValue) {
- TestUtil.logErr("Fail: invalid char returned");
- pass = false;
- }
- } else {
- TestUtil.logErr("Error: No Object with name charValue exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.itemExists("doubleValue")) {
- if (messageReceivedMapMessage
- .getDouble("doubleValue") != doubleValue) {
- TestUtil.logErr("Fail: invalid double returned");
- pass = false;
- }
- } else {
- TestUtil.logErr("Error: No Object with name doubleValue exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.itemExists("floatValue")) {
- if (messageReceivedMapMessage.getFloat("floatValue") != floatValue) {
- TestUtil.logErr("Fail: invalid float returned");
- pass = false;
- }
- } else {
- TestUtil.logErr("Error: No Object with name floatValue exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.itemExists("intValue")) {
- if (messageReceivedMapMessage.getInt("intValue") != intValue) {
- TestUtil.logErr("Fail: invalid int returned");
- pass = false;
- }
- } else {
- TestUtil.logErr("Error: No Object with name intValue exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception", e);
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.itemExists("longValue")) {
- if (messageReceivedMapMessage.getLong("longValue") != longValue) {
- TestUtil.logErr("Fail: invalid long returned");
- pass = false;
- }
- } else {
- TestUtil.logErr("Error: No Object with name longValue exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception", e);
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.itemExists("integerValue")) {
- if (!messageReceivedMapMessage.getObject("integerValue").toString()
- .equals(integerValue.toString())) {
- TestUtil.logErr("Fail: invalid object returned");
- pass = false;
- }
- } else {
- TestUtil.logErr("Error: No Object with name integerValue exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception", e);
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.itemExists("shortValue")) {
- if (messageReceivedMapMessage.getShort("shortValue") != shortValue) {
- TestUtil.logErr("Fail: invalid short returned");
- pass = false;
- }
- } else {
- TestUtil.logErr("Error: No Object with name shortValue exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.itemExists("stringValue")) {
- if (!messageReceivedMapMessage.getString("stringValue")
- .equals(stringValue)) {
- TestUtil.logErr("Fail: invalid string returned");
- pass = false;
- }
- } else {
- TestUtil.logErr("Error: No Object with name stringValue exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception", e);
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.itemExists("nullTest")) {
- if (messageReceivedMapMessage.getString("nullTest") != null) {
- TestUtil.logErr("Fail: null not returned from getString");
- pass = false;
- }
- } else {
- TestUtil.logErr("Error: No Object with name nullTest exists");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception", e);
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.itemExists("nullTestxyz")) {
- TestUtil.logErr("Fail: field with name nullTestxyz is unset");
- pass = false;
- } else if (messageReceivedMapMessage.getObject("nullTestxyz") != null) {
- pass = false;
- TestUtil.logErr("Error: field with name nullTestxyz should be null");
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception", e);
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("Error: mapMessageFullMsgQTest test failure");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("mapMessageFullMsgQTest");
- }
- }
-
- /*
- * @testName: MapMessageConversionQTestsBoolean
- *
- * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:457;
- * JMS:JAVADOC:433; JMS:JAVADOC:449; JMS:JAVADOC:796; JMS:JAVADOC:797;
- * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setBoolean to
- * write a boolean to the message. Verify the proper conversion support as in
- * 3.11.3
- */
-
- public void MapMessageConversionQTestsBoolean() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- boolean booleanValue = true;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionQTestsBoolean");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for boolean primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setBoolean("booleanValue", booleanValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- TestUtil.logTrace("Msg recvd: "
- + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
-
- // now test conversions for boolean
- // -----------------------------------------------
- // boolean to boolean - valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use readBoolean to read a boolean");
- try {
- if (messageReceived.getBoolean("booleanValue") == booleanValue) {
- TestUtil.logTrace("Pass: boolean to boolean - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use readString to read a boolean");
- try {
- String tmp = messageReceived.getString("booleanValue");
- if (Boolean.valueOf(booleanValue).toString().equals(tmp)) {
- TestUtil.logTrace("Pass: boolean to string - valid");
- } else {
- TestUtil.logErr("Fail: wrong value returned=" + tmp + ".");
- TestUtil.logErr("Expecting " + Boolean.valueOf(booleanValue) + ".");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readBytes[] to read a boolean - expect MessageFormatException");
- int nCount = 0;
-
- try {
- byte[] b = messageReceived.getBytes("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
- TestUtil.logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // boolean to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readByte to read a boolean - expect MessageFormatException");
- try {
- byte b = messageReceived.getByte("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readShort to read a boolean - expect MessageFormatException");
- try {
- short s = messageReceived.getShort("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readChar to read a boolean - expect MessageFormatException");
- try {
- char c = messageReceived.getChar("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to int invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readInt to read a boolean - expect MessageFormatException");
- try {
- int i = messageReceived.getInt("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to long invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readLong to read a boolean - expect MessageFormatException");
- try {
- long l = messageReceived.getLong("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readFloat to read a boolean - expect MessageFormatException");
- try {
- float f = messageReceived.getFloat("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readDouble to read a boolean - expect MessageFormatException");
- try {
- double d = messageReceived.getDouble("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionQTestsBoolean", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionQTestsByte
- *
- * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:459;
- * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443;
- * JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:798; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setByte to
- * write a byte. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionQTestsByte() throws Exception {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- byte byteValue = 127;
- boolean pass = true;
-
- try {
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionQTestsByte");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setByte("byteValue", byteValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- TestUtil.logTrace("Msg recvd: "
- + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
-
- // now test conversions for byte
- // -----------------------------------------------
- // byte to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a byte - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("byteValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a byte");
- try {
- if (messageReceived.getString("byteValue")
- .equals(Byte.toString(byteValue))) {
- TestUtil.logTrace("Pass: byte to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getBytes[] to read a byte - expect MessageFormatException");
- int nCount = 0;
-
- try {
- byte[] b = messageReceived.getBytes("byteValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to byte valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a byte");
- try {
- if (messageReceived.getByte("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to byte - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to short valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a byte");
- try {
- if (messageReceived.getShort("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to short - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a boolean - this is not valid");
- try {
- char c = messageReceived.getChar("byteValue");
-
- pass = false;
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to int valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a byte");
- try {
- if (messageReceived.getInt("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to int - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to long valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a byte");
- try {
- if (messageReceived.getLong("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to long - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a boolean - this is not valid");
- try {
- float f = messageReceived.getFloat("byteValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a boolean - this is not valid");
- try {
- double d = messageReceived.getDouble("byteValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionQTestsByte", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionQTestsShort
- *
- * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:461;
- * JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449;
- * JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:798; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setShort to
- * write a short. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionQTestsShort() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- short shortValue = 1;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionQTestsShort");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setShort("shortValue", shortValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- TestUtil.logTrace("Msg recvd: "
- + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
-
- // now test conversions for byte
- // -----------------------------------------------
- // short to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a short - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("shortValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a short");
- try {
- if (messageReceived.getString("shortValue")
- .equals(Short.toString(shortValue))) {
- TestUtil.logTrace("Pass: short to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getBytes[] to read a short - expect MessageFormatException");
- try {
- byte[] b = messageReceived.getBytes("shortValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a short - this is not valid");
- try {
- byte b = messageReceived.getByte("shortValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to short valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a short");
- try {
- if (messageReceived.getShort("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: short to short - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a short - this is not valid");
- try {
- char c = messageReceived.getChar("shortValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to int valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a short");
- try {
- if (messageReceived.getInt("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: short to int - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to long valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a short");
- try {
- if (messageReceived.getLong("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: short to long - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a short - this is not valid");
- try {
- float f = messageReceived.getFloat("shortValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a short - this is not valid");
- try {
- double d = messageReceived.getDouble("shortValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionQTestsShort", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionQTestsChar
- *
- * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:463;
- * JMS:JAVADOC:439; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setChar to
- * write a char. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionQTestsChar() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- char charValue = 'a';
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionQTestsChar");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setChar("charValue", charValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- TestUtil.logTrace("Msg recvd: "
- + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
-
- // now test conversions for byte
- // -----------------------------------------------
- // char to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a char - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a char");
- try {
- if (messageReceived.getString("charValue")
- .equals(Character.valueOf(charValue).toString())) {
- TestUtil.logTrace("Pass: char to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getBytes[] to read a char - expect MessageFormatException");
- try {
- byte[] b = messageReceived.getBytes("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a char - this is not valid");
- try {
- byte b = messageReceived.getByte("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a char");
- try {
- short s = messageReceived.getShort("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to char valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a char ");
- try {
- if (messageReceived.getChar("charValue") == charValue) {
- TestUtil.logTrace("Pass: char to char - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to int invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a char ");
- try {
- int i = messageReceived.getInt("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to long invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a char");
- try {
- long l = messageReceived.getLong("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a char - this is not valid");
- try {
- float f = messageReceived.getFloat("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a char - this is not valid");
- try {
- double d = messageReceived.getDouble("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionQTestsChar", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionQTestsInt
- *
- * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:465;
- * JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795;
- * JMS:JAVADOC:796; JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setInt to
- * write an int. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionQTestsInt() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- int intValue = 6;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionQTestsInt");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setInt("intValue", intValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- TestUtil.logTrace("Msg recvd: "
- + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
-
- // now test conversions for byte
- // -----------------------------------------------
- // int to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read an int - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read an int");
- try {
- if (messageReceived.getString("intValue")
- .equals(Integer.toString(intValue))) {
- TestUtil.logTrace("Pass: int to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getBytes[] to read an int - expect MessageFormatException");
- int nCount = 0;
-
- try {
- byte[] b = messageReceived.getBytes("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read an int - this is not valid");
- try {
- byte b = messageReceived.getByte("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read an int");
- try {
- short s = messageReceived.getShort("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read an int - this is not valid");
- try {
- char c = messageReceived.getChar("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to int valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read an int");
- try {
- if (messageReceived.getInt("intValue") == intValue) {
- TestUtil.logTrace("Pass: int to int - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to long valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read an int");
- try {
- if (messageReceived.getLong("intValue") == intValue) {
- TestUtil.logTrace("Pass: int to long - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read an int - this is not valid");
- try {
- float f = messageReceived.getFloat("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read an int - this is not valid");
- try {
- double d = messageReceived.getDouble("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionQTestsInt", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionQTestsLong
- *
- * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:467;
- * JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setLong to
- * write a long. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionQTestsLong() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- long longValue = 2;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionQTestsLong");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setLong("longValue", longValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- TestUtil.logTrace("Msg recvd: "
- + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
-
- // now test conversions for byte
- // -----------------------------------------------
- // long to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a long - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a long");
- try {
- if (messageReceived.getString("longValue")
- .equals(Long.toString(longValue))) {
- TestUtil.logTrace("Pass: long to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getBytes[] to read a long - expect MessageFormatException");
- try {
- byte[] b = messageReceived.getBytes("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read an long - this is not valid");
- try {
- byte b = messageReceived.getByte("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a long");
- try {
- short s = messageReceived.getShort("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a long - this is not valid");
- try {
- char c = messageReceived.getChar("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to int invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a long");
- try {
- int i = messageReceived.getInt("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to long valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a long");
- try {
- if (messageReceived.getLong("longValue") == longValue) {
- TestUtil.logTrace("Pass: int to long - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a long - this is not valid");
- try {
- float f = messageReceived.getFloat("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a long ");
- try {
- double d = messageReceived.getDouble("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionQTestsLong", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionQTestsFloat
- *
- * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:469;
- * JMS:JAVADOC:445; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setFloat to
- * write a float. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionQTestsFloat() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- float floatValue = 5;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionQTestsFloat");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setFloat("floatValue", floatValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- TestUtil.logTrace("Msg recvd: "
- + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
-
- // now test conversions for byte
- // -----------------------------------------------
- // float to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a float ");
- try {
- boolean b = messageReceived.getBoolean("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a float");
- try {
- if (messageReceived.getString("floatValue")
- .equals(Float.toString(floatValue))) {
- TestUtil.logTrace("Pass: float to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBytes[] to read a float ");
- try {
- byte[] b = messageReceived.getBytes("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a float ");
- try {
- byte b = messageReceived.getByte("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a float");
- try {
- short s = messageReceived.getShort("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a long ");
- try {
- char c = messageReceived.getChar("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to int invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a float");
- try {
- int i = messageReceived.getInt("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to long invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a long");
- try {
- long l = messageReceived.getLong("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to float valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a float ");
- try {
- if (messageReceived.getFloat("floatValue") == floatValue) {
- TestUtil.logTrace("Pass: float to float - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to double valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a float ");
- try {
- if (messageReceived.getDouble("floatValue") == floatValue) {
- TestUtil.logTrace("Pass: float to double - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionQTestsFloat", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionQTestsDouble
- *
- * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:471;
- * JMS:JAVADOC:447; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
- * JMS:JAVADOC:801; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setDouble to
- * write a double. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionQTestsDouble() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- double doubleValue = 3;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionQTestsDouble");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setDouble("doubleValue", doubleValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- TestUtil.logTrace("Msg recvd: "
- + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
-
- // now test conversions for byte
- // -----------------------------------------------
- // double to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a double ");
- try {
- boolean b = messageReceived.getBoolean("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a double");
- try {
- if (messageReceived.getString("doubleValue")
- .equals(Double.toString(doubleValue))) {
- TestUtil.logTrace("Pass: double to string");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBytes[] to read a double ");
- try {
- byte[] b = messageReceived.getBytes("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a double ");
- try {
- byte b = messageReceived.getByte("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a double");
- try {
- short s = messageReceived.getShort("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a double ");
- try {
- char c = messageReceived.getChar("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to int invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a double");
- try {
- int i = messageReceived.getInt("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to long invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a double");
- try {
- long l = messageReceived.getLong("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a double ");
- try {
- float f = messageReceived.getFloat("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to double valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read an float ");
- try {
- if (messageReceived.getDouble("doubleValue") == doubleValue) {
- TestUtil.logTrace("Pass: double to double ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionQTestsDouble", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionQTestsString
- *
- * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:JAVADOC:473;
- * JMS:JAVADOC:433; JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441;
- * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
- * JMS:JAVADOC:798; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setString to
- * write a string. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionQTestsString() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- boolean pass = true;
- String myString = "10";
- String myString2 = "true";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionQTestsString");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setString("myString", myString);
- messageSent.setString("myString2", myString2);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- TestUtil.logTrace("Msg recvd: "
- + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
-
- // now test conversions for String
- // -----------------------------------------------
- // string to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a String");
- try {
- if (messageReceived.getString("myString").equals(myString)) {
- TestUtil.logTrace("Pass: string to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBytes[] to read a String");
- try {
- byte[] b = messageReceived.getBytes("myString");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to byte valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a String");
- try {
- if (messageReceived.getByte("myString") == Byte.parseByte(myString)) {
- TestUtil.logTrace("Pass: String to byte ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to short valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a string");
- try {
- if (messageReceived.getShort("myString") == Short
- .parseShort(myString)) {
- TestUtil.logTrace("Pass: String to short ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a String ");
- try {
- char c = messageReceived.getChar("myString");
-
- TestUtil.logTrace("getChar returned " + c);
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // string to int valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a String");
- try {
- if (messageReceived.getInt("myString") == Integer.parseInt(myString)) {
- TestUtil.logTrace("Pass: String to int ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a String");
- try {
- if (messageReceived.getLong("myString") == Long.parseLong(myString)) {
- TestUtil.logTrace("Pass: String to long ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a String");
- try {
- if (messageReceived.getFloat("myString") == Float
- .parseFloat(myString)) {
- TestUtil.logTrace("Pass: String to float ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to double valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a String");
- try {
- if (messageReceived.getDouble("myString") == Double
- .parseDouble(myString)) {
- TestUtil.logTrace("Pass: String to double ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a string ");
- try {
- if (messageReceived.getBoolean("myString2") == Boolean
- .valueOf(myString2).booleanValue()) {
- TestUtil.logTrace("Pass: String to boolean ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a string that is not true");
- try {
- boolean b = messageReceived.getBoolean("myString");
-
- if (b != false) {
- TestUtil.logMsg("Fail: !true should have returned false");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: !true returned false");
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionQTestsString", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionQTestsBytes
- *
- * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:475;
- * JMS:JAVADOC:451; JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:797;
- * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:803;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setBytes to
- * write a byte[] to the message. Verify the proper conversion support as in
- * 3.11.3
- */
-
- public void MapMessageConversionQTestsBytes() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- byte[] byteValues = { 1, 2, 3 };
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionQTestsBytes");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte[] primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setBytes("byteValues", byteValues);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- TestUtil.logTrace("Msg recvd: "
- + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
-
- // now test conversions for boolean
- // -----------------------------------------------
- // byte[] to byte[] - valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBytes[] to read a byte[] ");
- try {
- byte[] b = messageReceived.getBytes("byteValues");
-
- for (int i = 0; i < b.length; i++) {
- if (b[i] != byteValues[i]) {
- TestUtil.logMsg("Fail: byte[] value returned is invalid");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte[] returned is valid");
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a byte[]");
- try {
- boolean b = messageReceived.getBoolean("byteValues");
-
- TestUtil.logMsg(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to string invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a byte[]");
- try {
- String s = messageReceived.getString("byteValues");
-
- TestUtil.logMsg(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getByte to read a byte[] - expect MessageFormatException");
- try {
- byte b = messageReceived.getByte("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getShort to read a byte[] - expect MessageFormatException");
- try {
- short s = messageReceived.getShort("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getChar to read a byte[] - expect MessageFormatException");
- try {
- char c = messageReceived.getChar("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to int invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getInt to read a byte[] - expect MessageFormatException");
- try {
- int i = messageReceived.getInt("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to long invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getLong to read a byte[] - expect MessageFormatException");
- try {
- long l = messageReceived.getLong("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getFloat to read a byte[] - expect MessageFormatException");
- try {
- float f = messageReceived.getFloat("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getDouble to read a byte[] - expect MessageFormatException");
- try {
- double d = messageReceived.getDouble("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionQTestsBytes", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionQTestsInvFormatString
- *
- * @assertion_ids: JMS:SPEC:76;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setString to
- * write a text string of "mytest string". Verify NumberFormatException is
- * thrown
- *
- */
-
- public void MapMessageConversionQTestsInvFormatString() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- boolean pass = true;
- String myString = "mytest string";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionQTestsInvFormatString");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setString("myString", myString);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- TestUtil.logTrace("Msg recvd: "
- + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
-
- // -----------------------------------------------
- // String to byte
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a String that is not valid ");
- try {
- byte b = messageReceived.getByte("myString");
-
- TestUtil.logMsg("Fail: java.lang.NumberFormatException expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to short
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a string that is not valid ");
- try {
- short s = messageReceived.getShort("myString");
-
- TestUtil.logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to int
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a String that is not valid ");
- try {
- int i = messageReceived.getInt("myString");
-
- TestUtil.logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a String that is not valid ");
- try {
- long l = messageReceived.getLong("myString");
-
- TestUtil.logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a String that is not valid ");
- try {
- float f = messageReceived.getFloat("myString");
-
- TestUtil.logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to double
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a String that is not valid ");
- try {
- double d = messageReceived.getDouble("myString");
-
- TestUtil.logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionQTestsInvFormatString", e);
- }
- }
-
- /*
- * @testName: mapMessageQNotWritable
- *
- * @assertion_ids: JMS:SPEC:73; JMS:JAVADOC:806; JMS:JAVADOC:808;
- * JMS:JAVADOC:810; JMS:JAVADOC:812; JMS:JAVADOC:814; JMS:JAVADOC:816;
- * JMS:JAVADOC:818; JMS:JAVADOC:820; JMS:JAVADOC:822; JMS:JAVADOC:824;
- * JMS:JAVADOC:826; JMS:JAVADOC:829;
- *
- * @test_Strategy: Create a MapMessage, send it to a Queue. Receive it and try
- * to write to the received Message's body, MessageNotWritableException should
- * be thrown.
- */
-
- public void mapMessageQNotWritable() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- boolean pass = true;
- byte bValue = 127;
- short sValue = 32767;
- char cValue = '\uFFFF';
- int iValue = 2147483647;
- long lValue = 9223372036854775807L;
- float fValue = 0.0f;
- double dValue = -0.0;
- String ssValue = "abc";
- byte[] bbValue = { 0, 88, 127 };
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageQNotWritable");
-
- // -----------------------------------------------------------------------------
- try {
- messageSent.setString("ssValue", ssValue);
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- throw new Exception("Error: failed to setString", e);
- }
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- TestUtil.logMsg("Writing a boolean ... ");
- try {
- messageReceived.setBoolean("pass", pass);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBoolean");
- } catch (MessageNotWriteableException e) {
- TestUtil.logMsg(
- "Got Expected MessageNotWriteableException with setBoolean");
- }
-
- TestUtil.logMsg("Writing a byte ... ");
- try {
- messageReceived.setByte("bValue", bValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setByte");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setByte");
- }
-
- TestUtil.logMsg("Writing a short ... ");
- try {
- messageReceived.setShort("sValue", sValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setShort");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setShort");
- }
-
- TestUtil.logMsg("Writing a char ... ");
- try {
- messageReceived.setChar("cValue", cValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setChar");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setChar");
- }
-
- TestUtil.logMsg("Writing a int ... ");
- try {
- messageReceived.setInt("iValue", iValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setInt");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setInt");
- }
-
- TestUtil.logMsg("Writing a long ... ");
- try {
- messageReceived.setLong("lValue", lValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setLong");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setLong");
- }
-
- TestUtil.logMsg("Writing a float ... ");
- try {
- messageReceived.setFloat("fValue", fValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setFloat");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setFloat");
- }
-
- TestUtil.logMsg("Writing a double ... ");
- try {
- messageReceived.setDouble("dValue", dValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setDouble");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setDouble");
- }
-
- TestUtil.logMsg("Writing a bytes... ");
- try {
- messageReceived.setBytes("bbValue", bbValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBytes");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setBytes");
- }
-
- TestUtil.logMsg("Writing a bytes... ");
- try {
- messageReceived.setBytes("bbValue", bbValue, 0, 1);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBytes");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setBytes");
- }
-
- TestUtil.logMsg("Writing a string ... ");
- try {
- messageReceived.setString("ssValue", ssValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setString");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setString");
- }
-
- TestUtil.logMsg("Writing a object ... ");
- try {
- messageReceived.setObject("oValue", new Integer(iValue));
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setObject");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setObject");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("mapMessageQNotWritable", e);
- }
- }
-
- /*
- * @testName: mapMessageQIllegalarg
- *
- * @assertion_ids: JMS:JAVADOC:805; JMS:JAVADOC:807; JMS:JAVADOC:809;
- * JMS:JAVADOC:811; JMS:JAVADOC:813; JMS:JAVADOC:815; JMS:JAVADOC:817;
- * JMS:JAVADOC:819; JMS:JAVADOC:821; JMS:JAVADOC:823; JMS:JAVADOC:825;
- * JMS:JAVADOC:827;
- *
- * @test_Strategy: Create a MapMessage. Write to the message using each type
- * of set method and as an object with null String as name. Verify that
- * IllegalArgumentException thrown.
- */
-
- public void mapMessageQIllegalarg() throws Exception {
- try {
- MapMessage messageSent = null;
- boolean pass = true;
- byte bValue = 127;
- short sValue = 32767;
- char cValue = '\uFFFF';
- int iValue = 2147483647;
- long lValue = 9223372036854775807L;
- float fValue = 0.0f;
- double dValue = -0.0;
- String ssValue = "abc";
- byte[] bbValue = { 0, 88, 127 };
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- messageSent = tool.getDefaultQueueSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageQIllegalarg");
-
- // -----------------------------------------------------------------------------
-
- TestUtil.logMsg("Writing a boolean ... ");
- try {
- messageSent.setBoolean("", pass);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBoolean");
- } catch (IllegalArgumentException e) {
- TestUtil
- .logMsg("Got Expected IllegalArgumentException with setBoolean");
- }
-
- TestUtil.logMsg("Writing a byte ... ");
- try {
- messageSent.setByte("", bValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setByte");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setByte");
- }
-
- TestUtil.logMsg("Writing a short ... ");
- try {
- messageSent.setShort("", sValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setShort");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setShort");
- }
-
- TestUtil.logMsg("Writing a char ... ");
- try {
- messageSent.setChar("", cValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setChar");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setChar");
- }
-
- TestUtil.logMsg("Writing a int ... ");
- try {
- messageSent.setInt("", iValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setInt");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setInt");
- }
-
- TestUtil.logMsg("Writing a long ... ");
- try {
- messageSent.setLong("", lValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setLong");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setLong");
- }
-
- TestUtil.logMsg("Writing a float ... ");
- try {
- messageSent.setFloat("", fValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setFloat");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setFloat");
- }
-
- TestUtil.logMsg("Writing a double ... ");
- try {
- messageSent.setDouble("", dValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setDouble");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setDouble");
- }
-
- TestUtil.logMsg("Writing a bytes... ");
- try {
- messageSent.setBytes("", bbValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBytes");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setBytes");
- }
-
- TestUtil.logMsg("Writing a bytes... ");
- try {
- messageSent.setBytes("", bbValue, 0, 1);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBytes");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setBytes");
- }
-
- TestUtil.logMsg("Writing a string ... ");
- try {
- messageSent.setString("", ssValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setString");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setString");
- }
-
- TestUtil.logMsg("Writing a object ... ");
- try {
- messageSent.setObject("", new Integer(iValue));
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setObject");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setObject");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("mapMessageQIllegalarg", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/mapMsgQueue/MapMsgQueueTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/mapMsgQueue/MapMsgQueueTestsIT.java
new file mode 100644
index 0000000000..aa5e8af57e
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/mapMsgQueue/MapMsgQueueTestsIT.java
@@ -0,0 +1,3156 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.mapMsgQueue;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.MapMessage;
+import jakarta.jms.MessageFormatException;
+import jakarta.jms.MessageNotWriteableException;
+
+
+public class MapMsgQueueTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.mapMsgQueue.MapMsgQueueTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(MapMsgQueueTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String password;
+
+ String mode;
+
+ String user;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+
+ queues = new ArrayList(2);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning: ", e);
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: mapMessageFullMsgQTest
+ *
+ * @assertion_ids: JMS:SPEC:74; JMS:SPEC:80; JMS:JAVADOC:211; JMS:JAVADOC:457;
+ * JMS:JAVADOC:459; JMS:JAVADOC:475; JMS:JAVADOC:477; JMS:JAVADOC:479;
+ * JMS:JAVADOC:461; JMS:JAVADOC:463; JMS:JAVADOC:465; JMS:JAVADOC:467;
+ * JMS:JAVADOC:469; JMS:JAVADOC:471; JMS:JAVADOC:473; JMS:JAVADOC:433;
+ * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:439; JMS:JAVADOC:441;
+ * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
+ * JMS:JAVADOC:451; JMS:JAVADOC:453; JMS:JAVADOC:455; JMS:JAVADOC:481;
+ *
+ * @test_Strategy: Create a MapMessage write to the message using each type of
+ * methods: setBoolean/Byte/Bytes/Bytes/Char/Double/Float and
+ * setInt/Long/Object/Short/String/String. Send the message. Verify on receive
+ * tha all data was received correctly using: 1. getMapNames that all fields are
+ * intact; 2. ItemExists that all fields are intact; 3.
+ * getBoolean/Byte/Bytes/Bytes/Char/Double/Float and
+ * getInt/Long/Object/Short/String/String that that all fields contain correct
+ * values; 4. an unset field is treated as null field.
+ */
+ @Test
+ public void mapMessageFullMsgQTest() throws Exception {
+ boolean pass = true;
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ byte[] bytesValueRecvd = { 0, 0, 0, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ short shortValue = 32767;
+ String stringValue = "Map Message Test";
+ Integer integerValue = Integer.valueOf(100);
+ String initial = "spring is here!";
+ Enumeration list;
+
+ try {
+ MapMessage messageSentMapMessage = null;
+ MapMessage messageReceivedMapMessage = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Queue.");
+ messageSentMapMessage = tool.getDefaultQueueSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageFullMsgQTest");
+ messageSentMapMessage.setBoolean("booleanValue", booleanValue);
+ messageSentMapMessage.setByte("byteValue", byteValue);
+ messageSentMapMessage.setBytes("bytesValue", bytesValue);
+ messageSentMapMessage.setBytes("bytesValue2", bytesValue, 0, 1);
+ messageSentMapMessage.setChar("charValue", charValue);
+ messageSentMapMessage.setDouble("doubleValue", doubleValue);
+ messageSentMapMessage.setFloat("floatValue", floatValue);
+ messageSentMapMessage.setInt("intValue", intValue);
+ messageSentMapMessage.setLong("longValue", longValue);
+ messageSentMapMessage.setObject("integerValue", integerValue);
+ messageSentMapMessage.setShort("shortValue", shortValue);
+ messageSentMapMessage.setString("stringValue", stringValue);
+ messageSentMapMessage.setString("nullTest", null);
+ tool.getDefaultQueueSender().send(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ list = messageReceivedMapMessage.getMapNames();
+ String name = null;
+ int it = 0;
+ int j = 0;
+ while (list.hasMoreElements()) {
+ name = (String) list.nextElement();
+ logger.log(Logger.Level.TRACE, "Object with name: " + name);
+ it++;
+ if (name.equals("booleanValue"))
+ j++;
+ else if (name.equals("byteValue"))
+ j++;
+ else if (name.equals("bytesValue"))
+ j++;
+ else if (name.equals("bytesValue2"))
+ j++;
+ else if (name.equals("charValue"))
+ j++;
+ else if (name.equals("doubleValue"))
+ j++;
+ else if (name.equals("floatValue"))
+ j++;
+ else if (name.equals("intValue"))
+ j++;
+ else if (name.equals("longValue"))
+ j++;
+ else if (name.equals("integerValue"))
+ j++;
+ else if (name.equals("shortValue"))
+ j++;
+ else if (name.equals("stringValue"))
+ j++;
+ else if (name.equals("nullTest"))
+ j++;
+ else
+ logger.log(Logger.Level.TRACE, "Object not created by the test with name: " + name);
+ }
+
+ if ((it < 13) || (j < 13))
+ logger.log(Logger.Level.ERROR, "Incorrect number of of Objects." + " Total number = " + it
+ + " Total created by the test = " + j);
+
+ try {
+ if (messageReceivedMapMessage.itemExists("booleanValue")) {
+ if (messageReceivedMapMessage.getBoolean("booleanValue") != booleanValue) {
+ logger.log(Logger.Level.ERROR, "Error: Invalid boolean returned="
+ + messageReceivedMapMessage.getBoolean("booleanValue"));
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name booleanValue exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception was returned: ", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.itemExists("byteValue")) {
+ if (messageReceivedMapMessage.getByte("byteValue") != byteValue) {
+ logger.log(Logger.Level.ERROR, "Fail: invalid byte returned");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name byteValue exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception was returned: ", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.itemExists("bytesValue")) {
+ byte[] b = messageReceivedMapMessage.getBytes("bytesValue");
+
+ for (int i = 0; i < b.length; i++) {
+ if (b[i] != bytesValue[i]) {
+ logger.log(Logger.Level.ERROR, "Fail: byte array " + i + " not valid");
+ pass = false;
+ }
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name bytesValue exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.itemExists("bytesValue2")) {
+ byte[] b = messageReceivedMapMessage.getBytes("bytesValue2");
+ if (b[0] != bytesValue[0]) {
+ logger.log(Logger.Level.ERROR, "Fail: byte array not valid");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name bytesValue2 exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.itemExists("charValue")) {
+ if (messageReceivedMapMessage.getChar("charValue") != charValue) {
+ logger.log(Logger.Level.ERROR, "Fail: invalid char returned");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name charValue exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.itemExists("doubleValue")) {
+ if (messageReceivedMapMessage.getDouble("doubleValue") != doubleValue) {
+ logger.log(Logger.Level.ERROR, "Fail: invalid double returned");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name doubleValue exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.itemExists("floatValue")) {
+ if (messageReceivedMapMessage.getFloat("floatValue") != floatValue) {
+ logger.log(Logger.Level.ERROR, "Fail: invalid float returned");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name floatValue exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.itemExists("intValue")) {
+ if (messageReceivedMapMessage.getInt("intValue") != intValue) {
+ logger.log(Logger.Level.ERROR, "Fail: invalid int returned");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name intValue exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.itemExists("longValue")) {
+ if (messageReceivedMapMessage.getLong("longValue") != longValue) {
+ logger.log(Logger.Level.ERROR, "Fail: invalid long returned");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name longValue exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.itemExists("integerValue")) {
+ if (!messageReceivedMapMessage.getObject("integerValue").toString()
+ .equals(integerValue.toString())) {
+ logger.log(Logger.Level.ERROR, "Fail: invalid object returned");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name integerValue exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.itemExists("shortValue")) {
+ if (messageReceivedMapMessage.getShort("shortValue") != shortValue) {
+ logger.log(Logger.Level.ERROR, "Fail: invalid short returned");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name shortValue exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.itemExists("stringValue")) {
+ if (!messageReceivedMapMessage.getString("stringValue").equals(stringValue)) {
+ logger.log(Logger.Level.ERROR, "Fail: invalid string returned");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name stringValue exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.itemExists("nullTest")) {
+ if (messageReceivedMapMessage.getString("nullTest") != null) {
+ logger.log(Logger.Level.ERROR, "Fail: null not returned from getString");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: No Object with name nullTest exists");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.itemExists("nullTestxyz")) {
+ logger.log(Logger.Level.ERROR, "Fail: field with name nullTestxyz is unset");
+ pass = false;
+ } else if (messageReceivedMapMessage.getObject("nullTestxyz") != null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: field with name nullTestxyz should be null");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception", e);
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("Error: mapMessageFullMsgQTest test failure");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("mapMessageFullMsgQTest");
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionQTestsBoolean
+ *
+ * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:457;
+ * JMS:JAVADOC:433; JMS:JAVADOC:449; JMS:JAVADOC:796; JMS:JAVADOC:797;
+ * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setBoolean to
+ * write a boolean to the message. Verify the proper conversion support as in
+ * 3.11.3
+ */
+ @Test
+ public void MapMessageConversionQTestsBoolean() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ boolean booleanValue = true;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionQTestsBoolean");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for boolean primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setBoolean("booleanValue", booleanValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Msg recvd: " + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // boolean to boolean - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a boolean");
+ try {
+ if (messageReceived.getBoolean("booleanValue") == booleanValue) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to boolean - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a boolean");
+ try {
+ String tmp = messageReceived.getString("booleanValue");
+ if (Boolean.valueOf(booleanValue).toString().equals(tmp)) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to string - valid");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: wrong value returned=" + tmp + ".");
+ logger.log(Logger.Level.ERROR, "Expecting " + Boolean.valueOf(booleanValue) + ".");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a boolean - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+ byte[] b = messageReceived.getBytes("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // boolean to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a boolean - expect MessageFormatException");
+ try {
+ byte b = messageReceived.getByte("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a boolean - expect MessageFormatException");
+ try {
+ short s = messageReceived.getShort("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a boolean - expect MessageFormatException");
+ try {
+ char c = messageReceived.getChar("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a boolean - expect MessageFormatException");
+ try {
+ int i = messageReceived.getInt("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a boolean - expect MessageFormatException");
+ try {
+ long l = messageReceived.getLong("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a boolean - expect MessageFormatException");
+ try {
+ float f = messageReceived.getFloat("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a boolean - expect MessageFormatException");
+ try {
+ double d = messageReceived.getDouble("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionQTestsBoolean", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionQTestsByte
+ *
+ * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:459;
+ * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443;
+ * JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:798; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setByte to write
+ * a byte. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionQTestsByte() throws Exception {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ byte byteValue = 127;
+ boolean pass = true;
+
+ try {
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionQTestsByte");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setByte("byteValue", byteValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Msg recvd: " + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // byte to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a byte - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("byteValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a byte");
+ try {
+ if (messageReceived.getString("byteValue").equals(Byte.toString(byteValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a byte - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+ byte[] b = messageReceived.getBytes("byteValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a byte");
+ try {
+ if (messageReceived.getByte("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to byte - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a byte");
+ try {
+ if (messageReceived.getShort("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to short - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a boolean - this is not valid");
+ try {
+ char c = messageReceived.getChar("byteValue");
+
+ pass = false;
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a byte");
+ try {
+ if (messageReceived.getInt("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to int - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a byte");
+ try {
+ if (messageReceived.getLong("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a boolean - this is not valid");
+ try {
+ float f = messageReceived.getFloat("byteValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a boolean - this is not valid");
+ try {
+ double d = messageReceived.getDouble("byteValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionQTestsByte", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionQTestsShort
+ *
+ * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:461;
+ * JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449;
+ * JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:798; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setShort to
+ * write a short. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionQTestsShort() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ short shortValue = 1;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionQTestsShort");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setShort("shortValue", shortValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Msg recvd: " + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // short to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a short - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("shortValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a short");
+ try {
+ if (messageReceived.getString("shortValue").equals(Short.toString(shortValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: short to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a short - expect MessageFormatException");
+ try {
+ byte[] b = messageReceived.getBytes("shortValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a short - this is not valid");
+ try {
+ byte b = messageReceived.getByte("shortValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a short");
+ try {
+ if (messageReceived.getShort("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to short - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a short - this is not valid");
+ try {
+ char c = messageReceived.getChar("shortValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a short");
+ try {
+ if (messageReceived.getInt("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to int - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a short");
+ try {
+ if (messageReceived.getLong("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a short - this is not valid");
+ try {
+ float f = messageReceived.getFloat("shortValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a short - this is not valid");
+ try {
+ double d = messageReceived.getDouble("shortValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionQTestsShort", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionQTestsChar
+ *
+ * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:463;
+ * JMS:JAVADOC:439; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setChar to write
+ * a char. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionQTestsChar() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ char charValue = 'a';
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionQTestsChar");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setChar("charValue", charValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Msg recvd: " + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // char to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a char - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a char");
+ try {
+ if (messageReceived.getString("charValue").equals(Character.valueOf(charValue).toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: char to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a char - expect MessageFormatException");
+ try {
+ byte[] b = messageReceived.getBytes("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a char - this is not valid");
+ try {
+ byte b = messageReceived.getByte("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a char");
+ try {
+ short s = messageReceived.getShort("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to char valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a char ");
+ try {
+ if (messageReceived.getChar("charValue") == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: char to char - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a char ");
+ try {
+ int i = messageReceived.getInt("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a char");
+ try {
+ long l = messageReceived.getLong("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a char - this is not valid");
+ try {
+ float f = messageReceived.getFloat("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a char - this is not valid");
+ try {
+ double d = messageReceived.getDouble("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionQTestsChar", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionQTestsInt
+ *
+ * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:465;
+ * JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795;
+ * JMS:JAVADOC:796; JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setInt to write
+ * an int. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionQTestsInt() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ int intValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionQTestsInt");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setInt("intValue", intValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Msg recvd: " + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // int to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read an int - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read an int");
+ try {
+ if (messageReceived.getString("intValue").equals(Integer.toString(intValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: int to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read an int - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+ byte[] b = messageReceived.getBytes("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read an int - this is not valid");
+ try {
+ byte b = messageReceived.getByte("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read an int");
+ try {
+ short s = messageReceived.getShort("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read an int - this is not valid");
+ try {
+ char c = messageReceived.getChar("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read an int");
+ try {
+ if (messageReceived.getInt("intValue") == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to int - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read an int");
+ try {
+ if (messageReceived.getLong("intValue") == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read an int - this is not valid");
+ try {
+ float f = messageReceived.getFloat("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read an int - this is not valid");
+ try {
+ double d = messageReceived.getDouble("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionQTestsInt", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionQTestsLong
+ *
+ * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:467;
+ * JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setLong to write
+ * a long. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionQTestsLong() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ long longValue = 2;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionQTestsLong");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setLong("longValue", longValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Msg recvd: " + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // long to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a long - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a long");
+ try {
+ if (messageReceived.getString("longValue").equals(Long.toString(longValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: long to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a long - expect MessageFormatException");
+ try {
+ byte[] b = messageReceived.getBytes("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read an long - this is not valid");
+ try {
+ byte b = messageReceived.getByte("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a long");
+ try {
+ short s = messageReceived.getShort("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a long - this is not valid");
+ try {
+ char c = messageReceived.getChar("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a long");
+ try {
+ int i = messageReceived.getInt("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a long");
+ try {
+ if (messageReceived.getLong("longValue") == longValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a long - this is not valid");
+ try {
+ float f = messageReceived.getFloat("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a long ");
+ try {
+ double d = messageReceived.getDouble("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionQTestsLong", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionQTestsFloat
+ *
+ * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:469;
+ * JMS:JAVADOC:445; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setFloat to
+ * write a float. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionQTestsFloat() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ float floatValue = 5;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionQTestsFloat");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setFloat("floatValue", floatValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Msg recvd: " + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // float to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a float ");
+ try {
+ boolean b = messageReceived.getBoolean("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a float");
+ try {
+ if (messageReceived.getString("floatValue").equals(Float.toString(floatValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: float to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a float ");
+ try {
+ byte[] b = messageReceived.getBytes("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a float ");
+ try {
+ byte b = messageReceived.getByte("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a float");
+ try {
+ short s = messageReceived.getShort("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a long ");
+ try {
+ char c = messageReceived.getChar("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a float");
+ try {
+ int i = messageReceived.getInt("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a long");
+ try {
+ long l = messageReceived.getLong("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a float ");
+ try {
+ if (messageReceived.getFloat("floatValue") == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to float - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a float ");
+ try {
+ if (messageReceived.getDouble("floatValue") == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to double - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionQTestsFloat", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionQTestsDouble
+ *
+ * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:471;
+ * JMS:JAVADOC:447; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
+ * JMS:JAVADOC:801; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setDouble to
+ * write a double. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionQTestsDouble() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ double doubleValue = 3;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionQTestsDouble");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setDouble("doubleValue", doubleValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Msg recvd: " + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // double to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a double ");
+ try {
+ boolean b = messageReceived.getBoolean("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a double");
+ try {
+ if (messageReceived.getString("doubleValue").equals(Double.toString(doubleValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: double to string");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a double ");
+ try {
+ byte[] b = messageReceived.getBytes("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a double ");
+ try {
+ byte b = messageReceived.getByte("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a double");
+ try {
+ short s = messageReceived.getShort("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a double ");
+ try {
+ char c = messageReceived.getChar("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a double");
+ try {
+ int i = messageReceived.getInt("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a double");
+ try {
+ long l = messageReceived.getLong("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a double ");
+ try {
+ float f = messageReceived.getFloat("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read an float ");
+ try {
+ if (messageReceived.getDouble("doubleValue") == doubleValue) {
+ logger.log(Logger.Level.TRACE, "Pass: double to double ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionQTestsDouble", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionQTestsString
+ *
+ * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:JAVADOC:473;
+ * JMS:JAVADOC:433; JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441;
+ * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
+ * JMS:JAVADOC:798; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setString to
+ * write a string. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionQTestsString() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ boolean pass = true;
+ String myString = "10";
+ String myString2 = "true";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionQTestsString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setString("myString", myString);
+ messageSent.setString("myString2", myString2);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Msg recvd: " + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
+
+ // now test conversions for String
+ // -----------------------------------------------
+ // string to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a String");
+ try {
+ if (messageReceived.getString("myString").equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: string to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a String");
+ try {
+ byte[] b = messageReceived.getBytes("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a String");
+ try {
+ if (messageReceived.getByte("myString") == Byte.parseByte(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to byte ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a string");
+ try {
+ if (messageReceived.getShort("myString") == Short.parseShort(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to short ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a String ");
+ try {
+ char c = messageReceived.getChar("myString");
+
+ logger.log(Logger.Level.TRACE, "getChar returned " + c);
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // string to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a String");
+ try {
+ if (messageReceived.getInt("myString") == Integer.parseInt(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to int ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a String");
+ try {
+ if (messageReceived.getLong("myString") == Long.parseLong(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to long ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a String");
+ try {
+ if (messageReceived.getFloat("myString") == Float.parseFloat(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to float ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a String");
+ try {
+ if (messageReceived.getDouble("myString") == Double.parseDouble(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to double ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a string ");
+ try {
+ if (messageReceived.getBoolean("myString2") == Boolean.valueOf(myString2).booleanValue()) {
+ logger.log(Logger.Level.TRACE, "Pass: String to boolean ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a string that is not true");
+ try {
+ boolean b = messageReceived.getBoolean("myString");
+
+ if (b != false) {
+ logger.log(Logger.Level.INFO, "Fail: !true should have returned false");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: !true returned false");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionQTestsString", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionQTestsBytes
+ *
+ * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:475;
+ * JMS:JAVADOC:451; JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:797;
+ * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:803;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setBytes to
+ * write a byte[] to the message. Verify the proper conversion support as in
+ * 3.11.3
+ */
+ @Test
+ public void MapMessageConversionQTestsBytes() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ byte[] byteValues = { 1, 2, 3 };
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionQTestsBytes");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte[] primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setBytes("byteValues", byteValues);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Msg recvd: " + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // byte[] to byte[] - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a byte[] ");
+ try {
+ byte[] b = messageReceived.getBytes("byteValues");
+
+ for (int i = 0; i < b.length; i++) {
+ if (b[i] != byteValues[i]) {
+ logger.log(Logger.Level.INFO, "Fail: byte[] value returned is invalid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte[] returned is valid");
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a byte[]");
+ try {
+ boolean b = messageReceived.getBoolean("byteValues");
+
+ logger.log(Logger.Level.INFO,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to string invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a byte[]");
+ try {
+ String s = messageReceived.getString("byteValues");
+
+ logger.log(Logger.Level.INFO,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a byte[] - expect MessageFormatException");
+ try {
+ byte b = messageReceived.getByte("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a byte[] - expect MessageFormatException");
+ try {
+ short s = messageReceived.getShort("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a byte[] - expect MessageFormatException");
+ try {
+ char c = messageReceived.getChar("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a byte[] - expect MessageFormatException");
+ try {
+ int i = messageReceived.getInt("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a byte[] - expect MessageFormatException");
+ try {
+ long l = messageReceived.getLong("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a byte[] - expect MessageFormatException");
+ try {
+ float f = messageReceived.getFloat("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a byte[] - expect MessageFormatException");
+ try {
+ double d = messageReceived.getDouble("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionQTestsBytes", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionQTestsInvFormatString
+ *
+ * @assertion_ids: JMS:SPEC:76;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setString to
+ * write a text string of "mytest string". Verify NumberFormatException is
+ * thrown
+ *
+ */
+ @Test
+ public void MapMessageConversionQTestsInvFormatString() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ boolean pass = true;
+ String myString = "mytest string";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionQTestsInvFormatString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setString("myString", myString);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Msg recvd: " + messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME"));
+
+ // -----------------------------------------------
+ // String to byte
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a String that is not valid ");
+ try {
+ byte b = messageReceived.getByte("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: java.lang.NumberFormatException expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to short
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a string that is not valid ");
+ try {
+ short s = messageReceived.getShort("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to int
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a String that is not valid ");
+ try {
+ int i = messageReceived.getInt("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a String that is not valid ");
+ try {
+ long l = messageReceived.getLong("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a String that is not valid ");
+ try {
+ float f = messageReceived.getFloat("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to double
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a String that is not valid ");
+ try {
+ double d = messageReceived.getDouble("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionQTestsInvFormatString", e);
+ }
+ }
+
+ /*
+ * @testName: mapMessageQNotWritable
+ *
+ * @assertion_ids: JMS:SPEC:73; JMS:JAVADOC:806; JMS:JAVADOC:808;
+ * JMS:JAVADOC:810; JMS:JAVADOC:812; JMS:JAVADOC:814; JMS:JAVADOC:816;
+ * JMS:JAVADOC:818; JMS:JAVADOC:820; JMS:JAVADOC:822; JMS:JAVADOC:824;
+ * JMS:JAVADOC:826; JMS:JAVADOC:829;
+ *
+ * @test_Strategy: Create a MapMessage, send it to a Queue. Receive it and try
+ * to write to the received Message's body, MessageNotWritableException should
+ * be thrown.
+ */
+ @Test
+ public void mapMessageQNotWritable() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ boolean pass = true;
+ byte bValue = 127;
+ short sValue = 32767;
+ char cValue = '\uFFFF';
+ int iValue = 2147483647;
+ long lValue = 9223372036854775807L;
+ float fValue = 0.0f;
+ double dValue = -0.0;
+ String ssValue = "abc";
+ byte[] bbValue = { 0, 88, 127 };
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageQNotWritable");
+
+ // -----------------------------------------------------------------------------
+ try {
+ messageSent.setString("ssValue", ssValue);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ throw new Exception("Error: failed to setString", e);
+ }
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ logger.log(Logger.Level.INFO, "Writing a boolean ... ");
+ try {
+ messageReceived.setBoolean("pass", pass);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBoolean");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setBoolean");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a byte ... ");
+ try {
+ messageReceived.setByte("bValue", bValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setByte");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setByte");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a short ... ");
+ try {
+ messageReceived.setShort("sValue", sValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setShort");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setShort");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a char ... ");
+ try {
+ messageReceived.setChar("cValue", cValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setChar");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setChar");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a int ... ");
+ try {
+ messageReceived.setInt("iValue", iValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setInt");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setInt");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a long ... ");
+ try {
+ messageReceived.setLong("lValue", lValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setLong");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setLong");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a float ... ");
+ try {
+ messageReceived.setFloat("fValue", fValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setFloat");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setFloat");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a double ... ");
+ try {
+ messageReceived.setDouble("dValue", dValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setDouble");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setDouble");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageReceived.setBytes("bbValue", bbValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBytes");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageReceived.setBytes("bbValue", bbValue, 0, 1);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBytes");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a string ... ");
+ try {
+ messageReceived.setString("ssValue", ssValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setString");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setString");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a object ... ");
+ try {
+ messageReceived.setObject("oValue", new Integer(iValue));
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setObject");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setObject");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("mapMessageQNotWritable", e);
+ }
+ }
+
+ /*
+ * @testName: mapMessageQIllegalarg
+ *
+ * @assertion_ids: JMS:JAVADOC:805; JMS:JAVADOC:807; JMS:JAVADOC:809;
+ * JMS:JAVADOC:811; JMS:JAVADOC:813; JMS:JAVADOC:815; JMS:JAVADOC:817;
+ * JMS:JAVADOC:819; JMS:JAVADOC:821; JMS:JAVADOC:823; JMS:JAVADOC:825;
+ * JMS:JAVADOC:827;
+ *
+ * @test_Strategy: Create a MapMessage. Write to the message using each type of
+ * set method and as an object with null String as name. Verify that
+ * IllegalArgumentException thrown.
+ */
+ @Test
+ public void mapMessageQIllegalarg() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ boolean pass = true;
+ byte bValue = 127;
+ short sValue = 32767;
+ char cValue = '\uFFFF';
+ int iValue = 2147483647;
+ long lValue = 9223372036854775807L;
+ float fValue = 0.0f;
+ double dValue = -0.0;
+ String ssValue = "abc";
+ byte[] bbValue = { 0, 88, 127 };
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ messageSent = tool.getDefaultQueueSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageQIllegalarg");
+
+ // -----------------------------------------------------------------------------
+
+ logger.log(Logger.Level.INFO, "Writing a boolean ... ");
+ try {
+ messageSent.setBoolean("", pass);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBoolean");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setBoolean");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a byte ... ");
+ try {
+ messageSent.setByte("", bValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setByte");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setByte");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a short ... ");
+ try {
+ messageSent.setShort("", sValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setShort");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setShort");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a char ... ");
+ try {
+ messageSent.setChar("", cValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setChar");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setChar");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a int ... ");
+ try {
+ messageSent.setInt("", iValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setInt");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setInt");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a long ... ");
+ try {
+ messageSent.setLong("", lValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setLong");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setLong");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a float ... ");
+ try {
+ messageSent.setFloat("", fValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setFloat");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setFloat");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a double ... ");
+ try {
+ messageSent.setDouble("", dValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setDouble");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setDouble");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageSent.setBytes("", bbValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBytes");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageSent.setBytes("", bbValue, 0, 1);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBytes");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a string ... ");
+ try {
+ messageSent.setString("", ssValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setString");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setString");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a object ... ");
+ try {
+ messageSent.setObject("", new Integer(iValue));
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setObject");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setObject");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("mapMessageQIllegalarg", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/mapMsgTopic/MapMsgTopicTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/mapMsgTopic/MapMsgTopicTests.java
deleted file mode 100644
index 8b3342052c..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/mapMsgTopic/MapMsgTopicTests.java
+++ /dev/null
@@ -1,3118 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.mapMsgTopic;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.MapMessage;
-import jakarta.jms.MessageFormatException;
-import jakarta.jms.MessageNotWriteableException;
-
-public class MapMsgTopicTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.mapMsgTopic.MapMsgTopicTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- MapMsgTopicTests theTests = new MapMsgTopicTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- TestUtil.logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.logErr("An error occurred while cleaning: ", e);
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: mapMessageFullMsgTopicTest
- *
- * @assertion_ids: JMS:SPEC:74; JMS:JAVADOC:211; JMS:JAVADOC:457;
- * JMS:JAVADOC:459; JMS:JAVADOC:475; JMS:JAVADOC:477; JMS:JAVADOC:479;
- * JMS:JAVADOC:461; JMS:JAVADOC:463; JMS:JAVADOC:465; JMS:JAVADOC:467;
- * JMS:JAVADOC:469; JMS:JAVADOC:471; JMS:JAVADOC:473; JMS:JAVADOC:433;
- * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:439; JMS:JAVADOC:441;
- * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
- * JMS:JAVADOC:451; JMS:JAVADOC:453;
- *
- * @test_Strategy: Create a MapMessage -. write to the message using each type
- * of method and as an object. Send the message. Verify the data received was
- * as sent.
- *
- *
- */
-
- public void mapMessageFullMsgTopicTest() throws Exception {
- boolean pass = true;
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- short shortValue = 32767;
- String stringValue = "Map Message Test";
- Integer integerValue = Integer.valueOf(100);
- String initial = "spring is here!";
-
- try {
- MapMessage messageSentMapMessage = null;
- MapMessage messageReceivedMapMessage = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
-
- // send and receive map message to Topic
- TestUtil.logTrace("Send MapMessage to Topic.");
- messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageFullMsgTopicTest");
- messageSentMapMessage.setBoolean("booleanValue", booleanValue);
- messageSentMapMessage.setByte("byteValue", byteValue);
- messageSentMapMessage.setBytes("bytesValue", bytesValue);
- messageSentMapMessage.setBytes("bytesValue2", bytesValue, 0, 1);
- messageSentMapMessage.setChar("charValue", charValue);
- messageSentMapMessage.setDouble("doubleValue", doubleValue);
- messageSentMapMessage.setFloat("floatValue", floatValue);
- messageSentMapMessage.setInt("intValue", intValue);
- messageSentMapMessage.setLong("longValue", longValue);
- messageSentMapMessage.setObject("integerValue", integerValue);
- messageSentMapMessage.setShort("shortValue", shortValue);
- messageSentMapMessage.setString("stringValue", stringValue);
- messageSentMapMessage.setString("nullTest", null);
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- try {
- if (messageReceivedMapMessage
- .getBoolean("booleanValue") == booleanValue) {
- TestUtil.logTrace("Pass: valid boolean returned");
- } else {
- TestUtil.logMsg("Fail: invalid boolean returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.getByte("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: valid byte returned");
- } else {
- TestUtil.logMsg("Fail: invalid byte returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- byte[] b = messageReceivedMapMessage.getBytes("bytesValue");
-
- for (int i = 0; i < b.length; i++) {
- if (b[i] != bytesValue[i]) {
- TestUtil.logMsg("Fail: byte array " + i + " not valid");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte array " + i + " valid");
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- byte[] b = messageReceivedMapMessage.getBytes("bytesValue2");
-
- if (b[0] != bytesValue[0]) {
- TestUtil.logMsg("Fail: byte array not valid");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte array valid");
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.getChar("charValue") == charValue) {
- TestUtil.logTrace("Pass: valid char returned");
- } else {
- TestUtil.logMsg("Fail: invalid char returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.getDouble("doubleValue") == doubleValue) {
- TestUtil.logTrace("Pass: valid double returned");
- } else {
- TestUtil.logMsg("Fail: invalid double returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.getFloat("floatValue") == floatValue) {
- TestUtil.logTrace("Pass: valid float returned");
- } else {
- TestUtil.logMsg("Fail: invalid float returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.getInt("intValue") == intValue) {
- TestUtil.logTrace("Pass: valid int returned");
- } else {
- TestUtil.logMsg("Fail: invalid int returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.getLong("longValue") == longValue) {
- TestUtil.logTrace("Pass: valid long returned");
- } else {
- TestUtil.logMsg("Fail: invalid long returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.getObject("integerValue").toString()
- .equals(integerValue.toString())) {
- TestUtil.logTrace("Pass: valid object returned");
- } else {
- TestUtil.logMsg("Fail: invalid object returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.getShort("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: valid short returned");
- } else {
- TestUtil.logMsg("Fail: invalid short returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.getString("stringValue")
- .equals(stringValue)) {
- TestUtil.logTrace("Pass: valid string returned");
- } else {
- TestUtil.logMsg("Fail: invalid string returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceivedMapMessage.getString("nullTest") == null) {
- TestUtil.logTrace("Pass: null returned");
- } else {
- TestUtil.logMsg("Fail: null not returned from getString");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Fail: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: mapMessageFullMsgTopicTest test failure");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("mapMessageFullMsgTopicTest");
- }
- }
-
- /*
- * @testName: MapMessageConversionTopicTestsBoolean
- *
- * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:457;
- * JMS:JAVADOC:433; JMS:JAVADOC:449; JMS:JAVADOC:796; JMS:JAVADOC:797;
- * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method writeBoolean
- * to write a boolean to the message. Verify the proper conversion support as
- * in 3.11.3
- */
-
- public void MapMessageConversionTopicTestsBoolean() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- boolean booleanValue = true;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionTopicTestsBoolean");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for boolean primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setBoolean("booleanValue", booleanValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for boolean
- // -----------------------------------------------
- // boolean to boolean - valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use readBoolean to read a boolean");
- try {
- if (messageReceived.getBoolean("booleanValue") == booleanValue) {
- TestUtil.logTrace("Pass: boolean to boolean - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use readString to read a boolean");
- try {
- if (messageReceived.getString("booleanValue")
- .equals((Boolean.valueOf(booleanValue)).toString())) {
- TestUtil.logTrace("Pass: boolean to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readBytes[] to read a boolean - expect MessageFormatException");
- int nCount = 0;
-
- try {
- byte[] b = messageReceived.getBytes("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- TestUtil.logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // boolean to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readByte to read a boolean - expect MessageFormatException");
- try {
- byte b = messageReceived.getByte("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readShort to read a boolean - expect MessageFormatException");
- try {
- short s = messageReceived.getShort("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readChar to read a boolean - expect MessageFormatException");
- try {
- char c = messageReceived.getChar("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to int invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readInt to read a boolean - expect MessageFormatException");
- try {
- int i = messageReceived.getInt("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to long invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readLong to read a boolean - expect MessageFormatException");
- try {
- long l = messageReceived.getLong("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readFloat to read a boolean - expect MessageFormatException");
- try {
- float f = messageReceived.getFloat("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use readDouble to read a boolean - expect MessageFormatException");
- try {
- double d = messageReceived.getDouble("booleanValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionTopicTestsBoolean", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionTopicTestsByte
- *
- * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:459;
- * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443;
- * JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:798; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setByte to
- * write a byte. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionTopicTestsByte() throws Exception {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- byte byteValue = 127;
- boolean pass = true;
-
- try {
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionTopicTestsByte");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setByte("byteValue", byteValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // byte to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a byte - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("byteValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a byte");
- try {
- if (messageReceived.getString("byteValue")
- .equals(Byte.toString(byteValue))) {
- TestUtil.logTrace("Pass: byte to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getBytes[] to read a byte - expect MessageFormatException");
- int nCount = 0;
-
- try {
- byte[] b = messageReceived.getBytes("byteValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to byte valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a byte");
- try {
- if (messageReceived.getByte("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to byte - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to short valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a byte");
- try {
- if (messageReceived.getShort("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to short - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a boolean - this is not valid");
- try {
- char c = messageReceived.getChar("byteValue");
-
- pass = false;
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to int valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a byte");
- try {
- if (messageReceived.getInt("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to int - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to long valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a byte");
- try {
- if (messageReceived.getLong("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to long - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a boolean - this is not valid");
- try {
- float f = messageReceived.getFloat("byteValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a boolean - this is not valid");
- try {
- double d = messageReceived.getDouble("byteValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionTopicTestsByte", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionTopicTestsShort
- *
- * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:461;
- * JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449;
- * JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:798; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method writeShort to
- * write a short. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionTopicTestsShort() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- short shortValue = 1;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionTopicTestsShort");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setShort("shortValue", shortValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // short to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a short - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("shortValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a short");
- try {
- if (messageReceived.getString("shortValue")
- .equals(Short.toString(shortValue))) {
- TestUtil.logTrace("Pass: short to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getBytes[] to read a short - expect MessageFormatException");
- try {
- byte[] b = messageReceived.getBytes("shortValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a short - this is not valid");
- try {
- byte b = messageReceived.getByte("shortValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to short valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a short");
- try {
- if (messageReceived.getShort("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: short to short - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a short - this is not valid");
- try {
- char c = messageReceived.getChar("shortValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to int valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a short");
- try {
- if (messageReceived.getInt("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: short to int - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to long valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a short");
- try {
- if (messageReceived.getLong("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: short to long - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a short - this is not valid");
- try {
- float f = messageReceived.getFloat("shortValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a short - this is not valid");
- try {
- double d = messageReceived.getDouble("shortValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionTopicTestsShort", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionTopicTestsChar
- *
- * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:463;
- * JMS:JAVADOC:439; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method writeChar to
- * write a char. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionTopicTestsChar() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- char charValue = 'a';
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionTopicTestsChar");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setChar("charValue", charValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // char to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a char - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a char");
- try {
- if (messageReceived.getString("charValue")
- .equals(Character.valueOf(charValue).toString())) {
- TestUtil.logTrace("Pass: char to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getBytes[] to read a char - expect MessageFormatException");
- try {
- byte[] b = messageReceived.getBytes("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a char - this is not valid");
- try {
- byte b = messageReceived.getByte("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a char");
- try {
- short s = messageReceived.getShort("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to char valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a char ");
- try {
- if (messageReceived.getChar("charValue") == charValue) {
- TestUtil.logTrace("Pass: char to char - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to int invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a char ");
- try {
- int i = messageReceived.getInt("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to long invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a char");
- try {
- long l = messageReceived.getLong("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a char - this is not valid");
- try {
- float f = messageReceived.getFloat("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a char - this is not valid");
- try {
- double d = messageReceived.getDouble("charValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionTopicTestsChar", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionTopicTestsInt
- *
- * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:465;
- * JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795;
- * JMS:JAVADOC:796; JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method writeInt to
- * write an int. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionTopicTestsInt() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- int intValue = 6;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionTopicTestsInt");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setInt("intValue", intValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // int to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read an int - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read an int");
- try {
- if (messageReceived.getString("intValue")
- .equals(Integer.toString(intValue))) {
- TestUtil.logTrace("Pass: int to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getBytes[] to read an int - expect MessageFormatException");
- int nCount = 0;
-
- try {
- byte[] b = messageReceived.getBytes("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read an int - this is not valid");
- try {
- byte b = messageReceived.getByte("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read an int");
- try {
- short s = messageReceived.getShort("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read an int - this is not valid");
- try {
- char c = messageReceived.getChar("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to int valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read an int");
- try {
- if (messageReceived.getInt("intValue") == intValue) {
- TestUtil.logTrace("Pass: int to int - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to long valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read an int");
- try {
- if (messageReceived.getLong("intValue") == intValue) {
- TestUtil.logTrace("Pass: int to long - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read an int - this is not valid");
- try {
- float f = messageReceived.getFloat("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read an int - this is not valid");
- try {
- double d = messageReceived.getDouble("intValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionTopicTestsInt", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionTopicTestsLong
- *
- * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:467;
- * JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method writeLong to
- * write a long. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionTopicTestsLong() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- long longValue = 2;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionTopicTestsLong");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setLong("longValue", longValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // long to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a long - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a long");
- try {
- if (messageReceived.getString("longValue")
- .equals(Long.toString(longValue))) {
- TestUtil.logTrace("Pass: long to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getBytes[] to read a long - expect MessageFormatException");
- try {
- byte[] b = messageReceived.getBytes("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read an long - this is not valid");
- try {
- byte b = messageReceived.getByte("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a long");
- try {
- short s = messageReceived.getShort("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a long - this is not valid");
- try {
- char c = messageReceived.getChar("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to int invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a long");
- try {
- int i = messageReceived.getInt("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to long valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a long");
- try {
- if (messageReceived.getLong("longValue") == longValue) {
- TestUtil.logTrace("Pass: int to long - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a long - this is not valid");
- try {
- float f = messageReceived.getFloat("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a long ");
- try {
- double d = messageReceived.getDouble("longValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionTopicTestsLong", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionTopicTestsFloat
- *
- * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:469;
- * JMS:JAVADOC:445; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method writeFloat to
- * write a float. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionTopicTestsFloat() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- float floatValue = 5;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionTopicTestsFloat");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setFloat("floatValue", floatValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // float to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a float ");
- try {
- boolean b = messageReceived.getBoolean("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a float");
- try {
- if (messageReceived.getString("floatValue")
- .equals(Float.toString(floatValue))) {
- TestUtil.logTrace("Pass: float to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBytes[] to read a float ");
- try {
- byte[] b = messageReceived.getBytes("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a float ");
- try {
- byte b = messageReceived.getByte("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a float");
- try {
- short s = messageReceived.getShort("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a long ");
- try {
- char c = messageReceived.getChar("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to int invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a float");
- try {
- int i = messageReceived.getInt("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to long invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a long");
- try {
- long l = messageReceived.getLong("floatValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to float valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a float ");
- try {
- if (messageReceived.getFloat("floatValue") == floatValue) {
- TestUtil.logTrace("Pass: float to float - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to double valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a float ");
- try {
- if (messageReceived.getDouble("floatValue") == floatValue) {
- TestUtil.logTrace("Pass: float to double - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionTopicTestsFloat", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionTopicTestsDouble
- *
- * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:471;
- * JMS:JAVADOC:447; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
- * JMS:JAVADOC:801; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method writeDouble to
- * write a double. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionTopicTestsDouble() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- double doubleValue = 3;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionTopicTestsDouble");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setDouble("doubleValue", doubleValue);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // double to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a double ");
- try {
- boolean b = messageReceived.getBoolean("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a double");
- try {
- if (messageReceived.getString("doubleValue")
- .equals(Double.toString(doubleValue))) {
- TestUtil.logTrace("Pass: double to string");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBytes[] to read a double ");
- try {
- byte[] b = messageReceived.getBytes("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a double ");
- try {
- byte b = messageReceived.getByte("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a double");
- try {
- short s = messageReceived.getShort("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a double ");
- try {
- char c = messageReceived.getChar("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to int invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a double");
- try {
- int i = messageReceived.getInt("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to long invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a double");
- try {
- long l = messageReceived.getLong("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a double ");
- try {
- float f = messageReceived.getFloat("doubleValue");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to double valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read an float ");
- try {
- if (messageReceived.getDouble("doubleValue") == doubleValue) {
- TestUtil.logTrace("Pass: double to double ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionTopicTestsDouble", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionTopicTestsString
- *
- * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:JAVADOC:473;
- * JMS:JAVADOC:433; JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441;
- * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
- * JMS:JAVADOC:798; JMS:JAVADOC:804;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method writeString to
- * write a string. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void MapMessageConversionTopicTestsString() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- boolean pass = true;
- String myString = "10";
- String myString2 = "true";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionTopicTestsString");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setString("myString", myString);
- messageSent.setString("myString2", myString2);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for String
- // -----------------------------------------------
- // string to string valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a String");
- try {
- if (messageReceived.getString("myString").equals(myString)) {
- TestUtil.logTrace("Pass: string to string - valid");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to byte[] invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBytes[] to read a String");
- try {
- byte[] b = messageReceived.getBytes("myString");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to byte valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a String");
- try {
- if (messageReceived.getByte("myString") == Byte.parseByte(myString)) {
- TestUtil.logTrace("Pass: String to byte ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to short valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a string");
- try {
- if (messageReceived.getShort("myString") == Short
- .parseShort(myString)) {
- TestUtil.logTrace("Pass: String to short ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getChar to read a String ");
- try {
- char c = messageReceived.getChar("myString");
-
- TestUtil.logTrace("getChar returned " + c);
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // string to int valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a String");
- try {
- if (messageReceived.getInt("myString") == Integer.parseInt(myString)) {
- TestUtil.logTrace("Pass: String to int ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a String");
- try {
- if (messageReceived.getLong("myString") == Long.parseLong(myString)) {
- TestUtil.logTrace("Pass: String to long ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a String");
- try {
- if (messageReceived.getFloat("myString") == Float
- .parseFloat(myString)) {
- TestUtil.logTrace("Pass: String to float ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to double valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a String");
- try {
- if (messageReceived.getDouble("myString") == Double
- .parseDouble(myString)) {
- TestUtil.logTrace("Pass: String to double ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a string ");
- try {
- if (messageReceived.getBoolean("myString2") == Boolean
- .valueOf(myString2).booleanValue()) {
- TestUtil.logTrace("Pass: String to boolean ");
- } else {
- TestUtil.logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a string that is not true");
- try {
- boolean b = messageReceived.getBoolean("myString");
-
- if (b != false) {
- TestUtil.logMsg("Fail: !true should have returned false");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: !true returned false");
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionTopicTestsString", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionTopicTestsBytes
- *
- * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:475;
- * JMS:JAVADOC:451; JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:797;
- * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:803;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method writeBytes to
- * write a byte[] to the message. Verify the proper conversion support as in
- * 3.11.3
- */
-
- public void MapMessageConversionTopicTestsBytes() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- byte[] byteValues = { 1, 2, 3 };
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionTopicTestsBytes");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte[] primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setBytes("byteValues", byteValues);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for boolean
- // -----------------------------------------------
- // byte[] to byte[] - valid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBytes[] to read a byte[] ");
- try {
- byte[] b = messageReceived.getBytes("byteValues");
-
- for (int i = 0; i < b.length; i++) {
- if (b[i] != byteValues[i]) {
- TestUtil.logMsg("Fail: byte[] value returned is invalid");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte[] returned is valid");
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to boolean - invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getBoolean to read a byte[]");
- try {
- boolean b = messageReceived.getBoolean("byteValues");
-
- TestUtil.logMsg(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to string invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getString to read a byte[]");
- try {
- String s = messageReceived.getString("byteValues");
-
- TestUtil.logMsg(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to byte invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getByte to read a byte[] - expect MessageFormatException");
- try {
- byte b = messageReceived.getByte("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to short invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getShort to read a byte[] - expect MessageFormatException");
- try {
- short s = messageReceived.getShort("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to char invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getChar to read a byte[] - expect MessageFormatException");
- try {
- char c = messageReceived.getChar("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to int invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getInt to read a byte[] - expect MessageFormatException");
- try {
- int i = messageReceived.getInt("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to long invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getLong to read a byte[] - expect MessageFormatException");
- try {
- long l = messageReceived.getLong("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to float invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getFloat to read a byte[] - expect MessageFormatException");
- try {
- float f = messageReceived.getFloat("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to double invalid
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg(
- "Use getDouble to read a byte[] - expect MessageFormatException");
- try {
- double d = messageReceived.getDouble("byteValues");
-
- TestUtil.logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionTopicTestsBytes", e);
- }
- }
-
- /*
- * @testName: MapMessageConversionTopicTestsInvFormatString
- *
- * @assertion_ids: JMS:SPEC:76;
- *
- * @test_Strategy: Create a MapMessage -. use MapMessage method setString to
- * write a text string of "mytest string". Verify NumberFormatException is
- * thrown
- *
- */
-
- public void MapMessageConversionTopicTestsInvFormatString() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- boolean pass = true;
- String myString = "mytest string";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionTopicTestsInvFormatString");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.setString("myString", myString);
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // -----------------------------------------------
- // String to byte
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getByte to read a String that is not valid ");
- try {
- byte b = messageReceived.getByte("myString");
-
- TestUtil.logMsg("Fail: java.lang.NumberFormatException expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to short
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getShort to read a string that is not valid ");
- try {
- short s = messageReceived.getShort("myString");
-
- TestUtil.logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to int
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getInt to read a String that is not valid ");
- try {
- int i = messageReceived.getInt("myString");
-
- TestUtil.logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getLong to read a String that is not valid ");
- try {
- long l = messageReceived.getLong("myString");
-
- TestUtil.logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getFloat to read a String that is not valid ");
- try {
- float f = messageReceived.getFloat("myString");
-
- TestUtil.logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to double
- // -----------------------------------------------
- TestUtil.logMsg("--");
- TestUtil.logMsg("Use getDouble to read a String that is not valid ");
- try {
- double d = messageReceived.getDouble("myString");
-
- TestUtil.logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("MapMessageConversionTopicTestsInvFormatString", e);
- }
- }
-
- /*
- * @testName: mapMessageTNotWritable
- *
- * @assertion_ids: JMS:SPEC:73; JMS:JAVADOC:806; JMS:JAVADOC:808;
- * JMS:JAVADOC:810; JMS:JAVADOC:812; JMS:JAVADOC:814; JMS:JAVADOC:816;
- * JMS:JAVADOC:818; JMS:JAVADOC:820; JMS:JAVADOC:822; JMS:JAVADOC:824;
- * JMS:JAVADOC:826; JMS:JAVADOC:829;
- *
- * @test_Strategy: Create a MapMessage, send it to a Topic Receive it and try
- * to write to the received Message's body, MessageNotWritableException should
- * be thrown.
- */
-
- public void mapMessageTNotWritable() throws Exception {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- boolean pass = true;
- byte bValue = 127;
- short sValue = 32767;
- char cValue = '\uFFFF';
- int iValue = 2147483647;
- long lValue = 9223372036854775807L;
- float fValue = 0.0f;
- double dValue = -0.0;
- String ssValue = "abc";
- byte[] bbValue = { 0, 88, 127 };
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageTNotWritable");
-
- // -----------------------------------------------------------------------------
- try {
- messageSent.setString("ssValue", ssValue);
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception was thrown: ", e);
- throw new Exception("Error: failed to setString", e);
- }
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- TestUtil.logMsg("Writing a boolean ... ");
- try {
- messageReceived.setBoolean("pass", pass);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBoolean");
- } catch (MessageNotWriteableException e) {
- TestUtil.logMsg(
- "Got Expected MessageNotWriteableException with setBoolean");
- }
-
- TestUtil.logMsg("Writing a byte ... ");
- try {
- messageReceived.setByte("bValue", bValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setByte");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setByte");
- }
-
- TestUtil.logMsg("Writing a short ... ");
- try {
- messageReceived.setShort("sValue", sValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setShort");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setShort");
- }
-
- TestUtil.logMsg("Writing a char ... ");
- try {
- messageReceived.setChar("cValue", cValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setChar");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setChar");
- }
-
- TestUtil.logMsg("Writing a int ... ");
- try {
- messageReceived.setInt("iValue", iValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setInt");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setInt");
- }
-
- TestUtil.logMsg("Writing a long ... ");
- try {
- messageReceived.setLong("lValue", lValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setLong");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setLong");
- }
-
- TestUtil.logMsg("Writing a float ... ");
- try {
- messageReceived.setFloat("fValue", fValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setFloat");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setFloat");
- }
-
- TestUtil.logMsg("Writing a double ... ");
- try {
- messageReceived.setDouble("dValue", dValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setDouble");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setDouble");
- }
-
- TestUtil.logMsg("Writing a bytes... ");
- try {
- messageReceived.setBytes("bbValue", bbValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBytes");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setBytes");
- }
-
- TestUtil.logMsg("Writing a bytes... ");
- try {
- messageReceived.setBytes("bbValue", bbValue, 0, 1);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBytes");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setBytes");
- }
-
- TestUtil.logMsg("Writing a string ... ");
- try {
- messageReceived.setString("ssValue", ssValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setString");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setString");
- }
-
- TestUtil.logMsg("Writing a object ... ");
- try {
- messageReceived.setObject("oValue", new Integer(iValue));
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setObject");
- } catch (MessageNotWriteableException e) {
- TestUtil
- .logMsg("Got Expected MessageNotWriteableException with setObject");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("mapMessageTNotWriteable", e);
- }
- }
-
- /*
- * @testName: mapMessageTIllegalarg
- *
- * @assertion_ids: JMS:JAVADOC:805; JMS:JAVADOC:807; JMS:JAVADOC:809;
- * JMS:JAVADOC:811; JMS:JAVADOC:813; JMS:JAVADOC:815; JMS:JAVADOC:817;
- * JMS:JAVADOC:819; JMS:JAVADOC:821; JMS:JAVADOC:823; JMS:JAVADOC:825;
- * JMS:JAVADOC:827;
- *
- * @test_Strategy: Create a MapMessage. Write to the message using each type
- * of set method and as an object with null String as name. Verify that
- * IllegalArgumentException thrown.
- */
-
- public void mapMessageTIllegalarg() throws Exception {
- try {
- MapMessage messageSent = null;
- boolean pass = true;
- byte bValue = 127;
- short sValue = 32767;
- char cValue = '\uFFFF';
- int iValue = 2147483647;
- long lValue = 9223372036854775807L;
- float fValue = 0.0f;
- double dValue = -0.0;
- String ssValue = "abc";
- byte[] bbValue = { 0, 88, 127 };
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- messageSent = tool.getDefaultTopicSession().createMapMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageTIllegalarg");
-
- // -----------------------------------------------------------------------------
-
- TestUtil.logMsg("Writing a boolean ... ");
- try {
- messageSent.setBoolean("", pass);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBoolean");
- } catch (IllegalArgumentException e) {
- TestUtil
- .logMsg("Got Expected IllegalArgumentException with setBoolean");
- }
-
- TestUtil.logMsg("Writing a byte ... ");
- try {
- messageSent.setByte("", bValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setByte");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setByte");
- }
-
- TestUtil.logMsg("Writing a short ... ");
- try {
- messageSent.setShort("", sValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setShort");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setShort");
- }
-
- TestUtil.logMsg("Writing a char ... ");
- try {
- messageSent.setChar("", cValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setChar");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setChar");
- }
-
- TestUtil.logMsg("Writing a int ... ");
- try {
- messageSent.setInt("", iValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setInt");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setInt");
- }
-
- TestUtil.logMsg("Writing a long ... ");
- try {
- messageSent.setLong("", lValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setLong");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setLong");
- }
-
- TestUtil.logMsg("Writing a float ... ");
- try {
- messageSent.setFloat("", fValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setFloat");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setFloat");
- }
- TestUtil.logMsg("Writing a double ... ");
- try {
- messageSent.setDouble("", dValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setDouble");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setDouble");
- }
-
- TestUtil.logMsg("Writing a bytes... ");
- try {
- messageSent.setBytes("", bbValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBytes");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setBytes");
- }
-
- TestUtil.logMsg("Writing a bytes... ");
- try {
- messageSent.setBytes("", bbValue, 0, 1);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBytes");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setBytes");
- }
-
- TestUtil.logMsg("Writing a string ... ");
- try {
- messageSent.setString("", ssValue);
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setString");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setString");
- }
-
- TestUtil.logMsg("Writing a object ... ");
- try {
- messageSent.setObject("", new Integer(iValue));
- TestUtil.logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setObject");
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Got Expected IllegalArgumentException with setObject");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("mapMessageTIllegalarg", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/mapMsgTopic/MapMsgTopicTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/mapMsgTopic/MapMsgTopicTestsIT.java
new file mode 100644
index 0000000000..921210cb00
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/mapMsgTopic/MapMsgTopicTestsIT.java
@@ -0,0 +1,3027 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.mapMsgTopic;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.MapMessage;
+import jakarta.jms.MessageFormatException;
+import jakarta.jms.MessageNotWriteableException;
+
+
+public class MapMsgTopicTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.mapMsgTopic.MapMsgTopicTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(MapMsgTopicTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList connections = null;
+
+ /* Run test in standalone mode */
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning: ", e);
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: mapMessageFullMsgTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:74; JMS:JAVADOC:211; JMS:JAVADOC:457;
+ * JMS:JAVADOC:459; JMS:JAVADOC:475; JMS:JAVADOC:477; JMS:JAVADOC:479;
+ * JMS:JAVADOC:461; JMS:JAVADOC:463; JMS:JAVADOC:465; JMS:JAVADOC:467;
+ * JMS:JAVADOC:469; JMS:JAVADOC:471; JMS:JAVADOC:473; JMS:JAVADOC:433;
+ * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:439; JMS:JAVADOC:441;
+ * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
+ * JMS:JAVADOC:451; JMS:JAVADOC:453;
+ *
+ * @test_Strategy: Create a MapMessage -. write to the message using each type
+ * of method and as an object. Send the message. Verify the data received was as
+ * sent.
+ *
+ *
+ */
+ @Test
+ public void mapMessageFullMsgTopicTest() throws Exception {
+ boolean pass = true;
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ short shortValue = 32767;
+ String stringValue = "Map Message Test";
+ Integer integerValue = Integer.valueOf(100);
+ String initial = "spring is here!";
+
+ try {
+ MapMessage messageSentMapMessage = null;
+ MapMessage messageReceivedMapMessage = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+
+ // send and receive map message to Topic
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Topic.");
+ messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageFullMsgTopicTest");
+ messageSentMapMessage.setBoolean("booleanValue", booleanValue);
+ messageSentMapMessage.setByte("byteValue", byteValue);
+ messageSentMapMessage.setBytes("bytesValue", bytesValue);
+ messageSentMapMessage.setBytes("bytesValue2", bytesValue, 0, 1);
+ messageSentMapMessage.setChar("charValue", charValue);
+ messageSentMapMessage.setDouble("doubleValue", doubleValue);
+ messageSentMapMessage.setFloat("floatValue", floatValue);
+ messageSentMapMessage.setInt("intValue", intValue);
+ messageSentMapMessage.setLong("longValue", longValue);
+ messageSentMapMessage.setObject("integerValue", integerValue);
+ messageSentMapMessage.setShort("shortValue", shortValue);
+ messageSentMapMessage.setString("stringValue", stringValue);
+ messageSentMapMessage.setString("nullTest", null);
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ try {
+ if (messageReceivedMapMessage.getBoolean("booleanValue") == booleanValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid boolean returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: invalid boolean returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.getByte("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid byte returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: invalid byte returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ byte[] b = messageReceivedMapMessage.getBytes("bytesValue");
+
+ for (int i = 0; i < b.length; i++) {
+ if (b[i] != bytesValue[i]) {
+ logger.log(Logger.Level.INFO, "Fail: byte array " + i + " not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte array " + i + " valid");
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ byte[] b = messageReceivedMapMessage.getBytes("bytesValue2");
+
+ if (b[0] != bytesValue[0]) {
+ logger.log(Logger.Level.INFO, "Fail: byte array not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte array valid");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.getChar("charValue") == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid char returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: invalid char returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.getDouble("doubleValue") == doubleValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid double returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: invalid double returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.getFloat("floatValue") == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid float returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: invalid float returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.getInt("intValue") == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid int returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: invalid int returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.getLong("longValue") == longValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid long returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: invalid long returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.getObject("integerValue").toString().equals(integerValue.toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: valid object returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: invalid object returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.getShort("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid short returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: invalid short returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.getString("stringValue").equals(stringValue)) {
+ logger.log(Logger.Level.TRACE, "Pass: valid string returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: invalid string returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceivedMapMessage.getString("nullTest") == null) {
+ logger.log(Logger.Level.TRACE, "Pass: null returned");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: null not returned from getString");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: mapMessageFullMsgTopicTest test failure");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("mapMessageFullMsgTopicTest");
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionTopicTestsBoolean
+ *
+ * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:457;
+ * JMS:JAVADOC:433; JMS:JAVADOC:449; JMS:JAVADOC:796; JMS:JAVADOC:797;
+ * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method writeBoolean to
+ * write a boolean to the message. Verify the proper conversion support as in
+ * 3.11.3
+ */
+ @Test
+ public void MapMessageConversionTopicTestsBoolean() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ boolean booleanValue = true;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionTopicTestsBoolean");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for boolean primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setBoolean("booleanValue", booleanValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // boolean to boolean - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a boolean");
+ try {
+ if (messageReceived.getBoolean("booleanValue") == booleanValue) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to boolean - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a boolean");
+ try {
+ if (messageReceived.getString("booleanValue").equals((Boolean.valueOf(booleanValue)).toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a boolean - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+ byte[] b = messageReceived.getBytes("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // boolean to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a boolean - expect MessageFormatException");
+ try {
+ byte b = messageReceived.getByte("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a boolean - expect MessageFormatException");
+ try {
+ short s = messageReceived.getShort("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a boolean - expect MessageFormatException");
+ try {
+ char c = messageReceived.getChar("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a boolean - expect MessageFormatException");
+ try {
+ int i = messageReceived.getInt("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a boolean - expect MessageFormatException");
+ try {
+ long l = messageReceived.getLong("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a boolean - expect MessageFormatException");
+ try {
+ float f = messageReceived.getFloat("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a boolean - expect MessageFormatException");
+ try {
+ double d = messageReceived.getDouble("booleanValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionTopicTestsBoolean", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionTopicTestsByte
+ *
+ * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:459;
+ * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443;
+ * JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:798; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setByte to write
+ * a byte. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionTopicTestsByte() throws Exception {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ byte byteValue = 127;
+ boolean pass = true;
+
+ try {
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionTopicTestsByte");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setByte("byteValue", byteValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // byte to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a byte - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("byteValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a byte");
+ try {
+ if (messageReceived.getString("byteValue").equals(Byte.toString(byteValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a byte - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+ byte[] b = messageReceived.getBytes("byteValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a byte");
+ try {
+ if (messageReceived.getByte("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to byte - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a byte");
+ try {
+ if (messageReceived.getShort("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to short - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a boolean - this is not valid");
+ try {
+ char c = messageReceived.getChar("byteValue");
+
+ pass = false;
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a byte");
+ try {
+ if (messageReceived.getInt("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to int - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a byte");
+ try {
+ if (messageReceived.getLong("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a boolean - this is not valid");
+ try {
+ float f = messageReceived.getFloat("byteValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a boolean - this is not valid");
+ try {
+ double d = messageReceived.getDouble("byteValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionTopicTestsByte", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionTopicTestsShort
+ *
+ * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:461;
+ * JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449;
+ * JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:798; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method writeShort to
+ * write a short. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionTopicTestsShort() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ short shortValue = 1;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionTopicTestsShort");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setShort("shortValue", shortValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // short to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a short - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("shortValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a short");
+ try {
+ if (messageReceived.getString("shortValue").equals(Short.toString(shortValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: short to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a short - expect MessageFormatException");
+ try {
+ byte[] b = messageReceived.getBytes("shortValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a short - this is not valid");
+ try {
+ byte b = messageReceived.getByte("shortValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a short");
+ try {
+ if (messageReceived.getShort("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to short - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a short - this is not valid");
+ try {
+ char c = messageReceived.getChar("shortValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a short");
+ try {
+ if (messageReceived.getInt("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to int - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a short");
+ try {
+ if (messageReceived.getLong("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a short - this is not valid");
+ try {
+ float f = messageReceived.getFloat("shortValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a short - this is not valid");
+ try {
+ double d = messageReceived.getDouble("shortValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionTopicTestsShort", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionTopicTestsChar
+ *
+ * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:463;
+ * JMS:JAVADOC:439; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method writeChar to
+ * write a char. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionTopicTestsChar() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ char charValue = 'a';
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionTopicTestsChar");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setChar("charValue", charValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // char to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a char - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a char");
+ try {
+ if (messageReceived.getString("charValue").equals(Character.valueOf(charValue).toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: char to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a char - expect MessageFormatException");
+ try {
+ byte[] b = messageReceived.getBytes("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a char - this is not valid");
+ try {
+ byte b = messageReceived.getByte("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a char");
+ try {
+ short s = messageReceived.getShort("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to char valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a char ");
+ try {
+ if (messageReceived.getChar("charValue") == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: char to char - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a char ");
+ try {
+ int i = messageReceived.getInt("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a char");
+ try {
+ long l = messageReceived.getLong("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a char - this is not valid");
+ try {
+ float f = messageReceived.getFloat("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a char - this is not valid");
+ try {
+ double d = messageReceived.getDouble("charValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionTopicTestsChar", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionTopicTestsInt
+ *
+ * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:465;
+ * JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795;
+ * JMS:JAVADOC:796; JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method writeInt to
+ * write an int. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionTopicTestsInt() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ int intValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionTopicTestsInt");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setInt("intValue", intValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // int to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read an int - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read an int");
+ try {
+ if (messageReceived.getString("intValue").equals(Integer.toString(intValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: int to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read an int - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+ byte[] b = messageReceived.getBytes("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read an int - this is not valid");
+ try {
+ byte b = messageReceived.getByte("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read an int");
+ try {
+ short s = messageReceived.getShort("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read an int - this is not valid");
+ try {
+ char c = messageReceived.getChar("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read an int");
+ try {
+ if (messageReceived.getInt("intValue") == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to int - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read an int");
+ try {
+ if (messageReceived.getLong("intValue") == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read an int - this is not valid");
+ try {
+ float f = messageReceived.getFloat("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read an int - this is not valid");
+ try {
+ double d = messageReceived.getDouble("intValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionTopicTestsInt", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionTopicTestsLong
+ *
+ * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:467;
+ * JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method writeLong to
+ * write a long. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionTopicTestsLong() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ long longValue = 2;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionTopicTestsLong");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setLong("longValue", longValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // long to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a long - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a long");
+ try {
+ if (messageReceived.getString("longValue").equals(Long.toString(longValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: long to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a long - expect MessageFormatException");
+ try {
+ byte[] b = messageReceived.getBytes("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read an long - this is not valid");
+ try {
+ byte b = messageReceived.getByte("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a long");
+ try {
+ short s = messageReceived.getShort("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a long - this is not valid");
+ try {
+ char c = messageReceived.getChar("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a long");
+ try {
+ int i = messageReceived.getInt("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a long");
+ try {
+ if (messageReceived.getLong("longValue") == longValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a long - this is not valid");
+ try {
+ float f = messageReceived.getFloat("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a long ");
+ try {
+ double d = messageReceived.getDouble("longValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionTopicTestsLong", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionTopicTestsFloat
+ *
+ * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:469;
+ * JMS:JAVADOC:445; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method writeFloat to
+ * write a float. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionTopicTestsFloat() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ float floatValue = 5;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionTopicTestsFloat");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setFloat("floatValue", floatValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // float to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a float ");
+ try {
+ boolean b = messageReceived.getBoolean("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a float");
+ try {
+ if (messageReceived.getString("floatValue").equals(Float.toString(floatValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: float to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a float ");
+ try {
+ byte[] b = messageReceived.getBytes("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a float ");
+ try {
+ byte b = messageReceived.getByte("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a float");
+ try {
+ short s = messageReceived.getShort("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a long ");
+ try {
+ char c = messageReceived.getChar("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a float");
+ try {
+ int i = messageReceived.getInt("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a long");
+ try {
+ long l = messageReceived.getLong("floatValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a float ");
+ try {
+ if (messageReceived.getFloat("floatValue") == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to float - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a float ");
+ try {
+ if (messageReceived.getDouble("floatValue") == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to double - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionTopicTestsFloat", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionTopicTestsDouble
+ *
+ * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:471;
+ * JMS:JAVADOC:447; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
+ * JMS:JAVADOC:801; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method writeDouble to
+ * write a double. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionTopicTestsDouble() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ double doubleValue = 3;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionTopicTestsDouble");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setDouble("doubleValue", doubleValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // double to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a double ");
+ try {
+ boolean b = messageReceived.getBoolean("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a double");
+ try {
+ if (messageReceived.getString("doubleValue").equals(Double.toString(doubleValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: double to string");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a double ");
+ try {
+ byte[] b = messageReceived.getBytes("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a double ");
+ try {
+ byte b = messageReceived.getByte("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a double");
+ try {
+ short s = messageReceived.getShort("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a double ");
+ try {
+ char c = messageReceived.getChar("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a double");
+ try {
+ int i = messageReceived.getInt("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a double");
+ try {
+ long l = messageReceived.getLong("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a double ");
+ try {
+ float f = messageReceived.getFloat("doubleValue");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read an float ");
+ try {
+ if (messageReceived.getDouble("doubleValue") == doubleValue) {
+ logger.log(Logger.Level.TRACE, "Pass: double to double ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionTopicTestsDouble", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionTopicTestsString
+ *
+ * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:JAVADOC:473;
+ * JMS:JAVADOC:433; JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441;
+ * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
+ * JMS:JAVADOC:798; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method writeString to
+ * write a string. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void MapMessageConversionTopicTestsString() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ boolean pass = true;
+ String myString = "10";
+ String myString2 = "true";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionTopicTestsString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setString("myString", myString);
+ messageSent.setString("myString2", myString2);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for String
+ // -----------------------------------------------
+ // string to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a String");
+ try {
+ if (messageReceived.getString("myString").equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: string to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a String");
+ try {
+ byte[] b = messageReceived.getBytes("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a String");
+ try {
+ if (messageReceived.getByte("myString") == Byte.parseByte(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to byte ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a string");
+ try {
+ if (messageReceived.getShort("myString") == Short.parseShort(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to short ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a String ");
+ try {
+ char c = messageReceived.getChar("myString");
+
+ logger.log(Logger.Level.TRACE, "getChar returned " + c);
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // string to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a String");
+ try {
+ if (messageReceived.getInt("myString") == Integer.parseInt(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to int ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a String");
+ try {
+ if (messageReceived.getLong("myString") == Long.parseLong(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to long ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a String");
+ try {
+ if (messageReceived.getFloat("myString") == Float.parseFloat(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to float ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a String");
+ try {
+ if (messageReceived.getDouble("myString") == Double.parseDouble(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to double ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a string ");
+ try {
+ if (messageReceived.getBoolean("myString2") == Boolean.valueOf(myString2).booleanValue()) {
+ logger.log(Logger.Level.TRACE, "Pass: String to boolean ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a string that is not true");
+ try {
+ boolean b = messageReceived.getBoolean("myString");
+
+ if (b != false) {
+ logger.log(Logger.Level.INFO, "Fail: !true should have returned false");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: !true returned false");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionTopicTestsString", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionTopicTestsBytes
+ *
+ * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:475;
+ * JMS:JAVADOC:451; JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:797;
+ * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:803;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method writeBytes to
+ * write a byte[] to the message. Verify the proper conversion support as in
+ * 3.11.3
+ */
+ @Test
+ public void MapMessageConversionTopicTestsBytes() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ byte[] byteValues = { 1, 2, 3 };
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionTopicTestsBytes");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte[] primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setBytes("byteValues", byteValues);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // byte[] to byte[] - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBytes[] to read a byte[] ");
+ try {
+ byte[] b = messageReceived.getBytes("byteValues");
+
+ for (int i = 0; i < b.length; i++) {
+ if (b[i] != byteValues[i]) {
+ logger.log(Logger.Level.INFO, "Fail: byte[] value returned is invalid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte[] returned is valid");
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getBoolean to read a byte[]");
+ try {
+ boolean b = messageReceived.getBoolean("byteValues");
+
+ logger.log(Logger.Level.INFO,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to string invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getString to read a byte[]");
+ try {
+ String s = messageReceived.getString("byteValues");
+
+ logger.log(Logger.Level.INFO,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a byte[] - expect MessageFormatException");
+ try {
+ byte b = messageReceived.getByte("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a byte[] - expect MessageFormatException");
+ try {
+ short s = messageReceived.getShort("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getChar to read a byte[] - expect MessageFormatException");
+ try {
+ char c = messageReceived.getChar("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a byte[] - expect MessageFormatException");
+ try {
+ int i = messageReceived.getInt("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a byte[] - expect MessageFormatException");
+ try {
+ long l = messageReceived.getLong("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a byte[] - expect MessageFormatException");
+ try {
+ float f = messageReceived.getFloat("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a byte[] - expect MessageFormatException");
+ try {
+ double d = messageReceived.getDouble("byteValues");
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionTopicTestsBytes", e);
+ }
+ }
+
+ /*
+ * @testName: MapMessageConversionTopicTestsInvFormatString
+ *
+ * @assertion_ids: JMS:SPEC:76;
+ *
+ * @test_Strategy: Create a MapMessage -. use MapMessage method setString to
+ * write a text string of "mytest string". Verify NumberFormatException is
+ * thrown
+ *
+ */
+ @Test
+ public void MapMessageConversionTopicTestsInvFormatString() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ boolean pass = true;
+ String myString = "mytest string";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionTopicTestsInvFormatString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.setString("myString", myString);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // -----------------------------------------------
+ // String to byte
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getByte to read a String that is not valid ");
+ try {
+ byte b = messageReceived.getByte("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: java.lang.NumberFormatException expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to short
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getShort to read a string that is not valid ");
+ try {
+ short s = messageReceived.getShort("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to int
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getInt to read a String that is not valid ");
+ try {
+ int i = messageReceived.getInt("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getLong to read a String that is not valid ");
+ try {
+ long l = messageReceived.getLong("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getFloat to read a String that is not valid ");
+ try {
+ float f = messageReceived.getFloat("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to double
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use getDouble to read a String that is not valid ");
+ try {
+ double d = messageReceived.getDouble("myString");
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("MapMessageConversionTopicTestsInvFormatString", e);
+ }
+ }
+
+ /*
+ * @testName: mapMessageTNotWritable
+ *
+ * @assertion_ids: JMS:SPEC:73; JMS:JAVADOC:806; JMS:JAVADOC:808;
+ * JMS:JAVADOC:810; JMS:JAVADOC:812; JMS:JAVADOC:814; JMS:JAVADOC:816;
+ * JMS:JAVADOC:818; JMS:JAVADOC:820; JMS:JAVADOC:822; JMS:JAVADOC:824;
+ * JMS:JAVADOC:826; JMS:JAVADOC:829;
+ *
+ * @test_Strategy: Create a MapMessage, send it to a Topic Receive it and try to
+ * write to the received Message's body, MessageNotWritableException should be
+ * thrown.
+ */
+ @Test
+ public void mapMessageTNotWritable() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ boolean pass = true;
+ byte bValue = 127;
+ short sValue = 32767;
+ char cValue = '\uFFFF';
+ int iValue = 2147483647;
+ long lValue = 9223372036854775807L;
+ float fValue = 0.0f;
+ double dValue = -0.0;
+ String ssValue = "abc";
+ byte[] bbValue = { 0, 88, 127 };
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageTNotWritable");
+
+ // -----------------------------------------------------------------------------
+ try {
+ messageSent.setString("ssValue", ssValue);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception was thrown: ", e);
+ throw new Exception("Error: failed to setString", e);
+ }
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ logger.log(Logger.Level.INFO, "Writing a boolean ... ");
+ try {
+ messageReceived.setBoolean("pass", pass);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBoolean");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setBoolean");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a byte ... ");
+ try {
+ messageReceived.setByte("bValue", bValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setByte");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setByte");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a short ... ");
+ try {
+ messageReceived.setShort("sValue", sValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setShort");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setShort");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a char ... ");
+ try {
+ messageReceived.setChar("cValue", cValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setChar");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setChar");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a int ... ");
+ try {
+ messageReceived.setInt("iValue", iValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setInt");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setInt");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a long ... ");
+ try {
+ messageReceived.setLong("lValue", lValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setLong");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setLong");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a float ... ");
+ try {
+ messageReceived.setFloat("fValue", fValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setFloat");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setFloat");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a double ... ");
+ try {
+ messageReceived.setDouble("dValue", dValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setDouble");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setDouble");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageReceived.setBytes("bbValue", bbValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBytes");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageReceived.setBytes("bbValue", bbValue, 0, 1);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBytes");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a string ... ");
+ try {
+ messageReceived.setString("ssValue", ssValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setString");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setString");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a object ... ");
+ try {
+ messageReceived.setObject("oValue", new Integer(iValue));
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setObject");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with setObject");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("mapMessageTNotWriteable", e);
+ }
+ }
+
+ /*
+ * @testName: mapMessageTIllegalarg
+ *
+ * @assertion_ids: JMS:JAVADOC:805; JMS:JAVADOC:807; JMS:JAVADOC:809;
+ * JMS:JAVADOC:811; JMS:JAVADOC:813; JMS:JAVADOC:815; JMS:JAVADOC:817;
+ * JMS:JAVADOC:819; JMS:JAVADOC:821; JMS:JAVADOC:823; JMS:JAVADOC:825;
+ * JMS:JAVADOC:827;
+ *
+ * @test_Strategy: Create a MapMessage. Write to the message using each type of
+ * set method and as an object with null String as name. Verify that
+ * IllegalArgumentException thrown.
+ */
+ @Test
+ public void mapMessageTIllegalarg() throws Exception {
+ try {
+ MapMessage messageSent = null;
+ boolean pass = true;
+ byte bValue = 127;
+ short sValue = 32767;
+ char cValue = '\uFFFF';
+ int iValue = 2147483647;
+ long lValue = 9223372036854775807L;
+ float fValue = 0.0f;
+ double dValue = -0.0;
+ String ssValue = "abc";
+ byte[] bbValue = { 0, 88, 127 };
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ messageSent = tool.getDefaultTopicSession().createMapMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageTIllegalarg");
+
+ // -----------------------------------------------------------------------------
+
+ logger.log(Logger.Level.INFO, "Writing a boolean ... ");
+ try {
+ messageSent.setBoolean("", pass);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBoolean");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setBoolean");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a byte ... ");
+ try {
+ messageSent.setByte("", bValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setByte");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setByte");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a short ... ");
+ try {
+ messageSent.setShort("", sValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setShort");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setShort");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a char ... ");
+ try {
+ messageSent.setChar("", cValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setChar");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setChar");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a int ... ");
+ try {
+ messageSent.setInt("", iValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setInt");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setInt");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a long ... ");
+ try {
+ messageSent.setLong("", lValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setLong");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setLong");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a float ... ");
+ try {
+ messageSent.setFloat("", fValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setFloat");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setFloat");
+ }
+ logger.log(Logger.Level.INFO, "Writing a double ... ");
+ try {
+ messageSent.setDouble("", dValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setDouble");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setDouble");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageSent.setBytes("", bbValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBytes");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageSent.setBytes("", bbValue, 0, 1);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBytes");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a string ... ");
+ try {
+ messageSent.setString("", ssValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setString");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setString");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a object ... ");
+ try {
+ messageSent.setObject("", new Integer(iValue));
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setObject");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setObject");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("mapMessageTIllegalarg", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/messageProducer/MessageProducerTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/messageProducer/MessageProducerTests.java
deleted file mode 100644
index ca8ad37f93..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/messageProducer/MessageProducerTests.java
+++ /dev/null
@@ -1,495 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.messageProducer;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.DeliveryMode;
-import jakarta.jms.Message;
-import jakarta.jms.MessageProducer;
-import jakarta.jms.Queue;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-
-public class MessageProducerTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.messageProducer.MessageProducerTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // Harness req's
- private Properties props = null;
-
- // JMS object
- private transient JmsTool tool = null;
-
- // properties read from ts.jte file
- long timeout;
-
- private String jmsUser;
-
- private String jmsPassword;
-
- private String mode;
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- MessageProducerTests theTests = new MessageProducerTests();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * @class.setup_props: jms_timeout;user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- logTrace("In setup");
- // get props
- jmsUser = p.getProperty("user");
- jmsPassword = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /*
- * cleanup() is called after each test
- */
- public void cleanup() throws Exception {
-
- if (tool != null) {
- try {
- if (tool.getDefaultConnection() != null) {
- TestUtil.logTrace("Closing default Connection");
- tool.getDefaultConnection().close();
- }
- } catch (Exception e) {
- TestUtil.logErr("Error closing Connection in cleanup: ", e);
- }
- }
- }
-
- private void flushTheQueue() throws Exception {
- try {
- if (tool != null)
- if (tool.getDefaultConnection() != null)
- cleanup();
-
- tool = new JmsTool(JmsTool.COMMON_Q, jmsUser, jmsPassword, mode);
-
- TestUtil.logTrace("Closing default Connection");
- tool.getDefaultConnection().close();
- } catch (Exception e) {
- TestUtil.logErr("Error closing connection and creating JmsTool: ", e);
- } finally {
- try {
- tool.flushDestination();
- } catch (Exception e) {
- TestUtil.logErr("Error flush Destination: ", e);
- }
- }
- }
-
- /*
- * @testName: sendQueueTest1
- *
- * @assertion_ids: JMS:JAVADOC:321; JMS:SPEC:253;
- *
- * @test_Strategy: Send and receive single message using
- * MessageProducer.send(Destination, Message) and
- * MessageConsumer.receive(long). Verify message receipt.
- */
-
- public void sendQueueTest1() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- String testName = "sendQueueTest1";
- String testMessage = "Just a test from sendQueueTest1";
- boolean pass = true;
- MessageProducer msgproducer = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, jmsUser, jmsPassword, mode);
- tool.getDefaultProducer().close();
- msgproducer = tool.getDefaultSession().createProducer((Queue) null);
- tool.getDefaultConnection().start();
-
- logMsg("Creating 1 message");
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText(testMessage);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
-
- logMsg("Sending message");
- msgproducer.send(tool.getDefaultDestination(), messageSent);
-
- logMsg("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultConsumer()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("didn't get any message");
- }
-
- // Check to see if correct message received
- if (!messageReceived.getText().equals(messageSent.getText())) {
- throw new Exception("didn't get the right message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- } finally {
- try {
- flushTheQueue();
- } catch (Exception e) {
- TestUtil.logErr("Error flushing Queue", e);
- }
- }
- }
-
- /*
- * @testName: sendQueueTest2
- *
- * @assertion_ids: JMS:JAVADOC:323; JMS:SPEC:253;
- *
- * @test_Strategy: Send and receive single message using
- * MessageProducer.send(Destination, Message, int, int, long) and
- * MessageConsumer.receive(long). Verify message receipt.
- */
-
- public void sendQueueTest2() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- String testName = "sendQueueTest2";
- String testMessage = "Just a test from sendQueueTest2";
- boolean pass = true;
- MessageProducer msgproducer = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, jmsUser, jmsPassword, mode);
- tool.getDefaultProducer().close();
- msgproducer = tool.getDefaultSession().createProducer((Queue) null);
- tool.getDefaultConnection().start();
-
- logMsg("Creating 1 message");
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText(testMessage);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
-
- logMsg("Sending message");
- msgproducer.send(tool.getDefaultDestination(), messageSent,
- DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY - 1, 0L);
-
- logMsg("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultConsumer()
- .receive(timeout);
- if (messageReceived == null) {
- logErr("didn't get any message");
- pass = false;
- } else if (!messageReceived.getText().equals(messageSent.getText())
- || messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
- || messageReceived
- .getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)) {
- pass = false;
- logErr("didn't get the right message.");
- logErr("text =" + messageReceived.getText());
- logErr("DeliveryMode =" + messageReceived.getJMSDeliveryMode());
- logErr("Priority =" + messageReceived.getJMSPriority());
- }
-
- if (!pass)
- throw new Exception(testName + " falied");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- } finally {
- try {
- flushTheQueue();
- } catch (Exception e) {
- TestUtil.logErr("Error flushing Queue", e);
- }
- }
- }
-
- /*
- * @testName: sendQueueTest3
- *
- * @assertion_ids: JMS:JAVADOC:319; JMS:JAVADOC:313; JMS:SPEC:253;
- *
- * @test_Strategy: Send and receive single message using
- * MessageProducer.send(Message, int, int, long) and
- * MessageConsumer.receive(long). Verify message receipt.
- */
-
- public void sendQueueTest3() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- String testName = "sendQueueTest3";
- String testMessage = "Just a test from sendQueueTest3";
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, jmsUser, jmsPassword, mode);
- tool.getDefaultConnection().start();
-
- if (!((Queue) tool.getDefaultProducer().getDestination()).getQueueName()
- .equals(((Queue) tool.getDefaultDestination()).getQueueName())) {
- pass = false;
- logErr("getDestination test failed: "
- + ((Queue) tool.getDefaultProducer().getDestination())
- .getQueueName());
- }
-
- logMsg("Creating 1 message");
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText(testMessage);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
-
- logMsg("Sending message");
- tool.getDefaultProducer().send(messageSent, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY - 1, 0L);
-
- logMsg("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultConsumer()
- .receive(timeout);
- if (messageReceived == null) {
- logErr("didn't get any message");
- pass = false;
- } else if (!messageReceived.getText().equals(messageSent.getText())
- || messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
- || messageReceived
- .getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)) {
- pass = false;
- logErr("didn't get the right message.");
- logErr("text =" + messageReceived.getText());
- logErr("DeliveryMode =" + messageReceived.getJMSDeliveryMode());
- logErr("Priority =" + messageReceived.getJMSPriority());
- }
-
- if (!pass)
- throw new Exception(testName + " falied");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- } finally {
- try {
- flushTheQueue();
- } catch (Exception e) {
- TestUtil.logErr("Error flushing Queue", e);
- }
- }
- }
-
- /*
- * @testName: sendTopicTest4
- *
- * @assertion_ids: JMS:JAVADOC:321; JMS:SPEC:253;
- *
- * @test_Strategy: Send and receive single message using
- * MessageProducer.send(Destination, Message) and
- * MessageConsumer.receive(long). Verify message receipt.
- */
-
- public void sendTopicTest4() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- String testName = "sendTopicTest4";
- String testMessage = "Just a test from sendTopicTest4";
- boolean pass = true;
- MessageProducer msgproducer = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, mode);
- tool.getDefaultProducer().close();
- msgproducer = tool.getDefaultSession().createProducer((Topic) null);
- tool.getDefaultConnection().start();
-
- logMsg("Creating 1 message");
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText(testMessage);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
-
- logMsg("Sending message");
- msgproducer.send(tool.getDefaultDestination(), messageSent);
-
- logMsg("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultConsumer()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("didn't get any message");
- }
-
- // Check to see if correct message received
- if (!messageReceived.getText().equals(messageSent.getText())) {
- throw new Exception("didn't get the right message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
-
- }
-
- /*
- * @testName: sendTopicTest5
- *
- * @assertion_ids: JMS:JAVADOC:323; JMS:SPEC:253;
- *
- * @test_Strategy: Send and receive single message using
- * MessageProducer.send(Destination, Message, int, int, long). and
- * MessageConsumer.receive(long). Verify message receipt.
- */
-
- public void sendTopicTest5() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- String testName = "sendTopicTest5";
- String testMessage = "Just a test from sendTopicTest5";
- boolean pass = true;
- MessageProducer msgproducer = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, mode);
- tool.getDefaultProducer().close();
- msgproducer = tool.getDefaultSession().createProducer((Topic) null);
- tool.getDefaultConnection().start();
-
- logMsg("Creating 1 message");
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText(testMessage);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
-
- logMsg("Sending message");
- msgproducer.send(tool.getDefaultDestination(), messageSent,
- DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY - 1, 0L);
-
- logMsg("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultConsumer()
- .receive(timeout);
- if (messageReceived == null) {
- logErr("didn't get any message");
- pass = false;
- } else if (!messageReceived.getText().equals(messageSent.getText())
- || messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
- || messageReceived
- .getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)) {
- pass = false;
- logErr("didn't get the right message.");
- logErr("text =" + messageReceived.getText());
- logErr("DeliveryMode =" + messageReceived.getJMSDeliveryMode());
- logErr("Priority =" + messageReceived.getJMSPriority());
- }
-
- if (!pass)
- throw new Exception(testName + " falied");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
- }
-
- /*
- * @testName: sendTopicTest6
- *
- * @assertion_ids: JMS:JAVADOC:319; JMS:JAVADOC:313; JMS:SPEC:253;
- *
- * @test_Strategy: Send and receive single message using
- * MessageProducer.send(Message, int, int, long) and
- * MessageConsumer.receive(long). Verify message receipt.
- */
-
- public void sendTopicTest6() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- String testName = "sendTopicTest6";
- String testMessage = "Just a test from sendTopicTest6";
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, mode);
- tool.getDefaultConnection().start();
-
- if (!((Topic) tool.getDefaultProducer().getDestination()).getTopicName()
- .equals(((Topic) tool.getDefaultDestination()).getTopicName())) {
- pass = false;
- logErr("getDestination test failed: "
- + ((Topic) tool.getDefaultProducer().getDestination())
- .getTopicName());
- }
-
- logMsg("Creating 1 message");
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText(testMessage);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
-
- logMsg("Sending message");
- tool.getDefaultProducer().send(messageSent, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY - 1, 0L);
-
- logMsg("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultConsumer()
- .receive(timeout);
- if (messageReceived == null) {
- logErr("didn't get any message");
- pass = false;
- } else if (!messageReceived.getText().equals(messageSent.getText())
- || messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
- || messageReceived
- .getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)) {
- pass = false;
- logErr("didn't get the right message.");
- logErr("text =" + messageReceived.getText());
- logErr("DeliveryMode =" + messageReceived.getJMSDeliveryMode());
- logErr("Priority =" + messageReceived.getJMSPriority());
- }
-
- if (!pass)
- throw new Exception(testName + " falied");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/messageProducer/MessageProducerTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/messageProducer/MessageProducerTestsIT.java
new file mode 100644
index 0000000000..dbfa29f3b8
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/messageProducer/MessageProducerTestsIT.java
@@ -0,0 +1,478 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.messageProducer;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.DeliveryMode;
+import jakarta.jms.Message;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Queue;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+
+
+public class MessageProducerTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.messageProducer.MessageProducerTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(MessageProducerTestsIT.class.getName());
+
+ // Harness req's
+ private Properties props = null;
+
+ // JMS object
+ private transient JmsTool tool = null;
+
+ // properties read
+ long timeout;
+
+ private String jmsUser;
+
+ private String jmsPassword;
+
+ private String mode;
+
+ /* Test setup: */
+
+ /*
+ * @class.setup_props: jms_timeout;user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, "In setup");
+ // get props
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /*
+ * cleanup() is called after each test
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+
+ if (tool != null) {
+ try {
+ if (tool.getDefaultConnection() != null) {
+ logger.log(Logger.Level.TRACE, "Closing default Connection");
+ tool.getDefaultConnection().close();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection in cleanup: ", e);
+ }
+ }
+ }
+
+ private void flushTheQueue() throws Exception {
+ try {
+ if (tool != null)
+ if (tool.getDefaultConnection() != null)
+ cleanup();
+
+ tool = new JmsTool(JmsTool.COMMON_Q, jmsUser, jmsPassword, mode);
+
+ logger.log(Logger.Level.TRACE, "Closing default Connection");
+ tool.getDefaultConnection().close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing connection and creating JmsTool: ", e);
+ } finally {
+ try {
+ tool.flushDestination();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error flush Destination: ", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: sendQueueTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:321; JMS:SPEC:253;
+ *
+ * @test_Strategy: Send and receive single message using
+ * MessageProducer.send(Destination, Message) and MessageConsumer.receive(long).
+ * Verify message receipt.
+ */
+ @Test
+ public void sendQueueTest1() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ String testName = "sendQueueTest1";
+ String testMessage = "Just a test from sendQueueTest1";
+ boolean pass = true;
+ MessageProducer msgproducer = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, jmsUser, jmsPassword, mode);
+ tool.getDefaultProducer().close();
+ msgproducer = tool.getDefaultSession().createProducer((Queue) null);
+ tool.getDefaultConnection().start();
+
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText(testMessage);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+
+ logger.log(Logger.Level.INFO, "Sending message");
+ msgproducer.send(tool.getDefaultDestination(), messageSent);
+
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultConsumer().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("didn't get any message");
+ }
+
+ // Check to see if correct message received
+ if (!messageReceived.getText().equals(messageSent.getText())) {
+ throw new Exception("didn't get the right message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ } finally {
+ try {
+ flushTheQueue();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error flushing Queue", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: sendQueueTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:323; JMS:SPEC:253;
+ *
+ * @test_Strategy: Send and receive single message using
+ * MessageProducer.send(Destination, Message, int, int, long) and
+ * MessageConsumer.receive(long). Verify message receipt.
+ */
+ @Test
+ public void sendQueueTest2() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ String testName = "sendQueueTest2";
+ String testMessage = "Just a test from sendQueueTest2";
+ boolean pass = true;
+ MessageProducer msgproducer = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, jmsUser, jmsPassword, mode);
+ tool.getDefaultProducer().close();
+ msgproducer = tool.getDefaultSession().createProducer((Queue) null);
+ tool.getDefaultConnection().start();
+
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText(testMessage);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+
+ logger.log(Logger.Level.INFO, "Sending message");
+ msgproducer.send(tool.getDefaultDestination(), messageSent, DeliveryMode.NON_PERSISTENT,
+ Message.DEFAULT_PRIORITY - 1, 0L);
+
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultConsumer().receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "didn't get any message");
+ pass = false;
+ } else if (!messageReceived.getText().equals(messageSent.getText())
+ || messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
+ || messageReceived.getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "didn't get the right message.");
+ logger.log(Logger.Level.ERROR, "text =" + messageReceived.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode =" + messageReceived.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority =" + messageReceived.getJMSPriority());
+ }
+
+ if (!pass)
+ throw new Exception(testName + " falied");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ } finally {
+ try {
+ flushTheQueue();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error flushing Queue", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: sendQueueTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:319; JMS:JAVADOC:313; JMS:SPEC:253;
+ *
+ * @test_Strategy: Send and receive single message using
+ * MessageProducer.send(Message, int, int, long) and
+ * MessageConsumer.receive(long). Verify message receipt.
+ */
+ @Test
+ public void sendQueueTest3() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ String testName = "sendQueueTest3";
+ String testMessage = "Just a test from sendQueueTest3";
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, jmsUser, jmsPassword, mode);
+ tool.getDefaultConnection().start();
+
+ if (!((Queue) tool.getDefaultProducer().getDestination()).getQueueName()
+ .equals(((Queue) tool.getDefaultDestination()).getQueueName())) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "getDestination test failed: "
+ + ((Queue) tool.getDefaultProducer().getDestination()).getQueueName());
+ }
+
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText(testMessage);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultProducer().send(messageSent, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY - 1, 0L);
+
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultConsumer().receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "didn't get any message");
+ pass = false;
+ } else if (!messageReceived.getText().equals(messageSent.getText())
+ || messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
+ || messageReceived.getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "didn't get the right message.");
+ logger.log(Logger.Level.ERROR, "text =" + messageReceived.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode =" + messageReceived.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority =" + messageReceived.getJMSPriority());
+ }
+
+ if (!pass)
+ throw new Exception(testName + " falied");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ } finally {
+ try {
+ flushTheQueue();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error flushing Queue", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: sendTopicTest4
+ *
+ * @assertion_ids: JMS:JAVADOC:321; JMS:SPEC:253;
+ *
+ * @test_Strategy: Send and receive single message using
+ * MessageProducer.send(Destination, Message) and MessageConsumer.receive(long).
+ * Verify message receipt.
+ */
+ @Test
+ public void sendTopicTest4() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ String testName = "sendTopicTest4";
+ String testMessage = "Just a test from sendTopicTest4";
+ boolean pass = true;
+ MessageProducer msgproducer = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, mode);
+ tool.getDefaultProducer().close();
+ msgproducer = tool.getDefaultSession().createProducer((Topic) null);
+ tool.getDefaultConnection().start();
+
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText(testMessage);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+
+ logger.log(Logger.Level.INFO, "Sending message");
+ msgproducer.send(tool.getDefaultDestination(), messageSent);
+
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultConsumer().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("didn't get any message");
+ }
+
+ // Check to see if correct message received
+ if (!messageReceived.getText().equals(messageSent.getText())) {
+ throw new Exception("didn't get the right message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+
+ }
+
+ /*
+ * @testName: sendTopicTest5
+ *
+ * @assertion_ids: JMS:JAVADOC:323; JMS:SPEC:253;
+ *
+ * @test_Strategy: Send and receive single message using
+ * MessageProducer.send(Destination, Message, int, int, long). and
+ * MessageConsumer.receive(long). Verify message receipt.
+ */
+ @Test
+ public void sendTopicTest5() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ String testName = "sendTopicTest5";
+ String testMessage = "Just a test from sendTopicTest5";
+ boolean pass = true;
+ MessageProducer msgproducer = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, mode);
+ tool.getDefaultProducer().close();
+ msgproducer = tool.getDefaultSession().createProducer((Topic) null);
+ tool.getDefaultConnection().start();
+
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText(testMessage);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+
+ logger.log(Logger.Level.INFO, "Sending message");
+ msgproducer.send(tool.getDefaultDestination(), messageSent, DeliveryMode.NON_PERSISTENT,
+ Message.DEFAULT_PRIORITY - 1, 0L);
+
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultConsumer().receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "didn't get any message");
+ pass = false;
+ } else if (!messageReceived.getText().equals(messageSent.getText())
+ || messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
+ || messageReceived.getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "didn't get the right message.");
+ logger.log(Logger.Level.ERROR, "text =" + messageReceived.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode =" + messageReceived.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority =" + messageReceived.getJMSPriority());
+ }
+
+ if (!pass)
+ throw new Exception(testName + " falied");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+ }
+
+ /*
+ * @testName: sendTopicTest6
+ *
+ * @assertion_ids: JMS:JAVADOC:319; JMS:JAVADOC:313; JMS:SPEC:253;
+ *
+ * @test_Strategy: Send and receive single message using
+ * MessageProducer.send(Message, int, int, long) and
+ * MessageConsumer.receive(long). Verify message receipt.
+ */
+ @Test
+ public void sendTopicTest6() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ String testName = "sendTopicTest6";
+ String testMessage = "Just a test from sendTopicTest6";
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, mode);
+ tool.getDefaultConnection().start();
+
+ if (!((Topic) tool.getDefaultProducer().getDestination()).getTopicName()
+ .equals(((Topic) tool.getDefaultDestination()).getTopicName())) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "getDestination test failed: "
+ + ((Topic) tool.getDefaultProducer().getDestination()).getTopicName());
+ }
+
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText(testMessage);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultProducer().send(messageSent, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY - 1, 0L);
+
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultConsumer().receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "didn't get any message");
+ pass = false;
+ } else if (!messageReceived.getText().equals(messageSent.getText())
+ || messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
+ || messageReceived.getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "didn't get the right message.");
+ logger.log(Logger.Level.ERROR, "text =" + messageReceived.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode =" + messageReceived.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority =" + messageReceived.getJMSPriority());
+ }
+
+ if (!pass)
+ throw new Exception(testName + " falied");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/messageQueue/MessageQueueTest.java b/jms/src/main/java/com/sun/ts/tests/jms/core/messageQueue/MessageQueueTest.java
deleted file mode 100644
index ea77dfdd20..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/messageQueue/MessageQueueTest.java
+++ /dev/null
@@ -1,741 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.messageQueue;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.MapMessage;
-import jakarta.jms.MessageNotWriteableException;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-
-public class MessageQueueTest extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.messageQueue.MessageQueueTest";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- MessageQueueTest theTests = new MessageQueueTest();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'numProducers' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(2);
- connections = new ArrayList(5);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: msgClearBodyQueueTest
- *
- * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
- * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291; JMS:JAVADOC:680;
- * JMS:JAVADOC:744;
- *
- * @test_Strategy: For each type of message, create and send a message Send
- * and receive single Text, map, bytes, stream, and object message call
- * clearBody, verify body is empty after clearBody. verify properties are not
- * effected by clearBody. Write to the message again 3.11
- */
-
- public void msgClearBodyQueueTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- byte bValue2 = 22;
- String id = null;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentStreamMessage = null;
- StreamMessage messageReceivedStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- BytesMessage messageReceivedBytesMessage = null;
- MapMessage messageReceivedMapMessage = null;
- MapMessage messageSentMapMessage = null;
- ObjectMessage messageSentObjectMsg = null;
- ObjectMessage messageReceivedObjectMsg = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- // send and receive Object message to Queue
- logTrace("Send ObjectMessage to Queue.");
- messageSentObjectMsg = tool.getDefaultQueueSession()
- .createObjectMessage();
- messageSentObjectMsg.setObject("Initial message");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgClearBodyQueueTest");
- tool.getDefaultQueueSender().send(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- try {
- logTrace("Testing Object message");
- logTrace("read 1st contents");
- logTrace(" " + messageReceivedObjectMsg.getObject());
- logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedObjectMsg.clearBody();
-
- // message body should now be empty
- if (messageReceivedObjectMsg.getObject() == null) {
- logTrace("Empty body after clearBody as expected: null");
- } else {
- logTrace("Fail: message body was not empty");
- pass = false;
- }
-
- // properties should not have been deleted by the clearBody method.
- if (messageSentObjectMsg.getStringProperty("COM_SUN_JMS_TESTNAME")
- .equals("msgClearBodyQueueTest")) {
- logTrace("Pass: Object properties read ok after clearBody called");
- } else {
- logMsg("Fail: Object properties cleared after clearBody called");
- pass = false;
- }
- logTrace("write 2nd contents");
- messageReceivedObjectMsg.setObject("new stuff here!!!!!!");
- logTrace("read 2nd contents");
- if (messageReceivedObjectMsg.getObject()
- .equals("new stuff here!!!!!!")) {
- logTrace("Pass:");
- } else {
- logMsg("Fail: ");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // send and receive map message to Queue
- logTrace("Send MapMessage to Queue.");
- messageSentMapMessage = tool.getDefaultQueueSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgClearBodyQueueTest");
- messageSentMapMessage.setString("aString", "Initial message");
- tool.getDefaultQueueSender().send(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- try {
- logTrace("Test for MapMessage ");
- logTrace("read 1st contents");
- logTrace(" " + messageReceivedMapMessage.getString("aString"));
- logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedMapMessage.clearBody();
-
- // message body should now be empty
- if (messageReceivedMapMessage.getString("aString") == null) {
- logTrace("Empty body after clearBody as expected: null");
- } else {
- logTrace("Fail: message body was not empty");
- pass = false;
- }
-
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedMapMessage.getStringProperty("COM_SUN_JMS_TESTNAME")
- .equals("msgClearBodyQueueTest")) {
- logTrace("Pass: Map properties read ok after clearBody called");
- } else {
- logMsg("Fail: Map properties cleared after clearBody called");
- pass = false;
- }
- logTrace("write 2nd contents");
- messageReceivedMapMessage.setString("yes", "new stuff !!!!!");
- logTrace("read 2nd contents");
- if (messageReceivedMapMessage.getString("yes")
- .equals("new stuff !!!!!")) {
- logTrace("PASS:");
- } else {
- logMsg("FAIL:");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // send and receive bytes message to Queue
- logTrace("Send BytesMessage to Queue.");
- messageSentBytesMessage = tool.getDefaultQueueSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgClearBodyQueueTest");
- messageSentBytesMessage.writeByte(bValue);
- tool.getDefaultQueueSender().send(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultQueueReceiver().receive(timeout);
- try {
- logTrace("Test BytesMessage ");
- logTrace("read 1st contents");
- logTrace(" " + messageReceivedBytesMessage.readByte());
- logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedBytesMessage.clearBody();
- logTrace(
- "Bytes message body should now be empty and in writeonly mode");
- try {
- byte b = messageReceivedBytesMessage.readByte();
-
- logTrace("Fail: MessageNotReadableException not thrown as expected");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageNotReadableException) {
- logTrace("Pass: MessageEOFException thrown as expected");
- } else {
- logMsg("Error: Unexpected exception " + e.getClass().getName()
- + " was thrown");
- pass = false;
- }
- }
-
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedBytesMessage
- .getStringProperty("COM_SUN_JMS_TESTNAME")
- .equals("msgClearBodyQueueTest")) {
- logTrace("Pass: Bytes msg properties read ok after clearBody called");
- } else {
- logMsg("Fail: Bytes msg properties cleared after clearBody called");
- pass = false;
- }
- logTrace("write 2nd contents");
- messageReceivedBytesMessage.writeByte(bValue2);
- logTrace("read 2nd contents");
- messageReceivedBytesMessage.reset();
- if (messageReceivedBytesMessage.readByte() == bValue2) {
- logTrace("Pass:");
- } else {
- logMsg("Fail:");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logTrace("sending a Stream message");
- messageSentStreamMessage = tool.getDefaultQueueSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgClearBodyQueueTest");
- messageSentStreamMessage.writeString("Testing...");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultQueueReceiver().receive(timeout);
- try {
- logTrace("Test StreamMessage ");
- logTrace("read 1st contents");
- logTrace(" " + messageReceivedStreamMessage.readString());
- logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedStreamMessage.clearBody();
- logTrace(
- "Stream message body should now be empty and in writeonly mode");
- try {
- String s = messageReceivedStreamMessage.readString();
-
- logMsg("Fail: MessageNotReadableException should have been thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageNotReadableException) {
- logTrace("Pass: MessageNotReadableException thrown as expected");
- } else {
- logMsg("Error: Unexpected exception " + e.getClass().getName()
- + " was thrown");
- pass = false;
- }
- }
-
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedStreamMessage
- .getStringProperty("COM_SUN_JMS_TESTNAME")
- .equals("msgClearBodyQueueTest")) {
- logTrace(
- "Pass: Stream msg properties read ok after clearBody called");
- } else {
- logMsg("Fail: Stream msg properties cleared after clearBody called");
- pass = false;
- }
- logTrace("write 2nd contents");
- messageReceivedStreamMessage.writeString("new data");
- logTrace("read 2nd contents");
- messageReceivedStreamMessage.reset();
- if (messageReceivedStreamMessage.readString().equals("new data")) {
- logTrace("Pass:");
- } else {
- logMsg("Fail:");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // Text Message
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgClearBodyQueueTest");
- logTrace("sending a Text message");
- tool.getDefaultQueueSender().send(messageSent);
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- try {
- logTrace("Test TextMessage ");
- logTrace("read 1st contents");
- logTrace(" " + messageReceived.getText());
- logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceived.clearBody();
-
- // message body should now be empty
- if (messageReceived.getText() == null) {
- logTrace("Empty body after clearBody as expected: null");
- } else {
- logTrace("Fail: message body was not empty");
- pass = false;
- }
-
- // properties should not have been deleted by the clearBody method.
- if (messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME")
- .equals("msgClearBodyQueueTest")) {
- logTrace("Pass: Text properties read ok after clearBody called");
- } else {
- logMsg("Fail: Text properties cleared after clearBody called");
- pass = false;
- }
- logTrace("write and read 2nd contents");
- messageReceived.setText("new data");
- if (messageReceived.getText().equals("new data")) {
- logTrace("Pass:");
- } else {
- logMsg("Fail:");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: clearBody test failure");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgClearBodyQueueTest");
- }
- }
-
- /*
- * @testName: msgResetQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:174; JMS:JAVADOC:584; JMS:JAVADOC:760;
- * JMS:JAVADOC:705;
- *
- * @test_Strategy: create a stream message and a byte message. write to the
- * message body, call the reset method, try to write to the body expect a
- * MessageNotWriteableException to be thrown.
- */
-
- public void msgResetQueueTest() throws Exception {
- boolean pass = true;
- int nInt = 1000;
-
- try {
- StreamMessage messageSentStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- // StreamMessage
- try {
- logTrace("creating a Stream message");
- messageSentStreamMessage = tool.getDefaultQueueSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgResetQueueTest1");
-
- // write to the message
- messageSentStreamMessage.writeString("Testing...");
- logMsg("reset stream message - now should be in readonly mode");
- messageSentStreamMessage.reset();
- messageSentStreamMessage.writeString("new data");
- logMsg(
- "Fail: message did not throw MessageNotWriteable exception as expected");
- pass = false;
- } catch (MessageNotWriteableException nw) {
- logTrace("Pass: MessageNotWriteable thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // BytesMessage
- try {
- logTrace("creating a Byte message");
- messageSentBytesMessage = tool.getDefaultQueueSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgResetQueueTest2");
-
- // write to the message
- messageSentBytesMessage.writeInt(nInt);
- logMsg("reset Byte message - now should be in readonly mode");
- messageSentBytesMessage.reset();
- messageSentBytesMessage.writeInt(nInt);
- logMsg(
- "Fail: message did not throw MessageNotWriteable exception as expected");
- pass = false;
- } catch (MessageNotWriteableException nw) {
- logTrace("Pass: MessageNotWriteable thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: msgResetQueueTest test failure");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgResetQueueTest");
- }
- }
-
- /*
- * @testName: readNullCharNotValidQueueTest
- *
- * @assertion_ids: JMS:SPEC:79; JMS:JAVADOC:134; JMS:JAVADOC:439;
- *
- * @test_Strategy: Write a null string to a MapMessage and then a
- * StreamMessage. Attempt to read the null value as a char.
- *
- */
-
- public void readNullCharNotValidQueueTest() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- MapMessage mapSent = null;
- MapMessage mapReceived = null;
- char c;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "readNullCharNotValidQueueTest");
-
- // -----------------------------------------------------------------------------
- // Stream Message
- // -----------------------------------------------------------------------------
- logTrace(
- "Write a null string to the stream message object with StreamMessage.writeString");
- messageSent.writeString(null);
- logTrace(" Send the message");
- tool.getDefaultQueueSender().send(messageSent);
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("Use readChar to read a null ");
- try {
- messageReceived.readChar();
- logTrace("Fail: NullPointerException was not thrown");
- pass = false;
- } catch (java.lang.NullPointerException e) {
- logTrace("Pass: NullPointerException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: Unexpected exception " + e.getClass().getName()
- + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------------------------------------
- // Map Message
- // -----------------------------------------------------------------------------
- mapSent = tool.getDefaultQueueSession().createMapMessage();
- mapSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "readNullCharNotValidQueueTest");
- logTrace(
- "Write a null string to the map message object with mapMessage.setString");
- mapSent.setString("WriteANull", null);
- logTrace(" Send the message");
- tool.getDefaultQueueSender().send(mapSent);
- mapReceived = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("Use readChar to read a null ");
- try {
- mapReceived.getChar("WriteANull");
- logMsg("Fail: NullPointerException was not thrown");
- pass = false;
- } catch (java.lang.NullPointerException e) {
- logTrace("Pass: NullPointerException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logMsg("Error: Unexpected exception " + e.getClass().getName()
- + " was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("readNullCharNotValidQueueTest", e);
- }
- }
-
- /*
- * @testName: messageQIllegalarg
- *
- * @assertion_ids: JMS:JAVADOC:775; JMS:JAVADOC:777; JMS:JAVADOC:779;
- * JMS:JAVADOC:781; JMS:JAVADOC:783; JMS:JAVADOC:785; JMS:JAVADOC:787;
- * JMS:JAVADOC:789; JMS:JAVADOC:791;
- *
- * @test_Strategy: Create a TextMessage. Write to the message using each type
- * of setProperty method and as an object with null String as name. Verify
- * that IllegalArgumentException thrown.
- */
-
- public void messageQIllegalarg() throws Exception {
- try {
- TextMessage messageSent = null;
- boolean pass = true;
- byte bValue = 127;
- short sValue = 32767;
- char cValue = '\uFFFF';
- int iValue = 2147483647;
- long lValue = 9223372036854775807L;
- float fValue = 0.0f;
- double dValue = -0.0;
- String ssValue = "abc";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "messageQIllegalarg");
-
- // -----------------------------------------------------------------------------
-
- logMsg("Writing a boolean property ... ");
- try {
- messageSent.setBooleanProperty("", pass);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBooleanProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setBooleanProperty");
- }
-
- logMsg("Writing a byte Property ... ");
- try {
- messageSent.setByteProperty("", bValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setByteProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setByteProperty");
- }
-
- logMsg("Writing a short Property... ");
- try {
- messageSent.setShortProperty("", sValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setShortProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setShortProperty");
- }
-
- logMsg("Writing a int Property ... ");
- try {
- messageSent.setIntProperty("", iValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setIntProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setIntProperty");
- }
-
- logMsg("Writing a long Property ... ");
- try {
- messageSent.setLongProperty("", lValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setLongProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setLongProperty");
- }
-
- logMsg("Writing a float Property ... ");
- try {
- messageSent.setFloatProperty("", fValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setFloatProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setFloatProperty");
- }
-
- logMsg("Writing a double Property ... ");
- try {
- messageSent.setDoubleProperty("", dValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setDoubleProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setDoubleProperty");
- }
-
- logMsg("Writing a string Property ... ");
- try {
- messageSent.setStringProperty("", ssValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setStringProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setStringProperty");
- }
-
- logMsg("Writing a object Property ... ");
- try {
- messageSent.setObjectProperty("", new Integer(iValue));
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setObjectProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setObjectProperty");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("messageQIllegalarg", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/messageQueue/MessageQueueTestIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/messageQueue/MessageQueueTestIT.java
new file mode 100644
index 0000000000..1cd7f775ed
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/messageQueue/MessageQueueTestIT.java
@@ -0,0 +1,698 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.messageQueue;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.MapMessage;
+import jakarta.jms.MessageNotWriteableException;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+
+
+public class MessageQueueTestIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.messageQueue.MessageQueueTestIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(MessageQueueTestIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'numProducers' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(2);
+ connections = new ArrayList(5);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: msgClearBodyQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
+ * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291; JMS:JAVADOC:680;
+ * JMS:JAVADOC:744;
+ *
+ * @test_Strategy: For each type of message, create and send a message Send and
+ * receive single Text, map, bytes, stream, and object message call clearBody,
+ * verify body is empty after clearBody. verify properties are not effected by
+ * clearBody. Write to the message again 3.11
+ */
+ @Test
+ public void msgClearBodyQueueTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ byte bValue2 = 22;
+ String id = null;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentStreamMessage = null;
+ StreamMessage messageReceivedStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ BytesMessage messageReceivedBytesMessage = null;
+ MapMessage messageReceivedMapMessage = null;
+ MapMessage messageSentMapMessage = null;
+ ObjectMessage messageSentObjectMsg = null;
+ ObjectMessage messageReceivedObjectMsg = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Queue.");
+ messageSentObjectMsg = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentObjectMsg.setObject("Initial message");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "msgClearBodyQueueTest");
+ tool.getDefaultQueueSender().send(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ try {
+ logger.log(Logger.Level.TRACE, "Testing Object message");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedObjectMsg.getObject());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedObjectMsg.clearBody();
+
+ // message body should now be empty
+ if (messageReceivedObjectMsg.getObject() == null) {
+ logger.log(Logger.Level.TRACE, "Empty body after clearBody as expected: null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: message body was not empty");
+ pass = false;
+ }
+
+ // properties should not have been deleted by the clearBody method.
+ if (messageSentObjectMsg.getStringProperty("COM_SUN_JMS_TESTNAME").equals("msgClearBodyQueueTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Object properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Object properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedObjectMsg.setObject("new stuff here!!!!!!");
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ if (messageReceivedObjectMsg.getObject().equals("new stuff here!!!!!!")) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: ");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Queue.");
+ messageSentMapMessage = tool.getDefaultQueueSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgClearBodyQueueTest");
+ messageSentMapMessage.setString("aString", "Initial message");
+ tool.getDefaultQueueSender().send(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ try {
+ logger.log(Logger.Level.TRACE, "Test for MapMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedMapMessage.getString("aString"));
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedMapMessage.clearBody();
+
+ // message body should now be empty
+ if (messageReceivedMapMessage.getString("aString") == null) {
+ logger.log(Logger.Level.TRACE, "Empty body after clearBody as expected: null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: message body was not empty");
+ pass = false;
+ }
+
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedMapMessage.getStringProperty("COM_SUN_JMS_TESTNAME")
+ .equals("msgClearBodyQueueTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Map properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Map properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedMapMessage.setString("yes", "new stuff !!!!!");
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ if (messageReceivedMapMessage.getString("yes").equals("new stuff !!!!!")) {
+ logger.log(Logger.Level.TRACE, "PASS:");
+ } else {
+ logger.log(Logger.Level.INFO, "FAIL:");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Queue.");
+ messageSentBytesMessage = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgClearBodyQueueTest");
+ messageSentBytesMessage.writeByte(bValue);
+ tool.getDefaultQueueSender().send(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ try {
+ logger.log(Logger.Level.TRACE, "Test BytesMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedBytesMessage.readByte());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedBytesMessage.clearBody();
+ logger.log(Logger.Level.TRACE, "Bytes message body should now be empty and in writeonly mode");
+ try {
+ byte b = messageReceivedBytesMessage.readByte();
+
+ logger.log(Logger.Level.TRACE, "Fail: MessageNotReadableException not thrown as expected");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageNotReadableException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageEOFException thrown as expected");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedBytesMessage.getStringProperty("COM_SUN_JMS_TESTNAME")
+ .equals("msgClearBodyQueueTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Bytes msg properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Bytes msg properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedBytesMessage.writeByte(bValue2);
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ messageReceivedBytesMessage.reset();
+ if (messageReceivedBytesMessage.readByte() == bValue2) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail:");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a Stream message");
+ messageSentStreamMessage = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgClearBodyQueueTest");
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ try {
+ logger.log(Logger.Level.TRACE, "Test StreamMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedStreamMessage.readString());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedStreamMessage.clearBody();
+ logger.log(Logger.Level.TRACE, "Stream message body should now be empty and in writeonly mode");
+ try {
+ String s = messageReceivedStreamMessage.readString();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageNotReadableException should have been thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageNotReadableException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotReadableException thrown as expected");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedStreamMessage.getStringProperty("COM_SUN_JMS_TESTNAME")
+ .equals("msgClearBodyQueueTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Stream msg properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Stream msg properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedStreamMessage.writeString("new data");
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ messageReceivedStreamMessage.reset();
+ if (messageReceivedStreamMessage.readString().equals("new data")) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail:");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // Text Message
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgClearBodyQueueTest");
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+ tool.getDefaultQueueSender().send(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ try {
+ logger.log(Logger.Level.TRACE, "Test TextMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceived.getText());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceived.clearBody();
+
+ // message body should now be empty
+ if (messageReceived.getText() == null) {
+ logger.log(Logger.Level.TRACE, "Empty body after clearBody as expected: null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: message body was not empty");
+ pass = false;
+ }
+
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME").equals("msgClearBodyQueueTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Text properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Text properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write and read 2nd contents");
+ messageReceived.setText("new data");
+ if (messageReceived.getText().equals("new data")) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail:");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: clearBody test failure");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgClearBodyQueueTest");
+ }
+ }
+
+ /*
+ * @testName: msgResetQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:174; JMS:JAVADOC:584; JMS:JAVADOC:760;
+ * JMS:JAVADOC:705;
+ *
+ * @test_Strategy: create a stream message and a byte message. write to the
+ * message body, call the reset method, try to write to the body expect a
+ * MessageNotWriteableException to be thrown.
+ */
+ @Test
+ public void msgResetQueueTest() throws Exception {
+ boolean pass = true;
+ int nInt = 1000;
+
+ try {
+ StreamMessage messageSentStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ // StreamMessage
+ try {
+ logger.log(Logger.Level.TRACE, "creating a Stream message");
+ messageSentStreamMessage = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgResetQueueTest1");
+
+ // write to the message
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.INFO, "reset stream message - now should be in readonly mode");
+ messageSentStreamMessage.reset();
+ messageSentStreamMessage.writeString("new data");
+ logger.log(Logger.Level.INFO, "Fail: message did not throw MessageNotWriteable exception as expected");
+ pass = false;
+ } catch (MessageNotWriteableException nw) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotWriteable thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // BytesMessage
+ try {
+ logger.log(Logger.Level.TRACE, "creating a Byte message");
+ messageSentBytesMessage = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgResetQueueTest2");
+
+ // write to the message
+ messageSentBytesMessage.writeInt(nInt);
+ logger.log(Logger.Level.INFO, "reset Byte message - now should be in readonly mode");
+ messageSentBytesMessage.reset();
+ messageSentBytesMessage.writeInt(nInt);
+ logger.log(Logger.Level.INFO, "Fail: message did not throw MessageNotWriteable exception as expected");
+ pass = false;
+ } catch (MessageNotWriteableException nw) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotWriteable thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: msgResetQueueTest test failure");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgResetQueueTest");
+ }
+ }
+
+ /*
+ * @testName: readNullCharNotValidQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:79; JMS:JAVADOC:134; JMS:JAVADOC:439;
+ *
+ * @test_Strategy: Write a null string to a MapMessage and then a StreamMessage.
+ * Attempt to read the null value as a char.
+ *
+ */
+ @Test
+ public void readNullCharNotValidQueueTest() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ MapMessage mapSent = null;
+ MapMessage mapReceived = null;
+ char c;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "readNullCharNotValidQueueTest");
+
+ // -----------------------------------------------------------------------------
+ // Stream Message
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE,
+ "Write a null string to the stream message object with StreamMessage.writeString");
+ messageSent.writeString(null);
+ logger.log(Logger.Level.TRACE, " Send the message");
+ tool.getDefaultQueueSender().send(messageSent);
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Use readChar to read a null ");
+ try {
+ messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: NullPointerException was not thrown");
+ pass = false;
+ } catch (java.lang.NullPointerException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------------------------------------
+ // Map Message
+ // -----------------------------------------------------------------------------
+ mapSent = tool.getDefaultQueueSession().createMapMessage();
+ mapSent.setStringProperty("COM_SUN_JMS_TESTNAME", "readNullCharNotValidQueueTest");
+ logger.log(Logger.Level.TRACE, "Write a null string to the map message object with mapMessage.setString");
+ mapSent.setString("WriteANull", null);
+ logger.log(Logger.Level.TRACE, " Send the message");
+ tool.getDefaultQueueSender().send(mapSent);
+ mapReceived = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Use readChar to read a null ");
+ try {
+ mapReceived.getChar("WriteANull");
+ logger.log(Logger.Level.INFO, "Fail: NullPointerException was not thrown");
+ pass = false;
+ } catch (java.lang.NullPointerException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("readNullCharNotValidQueueTest", e);
+ }
+ }
+
+ /*
+ * @testName: messageQIllegalarg
+ *
+ * @assertion_ids: JMS:JAVADOC:775; JMS:JAVADOC:777; JMS:JAVADOC:779;
+ * JMS:JAVADOC:781; JMS:JAVADOC:783; JMS:JAVADOC:785; JMS:JAVADOC:787;
+ * JMS:JAVADOC:789; JMS:JAVADOC:791;
+ *
+ * @test_Strategy: Create a TextMessage. Write to the message using each type of
+ * setProperty method and as an object with null String as name. Verify that
+ * IllegalArgumentException thrown.
+ */
+ @Test
+ public void messageQIllegalarg() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ boolean pass = true;
+ byte bValue = 127;
+ short sValue = 32767;
+ char cValue = '\uFFFF';
+ int iValue = 2147483647;
+ long lValue = 9223372036854775807L;
+ float fValue = 0.0f;
+ double dValue = -0.0;
+ String ssValue = "abc";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "messageQIllegalarg");
+
+ // -----------------------------------------------------------------------------
+
+ logger.log(Logger.Level.INFO, "Writing a boolean property ... ");
+ try {
+ messageSent.setBooleanProperty("", pass);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBooleanProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setBooleanProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a byte Property ... ");
+ try {
+ messageSent.setByteProperty("", bValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setByteProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setByteProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a short Property... ");
+ try {
+ messageSent.setShortProperty("", sValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setShortProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setShortProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a int Property ... ");
+ try {
+ messageSent.setIntProperty("", iValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setIntProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setIntProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a long Property ... ");
+ try {
+ messageSent.setLongProperty("", lValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setLongProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setLongProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a float Property ... ");
+ try {
+ messageSent.setFloatProperty("", fValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setFloatProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setFloatProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a double Property ... ");
+ try {
+ messageSent.setDoubleProperty("", dValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setDoubleProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setDoubleProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a string Property ... ");
+ try {
+ messageSent.setStringProperty("", ssValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setStringProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setStringProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a object Property ... ");
+ try {
+ messageSent.setObjectProperty("", new Integer(iValue));
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setObjectProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setObjectProperty");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("messageQIllegalarg", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/messageTopic/MessageTopicTest.java b/jms/src/main/java/com/sun/ts/tests/jms/core/messageTopic/MessageTopicTest.java
deleted file mode 100644
index 9d4d0a2fa0..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/messageTopic/MessageTopicTest.java
+++ /dev/null
@@ -1,711 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.messageTopic;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.MapMessage;
-import jakarta.jms.MessageNotWriteableException;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-
-public class MessageTopicTest extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.messageTopic.MessageTopicTest";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- MessageTopicTest theTests = new MessageTopicTest();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
-
- } catch (Exception e) {
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: msgClearBodyTopicTest
- *
- * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
- * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
- *
- * @test_Strategy: For each type of message, create and send a message Send
- * and receive single Text, map, bytes, stream, and object message call
- * clearBody, verify body is empty after clearBody. verify properties are not
- * effected by clearBody. Write to the message again 3.11
- */
-
- public void msgClearBodyTopicTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- byte bValue2 = 22;
- String id = null;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentStreamMessage = null;
- StreamMessage messageReceivedStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- BytesMessage messageReceivedBytesMessage = null;
- MapMessage messageReceivedMapMessage = null;
- MapMessage messageSentMapMessage = null;
- ObjectMessage messageSentObjectMsg = null;
- ObjectMessage messageReceivedObjectMsg = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
-
- // send and receive Object message to Topic
- logTrace("Send ObjectMessage to Topic.");
- messageSentObjectMsg = tool.getDefaultTopicSession()
- .createObjectMessage();
- messageSentObjectMsg.setObject("Initial message");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgClearBodyTopicTest");
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- try {
- logTrace("Testing Object message");
- logTrace("read 1st contents");
- logTrace(" " + messageReceivedObjectMsg.getObject());
- logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedObjectMsg.clearBody();
-
- // message body should now be empty
- if (messageReceivedObjectMsg.getObject() == null) {
- logTrace("Empty body after clearBody as expected: null");
- } else {
- logTrace("Fail: message body was not empty");
- pass = false;
- }
-
- // properties should not have been deleted by the clearBody method.
- if (messageSentObjectMsg.getStringProperty("COM_SUN_JMS_TESTNAME")
- .equals("msgClearBodyTopicTest")) {
- logTrace("Pass: Object properties read ok after clearBody called");
- } else {
- logErr("Fail: Object properties cleared after clearBody called");
- pass = false;
- }
- logTrace("write 2nd contents");
- messageReceivedObjectMsg.setObject("new stuff here!!!!!!");
- logTrace("read 2nd contents");
- if (messageReceivedObjectMsg.getObject()
- .equals("new stuff here!!!!!!")) {
- logTrace("Pass:");
- } else {
- logErr("Fail: ");
- pass = false;
- }
- } catch (Exception e) {
- logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // send and receive map message to Topic
- logTrace("Send MapMessage to Topic.");
- messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgClearBodyTopicTest");
- messageSentMapMessage.setString("aString", "Initial message");
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- try {
- logTrace("Test for MapMessage ");
- logTrace("read 1st contents");
- logTrace(" " + messageReceivedMapMessage.getString("aString"));
- logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedMapMessage.clearBody();
-
- // message body should now be empty
- if (messageReceivedMapMessage.getString("aString") == null) {
- logTrace("Empty body after clearBody as expected: null");
- } else {
- logTrace("Fail: message body was not empty");
- pass = false;
- }
-
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedMapMessage.getStringProperty("COM_SUN_JMS_TESTNAME")
- .equals("msgClearBodyTopicTest")) {
- logTrace("Pass: Map properties read ok after clearBody called");
- } else {
- logErr("Fail: Map properties cleared after clearBody called");
- pass = false;
- }
- logTrace("write 2nd contents");
- messageReceivedMapMessage.setString("yes", "new stuff !!!!!");
- logTrace("read 2nd contents");
- if (messageReceivedMapMessage.getString("yes")
- .equals("new stuff !!!!!")) {
- logTrace("PASS:");
- } else {
- logErr("FAIL:");
- pass = false;
- }
- } catch (Exception e) {
- logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // send and receive bytes message to Topic
- logTrace("Send BytesMessage to Topic.");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgClearBodyTopicTest");
- messageSentBytesMessage.writeByte(bValue);
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- try {
- logTrace("Test BytesMessage ");
- logTrace("read 1st contents");
- logTrace(" " + messageReceivedBytesMessage.readByte());
- logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedBytesMessage.clearBody();
- logTrace(
- "Bytes message body should now be empty and in writeonly mode");
- try {
- byte b = messageReceivedBytesMessage.readByte();
-
- logErr("Fail: MessageNotReadableException not thrown as expected");
- pass = false;
- } catch (jakarta.jms.MessageNotReadableException e) {
- logTrace("Pass: MessageNotReadableException thrown as expected");
- } catch (Exception ee) {
- logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedBytesMessage
- .getStringProperty("COM_SUN_JMS_TESTNAME")
- .equals("msgClearBodyTopicTest")) {
- logTrace("Pass: Bytes msg properties read ok after clearBody called");
- } else {
- logErr("Fail: Bytes msg properties cleared after clearBody called");
- pass = false;
- }
- logTrace("write 2nd contents");
- messageReceivedBytesMessage.writeByte(bValue2);
- logTrace("read 2nd contents");
- messageReceivedBytesMessage.reset();
- if (messageReceivedBytesMessage.readByte() == bValue2) {
- logTrace("Pass:");
- } else {
- logErr("Fail:");
- pass = false;
- }
- } catch (Exception e) {
- logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logTrace("sending a Stream message");
- messageSentStreamMessage = tool.getDefaultTopicSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgClearBodyTopicTest");
- messageSentStreamMessage.writeString("Testing...");
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- try {
- logTrace("Test StreamMessage ");
- logTrace("read 1st contents");
- logTrace(" " + messageReceivedStreamMessage.readString());
- logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedStreamMessage.clearBody();
- logTrace(
- "Stream message body should now be empty and in writeonly mode");
- try {
- String s = messageReceivedStreamMessage.readString();
-
- logErr("Fail: MessageNotReadableException should have been thrown");
- pass = false;
- } catch (jakarta.jms.MessageNotReadableException e) {
- logTrace("Pass: MessageNotReadableException thrown as expected");
- } catch (Exception ee) {
- logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedStreamMessage
- .getStringProperty("COM_SUN_JMS_TESTNAME")
- .equals("msgClearBodyTopicTest")) {
- logTrace(
- "Pass: Stream msg properties read ok after clearBody called");
- } else {
- logErr("Fail: Stream msg properties cleared after clearBody called");
- pass = false;
- }
- logTrace("write 2nd contents");
- messageReceivedStreamMessage.writeString("new data");
- logTrace("read 2nd contents");
- messageReceivedStreamMessage.reset();
- if (messageReceivedStreamMessage.readString().equals("new data")) {
- logTrace("Pass:");
- } else {
- logErr("Fail:");
- }
- } catch (Exception e) {
- logErr("Error: ", e);
- pass = false;
- }
-
- // Text Message
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgClearBodyTopicTest");
- logTrace("sending a Text message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- try {
- logTrace("Test TextMessage ");
- logTrace("read 1st contents");
- logTrace(" " + messageReceived.getText());
- logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceived.clearBody();
-
- // message body should now be empty
- if (messageReceived.getText() == null) {
- logTrace("Empty body after clearBody as expected: null");
- } else {
- logTrace("Fail: message body was not empty");
- pass = false;
- }
-
- // properties should not have been deleted by the clearBody method.
- if (messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME")
- .equals("msgClearBodyTopicTest")) {
- logTrace("Pass: Text properties read ok after clearBody called");
- } else {
- logErr("Fail: Text properties cleared after clearBody called");
- pass = false;
- }
- logTrace("write and read 2nd contents");
- messageReceived.setText("new data");
- if (messageReceived.getText().equals("new data")) {
- logTrace("Pass:");
- } else {
- logErr("Fail:");
- pass = false;
- }
- } catch (Exception e) {
- logErr("Error: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: clearBody test failure");
- }
- } catch (Exception e) {
- throw new Exception("msgClearBodyTopicTest", e);
- }
- }
-
- /*
- * @testName: msgResetTopicTest
- *
- * @assertion_ids: JMS:JAVADOC:174; JMS:JAVADOC:584;
- *
- * @test_Strategy: create a stream message and a byte message. write to the
- * message body, call the reset method, try to write to the body expect a
- * MessageNotWriteableException to be thrown.
- */
-
- public void msgResetTopicTest() throws Exception {
- boolean pass = true;
- int nInt = 1000;
-
- try {
- StreamMessage messageSentStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
-
- // StreamMessage
- try {
- logTrace("creating a Stream message");
- messageSentStreamMessage = tool.getDefaultTopicSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgResetTopicTest");
-
- // write to the message
- messageSentStreamMessage.writeString("Testing...");
- logMsg("reset stream message - now should be in readonly mode");
- messageSentStreamMessage.reset();
- messageSentStreamMessage.writeString("new data");
- logErr(
- "Fail: message did not throw MessageNotWriteable exception as expected");
- pass = false;
- } catch (MessageNotWriteableException nw) {
- logTrace("Pass: MessageNotWriteable thrown as expected");
- } catch (Exception e) {
- logErr("Error: ", e);
- pass = false;
- }
-
- // BytesMessage
- try {
- logTrace("creating a Byte message");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgResetTopicTest");
-
- // write to the message
- messageSentBytesMessage.writeInt(nInt);
- logMsg("reset Byte message - now should be in readonly mode");
- messageSentBytesMessage.reset();
- messageSentBytesMessage.writeInt(nInt);
- logErr(
- "Fail: message did not throw MessageNotWriteable exception as expected");
- pass = false;
- } catch (MessageNotWriteableException nw) {
- logTrace("Pass: MessageNotWriteable thrown as expected");
- } catch (Exception e) {
- logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: msgResetTopicTest test failure");
- }
- } catch (Exception e) {
- throw new Exception("msgResetTopicTest", e);
- }
- }
-
- /*
- * @testName: readNullCharNotValidTopicTest
- *
- * @assertion_ids: JMS:SPEC:79; JMS:JAVADOC:134; JMS:JAVADOC:439;
- *
- * @test_Strategy: Write a null string to a MapMessage and then a
- * StreamMessage. Attempt to read the null value as a char. Verify that a
- * NullPointerException is thrown.
- *
- */
-
- public void readNullCharNotValidTopicTest() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- MapMessage mapSent = null;
- MapMessage mapReceived = null;
- char c;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "readNullCharNotValidTopicTest");
-
- // -----------------------------------------------------------------------------
- // Stream Message
- // -----------------------------------------------------------------------------
- logTrace(
- "Write a null string to the stream message object with StreamMessage.writeString");
- messageSent.writeString(null);
- logTrace(" Send the message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("Use readChar to read a null ");
- try {
- messageReceived.readChar();
- logErr("Fail: NullPointerException was not thrown");
- pass = false;
- } catch (java.lang.NullPointerException e) {
- logTrace("Pass: NullPointerException thrown as expected");
- } catch (Exception e) {
- logErr("Error: Unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------------------------------------
- // Map Message
- // -----------------------------------------------------------------------------
- mapSent = tool.getDefaultTopicSession().createMapMessage();
- mapSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "readNullCharNotValidTopicTest");
- logTrace(
- "Write a null string to the map message object with mapMessage.setString");
- mapSent.setString("WriteANull", null);
- logTrace(" Send the message");
- tool.getDefaultTopicPublisher().publish(mapSent);
- mapReceived = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("Use readChar to read a null ");
- try {
- mapReceived.getChar("WriteANull");
- logErr("Fail: NullPointerException was not thrown");
- pass = false;
- } catch (java.lang.NullPointerException e) {
- logTrace("Pass: NullPointerException thrown as expected");
- } catch (Exception e) {
- logErr("Error: Unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("readNullCharNotValidTopicTest", e);
- }
- }
-
- /*
- * @testName: messageTIllegalarg
- *
- * @assertion_ids: JMS:JAVADOC:775; JMS:JAVADOC:777; JMS:JAVADOC:779;
- * JMS:JAVADOC:781; JMS:JAVADOC:783; JMS:JAVADOC:785; JMS:JAVADOC:787;
- * JMS:JAVADOC:789; JMS:JAVADOC:791;
- *
- * @test_Strategy: Create a TextMessage. Write to the message using each type
- * of setProperty method and as an object with null String as name. Verify
- * that IllegalArgumentException thrown.
- */
-
- public void messageTIllegalarg() throws Exception {
- try {
- TextMessage messageSent = null;
- boolean pass = true;
- byte bValue = 127;
- short sValue = 32767;
- char cValue = '\uFFFF';
- int iValue = 2147483647;
- long lValue = 9223372036854775807L;
- float fValue = 0.0f;
- double dValue = -0.0;
- String ssValue = "abc";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "messageTIllegalarg");
-
- // -----------------------------------------------------------------------------
-
- logMsg("Writing a boolean property ... ");
- try {
- messageSent.setBooleanProperty("", pass);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setBooleanProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setBooleanProperty");
- }
-
- logMsg("Writing a byte Property ... ");
- try {
- messageSent.setByteProperty("", bValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setByteProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setByteProperty");
- }
-
- logMsg("Writing a short Property... ");
- try {
- messageSent.setShortProperty("", sValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setShortProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setShortProperty");
- }
-
- logMsg("Writing a int Property ... ");
- try {
- messageSent.setIntProperty("", iValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setIntProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setIntProperty");
- }
-
- logMsg("Writing a long Property ... ");
- try {
- messageSent.setLongProperty("", lValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setLongProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setLongProperty");
- }
-
- logMsg("Writing a float Property ... ");
- try {
- messageSent.setFloatProperty("", fValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setFloatProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setFloatProperty");
- }
-
- logMsg("Writing a double Property ... ");
- try {
- messageSent.setDoubleProperty("", dValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setDoubleProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setDoubleProperty");
- }
-
- logMsg("Writing a string Property ... ");
- try {
- messageSent.setStringProperty("", ssValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setStringProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setStringProperty");
- }
-
- logMsg("Writing a object Property ... ");
- try {
- messageSent.setObjectProperty("", new Integer(iValue));
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to setObjectProperty");
- } catch (IllegalArgumentException e) {
- logMsg("Got Expected IllegalArgumentException with setObjectProperty");
- }
- } catch (Exception e) {
- throw new Exception("messageTIllegalarg", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/messageTopic/MessageTopicTestIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/messageTopic/MessageTopicTestIT.java
new file mode 100644
index 0000000000..2c25491000
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/messageTopic/MessageTopicTestIT.java
@@ -0,0 +1,670 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.messageTopic;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.MapMessage;
+import jakarta.jms.MessageNotWriteableException;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+
+
+public class MessageTopicTestIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.messageTopic.MessageTopicTestIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(MessageTopicTestIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+
+ } catch (Exception e) {
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: msgClearBodyTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
+ * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: For each type of message, create and send a message Send and
+ * receive single Text, map, bytes, stream, and object message call clearBody,
+ * verify body is empty after clearBody. verify properties are not effected by
+ * clearBody. Write to the message again 3.11
+ */
+ @Test
+ public void msgClearBodyTopicTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ byte bValue2 = 22;
+ String id = null;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentStreamMessage = null;
+ StreamMessage messageReceivedStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ BytesMessage messageReceivedBytesMessage = null;
+ MapMessage messageReceivedMapMessage = null;
+ MapMessage messageSentMapMessage = null;
+ ObjectMessage messageSentObjectMsg = null;
+ ObjectMessage messageReceivedObjectMsg = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Topic.");
+ messageSentObjectMsg = tool.getDefaultTopicSession().createObjectMessage();
+ messageSentObjectMsg.setObject("Initial message");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "msgClearBodyTopicTest");
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ try {
+ logger.log(Logger.Level.TRACE, "Testing Object message");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedObjectMsg.getObject());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedObjectMsg.clearBody();
+
+ // message body should now be empty
+ if (messageReceivedObjectMsg.getObject() == null) {
+ logger.log(Logger.Level.TRACE, "Empty body after clearBody as expected: null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: message body was not empty");
+ pass = false;
+ }
+
+ // properties should not have been deleted by the clearBody method.
+ if (messageSentObjectMsg.getStringProperty("COM_SUN_JMS_TESTNAME").equals("msgClearBodyTopicTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Object properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: Object properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedObjectMsg.setObject("new stuff here!!!!!!");
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ if (messageReceivedObjectMsg.getObject().equals("new stuff here!!!!!!")) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: ");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // send and receive map message to Topic
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Topic.");
+ messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgClearBodyTopicTest");
+ messageSentMapMessage.setString("aString", "Initial message");
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ try {
+ logger.log(Logger.Level.TRACE, "Test for MapMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedMapMessage.getString("aString"));
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedMapMessage.clearBody();
+
+ // message body should now be empty
+ if (messageReceivedMapMessage.getString("aString") == null) {
+ logger.log(Logger.Level.TRACE, "Empty body after clearBody as expected: null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: message body was not empty");
+ pass = false;
+ }
+
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedMapMessage.getStringProperty("COM_SUN_JMS_TESTNAME")
+ .equals("msgClearBodyTopicTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Map properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: Map properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedMapMessage.setString("yes", "new stuff !!!!!");
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ if (messageReceivedMapMessage.getString("yes").equals("new stuff !!!!!")) {
+ logger.log(Logger.Level.TRACE, "PASS:");
+ } else {
+ logger.log(Logger.Level.ERROR, "FAIL:");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Topic.");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgClearBodyTopicTest");
+ messageSentBytesMessage.writeByte(bValue);
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ try {
+ logger.log(Logger.Level.TRACE, "Test BytesMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedBytesMessage.readByte());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedBytesMessage.clearBody();
+ logger.log(Logger.Level.TRACE, "Bytes message body should now be empty and in writeonly mode");
+ try {
+ byte b = messageReceivedBytesMessage.readByte();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageNotReadableException not thrown as expected");
+ pass = false;
+ } catch (jakarta.jms.MessageNotReadableException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotReadableException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedBytesMessage.getStringProperty("COM_SUN_JMS_TESTNAME")
+ .equals("msgClearBodyTopicTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Bytes msg properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: Bytes msg properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedBytesMessage.writeByte(bValue2);
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ messageReceivedBytesMessage.reset();
+ if (messageReceivedBytesMessage.readByte() == bValue2) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail:");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a Stream message");
+ messageSentStreamMessage = tool.getDefaultTopicSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgClearBodyTopicTest");
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ try {
+ logger.log(Logger.Level.TRACE, "Test StreamMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedStreamMessage.readString());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedStreamMessage.clearBody();
+ logger.log(Logger.Level.TRACE, "Stream message body should now be empty and in writeonly mode");
+ try {
+ String s = messageReceivedStreamMessage.readString();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageNotReadableException should have been thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageNotReadableException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotReadableException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedStreamMessage.getStringProperty("COM_SUN_JMS_TESTNAME")
+ .equals("msgClearBodyTopicTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Stream msg properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: Stream msg properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedStreamMessage.writeString("new data");
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ messageReceivedStreamMessage.reset();
+ if (messageReceivedStreamMessage.readString().equals("new data")) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail:");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: ", e);
+ pass = false;
+ }
+
+ // Text Message
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgClearBodyTopicTest");
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ try {
+ logger.log(Logger.Level.TRACE, "Test TextMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceived.getText());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceived.clearBody();
+
+ // message body should now be empty
+ if (messageReceived.getText() == null) {
+ logger.log(Logger.Level.TRACE, "Empty body after clearBody as expected: null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: message body was not empty");
+ pass = false;
+ }
+
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceived.getStringProperty("COM_SUN_JMS_TESTNAME").equals("msgClearBodyTopicTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Text properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: Text properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write and read 2nd contents");
+ messageReceived.setText("new data");
+ if (messageReceived.getText().equals("new data")) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail:");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: clearBody test failure");
+ }
+ } catch (Exception e) {
+ throw new Exception("msgClearBodyTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: msgResetTopicTest
+ *
+ * @assertion_ids: JMS:JAVADOC:174; JMS:JAVADOC:584;
+ *
+ * @test_Strategy: create a stream message and a byte message. write to the
+ * message body, call the reset method, try to write to the body expect a
+ * MessageNotWriteableException to be thrown.
+ */
+ @Test
+ public void msgResetTopicTest() throws Exception {
+ boolean pass = true;
+ int nInt = 1000;
+
+ try {
+ StreamMessage messageSentStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+
+ // StreamMessage
+ try {
+ logger.log(Logger.Level.TRACE, "creating a Stream message");
+ messageSentStreamMessage = tool.getDefaultTopicSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgResetTopicTest");
+
+ // write to the message
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.INFO, "reset stream message - now should be in readonly mode");
+ messageSentStreamMessage.reset();
+ messageSentStreamMessage.writeString("new data");
+ logger.log(Logger.Level.ERROR, "Fail: message did not throw MessageNotWriteable exception as expected");
+ pass = false;
+ } catch (MessageNotWriteableException nw) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotWriteable thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: ", e);
+ pass = false;
+ }
+
+ // BytesMessage
+ try {
+ logger.log(Logger.Level.TRACE, "creating a Byte message");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgResetTopicTest");
+
+ // write to the message
+ messageSentBytesMessage.writeInt(nInt);
+ logger.log(Logger.Level.INFO, "reset Byte message - now should be in readonly mode");
+ messageSentBytesMessage.reset();
+ messageSentBytesMessage.writeInt(nInt);
+ logger.log(Logger.Level.ERROR, "Fail: message did not throw MessageNotWriteable exception as expected");
+ pass = false;
+ } catch (MessageNotWriteableException nw) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotWriteable thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: msgResetTopicTest test failure");
+ }
+ } catch (Exception e) {
+ throw new Exception("msgResetTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: readNullCharNotValidTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:79; JMS:JAVADOC:134; JMS:JAVADOC:439;
+ *
+ * @test_Strategy: Write a null string to a MapMessage and then a StreamMessage.
+ * Attempt to read the null value as a char. Verify that a NullPointerException
+ * is thrown.
+ *
+ */
+ @Test
+ public void readNullCharNotValidTopicTest() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ MapMessage mapSent = null;
+ MapMessage mapReceived = null;
+ char c;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "readNullCharNotValidTopicTest");
+
+ // -----------------------------------------------------------------------------
+ // Stream Message
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE,
+ "Write a null string to the stream message object with StreamMessage.writeString");
+ messageSent.writeString(null);
+ logger.log(Logger.Level.TRACE, " Send the message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Use readChar to read a null ");
+ try {
+ messageReceived.readChar();
+ logger.log(Logger.Level.ERROR, "Fail: NullPointerException was not thrown");
+ pass = false;
+ } catch (java.lang.NullPointerException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------------------------------------
+ // Map Message
+ // -----------------------------------------------------------------------------
+ mapSent = tool.getDefaultTopicSession().createMapMessage();
+ mapSent.setStringProperty("COM_SUN_JMS_TESTNAME", "readNullCharNotValidTopicTest");
+ logger.log(Logger.Level.TRACE, "Write a null string to the map message object with mapMessage.setString");
+ mapSent.setString("WriteANull", null);
+ logger.log(Logger.Level.TRACE, " Send the message");
+ tool.getDefaultTopicPublisher().publish(mapSent);
+ mapReceived = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Use readChar to read a null ");
+ try {
+ mapReceived.getChar("WriteANull");
+ logger.log(Logger.Level.ERROR, "Fail: NullPointerException was not thrown");
+ pass = false;
+ } catch (java.lang.NullPointerException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("readNullCharNotValidTopicTest", e);
+ }
+ }
+
+ /*
+ * @testName: messageTIllegalarg
+ *
+ * @assertion_ids: JMS:JAVADOC:775; JMS:JAVADOC:777; JMS:JAVADOC:779;
+ * JMS:JAVADOC:781; JMS:JAVADOC:783; JMS:JAVADOC:785; JMS:JAVADOC:787;
+ * JMS:JAVADOC:789; JMS:JAVADOC:791;
+ *
+ * @test_Strategy: Create a TextMessage. Write to the message using each type of
+ * setProperty method and as an object with null String as name. Verify that
+ * IllegalArgumentException thrown.
+ */
+ @Test
+ public void messageTIllegalarg() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ boolean pass = true;
+ byte bValue = 127;
+ short sValue = 32767;
+ char cValue = '\uFFFF';
+ int iValue = 2147483647;
+ long lValue = 9223372036854775807L;
+ float fValue = 0.0f;
+ double dValue = -0.0;
+ String ssValue = "abc";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "messageTIllegalarg");
+
+ // -----------------------------------------------------------------------------
+
+ logger.log(Logger.Level.INFO, "Writing a boolean property ... ");
+ try {
+ messageSent.setBooleanProperty("", pass);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setBooleanProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setBooleanProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a byte Property ... ");
+ try {
+ messageSent.setByteProperty("", bValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setByteProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setByteProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a short Property... ");
+ try {
+ messageSent.setShortProperty("", sValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setShortProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setShortProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a int Property ... ");
+ try {
+ messageSent.setIntProperty("", iValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setIntProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setIntProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a long Property ... ");
+ try {
+ messageSent.setLongProperty("", lValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setLongProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setLongProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a float Property ... ");
+ try {
+ messageSent.setFloatProperty("", fValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setFloatProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setFloatProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a double Property ... ");
+ try {
+ messageSent.setDoubleProperty("", dValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setDoubleProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setDoubleProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a string Property ... ");
+ try {
+ messageSent.setStringProperty("", ssValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setStringProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setStringProperty");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a object Property ... ");
+ try {
+ messageSent.setObjectProperty("", new Integer(iValue));
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to setObjectProperty");
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Got Expected IllegalArgumentException with setObjectProperty");
+ }
+ } catch (Exception e) {
+ throw new Exception("messageTIllegalarg", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/objectMsgQueue/ObjectMsgQueueTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/objectMsgQueue/ObjectMsgQueueTests.java
deleted file mode 100644
index fc604403e1..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/objectMsgQueue/ObjectMsgQueueTests.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.objectMsgQueue;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.MessageNotWriteableException;
-import jakarta.jms.ObjectMessage;
-
-public class ObjectMsgQueueTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.objectMsgQueue.ObjectMsgQueueTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ObjectMsgQueueTests theTests = new ObjectMsgQueueTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'numConsumers' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'numProducers' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(2);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: messageObjectCopyQTest
- *
- * @assertion_ids: JMS:SPEC:85; JMS:JAVADOC:291;
- *
- * @test_Strategy: Create an object message. Write a StringBuffer to the
- * message. modify the StringBuffer and send the msg, verify that it does not
- * effect the msg
- */
-
- public void messageObjectCopyQTest() throws Exception {
- boolean pass = true;
-
- try {
- ObjectMessage messageSentObject = null;
- ObjectMessage messageReceivedObject = null;
- StringBuffer sBuff = new StringBuffer("This is");
- String initial = "This is";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- messageSentObject = tool.getDefaultQueueSession().createObjectMessage();
- messageSentObject.setObject(sBuff);
- sBuff.append("a test ");
- messageSentObject.setStringProperty("COM_SUN_JMS_TESTNAME",
- "messageObjectCopyQTest");
- tool.getDefaultQueueSender().send(messageSentObject);
- messageReceivedObject = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logMsg("Ensure that changing the object did not change the message");
- StringBuffer s = (StringBuffer) messageReceivedObject.getObject();
-
- logTrace("s is " + s);
- if (s.toString().equals(initial)) {
- logTrace("Pass: msg was not changed");
- } else {
- logTrace("Fail: msg was changed!");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("messageObjectCopyQTest");
- }
- }
-
- /*
- * @testName: notWritableTest
- *
- * @assertion_ids: JMS:JAVADOC:717;
- *
- * @test_Strategy: Create an object message. Try to setObject upon receiving
- * the message. Verify that MessageNotWriteableException is thrown.
- */
-
- public void notWritableTest() throws Exception {
- boolean pass = true;
- StringBuffer sBuff = new StringBuffer("This is");
- String testName = "notWritableTest";
-
- try {
- ObjectMessage messageSentObject = null;
- ObjectMessage messageReceivedObject = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- messageSentObject = tool.getDefaultQueueSession().createObjectMessage();
- messageSentObject.setObject(sBuff);
- messageSentObject.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- tool.getDefaultQueueSender().send(messageSentObject);
-
- messageReceivedObject = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- try {
- messageReceivedObject.setObject(sBuff);
- TestUtil
- .logErr("Error: expected MessageNotWriteableException not thrown");
- pass = false;
- } catch (MessageNotWriteableException ex) {
- TestUtil.logTrace("Got expected MessageNotWriteableException");
- }
-
- if (!pass)
- throw new Exception(testName);
- } catch (Exception e) {
- TestUtil.logErr(testName + " failed: ", e);
- throw new Exception(testName);
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/objectMsgQueue/ObjectMsgQueueTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/objectMsgQueue/ObjectMsgQueueTestsIT.java
new file mode 100644
index 0000000000..979806f23e
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/objectMsgQueue/ObjectMsgQueueTestsIT.java
@@ -0,0 +1,230 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.objectMsgQueue;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.MessageNotWriteableException;
+import jakarta.jms.ObjectMessage;
+
+
+public class ObjectMsgQueueTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.objectMsgQueue.ObjectMsgQueueTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ObjectMsgQueueTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'numConsumers' is null");
+ }
+ if (password == null) {
+ throw new Exception("'numProducers' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(2);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: messageObjectCopyQTest
+ *
+ * @assertion_ids: JMS:SPEC:85; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Create an object message. Write a StringBuffer to the
+ * message. modify the StringBuffer and send the msg, verify that it does not
+ * effect the msg
+ */
+ @Test
+ public void messageObjectCopyQTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ ObjectMessage messageSentObject = null;
+ ObjectMessage messageReceivedObject = null;
+ StringBuffer sBuff = new StringBuffer("This is");
+ String initial = "This is";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ messageSentObject = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentObject.setObject(sBuff);
+ sBuff.append("a test ");
+ messageSentObject.setStringProperty("COM_SUN_JMS_TESTNAME", "messageObjectCopyQTest");
+ tool.getDefaultQueueSender().send(messageSentObject);
+ messageReceivedObject = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.INFO, "Ensure that changing the object did not change the message");
+ StringBuffer s = (StringBuffer) messageReceivedObject.getObject();
+
+ logger.log(Logger.Level.TRACE, "s is " + s);
+ if (s.toString().equals(initial)) {
+ logger.log(Logger.Level.TRACE, "Pass: msg was not changed");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: msg was changed!");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("messageObjectCopyQTest");
+ }
+ }
+
+ /*
+ * @testName: notWritableTest
+ *
+ * @assertion_ids: JMS:JAVADOC:717;
+ *
+ * @test_Strategy: Create an object message. Try to setObject upon receiving the
+ * message. Verify that MessageNotWriteableException is thrown.
+ */
+ @Test
+ public void notWritableTest() throws Exception {
+ boolean pass = true;
+ StringBuffer sBuff = new StringBuffer("This is");
+ String testName = "notWritableTest";
+
+ try {
+ ObjectMessage messageSentObject = null;
+ ObjectMessage messageReceivedObject = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ messageSentObject = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentObject.setObject(sBuff);
+ messageSentObject.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ tool.getDefaultQueueSender().send(messageSentObject);
+
+ messageReceivedObject = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ try {
+ messageReceivedObject.setObject(sBuff);
+ logger.log(Logger.Level.ERROR, "Error: expected MessageNotWriteableException not thrown");
+ pass = false;
+ } catch (MessageNotWriteableException ex) {
+ logger.log(Logger.Level.TRACE, "Got expected MessageNotWriteableException");
+ }
+
+ if (!pass)
+ throw new Exception(testName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, testName + " failed: ", e);
+ throw new Exception(testName);
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/objectMsgTopic/ObjectMsgTopicTest.java b/jms/src/main/java/com/sun/ts/tests/jms/core/objectMsgTopic/ObjectMsgTopicTest.java
deleted file mode 100644
index 5585ffc9f1..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/objectMsgTopic/ObjectMsgTopicTest.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.objectMsgTopic;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.ObjectMessage;
-
-public class ObjectMsgTopicTest extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.objectMsgTopic.ObjectMsgTopicTest";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- ObjectMsgTopicTest theTests = new ObjectMsgTopicTest();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: messageObjectCopyTopicTest
- *
- * @assertion_ids: JMS:SPEC:85; JMS:JAVADOC:291;
- *
- * @test_Strategy: Create an object message. Write a StringBuffer to the
- * message. modify the StringBuffer and send the msg, verify that it does not
- * effect the msg
- */
-
- public void messageObjectCopyTopicTest() throws Exception {
- boolean pass = true;
-
- try {
- ObjectMessage messageSentObjectMsg = null;
- ObjectMessage messageReceivedObjectMsg = null;
- StringBuffer sBuff = new StringBuffer("This is");
- String initial = "This is";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- messageSentObjectMsg = tool.getDefaultTopicSession()
- .createObjectMessage();
- messageSentObjectMsg.setObject(sBuff);
- sBuff.append("a test ");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "messageObjectCopyTopicTest");
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logMsg("Ensure that changing the object did not change the message");
- StringBuffer s = (StringBuffer) messageReceivedObjectMsg.getObject();
-
- logTrace("s is " + s);
- if (s.toString().equals(initial)) {
- logTrace("Pass: msg was not changed");
- } else {
- logTrace("Fail: msg was changed!");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("messageObjectCopyTopicTest");
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/objectMsgTopic/ObjectMsgTopicTestIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/objectMsgTopic/ObjectMsgTopicTestIT.java
new file mode 100644
index 0000000000..b5841b47ed
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/objectMsgTopic/ObjectMsgTopicTestIT.java
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.objectMsgTopic;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.ObjectMessage;
+
+
+public class ObjectMsgTopicTestIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.objectMsgTopic.ObjectMsgTopicTestIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ObjectMsgTopicTestIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: messageObjectCopyTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:85; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Create an object message. Write a StringBuffer to the
+ * message. modify the StringBuffer and send the msg, verify that it does not
+ * effect the msg
+ */
+ @Test
+ public void messageObjectCopyTopicTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ ObjectMessage messageSentObjectMsg = null;
+ ObjectMessage messageReceivedObjectMsg = null;
+ StringBuffer sBuff = new StringBuffer("This is");
+ String initial = "This is";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ messageSentObjectMsg = tool.getDefaultTopicSession().createObjectMessage();
+ messageSentObjectMsg.setObject(sBuff);
+ sBuff.append("a test ");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "messageObjectCopyTopicTest");
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.INFO, "Ensure that changing the object did not change the message");
+ StringBuffer s = (StringBuffer) messageReceivedObjectMsg.getObject();
+
+ logger.log(Logger.Level.TRACE, "s is " + s);
+ if (s.toString().equals(initial)) {
+ logger.log(Logger.Level.TRACE, "Pass: msg was not changed");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: msg was changed!");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("messageObjectCopyTopicTest");
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/queueConnection/QueueConnectionTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/queueConnection/QueueConnectionTests.java
deleted file mode 100644
index 3b48c1b92d..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/queueConnection/QueueConnectionTests.java
+++ /dev/null
@@ -1,361 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.queueConnection;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.ConnectionMetaData;
-import jakarta.jms.QueueConnection;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueSession;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-
-public class QueueConnectionTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.queueConnection.QueueConnectionTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- QueueConnectionTests theTests = new QueueConnectionTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue
- * Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(2);
- connections = new ArrayList(5);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- TestUtil.logMsg("Cleanup: Closing Queue Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: connNotStartedQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:272; JMS:SPEC:97;
- *
- * @test_Strategy: Send two messages to a queue; Receive only the second
- * message using selectors; Close receiver; Create another connection without
- * starting it; Create a new receiver in new connection and try to receive
- * first message with receiveNoWait() Should not get a message
- */
- public void connNotStartedQueueTest() throws Exception {
- boolean pass = true;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- QueueReceiver qRec = null;
-
- QueueConnection newConn = null;
- QueueSession newSess = null;
- QueueReceiver newRec = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueReceiver().close();
- qRec = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue(), "targetMessage = TRUE");
- tool.getDefaultQueueConnection().start();
-
- TestUtil.logMsg("Creating TextMessage");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "connNotStartedQueueTest");
-
- TestUtil.logMsg("Sending two TextMessages");
- messageSent.setBooleanProperty("targetMessage", false);
- tool.getDefaultQueueSender().send(messageSent);
- messageSent.setBooleanProperty("targetMessage", true);
- tool.getDefaultQueueSender().send(messageSent);
-
- TestUtil.logMsg("Receiving second message only");
- messageReceived = (TextMessage) qRec.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logErr("Fail: Did not receive any message");
- pass = false;
- } else if (messageReceived.getBooleanProperty("targetMessage") == false) {
- TestUtil.logErr("Fail: Received incorrect message");
- pass = false;
- }
-
- TestUtil
- .logMsg("Closing receiver, creating new connection without starting");
- qRec.close();
- tool.getDefaultQueueConnection().close();
-
- newConn = (QueueConnection) tool.getNewConnection(JmsTool.QUEUE, user,
- password);
- connections.add(newConn);
-
- newSess = newConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- newRec = newSess.createReceiver(tool.getDefaultQueue());
-
- TestUtil.logMsg("receiving first message");
- messageReceived = (TextMessage) newRec.receiveNoWait();
-
- // message should be null
- if (messageReceived == null) {
- TestUtil.logMsg("Pass: message not recevied");
- } else {
- TestUtil.logErr(
- "Fail: message received even though connection not started!");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("connNotStartedQueueTest");
- }
- }
-
- /*
- * @testName: metaDataTests
- *
- * @assertion_ids: JMS:JAVADOC:486; JMS:JAVADOC:488; JMS:JAVADOC:490;
- * JMS:JAVADOC:492; JMS:JAVADOC:494; JMS:JAVADOC:496; JMS:JAVADOC:498;
- *
- * @test_Strategy: Create a QueueConnection to get ConnectionMetaData. Verify
- * that all Content of the ConnectionMetaData matches the type defined in API
- * and JMS API version is correct.
- */
-
- public void metaDataTests() throws Exception {
- boolean pass = true;
- ConnectionMetaData data = null;
-
- try {
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- data = tool.getDefaultQueueConnection().getMetaData();
-
- if (!verifyMetaData(data))
- pass = false;
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- try {
- tool.getDefaultQueueConnection().close();
- } catch (Exception e) {
- logErr("Error closing QueueConnection in metaDataTests : ", e);
- }
- }
-
- try {
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- data = tool.getDefaultConnection().getMetaData();
-
- if (!verifyMetaData(data))
- pass = false;
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- try {
- tool.getDefaultConnection().close();
- } catch (Exception e) {
- logErr("Error closing Connection in metaDataTests : ", e);
- }
- }
-
- if (!pass) {
- throw new Exception("Error: metaDataTests failed");
- }
- }
-
- private boolean verifyMetaData(ConnectionMetaData data) {
- boolean pass = true;
-
- try {
- String tmp = data.getJMSVersion();
- TestUtil.logTrace("JMSVersion=" + tmp);
-
- if (!tmp.equals(JmsTool.JMS_VERSION)) {
- logErr("Error: incorrect JMSVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getJMSMajorVersion();
- TestUtil.logTrace("JMSMajorVersion=" + tmp);
-
- if (tmp != JmsTool.JMS_MAJOR_VERSION) {
- logErr("Error: incorrect JMSMajorVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- logErr("Error: incorrect type returned for JMSMajorVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getJMSMinorVersion();
- TestUtil.logTrace("JMSMinorVersion=" + tmp);
- } catch (Exception e) {
- logErr("Error: incorrect type returned for JMSMinorVersion: ", e);
- pass = false;
- }
-
- try {
- String tmp = data.getJMSProviderName();
- TestUtil.logTrace("JMSProviderName=" + tmp);
- } catch (Exception e) {
- logErr("Error: incorrect type returned for JMSProviderName: ", e);
- pass = false;
- }
-
- try {
- String tmp = data.getProviderVersion();
- TestUtil.logTrace("JMSProviderVersion=" + tmp);
- } catch (Exception e) {
- logErr("Error: incorrect type returned for ProviderVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getProviderMajorVersion();
- TestUtil.logTrace("ProviderMajorVersion=" + tmp);
- } catch (Exception e) {
- logErr("Error: incorrect type returned for ProviderMajorVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getProviderMinorVersion();
- TestUtil.logTrace("ProviderMinorVersion=" + tmp);
- } catch (Exception e) {
- logErr("Error: incorrect type returned for ProviderMinorVersion: ", e);
- pass = false;
- }
- return pass;
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/queueConnection/QueueConnectionTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/queueConnection/QueueConnectionTestsIT.java
new file mode 100644
index 0000000000..198e58f390
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/queueConnection/QueueConnectionTestsIT.java
@@ -0,0 +1,350 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.queueConnection;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.ConnectionMetaData;
+import jakarta.jms.QueueConnection;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueSession;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+
+
+public class QueueConnectionTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.queueConnection.QueueConnectionTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(QueueConnectionTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue Connection,
+ * as well as a default Queue and Topic. Tests that require multiple
+ * Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(2);
+ connections = new ArrayList(5);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: connNotStartedQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:272; JMS:SPEC:97;
+ *
+ * @test_Strategy: Send two messages to a queue; Receive only the second message
+ * using selectors; Close receiver; Create another connection without starting
+ * it; Create a new receiver in new connection and try to receive first message
+ * with receiveNoWait() Should not get a message
+ */
+ @Test
+ public void connNotStartedQueueTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ QueueReceiver qRec = null;
+
+ QueueConnection newConn = null;
+ QueueSession newSess = null;
+ QueueReceiver newRec = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueReceiver().close();
+ qRec = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue(), "targetMessage = TRUE");
+ tool.getDefaultQueueConnection().start();
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "connNotStartedQueueTest");
+
+ logger.log(Logger.Level.INFO, "Sending two TextMessages");
+ messageSent.setBooleanProperty("targetMessage", false);
+ tool.getDefaultQueueSender().send(messageSent);
+ messageSent.setBooleanProperty("targetMessage", true);
+ tool.getDefaultQueueSender().send(messageSent);
+
+ logger.log(Logger.Level.INFO, "Receiving second message only");
+ messageReceived = (TextMessage) qRec.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "Fail: Did not receive any message");
+ pass = false;
+ } else if (messageReceived.getBooleanProperty("targetMessage") == false) {
+ logger.log(Logger.Level.ERROR, "Fail: Received incorrect message");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO, "Closing receiver, creating new connection without starting");
+ qRec.close();
+ tool.getDefaultQueueConnection().close();
+
+ newConn = (QueueConnection) tool.getNewConnection(JmsTool.QUEUE, user, password);
+ connections.add(newConn);
+
+ newSess = newConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ newRec = newSess.createReceiver(tool.getDefaultQueue());
+
+ logger.log(Logger.Level.INFO, "receiving first message");
+ messageReceived = (TextMessage) newRec.receiveNoWait();
+
+ // message should be null
+ if (messageReceived == null) {
+ logger.log(Logger.Level.INFO, "Pass: message not recevied");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: message received even though connection not started!");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("connNotStartedQueueTest");
+ }
+ }
+
+ /*
+ * @testName: metaDataTests
+ *
+ * @assertion_ids: JMS:JAVADOC:486; JMS:JAVADOC:488; JMS:JAVADOC:490;
+ * JMS:JAVADOC:492; JMS:JAVADOC:494; JMS:JAVADOC:496; JMS:JAVADOC:498;
+ *
+ * @test_Strategy: Create a QueueConnection to get ConnectionMetaData. Verify
+ * that all Content of the ConnectionMetaData matches the type defined in API
+ * and JMS API version is correct.
+ */
+ @Test
+ public void metaDataTests() throws Exception {
+ boolean pass = true;
+ ConnectionMetaData data = null;
+
+ try {
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ data = tool.getDefaultQueueConnection().getMetaData();
+
+ if (!verifyMetaData(data))
+ pass = false;
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ try {
+ tool.getDefaultQueueConnection().close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing QueueConnection in metaDataTests : ", e);
+ }
+ }
+
+ try {
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ data = tool.getDefaultConnection().getMetaData();
+
+ if (!verifyMetaData(data))
+ pass = false;
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ try {
+ tool.getDefaultConnection().close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection in metaDataTests : ", e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("Error: metaDataTests failed");
+ }
+ }
+
+ private boolean verifyMetaData(ConnectionMetaData data) {
+ boolean pass = true;
+
+ try {
+ String tmp = data.getJMSVersion();
+ logger.log(Logger.Level.TRACE, "JMSVersion=" + tmp);
+
+ if (!tmp.equals(JmsTool.JMS_VERSION)) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getJMSMajorVersion();
+ logger.log(Logger.Level.TRACE, "JMSMajorVersion=" + tmp);
+
+ if (tmp != JmsTool.JMS_MAJOR_VERSION) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSMajorVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSMajorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getJMSMinorVersion();
+ logger.log(Logger.Level.TRACE, "JMSMinorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSMinorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = data.getJMSProviderName();
+ logger.log(Logger.Level.TRACE, "JMSProviderName=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSProviderName: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = data.getProviderVersion();
+ logger.log(Logger.Level.TRACE, "JMSProviderVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getProviderMajorVersion();
+ logger.log(Logger.Level.TRACE, "ProviderMajorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderMajorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getProviderMinorVersion();
+ logger.log(Logger.Level.TRACE, "ProviderMinorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderMinorVersion: ", e);
+ pass = false;
+ }
+ return pass;
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/queueMsgHeaders/QueueHeaderTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/queueMsgHeaders/QueueHeaderTests.java
deleted file mode 100644
index aa89c596da..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/queueMsgHeaders/QueueHeaderTests.java
+++ /dev/null
@@ -1,1860 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.core.queueMsgHeaders;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.DeliveryMode;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.Queue;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-
-public class QueueHeaderTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.queueMsgHeaders.QueueHeaderTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- QueueHeaderTests theTests = new QueueHeaderTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
- queues = new ArrayList(2);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * helper method for msgHdrIDQTest and msgHdrIDTopicTest verifies that the
- * JMSMessageID starts with ID:
- *
- *
- * @param String returned from getJMSMessageID
- *
- * @return boolean true if id correctly starts with ID:
- */
-
- private boolean chkMessageID(String id) {
- String status[] = { "Pass", "Fail" };
- boolean retcode = true;
-
- // message id must start with ID: - unless it is null
- int index = 0;
-
- if (id == null) {
- ;
- } else if (id.startsWith("ID:")) {
- ;
- } else {
- index = 1;
- retcode = false;
- }
- logTrace("Results: " + status[index]);
- return retcode;
- }
-
- /*
- * @testName: msgHdrIDQTest
- *
- * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343;
- *
- * @test_Strategy: Send to a Queue and receive Text, Map, Bytes, Stream, and
- * object message. call getJMSMessageID and verify that it starts with ID:
- */
-
- public void msgHdrIDQTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- String id = null;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- // send and receive Object message to Queue
- logTrace("Send ObjectMessage to Queue.");
- messageSentO = tool.getDefaultQueueSession().createObjectMessage();
- messageSentO.setObject("msgHdrIDQTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDQTest");
- tool.getDefaultQueueSender().send(messageSentO);
- messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("getJMSMessageID ");
- logTrace(" " + messageReceivedO.getJMSMessageID());
- id = messageReceivedO.getJMSMessageID();
- if (!chkMessageID(id)) {
- logMsg("ObjectMessage error: JMSMessageID does not start with ID:");
- pass = false;
- }
- // send and receive map message to Queue
- logTrace("Send MapMessage to Queue.");
- messageSentM = tool.getDefaultQueueSession().createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDQTest");
- messageSentM.setString("aString", "value");
- tool.getDefaultQueueSender().send(messageSentM);
- messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("getJMSMessageID ");
- logTrace(" " + messageReceivedM.getJMSMessageID());
- id = messageReceivedM.getJMSMessageID();
- if (!chkMessageID(id)) {
- logMsg("MapMessage error: JMSMessageID does not start with ID:");
- pass = false;
- }
-
- // send and receive bytes message to Queue
- logTrace("Send BytesMessage to Queue.");
- messageSentB = tool.getDefaultQueueSession().createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDQTest");
- messageSentB.writeByte(bValue);
- tool.getDefaultQueueSender().send(messageSentB);
- messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("getJMSMessageID ");
- logTrace(" " + messageReceivedB.getJMSMessageID());
- id = messageReceivedB.getJMSMessageID();
- if (!chkMessageID(id)) {
- logMsg("BytesMessage error: JMSMessageID does not start with ID:");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logTrace("sending a StreamMessage");
- messageSentS = tool.getDefaultQueueSession().createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDQTest");
- messageSentS.writeString("Testing...");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSentS);
- messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("getJMSMessageID ");
- logTrace(" " + messageReceivedS.getJMSMessageID());
- id = messageReceivedS.getJMSMessageID();
- if (!chkMessageID(id)) {
- logMsg("StreamMessage error: JMSMessageID does not start with ID:");
- pass = false;
- }
-
- // TextMessage
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("sending a TextMessage");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDQTest");
- logTrace("sending a TextMessage");
- tool.getDefaultQueueSender().send(messageSent);
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("getJMSMessageID ");
- logTrace(" " + messageReceived.getJMSMessageID());
- id = messageReceived.getJMSMessageID();
- if (!chkMessageID(id)) {
- logMsg("TextMessage error: JMSMessageID does not start with ID:");
- pass = false;
- }
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSMessageID returned from JMSMessageID");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrIDQTest");
- }
- }
-
- /*
- * @testName: msgHdrTimeStampQTest
- *
- * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347;
- *
- * @test_Strategy: With a queue destination Send a single Text, map, bytes,
- * stream, and object message check time of send against time send returns
- * JMSTimeStamp should be between these two
- */
-
- public void msgHdrTimeStampQTest() throws Exception {
- boolean pass = true;
- long timeBeforeSend;
- long timeAfterSend;
- byte bValue = 127;
-
- try {
- TextMessage messageSent = null;
- StreamMessage messageSentS = null;
- BytesMessage messageSentB = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- // send and receive Object message to Queue
- logTrace("Send ObjectMessage to Queue.");
- messageSentO = tool.getDefaultQueueSession().createObjectMessage();
- messageSentO.setObject("msgHdrTimeStampQTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampQTest");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultQueueSender().send(messageSentO);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- logTrace(" getJMSTimestamp");
- logTrace(" " + messageSentO.getJMSTimestamp());
- logTrace("Time at send is: " + timeBeforeSend);
- logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentO.getJMSTimestamp())
- && (timeAfterSend >= messageSentO.getJMSTimestamp())) {
- logTrace("ObjectMessage TimeStamp pass");
- } else {
- logMsg("Error: invalid timestamp from ObjectMessage");
- pass = false;
- }
-
- // send map message to Queue
- logTrace("Send MapMessage to Queue.");
- messageSentM = tool.getDefaultQueueSession().createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampQTest");
- messageSentM.setString("aString", "value");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultQueueSender().send(messageSentM);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- logTrace(" getJMSTimestamp");
- logTrace(" " + messageSentM.getJMSTimestamp());
- logTrace("Time at send is: " + timeBeforeSend);
- logTrace("Time after return fromsend is:" + timeAfterSend);
- if (!(timeBeforeSend <= messageSentM.getJMSTimestamp())
- && (timeAfterSend >= messageSentM.getJMSTimestamp())) {
- logErr("Error: invalid timestamp from MapMessage");
- pass = false;
- }
-
- // send and receive bytes message to Queue
- logTrace("Send BytesMessage to Queue.");
- messageSentB = tool.getDefaultQueueSession().createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampQTest");
- messageSentB.writeByte(bValue);
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultQueueSender().send(messageSentB);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- logTrace(" getJMSTimestamp");
- logTrace(" " + messageSentB.getJMSTimestamp());
- logTrace("Time at send is: " + timeBeforeSend);
- logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentB.getJMSTimestamp())
- && (timeAfterSend >= messageSentB.getJMSTimestamp())) {
- logTrace("BytesMessage TimeStamp pass");
- } else {
- logMsg("Error: invalid timestamp from BytesMessage");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logTrace("sending a StreamMessage");
- messageSentS = tool.getDefaultQueueSession().createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampQTest");
- messageSentS.writeString("Testing...");
- logTrace("Sending message");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultQueueSender().send(messageSentS);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- logTrace(" getJMSTimestamp");
- logTrace(" " + messageSentS.getJMSTimestamp());
- logTrace("Time at send is: " + timeBeforeSend);
- logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentS.getJMSTimestamp())
- && (timeAfterSend >= messageSentS.getJMSTimestamp())) {
- logTrace("StreamMessage TimeStamp pass");
- } else {
- logMsg("Error: invalid timestamp from StreamMessage");
- pass = false;
- }
-
- // TextMessage
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("sending a TextMessage");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampQTest");
- logTrace("sending a TextMessage");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultQueueSender().send(messageSent);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- logTrace(" getJMSTimestamp");
- logTrace(" " + messageSent.getJMSTimestamp());
- logTrace("Time at send is: " + timeBeforeSend);
- logTrace("Time after return fromsend is:" + timeAfterSend);
- if (!(timeBeforeSend <= messageSent.getJMSTimestamp())
- && (timeAfterSend >= messageSent.getJMSTimestamp())) {
- logErr("Error: invalid timestamp from TextMessage");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: invalid TimeStamp returned from JMSTimeStamp");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrTimeStampQTest");
- }
- }
-
- /*
- * @testName: msgHdrCorlIdQTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- * @test_Strategy: Send a message to a Queue with CorrelationID set. Receive
- * msg and verify the correlationid is as set by client
- */
-
- public void msgHdrCorlIdQTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- String jmsCorrelationID = "testCorrelationid";
- String testName = "msgHdrCorlIdQTest";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- logTrace("Send TextMessage to Queue.");
- messageSent.setJMSCorrelationID(jmsCorrelationID);
- try {
- tool.getDefaultQueueSender().send(messageSent);
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- logErr("messageReceived is null");
- pass = false;
- } else if (messageReceived.getJMSCorrelationID() == null) {
- pass = false;
- logErr("TextMessage Error: JMSCorrelationID returned a null");
- } else if (!messageReceived.getJMSCorrelationID()
- .equals(jmsCorrelationID)) {
- pass = false;
- logErr("TextMessage Error: JMSCorrelationID is incorrect");
- }
- } catch (java.lang.Exception e) {
- pass = false;
- logErr("Unexpected Exception: ", e);
- }
-
- // send and receive map message to Queue
- logTrace("Send MapMessage to Queue.");
- messageSentM = tool.getDefaultQueueSession().createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentM.setJMSCorrelationID(jmsCorrelationID);
- messageSentM.setString("aString", "value");
- tool.getDefaultQueueSender().send(messageSentM);
-
- messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedM.getJMSCorrelationID() == null) {
- pass = false;
- logErr("MapMessage Error: JMSCorrelationID returned a null");
- } else if (!messageReceivedM.getJMSCorrelationID()
- .equals(jmsCorrelationID)) {
- pass = false;
- logErr("MapMessage Error: JMSCorrelationID is incorrect");
- }
-
- // send and receive bytes message to Queue
- logTrace("Send BytesMessage to Queue.");
- messageSentB = tool.getDefaultQueueSession().createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentB.setJMSCorrelationID(jmsCorrelationID);
- messageSentB.writeByte(bValue);
- tool.getDefaultQueueSender().send(messageSentB);
-
- messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedB.getJMSCorrelationID() == null) {
- pass = false;
- logMsg("BytesMessage Error: JMSCorrelationID returned a null");
- } else if (!messageReceivedB.getJMSCorrelationID()
- .equals(jmsCorrelationID)) {
- pass = false;
- logMsg("Byte Message Error: JMSCorrelationID is incorrect");
- }
-
- // Send and receive a StreamMessage
- logTrace("sending a StreamMessage");
- messageSentS = tool.getDefaultQueueSession().createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentS.setJMSCorrelationID(jmsCorrelationID);
- messageSentS.writeString("Testing...");
- tool.getDefaultQueueSender().send(messageSentS);
-
- messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedS.getJMSCorrelationID() == null) {
- pass = false;
- logErr("StreamMessage Error: JMSCorrelationID returned a null");
- } else if (!messageReceivedS.getJMSCorrelationID()
- .equals(jmsCorrelationID)) {
- pass = false;
- logErr("StreamMessage Error: JMSCorrelationID is incorrect");
- }
-
- // send and receive Object message to Queue
- logTrace("Send ObjectMessage to Queue.");
- messageSentO = tool.getDefaultQueueSession().createObjectMessage();
- messageSentO.setObject("msgHdrIDQTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentO.setJMSCorrelationID(jmsCorrelationID);
- tool.getDefaultQueueSender().send(messageSentO);
-
- messageReceivedO = (ObjectMessage) (Message) tool
- .getDefaultQueueReceiver().receive(timeout);
- if (messageReceivedO.getJMSCorrelationID() == null) {
- pass = false;
- logMsg("ObjectMessage Error: JMSCorrelationID returned a null");
- } else if (!messageReceivedO.getJMSCorrelationID()
- .equals(jmsCorrelationID)) {
- pass = false;
- logMsg("ObjectMessage Error: JMSCorrelationID is incorrect");
- }
-
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSCorrelationID returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
- }
-
- /*
- * @testName: msgHdrReplyToQTest
- *
- * @assertion_ids: JMS:SPEC:12; JMS:SPEC:246.8; JMS:JAVADOC:359;
- * JMS:JAVADOC:361; JMS:JAVADOC:286; JMS:JAVADOC:289; JMS:JAVADOC:562;
- * JMS:JAVADOC:166;
- *
- * @test_Strategy: Send a message to a Queue with ReplyTo set to null and then
- * set to a destination test with Text, map, object, byte, and stream messages
- * verify on receive.
- *
- */
-
- public void msgHdrReplyToQTest() throws Exception {
- boolean pass = true;
- Queue replyQueue = null;
- byte bValue = 127;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrReplyToQTest");
- logTrace("Send Text message");
-
- // messageSent.setJMSReplyTo(tool.getDefaultQueue());
- tool.getDefaultQueueSender().send(messageSent);
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived.getJMSReplyTo() == null) {
- logTrace(" as expected replyto field is null");
- } else {
- logMsg(
- "ERROR: expected replyto field should have been null for this case");
- pass = false;
- }
- logTrace("Set ReplyTo and resend msg");
- messageSent.setJMSReplyTo(tool.getDefaultQueue());
- tool.getDefaultQueueSender().send(messageSent);
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- replyQueue = (Queue) messageReceived.getJMSReplyTo();
- logTrace("Queue name is " + replyQueue.getQueueName());
- if (replyQueue.getQueueName()
- .equals(tool.getDefaultQueue().getQueueName())) {
- logTrace("Pass ");
- } else {
- logMsg("TextMessage Failed");
- pass = false;
- }
-
- // send and receive Object message to Queue
- logTrace("Send ObjectMessage to Queue.");
- messageSentO = tool.getDefaultQueueSession().createObjectMessage();
- messageSentO.setObject("msgHdrReplyToQTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrReplyToQTest");
- tool.getDefaultQueueSender().send(messageSentO);
- messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedO.getJMSReplyTo() == null) {
- logTrace(" as expected replyto field is null");
- } else {
- replyQueue = (Queue) messageReceivedO.getJMSReplyTo();
- logMsg("ReplyTo is: " + replyQueue.toString());
- logMsg("ERROR: expected replyto field to be null in this case");
- pass = false;
- }
- logTrace("Set ReplyTo and resend msg");
- messageSentO.setJMSReplyTo(tool.getDefaultQueue());
- tool.getDefaultQueueSender().send(messageSentO);
- messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- replyQueue = (Queue) messageReceivedO.getJMSReplyTo();
- logTrace("Queue name is " + replyQueue.getQueueName());
- if (replyQueue.getQueueName()
- .equals(tool.getDefaultQueue().getQueueName())) {
- logTrace("Pass ");
- } else {
- logMsg("ObjectMessage ReplyTo Failed");
- pass = false;
- }
-
- // send and receive map message to Queue
- logTrace("Send MapMessage to Queue.");
- messageSentM = tool.getDefaultQueueSession().createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrReplyToQTest");
- messageSentM.setString("aString", "value");
- tool.getDefaultQueueSender().send(messageSentM);
- messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedM.getJMSReplyTo() == null) {
- logTrace(" as expected replyto field is null");
- } else {
- logMsg("ERROR: expected replyto field to be null in this case");
- pass = false;
- }
- logTrace("Set ReplyTo and resend msg");
- messageSentM.setJMSReplyTo(tool.getDefaultQueue());
- tool.getDefaultQueueSender().send(messageSentM);
- messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("Received Map message ");
- replyQueue = (Queue) messageReceivedM.getJMSReplyTo();
- logTrace("Queue name is " + replyQueue.getQueueName());
- if (replyQueue.getQueueName()
- .equals(tool.getDefaultQueue().getQueueName())) {
- logTrace("Pass ");
- } else {
- logMsg("MapMessage ReplyTo Failed");
- pass = false;
- }
-
- // send and receive bytes message to Queue
- logTrace("Send BytesMessage to Queue.");
- messageSentB = tool.getDefaultQueueSession().createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrReplyToQTest");
- messageSentB.writeByte(bValue);
- tool.getDefaultQueueSender().send(messageSentB);
- messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedB.getJMSReplyTo() == null) {
- logTrace(" as expected replyto field is null");
- } else {
- logMsg("ERROR: expected replyto field to be null in this case");
- pass = false;
- }
- logTrace("Set ReplyTo and resend msg");
- messageSentB.setJMSReplyTo(tool.getDefaultQueue());
- tool.getDefaultQueueSender().send(messageSentB);
- messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("Received Bytes message ");
- replyQueue = (Queue) messageReceivedB.getJMSReplyTo();
- logTrace("Queue name is " + replyQueue.getQueueName());
- if (replyQueue.getQueueName()
- .equals(tool.getDefaultQueue().getQueueName())) {
- logTrace("Pass ");
- } else {
- logMsg("BytesMessage ReplyTo Failed");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- messageSentS = tool.getDefaultQueueSession().createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrReplyToQTest");
- messageSentS.writeString("Testing...");
- logTrace("Sending StreamMessage");
- tool.getDefaultQueueSender().send(messageSentS);
- messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedS.getJMSReplyTo() == null) {
- logTrace(" as expected replyto field is null");
- } else {
- replyQueue = (Queue) messageReceivedS.getJMSReplyTo();
- logMsg("ERROR: expected replyto field to be null in this case");
- pass = false;
- }
- logTrace("Set ReplyTo and resend msg");
- messageSentS.setJMSReplyTo(tool.getDefaultQueue());
- tool.getDefaultQueueSender().send(messageSentS);
- messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("Received Stream message ");
- replyQueue = (Queue) messageReceivedS.getJMSReplyTo();
- logTrace("Queue name is " + replyQueue.getQueueName());
- if (replyQueue.getQueueName()
- .equals(tool.getDefaultQueue().getQueueName())) {
- logTrace("Pass ");
- } else {
- logMsg("StreamMessage ReplyTo Failed");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: invalid Replyto returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrReplyToQTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSTypeQTest
- *
- * @assertion_ids: JMS:SPEC:246.9; JMS:JAVADOC:375; JMS:JAVADOC:377;
- *
- * @test_Strategy: Send a message to a Queue with JMSType set to TESTMSG test
- * with Text, map, object, byte, and stream messages verify on receive.
- *
- */
-
- public void msgHdrJMSTypeQTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- String type = "TESTMSG";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSTypeQTest");
- logTrace("JMSType test - Send a TextMessage");
- messageSent.setJMSType(type);
- tool.getDefaultQueueSender().send(messageSent);
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSType is " + (String) messageReceived.getJMSType());
- if (messageReceived.getJMSType().equals(type)) {
- logTrace("Pass ");
- } else {
- logMsg("TextMessage Failed");
- pass = false;
- }
-
- // send and receive Object message to Queue
- logTrace("JMSType test - Send ObjectMessage to Queue.");
- messageSentO = tool.getDefaultQueueSession().createObjectMessage();
- messageSentO.setObject("msgHdrJMSTypeQTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSTypeQTest");
- messageSentO.setJMSType(type);
- tool.getDefaultQueueSender().send(messageSentO);
- messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSType is " + (String) messageReceivedO.getJMSType());
- if (messageReceivedO.getJMSType().equals(type)) {
- logTrace("Pass ");
- } else {
- logMsg("ObjectMessage JMSType Failed");
- pass = false;
- }
-
- // send and receive map message to Queue
- logTrace("JMSType test - Send MapMessage to Queue.");
- messageSentM = tool.getDefaultQueueSession().createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSTypeQTest");
- messageSentM.setString("aString", "value");
- messageSentM.setJMSType(type);
- tool.getDefaultQueueSender().send(messageSentM);
- messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSType is " + (String) messageReceivedM.getJMSType());
- if (messageReceivedM.getJMSType().equals(type)) {
- logTrace("Pass ");
- } else {
- logMsg("MapMessage JMSType Failed");
- pass = false;
- }
-
- // send and receive bytes message to Queue
- logTrace("JMSType test - Send BytesMessage to Queue.");
- messageSentB = tool.getDefaultQueueSession().createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSTypeQTest");
- messageSentB.writeByte(bValue);
- messageSentB.setJMSType(type);
- tool.getDefaultQueueSender().send(messageSentB);
- messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSType is " + (String) messageReceivedB.getJMSType());
- if (messageReceivedB.getJMSType().equals(type)) {
- logTrace("Pass ");
- } else {
- logMsg("BytesMessage JMSType Failed");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logTrace("JMSType test - sending a StreamMessage");
- messageSentS = tool.getDefaultQueueSession().createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSTypeQTest");
- messageSentS.writeString("Testing...");
- messageSentS.setJMSType(type);
- tool.getDefaultQueueSender().send(messageSentS);
- messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSType is " + (String) messageReceivedS.getJMSType());
- if (messageReceivedS.getJMSType().equals(type)) {
- logTrace("Pass ");
- } else {
- logMsg("StreamMessage JMSType Failed");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: invalid JMSType returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrJMSTypeQTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSPriorityQTest
- *
- * @assertion_ids: JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140; JMS:JAVADOC:305;
- * JMS:JAVADOC:383;
- *
- * @test_Strategy: Send a message to a Queue with JMSPriority set to 2 test
- * with Text, map, object, byte, and stream messages verify on receive.
- *
- */
-
- public void msgHdrJMSPriorityQTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- int priority = 2;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityQTest");
- logTrace("JMSPriority test - Send a TextMessage");
- tool.getDefaultQueueSender().setPriority(priority);
- tool.getDefaultQueueSender().send(messageSent);
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSPriority is " + messageReceived.getJMSPriority());
- if (messageReceived.getJMSPriority() == priority) {
- logTrace("Pass ");
- } else {
- logMsg("TextMessage Failed");
- pass = false;
- }
-
- // send and receive Object message to Queue
- logTrace("JMSPriority test - Send ObjectMessage to Queue.");
- messageSentO = tool.getDefaultQueueSession().createObjectMessage();
- messageSentO.setObject("msgHdrJMSPriorityQTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityQTest");
- tool.getDefaultQueueSender().setPriority(priority);
- tool.getDefaultQueueSender().send(messageSentO);
- messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSPriority is " + messageReceivedO.getJMSPriority());
- if (messageReceivedO.getJMSPriority() == priority) {
- logTrace("Pass ");
- } else {
- logMsg("ObjectMessage JMSPriority Failed");
- pass = false;
- }
-
- // send and receive map message to Queue
- logTrace("JMSPriority test - Send MapMessage to Queue.");
- messageSentM = tool.getDefaultQueueSession().createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityQTest");
- messageSentM.setString("aString", "value");
- tool.getDefaultQueueSender().setPriority(priority);
- tool.getDefaultQueueSender().send(messageSentM);
- messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSPriority is " + messageReceivedM.getJMSPriority());
- if (messageReceivedM.getJMSPriority() == priority) {
- logTrace("Pass ");
- } else {
- logMsg("MapMessage JMSPriority Failed");
- pass = false;
- }
-
- // send and receive bytes message to Queue
- logTrace("JMSPriority test - Send BytesMessage to Queue.");
- messageSentB = tool.getDefaultQueueSession().createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityQTest");
- messageSentB.writeByte(bValue);
- tool.getDefaultQueueSender().setPriority(priority);
- tool.getDefaultQueueSender().send(messageSentB);
- messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSPriority is " + messageReceivedB.getJMSPriority());
- if (messageReceivedB.getJMSPriority() == priority) {
- logTrace("Pass ");
- } else {
- logMsg("BytesMessage JMSPriority Failed");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logTrace("JMSPriority test - sending a StreamMessage");
- messageSentS = tool.getDefaultQueueSession().createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityQTest");
- messageSentS.writeString("Testing...");
- tool.getDefaultQueueSender().setPriority(priority);
- tool.getDefaultQueueSender().send(messageSentS);
- messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSPriority is " + messageReceivedS.getJMSPriority());
- if (messageReceivedS.getJMSPriority() == priority) {
- logTrace("Pass ");
- } else {
- logMsg("StreamMessage JMSPriority Failed");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: invalid JMSPriority returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrJMSPriorityQTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSExpirationQueueTest
- *
- * @assertion_ids: JMS:SPEC:15.1; JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140;
- * JMS:JAVADOC:309; JMS:JAVADOC:379;
- *
- * @test_Strategy: 1. Send a message to a Queue with time to live set to 0.
- * Verify on receive that JMSExpiration gets set to 0. Test with Text, Map,
- * Object, Bytes, and Stream messages. 2. Send a message to a Queue with time
- * to live set to non-0; Verify on receive that JMSExpiration gets set
- * correctly.
- */
-
- public void msgHdrJMSExpirationQueueTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- long forever = 0L;
- long timeToLive = timeout;
- String testName = "msgHdrJMSExpirationQueueTest";
- long timeBeforeSend = 0L;
- long timeAfterSend = 0L;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- logTrace("JMSExpiration test - Send a TextMessage");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("sending a TextMessage");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- tool.getDefaultQueueSender().setTimeToLive(forever);
- tool.getDefaultQueueSender().send(messageSent);
-
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived.getJMSExpiration() != forever) {
- logErr("TextMessage Failed");
- pass = false;
- }
-
- logTrace("JMSExpiration test - Send a TextMessage");
- tool.getDefaultQueueSender().setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultQueueSender().send(messageSent);
- timeAfterSend = System.currentTimeMillis();
-
- long exp = messageSent.getJMSExpiration();
- TestUtil.logTrace("JMSExpiration is set to=" + exp);
- TestUtil.logTrace("Time before send=" + timeBeforeSend);
- TestUtil.logTrace("Time after send=" + timeAfterSend);
- TestUtil.logTrace("Time to Live =" + timeToLive);
-
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived.getJMSExpiration() != exp) {
- TestUtil
- .logErr("TextMessage Failed: JMSExpiration didnot set correctly = "
- + messageReceived.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- }
-
- // send and receive Object message to Queue
- logTrace("JMSExpiration test - Send ObjectMessage to Queue.");
- messageSentO = tool.getDefaultQueueSession().createObjectMessage();
- messageSentO.setObject("msgHdrJMSExpirationQueueTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- tool.getDefaultQueueSender().setTimeToLive(forever);
- tool.getDefaultQueueSender().send(messageSentO);
- messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedO.getJMSExpiration() != forever) {
- logMsg("ObjectMessage JMSExpiration Failed");
- pass = false;
- }
-
- logTrace("JMSExpiration test - Send an ObjectMessage");
- tool.getDefaultQueueSender().setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultQueueSender().send(messageSentO);
- timeAfterSend = System.currentTimeMillis();
-
- exp = messageSentO.getJMSExpiration();
- TestUtil.logTrace("JMSExpiration is set to=" + exp);
- TestUtil.logTrace("Time before send=" + timeBeforeSend);
- TestUtil.logTrace("Time after send=" + timeAfterSend);
- TestUtil.logTrace("Time to Live =" + timeToLive);
-
- messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedO.getJMSExpiration() != exp) {
- logErr("ObjectMessage Failed: JMSExpiration didnot set correctly = "
- + messageReceivedO.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- }
-
- // send and receive map message to Queue
- logTrace("JMSExpiration test - Send MapMessage to Queue.");
- messageSentM = tool.getDefaultQueueSession().createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentM.setString("aString", "value");
- tool.getDefaultQueueSender().setTimeToLive(forever);
- tool.getDefaultQueueSender().send(messageSentM);
- messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedM.getJMSExpiration() != forever) {
- logMsg("MapMessage JMSExpiration Failed");
- pass = false;
- }
-
- logTrace("JMSExpiration test - Send a MapMessage");
- tool.getDefaultQueueSender().setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultQueueSender().send(messageSentM);
- timeAfterSend = System.currentTimeMillis();
-
- exp = messageSentM.getJMSExpiration();
- TestUtil.logTrace("JMSExpiration is set to=" + exp);
- TestUtil.logTrace("Time before send=" + timeBeforeSend);
- TestUtil.logTrace("Time after send=" + timeAfterSend);
- TestUtil.logTrace("Time to Live =" + timeToLive);
-
- messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedM.getJMSExpiration() != exp) {
- logErr("MapMessage Failed: JMSExpiration didnot set correctly = "
- + messageReceivedM.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- }
-
- // send and receive bytes message to Queue
- logTrace("JMSExpiration test - Send BytesMessage to Queue.");
- messageSentB = tool.getDefaultQueueSession().createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentB.writeByte(bValue);
- tool.getDefaultQueueSender().setTimeToLive(forever);
- tool.getDefaultQueueSender().send(messageSentB);
- messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedB.getJMSExpiration() != forever) {
- logMsg("BytesMessage JMSExpiration Failed");
- pass = false;
- }
-
- logTrace("JMSExpiration test - Send a BytesMessage");
- tool.getDefaultQueueSender().setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultQueueSender().send(messageSentB);
- timeAfterSend = System.currentTimeMillis();
-
- exp = messageSentB.getJMSExpiration();
- TestUtil.logTrace("JMSExpiration is set to=" + exp);
- TestUtil.logTrace("Time before send=" + timeBeforeSend);
- TestUtil.logTrace("Time after send=" + timeAfterSend);
- TestUtil.logTrace("Time to Live =" + timeToLive);
-
- messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedB.getJMSExpiration() != exp) {
- logErr("BytesMessage Failed: JMSExpiration didnot set correctly = "
- + messageReceivedB.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logTrace("JMSExpiration test - sending a StreamMessage");
- messageSentS = tool.getDefaultQueueSession().createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentS.writeString("Testing...");
- tool.getDefaultQueueSender().setTimeToLive(forever);
- tool.getDefaultQueueSender().send(messageSentS);
- messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedS.getJMSExpiration() != forever) {
- logMsg("StreamMessage JMSExpiration Failed");
- pass = false;
- }
-
- logTrace("JMSExpiration test - Send a StreamMessage");
- tool.getDefaultQueueSender().setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultQueueSender().send(messageSentS);
- timeAfterSend = System.currentTimeMillis();
-
- exp = messageSentS.getJMSExpiration();
- TestUtil.logTrace("JMSExpiration is set to=" + exp);
- TestUtil.logTrace("Time before send=" + timeBeforeSend);
- TestUtil.logTrace("Time after send=" + timeAfterSend);
- TestUtil.logTrace("Time to Live =" + timeToLive);
-
- messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedS.getJMSExpiration() != exp) {
- logErr("StreamMessage Failed: JMSExpiration didnot set correctly = "
- + messageReceivedS.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- }
-
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSExpiration returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
- }
-
- /*
- * @testName: msgHdrJMSDestinationQTest
- *
- * @assertion_ids: JMS:SPEC:2; JMS:JAVADOC:363; JMS:JAVADOC:286;
- *
- * @test_Strategy: Create and send a message to the default Queue. Receive msg
- * and verify that JMSDestination is set to the default Queue test with Text,
- * map, object, byte, and stream messages
- */
-
- public void msgHdrJMSDestinationQTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- Queue replyDestination = null;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDestinationQTest");
- logTrace("Send TextMessage to Queue.");
- tool.getDefaultQueueSender().send(messageSent);
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSDestination: " + messageReceived.getJMSDestination());
- replyDestination = (Queue) messageReceived.getJMSDestination();
- if (replyDestination == null) {
- pass = false;
- logMsg("TextMessage Error: JMSDestination returned a null");
- } else {
- logTrace("Queue name is " + replyDestination.getQueueName());
- if (replyDestination.getQueueName()
- .equals(tool.getDefaultQueue().getQueueName())) {
- logTrace("Pass ");
- } else {
- logMsg("TextMessage Failed");
- pass = false;
- }
- }
-
- // send and receive Object message to Queue
- logTrace("Send ObjectMessage to Queue.");
- messageSentO = tool.getDefaultQueueSession().createObjectMessage();
- messageSentO.setObject("msgHdrJMSDestinationQTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDestinationQTest");
- tool.getDefaultQueueSender().send(messageSentO);
- messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSDestination: " + messageReceivedO.getJMSDestination());
- replyDestination = (Queue) messageReceived.getJMSDestination();
- if (replyDestination == null) {
- pass = false;
- logMsg("ObjectMessage Error: JMSDestination returned a null");
- } else {
- logTrace("Queue name is " + replyDestination.getQueueName());
- if (replyDestination.getQueueName()
- .equals(tool.getDefaultQueue().getQueueName())) {
- logTrace("Pass ");
- } else {
- logMsg("ObjectMessage Failed");
- pass = false;
- }
- }
-
- // send and receive map message to Queue
- logTrace("Send MapMessage to Queue.");
- messageSentM = tool.getDefaultQueueSession().createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDestinationQTest");
- messageSentM.setString("aString", "value");
- tool.getDefaultQueueSender().send(messageSentM);
- messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSDestination: " + messageReceivedM.getJMSDestination());
- replyDestination = (Queue) messageReceived.getJMSDestination();
- if (replyDestination == null) {
- pass = false;
- logMsg("MapMessage Error: JMSDestination returned a null");
- } else {
- logTrace("Queue name is " + replyDestination.getQueueName());
- if (replyDestination.getQueueName()
- .equals(tool.getDefaultQueue().getQueueName())) {
- logTrace("Pass ");
- } else {
- logMsg("MapMessage Failed");
- pass = false;
- }
- }
-
- // send and receive bytes message to Queue
- logTrace("Send BytesMessage to Queue.");
- messageSentB = tool.getDefaultQueueSession().createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDestinationQTest");
- messageSentB.writeByte(bValue);
- tool.getDefaultQueueSender().send(messageSentB);
- messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSDestination: " + messageReceivedB.getJMSDestination());
- replyDestination = (Queue) messageReceived.getJMSDestination();
- if (replyDestination == null) {
- pass = false;
- logMsg("BytesMessage Error: JMSDestination returned a null");
- } else {
- logTrace("Queue name is " + replyDestination.getQueueName());
- if (replyDestination.getQueueName()
- .equals(tool.getDefaultQueue().getQueueName())) {
- logTrace("Pass ");
- } else {
- logMsg("BytesMessage Failed");
- pass = false;
- }
- }
-
- // Send and receive a StreamMessage
- logTrace("sending a StreamMessage");
- messageSentS = tool.getDefaultQueueSession().createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDestinationQTest");
- messageSentS.writeString("Testing...");
- logTrace("Sending StreamMessage");
- tool.getDefaultQueueSender().send(messageSentS);
- messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- logTrace("JMSDestination: " + messageReceivedS.getJMSDestination());
- replyDestination = (Queue) messageReceived.getJMSDestination();
- if (replyDestination == null) {
- pass = false;
- logMsg("StreamMessage Error: JMSDestination returned a null");
- } else {
- logTrace("Queue name is " + replyDestination.getQueueName());
- if (replyDestination.getQueueName()
- .equals(tool.getDefaultQueue().getQueueName())) {
- logTrace("Pass ");
- } else {
- logMsg("StreamMessage Failed");
- pass = false;
- }
- }
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSDestination returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrJMSDestinationQTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSDeliveryModeQTest
- *
- * @assertion_ids: JMS:SPEC:3; JMS:SPEC:140; JMS:SPEC:246.2; JMS:JAVADOC:301;
- * JMS:JAVADOC:367; JMS:JAVADOC:369;
- *
- * @test_Strategy: 1. Create and send a message to the default Queue. Receive
- * the msg and verify that JMSDeliveryMode is set the default delivery mode of
- * persistent. 2. Create and test another message with a nonpersistent
- * delivery mode. Test with Text, map, object, byte, and stream messages 3.
- * Set JMSDeliveryMode to Message after receive. Verify that JMSDeliveryMode
- * is set correctly.
- */
-
- public void msgHdrJMSDeliveryModeQTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- String testName = "msgHdrJMSDeliveryModeQTest";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- logTrace("send TextMessage to Queue.");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- tool.getDefaultQueueSender().send(messageSent);
-
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logErr(
- "TextMessage Error: JMSDeliveryMode should be set to persistent as default");
- }
-
- messageReceived.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logErr(
- "TextMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
- }
-
- // send and receive Object message to Queue
- logTrace("send ObjectMessage to Queue.");
- messageSentO = tool.getDefaultQueueSession().createObjectMessage();
- messageSentO.setObject("Test for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- tool.getDefaultQueueSender().send(messageSentO);
-
- messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedO.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logMsg(
- "ObjectMessage Error: JMSDeliveryMode should be set to persistent as default");
- }
-
- messageReceivedO.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
- if (messageReceivedO
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logErr(
- "ObjectMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
- }
-
- // send and receive map message to Queue
- logTrace("send MapMessage to Queue.");
- messageSentM = tool.getDefaultQueueSession().createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentM.setString("aString", "value");
- tool.getDefaultQueueSender().send(messageSentM);
-
- messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedM.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logMsg(
- "MapMessage Error: JMSDeliveryMode should be set to persistent as default");
- }
-
- messageReceivedM.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
- if (messageReceivedM
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logErr(
- "MapMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
- }
-
- // send and receive bytes message to Queue
- logTrace("send BytesMessage to Queue.");
- messageSentB = tool.getDefaultQueueSession().createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentB.writeByte(bValue);
- tool.getDefaultQueueSender().send(messageSentB);
-
- messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedB.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logErr(
- "BytesMessage Error: JMSDeliveryMode should be set to persistent as default");
- }
-
- messageReceivedB.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
- if (messageReceivedB
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logErr(
- "BytesMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
- }
-
- // send and receive a StreamMessage
- logTrace("sending a StreamMessage");
- messageSentS = tool.getDefaultQueueSession().createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentS.writeString("Testing...");
- tool.getDefaultQueueSender().send(messageSentS);
-
- messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedS.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logErr(
- "StreamMessage Error: JMSDeliveryMode should be set to persistent as default");
- }
-
- messageReceivedS.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
- if (messageReceivedS
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logErr(
- "StreamMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
- }
-
- // Test again - this time set delivery mode to persistent
- logTrace("send TextMessage to Queue.");
- tool.getDefaultQueueSender().setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- tool.getDefaultQueueSender().send(messageSent);
-
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logErr(
- "TextMessage Error: JMSDeliveryMode should be set to NON_PERSISTENT");
- }
-
- messageReceived.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logErr(
- "TextMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
- }
-
- // send and receive Object message to Queue
- logTrace("send ObjectMessage to Queue.");
- messageSentO = tool.getDefaultQueueSession().createObjectMessage();
- messageSentO.setObject("msgHdrJMSDeliveryModeQTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- tool.getDefaultQueueSender().send(messageSentO);
-
- messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedO
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logErr(
- "ObjectMessage Error: JMSDeliveryMode should be set to NON_PERSISTENT");
- }
-
- messageReceivedO.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
- if (messageReceivedO.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logErr(
- "ObjectMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
- }
-
- // send and receive map message to Queue
- logTrace("send MapMessage to Queue.");
- messageSentM = tool.getDefaultQueueSession().createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentM.setString("aString", "value");
- tool.getDefaultQueueSender().send(messageSentM);
-
- messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedM
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logErr(
- "MapMessage Error: JMSDeliveryMode should be set to NON_PERSISTENT");
- }
-
- messageReceivedM.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
- if (messageReceivedM.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logErr(
- "MapMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
- }
-
- // send and receive bytes message to Queue
- logTrace("send BytesMessage to Queue.");
- messageSentB = tool.getDefaultQueueSession().createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentB.writeByte(bValue);
- tool.getDefaultQueueSender().send(messageSentB);
-
- messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedB
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logErr(
- "BytesMessage Error: JMSDeliveryMode should be set to NON_PERSISTENT");
- }
-
- messageReceivedB.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
- if (messageReceivedB.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logErr(
- "BytesMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
- }
-
- // send and receive a StreamMessage
- logTrace("sending a StreamMessage");
- messageSentS = tool.getDefaultQueueSession().createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentS.writeString("Testing...");
- tool.getDefaultQueueSender().send(messageSentS);
-
- messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedS
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logErr(
- "StreamMessage Error: JMSDeliveryMode should be set to NON_PERSISTENT");
- }
-
- messageReceivedS.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
- if (messageReceivedS.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logErr(
- "StreamMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
- }
-
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSDeliveryMode returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
- }
-
- /*
- * @testName: msgHdrJMSRedeliveredTest
- *
- * @assertion_ids: JMS:JAVADOC:371; JMS:JAVADOC:373;
- *
- * @test_Strategy: 1. Create and send a message to the default Queue. Verify
- * at the receive that JMSRedelivered is false; 3. Set JMSRedelivered to true
- * after receive. Verify that JMSRedelivered is set correctly. Test with Text,
- * Map, Object, Bytes, and Stream messages
- */
-
- public void msgHdrJMSRedeliveredTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- String testName = "msgHdrJMSRedeliveredTest";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- logTrace("send TextMessage to Queue.");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- tool.getDefaultQueueSender().send(messageSent);
-
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived.getJMSRedelivered() != false) {
- pass = false;
- logErr("TextMessage Error: JMSRedelivered should be false");
- }
-
- messageReceived.setJMSRedelivered(true);
- if (messageReceived.getJMSRedelivered() != true) {
- pass = false;
- logErr(
- "TextMessage Error: JMSRedelivered not set correctly by setJMSRedelivered");
- }
-
- // send and receive Object message to Queue
- logTrace("send ObjectMessage to Queue.");
- messageSentO = tool.getDefaultQueueSession().createObjectMessage();
- messageSentO.setObject("Test for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- tool.getDefaultQueueSender().send(messageSentO);
-
- messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedO.getJMSRedelivered() != false) {
- pass = false;
- logErr("ObjectMessage Error: JMSRedelivered should be false");
- }
-
- messageReceivedO.setJMSRedelivered(true);
- if (messageReceivedO.getJMSRedelivered() != true) {
- pass = false;
- logErr(
- "ObjectMessage Error: JMSRedelivered not set correctly by setJMSRedelivered");
- }
-
- // send and receive map message to Queue
- logTrace("send MapMessage to Queue.");
- messageSentM = tool.getDefaultQueueSession().createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentM.setString("aString", "value");
- tool.getDefaultQueueSender().send(messageSentM);
-
- messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedM.getJMSRedelivered() != false) {
- pass = false;
- logErr("MapMessage Error: JMSRedelivered should be false");
- }
-
- messageReceivedM.setJMSRedelivered(true);
- if (messageReceivedM.getJMSRedelivered() != true) {
- pass = false;
- logErr(
- "MapMessage Error: JMSRedelivered not set correctly by setJMSRedelivered");
- }
-
- // send and receive bytes message to Queue
- logTrace("send BytesMessage to Queue.");
- messageSentB = tool.getDefaultQueueSession().createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentB.writeByte(bValue);
- tool.getDefaultQueueSender().send(messageSentB);
-
- messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedB.getJMSRedelivered() != false) {
- pass = false;
- logErr("BytesMessage Error: JMSRedelivered should be false");
- }
-
- messageReceivedB.setJMSRedelivered(true);
- if (messageReceivedB.getJMSRedelivered() != true) {
- pass = false;
- logErr(
- "BytesMessage Error: JMSRedelivered not set correctly by setJMSRedelivered");
- }
-
- // send and receive a StreamMessage
- logTrace("sending a StreamMessage");
- messageSentS = tool.getDefaultQueueSession().createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentS.writeString("Testing...");
- tool.getDefaultQueueSender().send(messageSentS);
-
- messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceivedS.getJMSRedelivered() != false) {
- pass = false;
- logErr("StreamMessage Error: JMSRedelivered should be false");
- }
-
- messageReceivedS.setJMSRedelivered(true);
- if (messageReceivedS.getJMSRedelivered() != true) {
- pass = false;
- logErr(
- "StreamMessage Error: JMSRedelivered not set correctly by setJMSRedelivered");
- }
-
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSDeliveryMode returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/queueMsgHeaders/QueueHeaderTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/queueMsgHeaders/QueueHeaderTestsIT.java
new file mode 100644
index 0000000000..6f4c775fe6
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/queueMsgHeaders/QueueHeaderTestsIT.java
@@ -0,0 +1,1731 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.core.queueMsgHeaders;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.DeliveryMode;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.Queue;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+
+
+public class QueueHeaderTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.queueMsgHeaders.QueueHeaderTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(QueueHeaderTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+ queues = new ArrayList(2);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * helper method for msgHdrIDQTest and msgHdrIDTopicTest verifies that the
+ * JMSMessageID starts with ID:
+ *
+ *
+ * @param String returned from getJMSMessageID
+ *
+ * @return boolean true if id correctly starts with ID:
+ */
+ @Test
+ private boolean chkMessageID(String id) {
+ String status[] = { "Pass", "Fail" };
+ boolean retcode = true;
+
+ // message id must start with ID: - unless it is null
+ int index = 0;
+
+ if (id == null) {
+ ;
+ } else if (id.startsWith("ID:")) {
+ ;
+ } else {
+ index = 1;
+ retcode = false;
+ }
+ logger.log(Logger.Level.TRACE, "Results: " + status[index]);
+ return retcode;
+ }
+
+ /*
+ * @testName: msgHdrIDQTest
+ *
+ * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343;
+ *
+ * @test_Strategy: Send to a Queue and receive Text, Map, Bytes, Stream, and
+ * object message. call getJMSMessageID and verify that it starts with ID:
+ */
+ @Test
+ public void msgHdrIDQTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ String id = null;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Queue.");
+ messageSentO = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentO.setObject("msgHdrIDQTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDQTest");
+ tool.getDefaultQueueSender().send(messageSentO);
+ messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "getJMSMessageID ");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedO.getJMSMessageID());
+ id = messageReceivedO.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.INFO, "ObjectMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ }
+ // send and receive map message to Queue
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Queue.");
+ messageSentM = tool.getDefaultQueueSession().createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDQTest");
+ messageSentM.setString("aString", "value");
+ tool.getDefaultQueueSender().send(messageSentM);
+ messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "getJMSMessageID ");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedM.getJMSMessageID());
+ id = messageReceivedM.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.INFO, "MapMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Queue.");
+ messageSentB = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDQTest");
+ messageSentB.writeByte(bValue);
+ tool.getDefaultQueueSender().send(messageSentB);
+ messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "getJMSMessageID ");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedB.getJMSMessageID());
+ id = messageReceivedB.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.INFO, "BytesMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a StreamMessage");
+ messageSentS = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDQTest");
+ messageSentS.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSentS);
+ messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "getJMSMessageID ");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedS.getJMSMessageID());
+ id = messageReceivedS.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.INFO, "StreamMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ }
+
+ // TextMessage
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("sending a TextMessage");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDQTest");
+ logger.log(Logger.Level.TRACE, "sending a TextMessage");
+ tool.getDefaultQueueSender().send(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "getJMSMessageID ");
+ logger.log(Logger.Level.TRACE, " " + messageReceived.getJMSMessageID());
+ id = messageReceived.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.INFO, "TextMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSMessageID returned from JMSMessageID");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrIDQTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrTimeStampQTest
+ *
+ * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347;
+ *
+ * @test_Strategy: With a queue destination Send a single Text, map, bytes,
+ * stream, and object message check time of send against time send returns
+ * JMSTimeStamp should be between these two
+ */
+ @Test
+ public void msgHdrTimeStampQTest() throws Exception {
+ boolean pass = true;
+ long timeBeforeSend;
+ long timeAfterSend;
+ byte bValue = 127;
+
+ try {
+ TextMessage messageSent = null;
+ StreamMessage messageSentS = null;
+ BytesMessage messageSentB = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Queue.");
+ messageSentO = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentO.setObject("msgHdrTimeStampQTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampQTest");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultQueueSender().send(messageSentO);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSentO.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentO.getJMSTimestamp())
+ && (timeAfterSend >= messageSentO.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "ObjectMessage TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from ObjectMessage");
+ pass = false;
+ }
+
+ // send map message to Queue
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Queue.");
+ messageSentM = tool.getDefaultQueueSession().createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampQTest");
+ messageSentM.setString("aString", "value");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultQueueSender().send(messageSentM);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSentM.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if (!(timeBeforeSend <= messageSentM.getJMSTimestamp())
+ && (timeAfterSend >= messageSentM.getJMSTimestamp())) {
+ logger.log(Logger.Level.ERROR, "Error: invalid timestamp from MapMessage");
+ pass = false;
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Queue.");
+ messageSentB = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampQTest");
+ messageSentB.writeByte(bValue);
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultQueueSender().send(messageSentB);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSentB.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentB.getJMSTimestamp())
+ && (timeAfterSend >= messageSentB.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "BytesMessage TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from BytesMessage");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a StreamMessage");
+ messageSentS = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampQTest");
+ messageSentS.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending message");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultQueueSender().send(messageSentS);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSentS.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentS.getJMSTimestamp())
+ && (timeAfterSend >= messageSentS.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "StreamMessage TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from StreamMessage");
+ pass = false;
+ }
+
+ // TextMessage
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("sending a TextMessage");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampQTest");
+ logger.log(Logger.Level.TRACE, "sending a TextMessage");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultQueueSender().send(messageSent);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSent.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if (!(timeBeforeSend <= messageSent.getJMSTimestamp())
+ && (timeAfterSend >= messageSent.getJMSTimestamp())) {
+ logger.log(Logger.Level.ERROR, "Error: invalid timestamp from TextMessage");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid TimeStamp returned from JMSTimeStamp");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrTimeStampQTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrCorlIdQTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ * @test_Strategy: Send a message to a Queue with CorrelationID set. Receive msg
+ * and verify the correlationid is as set by client
+ */
+ @Test
+ public void msgHdrCorlIdQTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ String jmsCorrelationID = "testCorrelationid";
+ String testName = "msgHdrCorlIdQTest";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ logger.log(Logger.Level.TRACE, "Send TextMessage to Queue.");
+ messageSent.setJMSCorrelationID(jmsCorrelationID);
+ try {
+ tool.getDefaultQueueSender().send(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "messageReceived is null");
+ pass = false;
+ } else if (messageReceived.getJMSCorrelationID() == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TextMessage Error: JMSCorrelationID returned a null");
+ } else if (!messageReceived.getJMSCorrelationID().equals(jmsCorrelationID)) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TextMessage Error: JMSCorrelationID is incorrect");
+ }
+ } catch (java.lang.Exception e) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Unexpected Exception: ", e);
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Queue.");
+ messageSentM = tool.getDefaultQueueSession().createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentM.setJMSCorrelationID(jmsCorrelationID);
+ messageSentM.setString("aString", "value");
+ tool.getDefaultQueueSender().send(messageSentM);
+
+ messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedM.getJMSCorrelationID() == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "MapMessage Error: JMSCorrelationID returned a null");
+ } else if (!messageReceivedM.getJMSCorrelationID().equals(jmsCorrelationID)) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "MapMessage Error: JMSCorrelationID is incorrect");
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Queue.");
+ messageSentB = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentB.setJMSCorrelationID(jmsCorrelationID);
+ messageSentB.writeByte(bValue);
+ tool.getDefaultQueueSender().send(messageSentB);
+
+ messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedB.getJMSCorrelationID() == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "BytesMessage Error: JMSCorrelationID returned a null");
+ } else if (!messageReceivedB.getJMSCorrelationID().equals(jmsCorrelationID)) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Byte Message Error: JMSCorrelationID is incorrect");
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a StreamMessage");
+ messageSentS = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentS.setJMSCorrelationID(jmsCorrelationID);
+ messageSentS.writeString("Testing...");
+ tool.getDefaultQueueSender().send(messageSentS);
+
+ messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedS.getJMSCorrelationID() == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "StreamMessage Error: JMSCorrelationID returned a null");
+ } else if (!messageReceivedS.getJMSCorrelationID().equals(jmsCorrelationID)) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "StreamMessage Error: JMSCorrelationID is incorrect");
+ }
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Queue.");
+ messageSentO = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentO.setObject("msgHdrIDQTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentO.setJMSCorrelationID(jmsCorrelationID);
+ tool.getDefaultQueueSender().send(messageSentO);
+
+ messageReceivedO = (ObjectMessage) (Message) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedO.getJMSCorrelationID() == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "ObjectMessage Error: JMSCorrelationID returned a null");
+ } else if (!messageReceivedO.getJMSCorrelationID().equals(jmsCorrelationID)) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "ObjectMessage Error: JMSCorrelationID is incorrect");
+ }
+
+ if (!pass) {
+ throw new Exception("Error: invalid JMSCorrelationID returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+ }
+
+ /*
+ * @testName: msgHdrReplyToQTest
+ *
+ * @assertion_ids: JMS:SPEC:12; JMS:SPEC:246.8; JMS:JAVADOC:359;
+ * JMS:JAVADOC:361; JMS:JAVADOC:286; JMS:JAVADOC:289; JMS:JAVADOC:562;
+ * JMS:JAVADOC:166;
+ *
+ * @test_Strategy: Send a message to a Queue with ReplyTo set to null and then
+ * set to a destination test with Text, map, object, byte, and stream messages
+ * verify on receive.
+ *
+ */
+ @Test
+ public void msgHdrReplyToQTest() throws Exception {
+ boolean pass = true;
+ Queue replyQueue = null;
+ byte bValue = 127;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrReplyToQTest");
+ logger.log(Logger.Level.TRACE, "Send Text message");
+
+ // messageSent.setJMSReplyTo(tool.getDefaultQueue());
+ tool.getDefaultQueueSender().send(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived.getJMSReplyTo() == null) {
+ logger.log(Logger.Level.TRACE, " as expected replyto field is null");
+ } else {
+ logger.log(Logger.Level.INFO, "ERROR: expected replyto field should have been null for this case");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Set ReplyTo and resend msg");
+ messageSent.setJMSReplyTo(tool.getDefaultQueue());
+ tool.getDefaultQueueSender().send(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ replyQueue = (Queue) messageReceived.getJMSReplyTo();
+ logger.log(Logger.Level.TRACE, "Queue name is " + replyQueue.getQueueName());
+ if (replyQueue.getQueueName().equals(tool.getDefaultQueue().getQueueName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage Failed");
+ pass = false;
+ }
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Queue.");
+ messageSentO = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentO.setObject("msgHdrReplyToQTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrReplyToQTest");
+ tool.getDefaultQueueSender().send(messageSentO);
+ messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedO.getJMSReplyTo() == null) {
+ logger.log(Logger.Level.TRACE, " as expected replyto field is null");
+ } else {
+ replyQueue = (Queue) messageReceivedO.getJMSReplyTo();
+ logger.log(Logger.Level.INFO, "ReplyTo is: " + replyQueue.toString());
+ logger.log(Logger.Level.INFO, "ERROR: expected replyto field to be null in this case");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Set ReplyTo and resend msg");
+ messageSentO.setJMSReplyTo(tool.getDefaultQueue());
+ tool.getDefaultQueueSender().send(messageSentO);
+ messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ replyQueue = (Queue) messageReceivedO.getJMSReplyTo();
+ logger.log(Logger.Level.TRACE, "Queue name is " + replyQueue.getQueueName());
+ if (replyQueue.getQueueName().equals(tool.getDefaultQueue().getQueueName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage ReplyTo Failed");
+ pass = false;
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Queue.");
+ messageSentM = tool.getDefaultQueueSession().createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrReplyToQTest");
+ messageSentM.setString("aString", "value");
+ tool.getDefaultQueueSender().send(messageSentM);
+ messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedM.getJMSReplyTo() == null) {
+ logger.log(Logger.Level.TRACE, " as expected replyto field is null");
+ } else {
+ logger.log(Logger.Level.INFO, "ERROR: expected replyto field to be null in this case");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Set ReplyTo and resend msg");
+ messageSentM.setJMSReplyTo(tool.getDefaultQueue());
+ tool.getDefaultQueueSender().send(messageSentM);
+ messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received Map message ");
+ replyQueue = (Queue) messageReceivedM.getJMSReplyTo();
+ logger.log(Logger.Level.TRACE, "Queue name is " + replyQueue.getQueueName());
+ if (replyQueue.getQueueName().equals(tool.getDefaultQueue().getQueueName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage ReplyTo Failed");
+ pass = false;
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Queue.");
+ messageSentB = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrReplyToQTest");
+ messageSentB.writeByte(bValue);
+ tool.getDefaultQueueSender().send(messageSentB);
+ messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedB.getJMSReplyTo() == null) {
+ logger.log(Logger.Level.TRACE, " as expected replyto field is null");
+ } else {
+ logger.log(Logger.Level.INFO, "ERROR: expected replyto field to be null in this case");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Set ReplyTo and resend msg");
+ messageSentB.setJMSReplyTo(tool.getDefaultQueue());
+ tool.getDefaultQueueSender().send(messageSentB);
+ messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received Bytes message ");
+ replyQueue = (Queue) messageReceivedB.getJMSReplyTo();
+ logger.log(Logger.Level.TRACE, "Queue name is " + replyQueue.getQueueName());
+ if (replyQueue.getQueueName().equals(tool.getDefaultQueue().getQueueName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage ReplyTo Failed");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ messageSentS = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrReplyToQTest");
+ messageSentS.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending StreamMessage");
+ tool.getDefaultQueueSender().send(messageSentS);
+ messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedS.getJMSReplyTo() == null) {
+ logger.log(Logger.Level.TRACE, " as expected replyto field is null");
+ } else {
+ replyQueue = (Queue) messageReceivedS.getJMSReplyTo();
+ logger.log(Logger.Level.INFO, "ERROR: expected replyto field to be null in this case");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Set ReplyTo and resend msg");
+ messageSentS.setJMSReplyTo(tool.getDefaultQueue());
+ tool.getDefaultQueueSender().send(messageSentS);
+ messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received Stream message ");
+ replyQueue = (Queue) messageReceivedS.getJMSReplyTo();
+ logger.log(Logger.Level.TRACE, "Queue name is " + replyQueue.getQueueName());
+ if (replyQueue.getQueueName().equals(tool.getDefaultQueue().getQueueName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage ReplyTo Failed");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid Replyto returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrReplyToQTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSTypeQTest
+ *
+ * @assertion_ids: JMS:SPEC:246.9; JMS:JAVADOC:375; JMS:JAVADOC:377;
+ *
+ * @test_Strategy: Send a message to a Queue with JMSType set to TESTMSG test
+ * with Text, map, object, byte, and stream messages verify on receive.
+ *
+ */
+ @Test
+ public void msgHdrJMSTypeQTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ String type = "TESTMSG";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSTypeQTest");
+ logger.log(Logger.Level.TRACE, "JMSType test - Send a TextMessage");
+ messageSent.setJMSType(type);
+ tool.getDefaultQueueSender().send(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSType is " + (String) messageReceived.getJMSType());
+ if (messageReceived.getJMSType().equals(type)) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage Failed");
+ pass = false;
+ }
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "JMSType test - Send ObjectMessage to Queue.");
+ messageSentO = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentO.setObject("msgHdrJMSTypeQTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSTypeQTest");
+ messageSentO.setJMSType(type);
+ tool.getDefaultQueueSender().send(messageSentO);
+ messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSType is " + (String) messageReceivedO.getJMSType());
+ if (messageReceivedO.getJMSType().equals(type)) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSType Failed");
+ pass = false;
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.TRACE, "JMSType test - Send MapMessage to Queue.");
+ messageSentM = tool.getDefaultQueueSession().createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSTypeQTest");
+ messageSentM.setString("aString", "value");
+ messageSentM.setJMSType(type);
+ tool.getDefaultQueueSender().send(messageSentM);
+ messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSType is " + (String) messageReceivedM.getJMSType());
+ if (messageReceivedM.getJMSType().equals(type)) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSType Failed");
+ pass = false;
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "JMSType test - Send BytesMessage to Queue.");
+ messageSentB = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSTypeQTest");
+ messageSentB.writeByte(bValue);
+ messageSentB.setJMSType(type);
+ tool.getDefaultQueueSender().send(messageSentB);
+ messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSType is " + (String) messageReceivedB.getJMSType());
+ if (messageReceivedB.getJMSType().equals(type)) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSType Failed");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "JMSType test - sending a StreamMessage");
+ messageSentS = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSTypeQTest");
+ messageSentS.writeString("Testing...");
+ messageSentS.setJMSType(type);
+ tool.getDefaultQueueSender().send(messageSentS);
+ messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSType is " + (String) messageReceivedS.getJMSType());
+ if (messageReceivedS.getJMSType().equals(type)) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSType Failed");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSType returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrJMSTypeQTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSPriorityQTest
+ *
+ * @assertion_ids: JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140; JMS:JAVADOC:305;
+ * JMS:JAVADOC:383;
+ *
+ * @test_Strategy: Send a message to a Queue with JMSPriority set to 2 test with
+ * Text, map, object, byte, and stream messages verify on receive.
+ *
+ */
+ @Test
+ public void msgHdrJMSPriorityQTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ int priority = 2;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityQTest");
+ logger.log(Logger.Level.TRACE, "JMSPriority test - Send a TextMessage");
+ tool.getDefaultQueueSender().setPriority(priority);
+ tool.getDefaultQueueSender().send(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSPriority is " + messageReceived.getJMSPriority());
+ if (messageReceived.getJMSPriority() == priority) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage Failed");
+ pass = false;
+ }
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "JMSPriority test - Send ObjectMessage to Queue.");
+ messageSentO = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentO.setObject("msgHdrJMSPriorityQTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityQTest");
+ tool.getDefaultQueueSender().setPriority(priority);
+ tool.getDefaultQueueSender().send(messageSentO);
+ messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSPriority is " + messageReceivedO.getJMSPriority());
+ if (messageReceivedO.getJMSPriority() == priority) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSPriority Failed");
+ pass = false;
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.TRACE, "JMSPriority test - Send MapMessage to Queue.");
+ messageSentM = tool.getDefaultQueueSession().createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityQTest");
+ messageSentM.setString("aString", "value");
+ tool.getDefaultQueueSender().setPriority(priority);
+ tool.getDefaultQueueSender().send(messageSentM);
+ messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSPriority is " + messageReceivedM.getJMSPriority());
+ if (messageReceivedM.getJMSPriority() == priority) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSPriority Failed");
+ pass = false;
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "JMSPriority test - Send BytesMessage to Queue.");
+ messageSentB = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityQTest");
+ messageSentB.writeByte(bValue);
+ tool.getDefaultQueueSender().setPriority(priority);
+ tool.getDefaultQueueSender().send(messageSentB);
+ messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSPriority is " + messageReceivedB.getJMSPriority());
+ if (messageReceivedB.getJMSPriority() == priority) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSPriority Failed");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "JMSPriority test - sending a StreamMessage");
+ messageSentS = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityQTest");
+ messageSentS.writeString("Testing...");
+ tool.getDefaultQueueSender().setPriority(priority);
+ tool.getDefaultQueueSender().send(messageSentS);
+ messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSPriority is " + messageReceivedS.getJMSPriority());
+ if (messageReceivedS.getJMSPriority() == priority) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSPriority Failed");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSPriority returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrJMSPriorityQTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSExpirationQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:15.1; JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140;
+ * JMS:JAVADOC:309; JMS:JAVADOC:379;
+ *
+ * @test_Strategy: 1. Send a message to a Queue with time to live set to 0.
+ * Verify on receive that JMSExpiration gets set to 0. Test with Text, Map,
+ * Object, Bytes, and Stream messages. 2. Send a message to a Queue with time to
+ * live set to non-0; Verify on receive that JMSExpiration gets set correctly.
+ */
+ @Test
+ public void msgHdrJMSExpirationQueueTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ long forever = 0L;
+ long timeToLive = timeout;
+ String testName = "msgHdrJMSExpirationQueueTest";
+ long timeBeforeSend = 0L;
+ long timeAfterSend = 0L;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ logger.log(Logger.Level.TRACE, "JMSExpiration test - Send a TextMessage");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("sending a TextMessage");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ tool.getDefaultQueueSender().setTimeToLive(forever);
+ tool.getDefaultQueueSender().send(messageSent);
+
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.ERROR, "TextMessage Failed");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.TRACE, "JMSExpiration test - Send a TextMessage");
+ tool.getDefaultQueueSender().setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultQueueSender().send(messageSent);
+ timeAfterSend = System.currentTimeMillis();
+
+ long exp = messageSent.getJMSExpiration();
+ logger.log(Logger.Level.TRACE, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.TRACE, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.TRACE, "Time to Live =" + timeToLive);
+
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "TextMessage Failed: JMSExpiration didnot set correctly = "
+ + messageReceived.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ }
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "JMSExpiration test - Send ObjectMessage to Queue.");
+ messageSentO = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentO.setObject("msgHdrJMSExpirationQueueTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ tool.getDefaultQueueSender().setTimeToLive(forever);
+ tool.getDefaultQueueSender().send(messageSentO);
+ messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedO.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSExpiration Failed");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.TRACE, "JMSExpiration test - Send an ObjectMessage");
+ tool.getDefaultQueueSender().setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultQueueSender().send(messageSentO);
+ timeAfterSend = System.currentTimeMillis();
+
+ exp = messageSentO.getJMSExpiration();
+ logger.log(Logger.Level.TRACE, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.TRACE, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.TRACE, "Time to Live =" + timeToLive);
+
+ messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedO.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage Failed: JMSExpiration didnot set correctly = "
+ + messageReceivedO.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.TRACE, "JMSExpiration test - Send MapMessage to Queue.");
+ messageSentM = tool.getDefaultQueueSession().createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentM.setString("aString", "value");
+ tool.getDefaultQueueSender().setTimeToLive(forever);
+ tool.getDefaultQueueSender().send(messageSentM);
+ messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedM.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.INFO, "MapMessage JMSExpiration Failed");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.TRACE, "JMSExpiration test - Send a MapMessage");
+ tool.getDefaultQueueSender().setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultQueueSender().send(messageSentM);
+ timeAfterSend = System.currentTimeMillis();
+
+ exp = messageSentM.getJMSExpiration();
+ logger.log(Logger.Level.TRACE, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.TRACE, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.TRACE, "Time to Live =" + timeToLive);
+
+ messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedM.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "MapMessage Failed: JMSExpiration didnot set correctly = "
+ + messageReceivedM.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "JMSExpiration test - Send BytesMessage to Queue.");
+ messageSentB = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentB.writeByte(bValue);
+ tool.getDefaultQueueSender().setTimeToLive(forever);
+ tool.getDefaultQueueSender().send(messageSentB);
+ messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedB.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSExpiration Failed");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.TRACE, "JMSExpiration test - Send a BytesMessage");
+ tool.getDefaultQueueSender().setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultQueueSender().send(messageSentB);
+ timeAfterSend = System.currentTimeMillis();
+
+ exp = messageSentB.getJMSExpiration();
+ logger.log(Logger.Level.TRACE, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.TRACE, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.TRACE, "Time to Live =" + timeToLive);
+
+ messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedB.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "BytesMessage Failed: JMSExpiration didnot set correctly = "
+ + messageReceivedB.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "JMSExpiration test - sending a StreamMessage");
+ messageSentS = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentS.writeString("Testing...");
+ tool.getDefaultQueueSender().setTimeToLive(forever);
+ tool.getDefaultQueueSender().send(messageSentS);
+ messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedS.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSExpiration Failed");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.TRACE, "JMSExpiration test - Send a StreamMessage");
+ tool.getDefaultQueueSender().setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultQueueSender().send(messageSentS);
+ timeAfterSend = System.currentTimeMillis();
+
+ exp = messageSentS.getJMSExpiration();
+ logger.log(Logger.Level.TRACE, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.TRACE, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.TRACE, "Time to Live =" + timeToLive);
+
+ messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedS.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "StreamMessage Failed: JMSExpiration didnot set correctly = "
+ + messageReceivedS.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("Error: invalid JMSExpiration returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSDestinationQTest
+ *
+ * @assertion_ids: JMS:SPEC:2; JMS:JAVADOC:363; JMS:JAVADOC:286;
+ *
+ * @test_Strategy: Create and send a message to the default Queue. Receive msg
+ * and verify that JMSDestination is set to the default Queue test with Text,
+ * map, object, byte, and stream messages
+ */
+ @Test
+ public void msgHdrJMSDestinationQTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ Queue replyDestination = null;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDestinationQTest");
+ logger.log(Logger.Level.TRACE, "Send TextMessage to Queue.");
+ tool.getDefaultQueueSender().send(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDestination: " + messageReceived.getJMSDestination());
+ replyDestination = (Queue) messageReceived.getJMSDestination();
+ if (replyDestination == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "TextMessage Error: JMSDestination returned a null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Queue name is " + replyDestination.getQueueName());
+ if (replyDestination.getQueueName().equals(tool.getDefaultQueue().getQueueName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage Failed");
+ pass = false;
+ }
+ }
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Queue.");
+ messageSentO = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentO.setObject("msgHdrJMSDestinationQTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDestinationQTest");
+ tool.getDefaultQueueSender().send(messageSentO);
+ messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDestination: " + messageReceivedO.getJMSDestination());
+ replyDestination = (Queue) messageReceived.getJMSDestination();
+ if (replyDestination == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "ObjectMessage Error: JMSDestination returned a null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Queue name is " + replyDestination.getQueueName());
+ if (replyDestination.getQueueName().equals(tool.getDefaultQueue().getQueueName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage Failed");
+ pass = false;
+ }
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Queue.");
+ messageSentM = tool.getDefaultQueueSession().createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDestinationQTest");
+ messageSentM.setString("aString", "value");
+ tool.getDefaultQueueSender().send(messageSentM);
+ messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDestination: " + messageReceivedM.getJMSDestination());
+ replyDestination = (Queue) messageReceived.getJMSDestination();
+ if (replyDestination == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "MapMessage Error: JMSDestination returned a null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Queue name is " + replyDestination.getQueueName());
+ if (replyDestination.getQueueName().equals(tool.getDefaultQueue().getQueueName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage Failed");
+ pass = false;
+ }
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Queue.");
+ messageSentB = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDestinationQTest");
+ messageSentB.writeByte(bValue);
+ tool.getDefaultQueueSender().send(messageSentB);
+ messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDestination: " + messageReceivedB.getJMSDestination());
+ replyDestination = (Queue) messageReceived.getJMSDestination();
+ if (replyDestination == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "BytesMessage Error: JMSDestination returned a null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Queue name is " + replyDestination.getQueueName());
+ if (replyDestination.getQueueName().equals(tool.getDefaultQueue().getQueueName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage Failed");
+ pass = false;
+ }
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a StreamMessage");
+ messageSentS = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDestinationQTest");
+ messageSentS.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending StreamMessage");
+ tool.getDefaultQueueSender().send(messageSentS);
+ messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDestination: " + messageReceivedS.getJMSDestination());
+ replyDestination = (Queue) messageReceived.getJMSDestination();
+ if (replyDestination == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "StreamMessage Error: JMSDestination returned a null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Queue name is " + replyDestination.getQueueName());
+ if (replyDestination.getQueueName().equals(tool.getDefaultQueue().getQueueName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage Failed");
+ pass = false;
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSDestination returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrJMSDestinationQTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSDeliveryModeQTest
+ *
+ * @assertion_ids: JMS:SPEC:3; JMS:SPEC:140; JMS:SPEC:246.2; JMS:JAVADOC:301;
+ * JMS:JAVADOC:367; JMS:JAVADOC:369;
+ *
+ * @test_Strategy: 1. Create and send a message to the default Queue. Receive
+ * the msg and verify that JMSDeliveryMode is set the default delivery mode of
+ * persistent. 2. Create and test another message with a nonpersistent delivery
+ * mode. Test with Text, map, object, byte, and stream messages 3. Set
+ * JMSDeliveryMode to Message after receive. Verify that JMSDeliveryMode is set
+ * correctly.
+ */
+ @Test
+ public void msgHdrJMSDeliveryModeQTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ String testName = "msgHdrJMSDeliveryModeQTest";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ logger.log(Logger.Level.TRACE, "send TextMessage to Queue.");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ tool.getDefaultQueueSender().send(messageSent);
+
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "TextMessage Error: JMSDeliveryMode should be set to persistent as default");
+ }
+
+ messageReceived.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "TextMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
+ }
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "send ObjectMessage to Queue.");
+ messageSentO = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentO.setObject("Test for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ tool.getDefaultQueueSender().send(messageSentO);
+
+ messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedO.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO,
+ "ObjectMessage Error: JMSDeliveryMode should be set to persistent as default");
+ }
+
+ messageReceivedO.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ if (messageReceivedO.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "ObjectMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.TRACE, "send MapMessage to Queue.");
+ messageSentM = tool.getDefaultQueueSession().createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentM.setString("aString", "value");
+ tool.getDefaultQueueSender().send(messageSentM);
+
+ messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedM.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO,
+ "MapMessage Error: JMSDeliveryMode should be set to persistent as default");
+ }
+
+ messageReceivedM.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ if (messageReceivedM.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "MapMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "send BytesMessage to Queue.");
+ messageSentB = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentB.writeByte(bValue);
+ tool.getDefaultQueueSender().send(messageSentB);
+
+ messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedB.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "BytesMessage Error: JMSDeliveryMode should be set to persistent as default");
+ }
+
+ messageReceivedB.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ if (messageReceivedB.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "BytesMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
+ }
+
+ // send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a StreamMessage");
+ messageSentS = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentS.writeString("Testing...");
+ tool.getDefaultQueueSender().send(messageSentS);
+
+ messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedS.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "StreamMessage Error: JMSDeliveryMode should be set to persistent as default");
+ }
+
+ messageReceivedS.setJMSDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ if (messageReceivedS.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "StreamMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
+ }
+
+ // Test again - this time set delivery mode to persistent
+ logger.log(Logger.Level.TRACE, "send TextMessage to Queue.");
+ tool.getDefaultQueueSender().setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ tool.getDefaultQueueSender().send(messageSent);
+
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TextMessage Error: JMSDeliveryMode should be set to NON_PERSISTENT");
+ }
+
+ messageReceived.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "TextMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
+ }
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "send ObjectMessage to Queue.");
+ messageSentO = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentO.setObject("msgHdrJMSDeliveryModeQTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ tool.getDefaultQueueSender().send(messageSentO);
+
+ messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedO.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "ObjectMessage Error: JMSDeliveryMode should be set to NON_PERSISTENT");
+ }
+
+ messageReceivedO.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
+ if (messageReceivedO.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "ObjectMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.TRACE, "send MapMessage to Queue.");
+ messageSentM = tool.getDefaultQueueSession().createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentM.setString("aString", "value");
+ tool.getDefaultQueueSender().send(messageSentM);
+
+ messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedM.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "MapMessage Error: JMSDeliveryMode should be set to NON_PERSISTENT");
+ }
+
+ messageReceivedM.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
+ if (messageReceivedM.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "MapMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "send BytesMessage to Queue.");
+ messageSentB = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentB.writeByte(bValue);
+ tool.getDefaultQueueSender().send(messageSentB);
+
+ messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedB.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "BytesMessage Error: JMSDeliveryMode should be set to NON_PERSISTENT");
+ }
+
+ messageReceivedB.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
+ if (messageReceivedB.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "BytesMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
+ }
+
+ // send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a StreamMessage");
+ messageSentS = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentS.writeString("Testing...");
+ tool.getDefaultQueueSender().send(messageSentS);
+
+ messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedS.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "StreamMessage Error: JMSDeliveryMode should be set to NON_PERSISTENT");
+ }
+
+ messageReceivedS.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
+ if (messageReceivedS.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "StreamMessage Error: JMSDeliveryMode not set correctly by setJMSDeliveryMode");
+ }
+
+ if (!pass) {
+ throw new Exception("Error: invalid JMSDeliveryMode returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSRedeliveredTest
+ *
+ * @assertion_ids: JMS:JAVADOC:371; JMS:JAVADOC:373;
+ *
+ * @test_Strategy: 1. Create and send a message to the default Queue. Verify at
+ * the receive that JMSRedelivered is false; 3. Set JMSRedelivered to true after
+ * receive. Verify that JMSRedelivered is set correctly. Test with Text, Map,
+ * Object, Bytes, and Stream messages
+ */
+ @Test
+ public void msgHdrJMSRedeliveredTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ String testName = "msgHdrJMSRedeliveredTest";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ logger.log(Logger.Level.TRACE, "send TextMessage to Queue.");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ tool.getDefaultQueueSender().send(messageSent);
+
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived.getJMSRedelivered() != false) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TextMessage Error: JMSRedelivered should be false");
+ }
+
+ messageReceived.setJMSRedelivered(true);
+ if (messageReceived.getJMSRedelivered() != true) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "TextMessage Error: JMSRedelivered not set correctly by setJMSRedelivered");
+ }
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "send ObjectMessage to Queue.");
+ messageSentO = tool.getDefaultQueueSession().createObjectMessage();
+ messageSentO.setObject("Test for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ tool.getDefaultQueueSender().send(messageSentO);
+
+ messageReceivedO = (ObjectMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedO.getJMSRedelivered() != false) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "ObjectMessage Error: JMSRedelivered should be false");
+ }
+
+ messageReceivedO.setJMSRedelivered(true);
+ if (messageReceivedO.getJMSRedelivered() != true) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "ObjectMessage Error: JMSRedelivered not set correctly by setJMSRedelivered");
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.TRACE, "send MapMessage to Queue.");
+ messageSentM = tool.getDefaultQueueSession().createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentM.setString("aString", "value");
+ tool.getDefaultQueueSender().send(messageSentM);
+
+ messageReceivedM = (MapMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedM.getJMSRedelivered() != false) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "MapMessage Error: JMSRedelivered should be false");
+ }
+
+ messageReceivedM.setJMSRedelivered(true);
+ if (messageReceivedM.getJMSRedelivered() != true) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "MapMessage Error: JMSRedelivered not set correctly by setJMSRedelivered");
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "send BytesMessage to Queue.");
+ messageSentB = tool.getDefaultQueueSession().createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentB.writeByte(bValue);
+ tool.getDefaultQueueSender().send(messageSentB);
+
+ messageReceivedB = (BytesMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedB.getJMSRedelivered() != false) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "BytesMessage Error: JMSRedelivered should be false");
+ }
+
+ messageReceivedB.setJMSRedelivered(true);
+ if (messageReceivedB.getJMSRedelivered() != true) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "BytesMessage Error: JMSRedelivered not set correctly by setJMSRedelivered");
+ }
+
+ // send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a StreamMessage");
+ messageSentS = tool.getDefaultQueueSession().createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentS.writeString("Testing...");
+ tool.getDefaultQueueSender().send(messageSentS);
+
+ messageReceivedS = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceivedS.getJMSRedelivered() != false) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "StreamMessage Error: JMSRedelivered should be false");
+ }
+
+ messageReceivedS.setJMSRedelivered(true);
+ if (messageReceivedS.getJMSRedelivered() != true) {
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "StreamMessage Error: JMSRedelivered not set correctly by setJMSRedelivered");
+ }
+
+ if (!pass) {
+ throw new Exception("Error: invalid JMSDeliveryMode returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/queueMsgProperties/QueuePropertyTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/queueMsgProperties/QueuePropertyTests.java
deleted file mode 100644
index f6b06b2ecd..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/queueMsgProperties/QueuePropertyTests.java
+++ /dev/null
@@ -1,1707 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.queueMsgProperties;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.ConnectionMetaData;
-import jakarta.jms.MessageFormatException;
-import jakarta.jms.MessageNotWriteableException;
-import jakarta.jms.TextMessage;
-
-public class QueuePropertyTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.queueMsgProperties.QueuePropertyTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- QueuePropertyTests theTests = new QueuePropertyTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- logMsg("Didn't get expected exception");
- throw new Exception("Didn't catch expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
- queues = new ArrayList(2);
- connections = new ArrayList(3);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: msgPropertiesQTest
- *
- * @assertion_ids: JMS:SPEC:20.1; JMS:SPEC:20.2; JMS:SPEC:20.3; JMS:SPEC:20.4;
- * JMS:SPEC:20.5; JMS:SPEC:20.6; JMS:SPEC:20.7; JMS:SPEC:20.8; JMS:SPEC:21;
- * JMS:SPEC:23; JMS:SPEC:24; JMS:SPEC:25; JMS:SPEC:26; JMS:SPEC:10;
- * JMS:SPEC:27; JMS:SPEC:28; JMS:SPEC:29; JMS:SPEC:31; JMS:SPEC:32;
- * JMS:SPEC:34; JMS:SPEC:19; JMS:SPEC:70; JMS:SPEC:71; JMS:JAVADOC:411;
- * JMS:JAVADOC:413; JMS:JAVADOC:415; JMS:JAVADOC:417; JMS:JAVADOC:419;
- * JMS:JAVADOC:421; JMS:JAVADOC:423; JMS:JAVADOC:425; JMS:JAVADOC:427;
- * JMS:JAVADOC:409; JMS:JAVADOC:391; JMS:JAVADOC:393; JMS:JAVADOC:395;
- * JMS:JAVADOC:397; JMS:JAVADOC:399; JMS:JAVADOC:401; JMS:JAVADOC:403;
- * JMS:JAVADOC:405; JMS:JAVADOC:407; JMS:JAVADOC:500; JMS:JAVADOC:516;
- * JMS:JAVADOC:387; JMS:JAVADOC:792; JMS:JAVADOC:776; JMS:JAVADOC:778;
- * JMS:JAVADOC:780; JMS:JAVADOC:782; JMS:JAVADOC:784; JMS:JAVADOC:786;
- * JMS:JAVADOC:788; JMS:JAVADOC:790; JMS:JAVADOC:793;
- *
- * @test_Strategy: set and read properties for boolean, byte, short, int,
- * long, float, double, and String. Verify expected results set and read
- * properties for Boolean, Byte, Short, Int, Long, Float, Double, and String.
- * Verify expected results.
- *
- * When a client receives a message it is in read-only mode. Send a message
- * and have the client attempt modify the properties. Verify that a
- * MessageNotWriteableException is thrown. Call setObject property with an
- * invalid object and verify that a MessageFormatException is thrown
- *
- * call property get methods( other than getStringProperty and
- * getObjectProperty) for non-existent properties and verify that a null
- * pointer exception is returned. call getStringProperty and getObjectProperty
- * for non-existent properties and verify that a null is returned.
- *
- * set object properties and verify the correct value is returned with the
- * getObjectProperty method.
- *
- * call the clearProperties method on the received message and verify that the
- * messages properties were deleted. Test that getObjectProperty returns a
- * null and the getShortProperty throws a null pointer exception.
- *
- * After clearing the message properties, call getText and verify that the
- * message body has not been cleared.
- *
- * call getJMSXPropertyNames() and verify that the names of the required JMSX
- * properties for JMSXGroupID and JMSXGroupSeq are returned.
- */
- public void msgPropertiesQTest() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- Enumeration propertyNames = null;
- Enumeration jmsxDefined = null;
- int numPropertyNames = 18;
-
- String testMessageBody = "Testing...";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText(testMessageBody);
-
- // ------------------------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- messageSent.setBooleanProperty("TESTBOOLEAN", bool);
- messageSent.setByteProperty("TESTBYTE", bValue);
- messageSent.setShortProperty("TESTSHORT", nShort);
- messageSent.setIntProperty("TESTINT", nInt);
- messageSent.setFloatProperty("TESTFLOAT", nFloat);
- messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
- messageSent.setStringProperty("TESTSTRING", "test");
- messageSent.setLongProperty("TESTLONG", nLong);
-
- // ------------------------------------------------------------------------------
- // set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
- // String.
- // ------------------------------------------------------------------------------
- messageSent.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
- messageSent.setObjectProperty("OBJTESTBYTE", Byte.valueOf(bValue));
- messageSent.setObjectProperty("OBJTESTSHORT", Short.valueOf(nShort));
- messageSent.setObjectProperty("OBJTESTINT", Integer.valueOf(nInt));
- messageSent.setObjectProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
- messageSent.setObjectProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
- messageSent.setObjectProperty("OBJTESTSTRING", "test");
- messageSent.setObjectProperty("OBJTESTLONG", Long.valueOf(nLong));
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesQTest");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // ------------------------------------------------------------------------------
- // An attempt to use any other class than Boolean, Byte, Short, Int, Long,
- // Float,
- // Double, and Stringmust throw a JMS MessageFormatException.
- // ------------------------------------------------------------------------------
- try {
- messageSent.setObjectProperty("OBJTESTLONG", new Object());
- logMsg("Error: expected MessageFormatException from invalid ");
- logMsg("call to setObjectProperty did not occur!");
- pass = false;
- } catch (MessageFormatException fe) {
- logTrace("Pass: ");
- logTrace(
- " MessageFormatException as expected from invalid setObjectProperty call");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("from call to setObjectProperty!");
- logMsg(ee.getMessage());
- pass = false;
- }
-
- // iterate thru the property names
- int i = 0;
- propertyNames = messageReceived.getPropertyNames();
- do {
- String tmp = (String) propertyNames.nextElement();
- logTrace("+++++++ Property Name is: " + tmp);
- if (tmp.indexOf("JMS") != 0)
- i++;
- else if (tmp.equals("JMSXDeliveryCount"))
- i++;
- } while (propertyNames.hasMoreElements());
-
- if (i == numPropertyNames) {
- logTrace(
- "Pass: # of properties is " + numPropertyNames + " as expected");
- } else {
- logMsg("Error: expected " + numPropertyNames
- + " property names, but returned " + i);
- pass = false;
- }
-
- // -------------------------------------------------------------------------
- // Received message should be read-only - verify proper exception is
- // thrown
- // when trying to modify msg properties.
- // ------------------------------------------------------------------------
- try {
- messageReceived.setBooleanProperty("TESTBOOLEAN", bool);
- logMsg("Error: exception should have occurred for setBooleanProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- logTrace("Pass: exception as expected for setBooleanProperty ");
- }
- try {
- messageReceived.setByteProperty("TESTBYTE", bValue);
- logMsg("Error: exception should have occurred for setByteProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- logTrace("Pass: exception as expected for setByteProperty ");
- }
- try {
- messageReceived.setShortProperty("TESTSHORT", nShort);
- pass = false;
- logMsg("Error: exception should have occurred for setShortProperty");
- } catch (MessageNotWriteableException aBool) {
- logTrace("Pass: exception as expected for setShortProperty ");
- }
- try {
- messageReceived.setIntProperty("TESTINT", nInt);
- logMsg("Error: exception should have occurred for setIntProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- logTrace("Pass: exception as expected for setIntProperty ");
- }
- try {
- messageReceived.setFloatProperty("TESTFLOAT", nFloat);
- logMsg("Error: exception should have occurred for setFloatProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- logTrace("Pass: exception as expected for setFloatProperty ");
- }
- try {
- messageReceived.setDoubleProperty("TESTDOUBLE", nDouble);
- logMsg("Error: exception should have occurred for setDoubleProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- logTrace("Pass: exception as expected for setDoubleProperty ");
- }
- try {
- messageReceived.setStringProperty("TESTSTRING", testString);
- logMsg("Error: exception should have occurred for setStringProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- logTrace("Pass: exception as expected for setStringProperty ");
- }
- try {
- messageReceived.setLongProperty("TESTLONG", nLong);
- logMsg("Error: exception should have occurred for setLongProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- logTrace("Pass: exception as expected for setLongProperty ");
- }
- try {
- messageReceived.setObjectProperty("OBJTESTBOOLEAN",
- Boolean.valueOf(bool));
- logMsg("Error: exception should have occurred for setObjectProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- logTrace("Pass: exception as expected for setObjectProperty ");
- }
-
- // --------------------------------------------------------------------------------
- // read and verify the property values for primitive types in the received
- // message
- // --------------------------------------------------------------------------------
- if (messageReceived.getBooleanProperty("TESTBOOLEAN") == bool) {
- logTrace("Pass: getBooleanProperty returned correct value");
- } else {
- logMsg("Error: incorrect value returned from getBooleanProperty");
- pass = false;
- }
- if (messageReceived.getByteProperty("TESTBYTE") == bValue) {
- logTrace("Pass: getByteProperty returned correct value");
- } else {
- logMsg("Error: incorrect value returned from getByteProperty");
- pass = false;
- }
- if (messageReceived.getLongProperty("TESTLONG") == nLong) {
- logTrace("Pass: getLongProperty returned correct value");
- } else {
- logMsg("Error: incorrect value returned from getLongProperty");
- pass = false;
- }
- if (messageReceived.getStringProperty("TESTSTRING").equals(testString)) {
- logTrace("Pass: getStringProperty returned correct value");
- } else {
- logMsg("Error: incorrect value returned from getStringProperty");
- pass = false;
- }
- if (messageReceived.getDoubleProperty("TESTDOUBLE") == nDouble) {
- logTrace("Pass: getDoubleProperty returned correct value");
- } else {
- logMsg("Error: incorrect value returned from getDoubleProperty");
- pass = false;
- }
- if (messageReceived.getFloatProperty("TESTFLOAT") == nFloat) {
- logTrace("Pass: getFloatProperty returned correct value");
- } else {
- logMsg("Error: incorrect value returned from getFloatProperty");
- pass = false;
- }
- if (messageReceived.getIntProperty("TESTINT") == nInt) {
- logTrace("Pass: getIntProperty returned correct value");
- } else {
- logMsg("Error: incorrect value returned from getIntProperty");
- pass = false;
- }
- if (messageReceived.getShortProperty("TESTSHORT") == nShort) {
- logTrace("Pass: getShortProperty returned correct value");
- } else {
- logMsg("Error: incorrect value returned from getShortProperty");
- pass = false;
- }
-
- // --------------------------------------------------------------------------------
- // The other property get methods ( other than getStringProperty and
- // getObjectProperty) must behave as if the property exists with a
- // null value
- // --------------------------------------------------------------------------------
- try {
- boolean b = messageReceived.getBooleanProperty("TESTDUMMY");
- if (b != false) {
- logMsg("Error: should havereceived false for getBooleanProperty");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- pass = false;
- }
- try {
- byte value = messageReceived.getByteProperty("TESTDUMMY");
-
- logMsg(
- "Error: NumberFormatException should have occurred for getByteProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logTrace("Pass: NumberFormatException as expected ");
- }
- try {
- short value = messageReceived.getShortProperty("TESTDUMMY");
-
- logMsg(
- "Error: NumberFormatException should have occurred for getShortProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logTrace("Pass: NumberFormatException as expected ");
- }
- try {
- int value = messageReceived.getIntProperty("TESTDUMMY");
-
- logMsg(
- "Error: NumberFormatException should have occurred for getIntProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logTrace("Pass: NumberFormatException as expected ");
- }
- try {
- long value = messageReceived.getLongProperty("TESTDUMMY");
-
- logMsg(
- "Error: NumberFormatException should have occurred for getLongProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logTrace("Pass: NumberFormatException as expected ");
- }
- try {
- float value = messageReceived.getFloatProperty("TESTDUMMY");
-
- logMsg(
- "Error: NullPointerException should have occurred for getFloatProperty");
- pass = false;
- } catch (java.lang.NullPointerException np) {
- logTrace("Pass: NullPointerException as expected ");
- }
- try {
- double value = messageReceived.getDoubleProperty("TESTDUMMY");
-
- logMsg(
- "Error: NullPointerException should have occurred for getDoubleProperty");
- pass = false;
- } catch (java.lang.NullPointerException np) {
- logTrace("Pass: NullPointerException as expected ");
- }
-
- // --------------------------------------------------------------------------------
- // Getting a property value for a name which has not been set returns a
- // null value.
- // (For getStringProperty and getObjectProperty)
- // --------------------------------------------------------------------------------
- String value = messageReceived.getStringProperty("TESTDUMMY");
-
- if (value == null) {
- logTrace("Pass: getStringProperty returned correct value");
- } else {
- logMsg(
- "Error: expected a null return from getStringProperty for invalid property");
- pass = false;
- }
- Boolean aBool = (Boolean) messageReceived.getObjectProperty("TESTDUMMY");
-
- if (aBool == null) {
- logTrace("Pass: getObjectProperty returned correct value for Boolean");
- } else {
- logMsg(
- "Error: expected a null return from getObjectProperty for invalid property");
- pass = false;
- }
-
- // --------------------------------------------------------------------------------
- // read and verify the property values for getObject in the received
- // message
- // --------------------------------------------------------------------------------
- Boolean boolValue = (Boolean) messageReceived
- .getObjectProperty("OBJTESTBOOLEAN");
-
- if (boolValue.booleanValue() == bool) {
- logTrace("Pass: getObjectProperty returned correct value for Boolean");
- } else {
- logMsg("Error: incorrect value returned for Boolean");
- pass = false;
- }
- Byte byteValue = (Byte) messageReceived.getObjectProperty("OBJTESTBYTE");
-
- if (byteValue.byteValue() == bValue) {
- logTrace("Pass: getObjectProperty returned correct Byte value");
- } else {
- logMsg("Error: incorrect value returned from Byte");
- pass = false;
- }
- Long lValue = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
-
- if (lValue.longValue() == nLong) {
- logTrace("Pass: getObjectProperty returned correct value for Long");
- } else {
- logMsg(
- "Error: getObjectProperty returned incorrect value returned for Long");
- pass = false;
- }
-
- // String value =
- // (String)messageReceived.getObjectProperty("OBJTESTSTRING");
- if (messageReceived.getObjectProperty("OBJTESTSTRING")
- .equals(testString)) {
- logTrace("Pass: getObjectProperty returned correct value for String");
- } else {
- logMsg("Error: getObjectProperty returned incorrect value for String");
- pass = false;
- }
- Double dValue = (Double) messageReceived
- .getObjectProperty("OBJTESTDOUBLE");
-
- if (dValue.doubleValue() == nDouble) {
- logTrace("Pass: getObjectProperty returned correct value for Double");
- } else {
- logMsg("Error: getObjectProperty returned incorrect value for Double");
- pass = false;
- }
- Float fValue = (Float) messageReceived.getObjectProperty("OBJTESTFLOAT");
-
- if (fValue.floatValue() == nFloat) {
- logTrace("Pass: getObjectProperty returned correct value for Float");
- } else {
- logMsg("Error: getObjectProperty returned incorrect value for Float");
- pass = false;
- }
- Integer iValue = (Integer) messageReceived
- .getObjectProperty("OBJTESTINT");
-
- if (iValue.intValue() == nInt) {
- logTrace("Pass: getObjectProperty returned correct value for Integer");
- } else {
- logMsg("Error: getObjectProperty returned incorrect value for Integer");
- pass = false;
- }
- Short sValue = (Short) messageReceived.getObjectProperty("OBJTESTSHORT");
-
- if (sValue.shortValue() == nShort) {
- logTrace("Pass: getObjectProperty returned correct value for Short");
- } else {
- logMsg("Error: getObjectProperty returned incorrect value for Short");
- pass = false;
- }
-
- // clear message properties
- messageReceived.clearProperties();
-
- // -------------------------------------------------------------------
- // A message?s properties are deleted by the clearProperties method.
- // This leaves the message with an empty set of properties.
- // -------------------------------------------------------------------
- Long aLong = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
-
- if (aLong == null) {
- logTrace("Pass: property was cleared");
- } else {
- logMsg(
- "Error: getObjectProperty should have returned null for cleared property");
- pass = false;
- }
- try {
- short aShort = messageReceived.getShortProperty("TESTSHORT");
-
- logMsg(
- "Error: NumberFormatException should have occurred for getShortProperty");
- logMsg("Properties have been cleared!");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logTrace("Pass: NumberFormatException as expected ");
- }
-
- // -------------------------------------------------------------------
- // A message?s properties are deleted by the clearProperties method.
- // This leaves the message with an empty set of properties.
- // -------------------------------------------------------------------
- aLong = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
-
- if (aLong == null) {
- logTrace("Pass: property was cleared");
- } else {
- logMsg(
- "Error: getObjectProperty should have returned null for cleared property");
- pass = false;
- }
- try {
- short aShort = messageReceived.getShortProperty("TESTSHORT");
-
- logMsg(
- "Error: NumberFormatException should have occurred for getShortProperty");
- logMsg("Properties have been cleared!");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logTrace("Pass: NumberFormatException as expected ");
- }
-
- // -------------------------------------------------------------------
- // clearing the message property should not effect the message body.
- // -------------------------------------------------------------------
- logMsg("Message body is : " + messageReceived.getText());
- if (messageReceived.getText().equals(testMessageBody)) {
- logTrace("Pass: able to read message body after clearProperties");
- } else {
- logMsg("Error: unable to read message body after clearProperties");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // ConnectionMetaData.getJMSXPropertyNames() method returns the
- // names of the JMSX properties supported by a connection.
- // -------------------------------------------------------------------
- try {
- ConnectionMetaData data = tool.getDefaultQueueConnection()
- .getMetaData();
- Enumeration cmd = data.getJMSXPropertyNames();
- String propName;
-
- if (cmd == null) {
- logMsg("Error: no JMSX property names were returned!");
- logMsg(
- "expected JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount at a miniumum");
- pass = false;
- } else {
- int iCount = 0;
-
- do {
- propName = (String) cmd.nextElement();
- logTrace(propName);
- if (propName.equals("JMSXGroupID")
- || propName.equals("JMSXGroupSeq")
- || propName.equals("JMSXDeliveryCount")) {
- iCount++;
- }
- } while (cmd.hasMoreElements());
- if (iCount > 1) {
- logTrace("Pass:");
- } else {
- logMsg("Error: Expected property names not returned");
- pass = false;
- }
- }
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg("attempting to read JMSX property names.");
- logMsg("Error: unexpected exception: " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during property tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgPropertiesQTest failed");
- }
- }
-
- /*
- * @testName: msgPropertiesConversionQTest
- *
- * @assertion_ids: JMS:SPEC:22.1; JMS:SPEC:22.2; JMS:SPEC:22.3; JMS:SPEC:22.4;
- * JMS:SPEC:22.5; JMS:SPEC:22.6; JMS:SPEC:22.7; JMS:SPEC:22.8; JMS:SPEC:22.9;
- * JMS:SPEC:22.10; JMS:SPEC:22.11; JMS:SPEC:22.12; JMS:SPEC:22.13;
- * JMS:SPEC:22.14; JMS:SPEC:22.15; JMS:SPEC:22.16; JMS:JAVADOC:768;
- * JMS:JAVADOC:769; JMS:JAVADOC:770; JMS:JAVADOC:771; JMS:JAVADOC:767;
- * JMS:JAVADOC:772; JMS:JAVADOC:773; JMS:JAVADOC:774;
- *
- * @test_Strategy: create a message, set properties for all of the primitive
- * types verify the conversion by getting the properties.
- */
- public void msgPropertiesConversionQTest() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- String testMessageBody = "Testing...";
- int ntest = 0;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText(testMessageBody);
-
- // ------------------------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- messageSent.setBooleanProperty("TESTBOOLEAN", bool);
- messageSent.setByteProperty("TESTBYTE", bValue);
- messageSent.setShortProperty("TESTSHORT", nShort);
- messageSent.setIntProperty("TESTINT", nInt);
- messageSent.setFloatProperty("TESTFLOAT", nFloat);
- messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
- messageSent.setStringProperty("TESTSTRING", "test");
- messageSent.setLongProperty("TESTLONG", nLong);
- messageSent.setStringProperty("TESTSTRINGTRUE", "true");
- messageSent.setStringProperty("TESTSTRINGFALSE", "false");
- messageSent.setStringProperty("TESTSTRING1", "1");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesConversionQTest");
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // -------------------------------------------------------------------
- // test conversions for property values
- // -------------------------------------------------------------------
- // property set as boolean can be read only as string or boolean
- // -------------------------------------------------------------------
- // valid - boolean to string
- String myBool = messageReceived.getStringProperty("TESTBOOLEAN");
-
- if (Boolean.valueOf(myBool).booleanValue() == bool) {
- logTrace("Pass: conversion from boolean to string - ok");
- } else {
- logMsg("Error: conversion from boolean to string failed");
- pass = false;
- }
-
- // invalid - boolean to byte
- try {
- messageReceived.getByteProperty("TESTBOOLEAN");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: boolean to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
-
- // logMsg("Error: unexpected error " + ee.getClass().getName() + " was
- // thrown");
- logMsg("Error: did not catch expected Exception -- boolean to byte");
- pass = false;
- }
-
- // invalid - boolean to short
- try {
- messageReceived.getShortProperty("TESTBOOLEAN");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: boolean to short ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- boolean to short");
- pass = false;
- }
-
- // invalid - boolean to int
- try {
- messageReceived.getIntProperty("TESTBOOLEAN");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: boolean to int ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception --boolean to int ");
- pass = false;
- }
-
- // invalid - boolean to long
- try {
- messageReceived.getLongProperty("TESTBOOLEAN");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: boolean to long ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- boolean to long");
- pass = false;
- }
-
- // invalid - boolean to float
- try {
- messageReceived.getFloatProperty("TESTBOOLEAN");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: boolean to float ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- boolean to float");
- pass = false;
- }
-
- // invalid - boolean to double
- try {
- messageReceived.getDoubleProperty("TESTBOOLEAN");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: boolean to double ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- boolean to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as byte can be read as a byte,short,int,long or string
- // valid - byte to string
- String myByte = messageReceived.getStringProperty("TESTBYTE");
-
- if (Byte.valueOf(myByte).byteValue() == bValue) {
- logTrace("Pass: conversion from byte to string - ok");
- } else {
- logMsg("Error: conversion from byte to string failed");
- pass = false;
- }
-
- // valid - byte to short
- if (messageReceived.getShortProperty("TESTBYTE") == bValue) {
- logTrace("Pass: conversion from byte to short - ok");
- } else {
- logMsg("Error: conversion from byte to short failed");
- pass = false;
- }
-
- // valid - byte to int
- if (messageReceived.getIntProperty("TESTBYTE") == bValue) {
- logTrace("Pass: conversion from byte to int - ok");
- } else {
- logMsg("Error: conversion from byte to int failed");
- pass = false;
- }
-
- // valid - byte to long
- if (messageReceived.getLongProperty("TESTBYTE") == bValue) {
- logTrace("Pass: conversion from byte to long - ok");
- } else {
- logMsg("Error: conversion from byte to long failed");
- pass = false;
- }
-
- // invalid - byte to boolean
- try {
- messageReceived.getBooleanProperty("TESTBYTE");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: byte to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- byte to boolean");
- pass = false;
- }
-
- // invalid - byte to float
- try {
- messageReceived.getFloatProperty("TESTBYTE");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: byte to float ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception --byte to float ");
- pass = false;
- }
-
- // invalid - byte to double
- try {
- messageReceived.getDoubleProperty("TESTBYTE");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: byte to double ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- byte to double");
- pass = false;
- }
-
- // -------------------------------------------------
- // property set as short can be read as short,int,long or string
- // valid - short to string
- String myshort = messageReceived.getStringProperty("TESTSHORT");
-
- if (Short.valueOf(myshort).shortValue() == nShort) {
- logTrace("Pass: conversion from short to string - ok");
- } else {
- logMsg("Error: conversion from short to string failed");
- pass = false;
- }
-
- // valid - short to int
- if (messageReceived.getIntProperty("TESTSHORT") == nShort) {
- logTrace("Pass: conversion from short to int - ok");
- } else {
- logMsg("Error: conversion from short to int failed");
- pass = false;
- }
-
- // valid - short to long
- if (messageReceived.getLongProperty("TESTSHORT") == nShort) {
- logTrace("Pass: conversion from short to long - ok");
- } else {
- logMsg("Error: conversion from short to long failed");
- pass = false;
- }
-
- // invalid - short to boolean
- try {
- messageReceived.getBooleanProperty("TESTSHORT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: short to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- short to boolean");
- pass = false;
- }
-
- // invalid - short to byte
- try {
- messageReceived.getByteProperty("TESTSHORT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: short to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- short to byte");
- pass = false;
- }
-
- // invalid - short to float
- try {
- messageReceived.getFloatProperty("TESTSHORT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: short to float ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- short to float");
- pass = false;
- }
-
- // invalid - short to double
- try {
- messageReceived.getDoubleProperty("TESTSHORT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: short to double ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- short to double");
- pass = false;
- }
-
- // -------------------------------------------------
- // property set as int can be read only as int, long or string
- // valid - int to string
- if (Integer.valueOf(messageReceived.getStringProperty("TESTINT"))
- .intValue() == nInt) {
- logTrace("Pass: conversion from int to string - ok");
- } else {
- logMsg("Error: conversion from int to string failed");
- pass = false;
- }
-
- // valid - int to long
- if (messageReceived.getLongProperty("TESTINT") == nInt) {
- logTrace("Pass: conversion from int to long - ok");
- } else {
- logMsg("Error: conversion from int to long failed");
- pass = false;
- }
-
- // invalid - int to boolean
- try {
- messageReceived.getBooleanProperty("TESTINT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: int to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- int to boolean");
- pass = false;
- }
-
- // invalid - int to byte
- try {
- messageReceived.getByteProperty("TESTINT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: int to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- int to byte");
- pass = false;
- }
-
- // invalid - int to short
- try {
- messageReceived.getShortProperty("TESTINT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: int to short ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected -- int to short ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception ");
- pass = false;
- }
-
- // invalid - int to float
- try {
- messageReceived.getFloatProperty("TESTINT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: int to float ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- int to float");
- pass = false;
- }
-
- // invalid - int to double
- try {
- messageReceived.getDoubleProperty("TESTINT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: int to double ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- int to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as long can be read only as long,or a string
- // valid - long to string
- if (Long.valueOf(messageReceived.getStringProperty("TESTLONG"))
- .longValue() == nLong) {
- logTrace("Pass: conversion from long to string - ok");
- } else {
- logMsg("Error: conversion from long to string failed");
- pass = false;
- }
-
- // invalid - long to boolean
- try {
- messageReceived.getBooleanProperty("TESTLONG");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: long to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- long to boolean");
- pass = false;
- }
-
- // invalid - long to byte
- try {
- messageReceived.getByteProperty("TESTLONG");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: long to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- long to byte");
- pass = false;
- }
-
- // invalid - long to short
- try {
- messageReceived.getShortProperty("TESTLONG");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: long to short ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- long to short ");
- pass = false;
- }
-
- // invalid - long to int
- try {
- messageReceived.getIntProperty("TESTLONG");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: long to int ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- long to int");
- pass = false;
- }
-
- // invalid - long to float
- try {
- messageReceived.getFloatProperty("TESTLONG");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: long to float ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- long to float");
- pass = false;
- }
-
- // invalid - long to double
- try {
- messageReceived.getDoubleProperty("TESTLONG");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: long to double ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- long to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as float can be read only as float,double or a string
- // valid - float to string
- if (Float.valueOf(messageReceived.getStringProperty("TESTFLOAT"))
- .floatValue() == nFloat) {
- logTrace("Pass: conversion from float to string - ok");
- } else {
- logMsg("Error: conversion from float to string failed");
- pass = false;
- }
-
- // valid - float to double
- if (messageReceived.getDoubleProperty("TESTFLOAT") == nFloat) {
- logTrace("Pass: conversion from long to double - ok");
- } else {
- logMsg("Error: conversion from long to double failed");
- pass = false;
- }
-
- // invalid - float to boolean
- try {
- messageReceived.getBooleanProperty("TESTFLOAT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: float to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- float to boolean ");
- pass = false;
- }
-
- // invalid - float to byte
- try {
- messageReceived.getByteProperty("TESTFLOAT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: float to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- float to byte");
- pass = false;
- }
-
- // invalid - float to short
- try {
- messageReceived.getShortProperty("TESTFLOAT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: float to short ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception - float to short ");
- pass = false;
- }
-
- // invalid - float to int
- try {
- messageReceived.getIntProperty("TESTFLOAT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: float to int ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception --- float to int");
- pass = false;
- }
-
- // invalid - float to long
- try {
- messageReceived.getLongProperty("TESTFLOAT");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: float to long ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- float to long");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as double can be read only as double or string
- // valid - double to string
- if (Double.valueOf(messageReceived.getStringProperty("TESTDOUBLE"))
- .doubleValue() == nDouble) {
- logTrace("Pass: conversion from double to string - ok");
- } else {
- logMsg("Error: conversion from double to string failed");
- pass = false;
- }
-
- // invalid - double to boolean
- try {
- messageReceived.getBooleanProperty("TESTDOUBLE");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: double to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- double to boolean ");
- pass = false;
- }
-
- // invalid - double to byte
- try {
- messageReceived.getByteProperty("TESTDOUBLE");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: double to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- double to byte ");
- pass = false;
- }
-
- // invalid - double to short
- try {
- messageReceived.getShortProperty("TESTDOUBLE");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: double to short ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- double to short");
- pass = false;
- }
-
- // invalid - double to int
- try {
- messageReceived.getIntProperty("TESTDOUBLE");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: double to int ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception --- double to int ");
- pass = false;
- }
-
- // invalid - double to long
- try {
- messageReceived.getLongProperty("TESTDOUBLE");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: double to long ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- double to long");
- pass = false;
- }
-
- // invalid - double to float
- try {
- messageReceived.getFloatProperty("TESTDOUBLE");
- logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- logMsg("unsupported conversion: double to float ");
- pass = false;
- } catch (MessageFormatException me) {
- logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- logMsg(ee.getMessage());
- logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- logMsg("Error: did not catch expected Exception -- double to float");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as string can be read as boolean, byte, short,
- // int, long, float, double, and String.
- // valid - string to boolean
- if ((messageReceived.getBooleanProperty("TESTSTRINGTRUE")) == true) {
- logTrace("Pass: conversion from string to boolean - expect true - ok");
- } else {
- logMsg(
- "Error: conversion from string to boolean - expect true - failed");
- pass = false;
- }
- if ((messageReceived.getBooleanProperty("TESTSTRINGFALSE")) == false) {
- logTrace("Pass: conversion from string to boolean expect false - ok");
- } else {
- logMsg(
- "Error: conversion from string to boolean expect false - failed");
- pass = false;
- }
-
- // valid - string to byte
- if (messageReceived.getByteProperty("TESTSTRING1") == 1) {
- logTrace("Pass: conversion from string to byte - ok");
- } else {
- logMsg("Error: conversion from string to byte failed");
- pass = false;
- }
-
- // valid - string to short
- if (messageReceived.getShortProperty("TESTSTRING1") == 1) {
- logTrace("Pass: conversion from string to short - ok");
- } else {
- logMsg("Error: conversion from string to short failed");
- pass = false;
- }
-
- // valid - string to int
- if (messageReceived.getIntProperty("TESTSTRING1") == 1) {
- logTrace("Pass: conversion from string to int - ok");
- } else {
- logMsg("Error: conversion from string to int failed");
- pass = false;
- }
-
- // valid - string to long
- if (messageReceived.getLongProperty("TESTSTRING1") == 1) {
- logTrace("Pass: conversion from string to long - ok");
- } else {
- logMsg("Error: conversion from string to long failed");
- pass = false;
- }
-
- // valid - string to float
- if (messageReceived.getFloatProperty("TESTSTRING1") == 1) {
- logTrace("Pass: conversion from string to float - ok");
- } else {
- logMsg("Error: conversion from string to float failed");
- pass = false;
- }
-
- // valid - string to double
- if (messageReceived.getDoubleProperty("TESTSTRING1") == 1) {
- logTrace("Pass: conversion from string to double - ok");
- } else {
- logMsg("Error: conversion from string to double failed");
- pass = false;
- }
- if (!pass) {
- throw new Exception(
- "Error: failures occurred during property conversion tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgPropertiesConversionQTest failed");
- }
- }
-
- /*
- * @testName: msgPropertyExistTest
- *
- * @assertion_ids: JMS:JAVADOC:411; JMS:JAVADOC:413; JMS:JAVADOC:415;
- * JMS:JAVADOC:417; JMS:JAVADOC:419; JMS:JAVADOC:421; JMS:JAVADOC:423;
- * JMS:JAVADOC:425; JMS:JAVADOC:427; JMS:JAVADOC:389;
- *
- * @test_Strategy: Set and read properties for boolean, byte, short, int,
- * long, float, double, and String. Verify expected results
- */
- public void msgPropertyExistTest() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- Enumeration propertyNames = null;
- String testMessageBody = "Testing msgPropertyExistTest";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText(testMessageBody);
-
- // ------------------------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- messageSent.setBooleanProperty("TESTBOOLEAN", bool);
- messageSent.setByteProperty("TESTBYTE", bValue);
- messageSent.setShortProperty("TESTSHORT", nShort);
- messageSent.setIntProperty("TESTINT", nInt);
- messageSent.setFloatProperty("TESTFLOAT", nFloat);
- messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
- messageSent.setStringProperty("TESTSTRING", "test");
- messageSent.setLongProperty("TESTLONG", nLong);
- messageSent.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
-
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
-
- logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // iterate thru the property names
- int i = 0;
- propertyNames = messageReceived.getPropertyNames();
- do {
- String tmp = (String) propertyNames.nextElement();
-
- if (tmp.indexOf("JMS") != 0) {
- i++;
- if (tmp.equals("TESTBOOLEAN") || tmp.equals("TESTBYTE")
- || tmp.equals("TESTINT") || tmp.equals("TESTSHORT")
- || tmp.equals("TESTFLOAT") || tmp.equals("TESTDOUBLE")
- || tmp.equals("TESTSTRING") || tmp.equals("TESTLONG")
- || tmp.equals("OBJTESTBOOLEAN")) {
- logTrace("+++++++Appclication Property set by client is: " + tmp);
- if (!messageReceived.propertyExists(tmp)) {
- pass = messageReceived.propertyExists(tmp);
- logErr("Positive propertyExists test failed for " + tmp);
- } else if (messageReceived.propertyExists(tmp + "1")) {
- pass = false;
- logErr("Negative propertyExists test failed for " + tmp + "1");
- }
- } else {
- logErr("+++++++Appclication Property not set by client: " + tmp);
- pass = false;
- }
- } else {
- logTrace("+++++++ JMSProperty Name is: " + tmp);
- }
- } while (propertyNames.hasMoreElements());
-
- if (!pass) {
- throw new Exception("Error: failures occurred during propertyExists tests");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgPropertyExistTest failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/queueMsgProperties/QueuePropertyTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/queueMsgProperties/QueuePropertyTestsIT.java
new file mode 100644
index 0000000000..143ba5dbfa
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/queueMsgProperties/QueuePropertyTestsIT.java
@@ -0,0 +1,1638 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.queueMsgProperties;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.ConnectionMetaData;
+import jakarta.jms.MessageFormatException;
+import jakarta.jms.MessageNotWriteableException;
+import jakarta.jms.TextMessage;
+
+
+public class QueuePropertyTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.queueMsgProperties.QueuePropertyTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(QueuePropertyTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't catch expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+ queues = new ArrayList(2);
+ connections = new ArrayList(3);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: msgPropertiesQTest
+ *
+ * @assertion_ids: JMS:SPEC:20.1; JMS:SPEC:20.2; JMS:SPEC:20.3; JMS:SPEC:20.4;
+ * JMS:SPEC:20.5; JMS:SPEC:20.6; JMS:SPEC:20.7; JMS:SPEC:20.8; JMS:SPEC:21;
+ * JMS:SPEC:23; JMS:SPEC:24; JMS:SPEC:25; JMS:SPEC:26; JMS:SPEC:10; JMS:SPEC:27;
+ * JMS:SPEC:28; JMS:SPEC:29; JMS:SPEC:31; JMS:SPEC:32; JMS:SPEC:34; JMS:SPEC:19;
+ * JMS:SPEC:70; JMS:SPEC:71; JMS:JAVADOC:411; JMS:JAVADOC:413; JMS:JAVADOC:415;
+ * JMS:JAVADOC:417; JMS:JAVADOC:419; JMS:JAVADOC:421; JMS:JAVADOC:423;
+ * JMS:JAVADOC:425; JMS:JAVADOC:427; JMS:JAVADOC:409; JMS:JAVADOC:391;
+ * JMS:JAVADOC:393; JMS:JAVADOC:395; JMS:JAVADOC:397; JMS:JAVADOC:399;
+ * JMS:JAVADOC:401; JMS:JAVADOC:403; JMS:JAVADOC:405; JMS:JAVADOC:407;
+ * JMS:JAVADOC:500; JMS:JAVADOC:516; JMS:JAVADOC:387; JMS:JAVADOC:792;
+ * JMS:JAVADOC:776; JMS:JAVADOC:778; JMS:JAVADOC:780; JMS:JAVADOC:782;
+ * JMS:JAVADOC:784; JMS:JAVADOC:786; JMS:JAVADOC:788; JMS:JAVADOC:790;
+ * JMS:JAVADOC:793;
+ *
+ * @test_Strategy: set and read properties for boolean, byte, short, int, long,
+ * float, double, and String. Verify expected results set and read properties
+ * for Boolean, Byte, Short, Int, Long, Float, Double, and String. Verify
+ * expected results.
+ *
+ * When a client receives a message it is in read-only mode. Send a message and
+ * have the client attempt modify the properties. Verify that a
+ * MessageNotWriteableException is thrown. Call setObject property with an
+ * invalid object and verify that a MessageFormatException is thrown
+ *
+ * call property get methods( other than getStringProperty and
+ * getObjectProperty) for non-existent properties and verify that a null pointer
+ * exception is returned. call getStringProperty and getObjectProperty for
+ * non-existent properties and verify that a null is returned.
+ *
+ * set object properties and verify the correct value is returned with the
+ * getObjectProperty method.
+ *
+ * call the clearProperties method on the received message and verify that the
+ * messages properties were deleted. Test that getObjectProperty returns a null
+ * and the getShortProperty throws a null pointer exception.
+ *
+ * After clearing the message properties, call getText and verify that the
+ * message body has not been cleared.
+ *
+ * call getJMSXPropertyNames() and verify that the names of the required JMSX
+ * properties for JMSXGroupID and JMSXGroupSeq are returned.
+ */
+ @Test
+ public void msgPropertiesQTest() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ Enumeration propertyNames = null;
+ Enumeration jmsxDefined = null;
+ int numPropertyNames = 18;
+
+ String testMessageBody = "Testing...";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText(testMessageBody);
+
+ // ------------------------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ messageSent.setBooleanProperty("TESTBOOLEAN", bool);
+ messageSent.setByteProperty("TESTBYTE", bValue);
+ messageSent.setShortProperty("TESTSHORT", nShort);
+ messageSent.setIntProperty("TESTINT", nInt);
+ messageSent.setFloatProperty("TESTFLOAT", nFloat);
+ messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
+ messageSent.setStringProperty("TESTSTRING", "test");
+ messageSent.setLongProperty("TESTLONG", nLong);
+
+ // ------------------------------------------------------------------------------
+ // set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ messageSent.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ messageSent.setObjectProperty("OBJTESTBYTE", Byte.valueOf(bValue));
+ messageSent.setObjectProperty("OBJTESTSHORT", Short.valueOf(nShort));
+ messageSent.setObjectProperty("OBJTESTINT", Integer.valueOf(nInt));
+ messageSent.setObjectProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
+ messageSent.setObjectProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
+ messageSent.setObjectProperty("OBJTESTSTRING", "test");
+ messageSent.setObjectProperty("OBJTESTLONG", Long.valueOf(nLong));
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesQTest");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // ------------------------------------------------------------------------------
+ // An attempt to use any other class than Boolean, Byte, Short, Int, Long,
+ // Float,
+ // Double, and Stringmust throw a JMS MessageFormatException.
+ // ------------------------------------------------------------------------------
+ try {
+ messageSent.setObjectProperty("OBJTESTLONG", new Object());
+ logger.log(Logger.Level.INFO, "Error: expected MessageFormatException from invalid ");
+ logger.log(Logger.Level.INFO, "call to setObjectProperty did not occur!");
+ pass = false;
+ } catch (MessageFormatException fe) {
+ logger.log(Logger.Level.TRACE, "Pass: ");
+ logger.log(Logger.Level.TRACE,
+ " MessageFormatException as expected from invalid setObjectProperty call");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "from call to setObjectProperty!");
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ pass = false;
+ }
+
+ // iterate thru the property names
+ int i = 0;
+ propertyNames = messageReceived.getPropertyNames();
+ do {
+ String tmp = (String) propertyNames.nextElement();
+ logger.log(Logger.Level.TRACE, "+++++++ Property Name is: " + tmp);
+ if (tmp.indexOf("JMS") != 0)
+ i++;
+ else if (tmp.equals("JMSXDeliveryCount"))
+ i++;
+ } while (propertyNames.hasMoreElements());
+
+ if (i == numPropertyNames) {
+ logger.log(Logger.Level.TRACE, "Pass: # of properties is " + numPropertyNames + " as expected");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: expected " + numPropertyNames + " property names, but returned " + i);
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------------
+ // Received message should be read-only - verify proper exception is
+ // thrown
+ // when trying to modify msg properties.
+ // ------------------------------------------------------------------------
+ try {
+ messageReceived.setBooleanProperty("TESTBOOLEAN", bool);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setBooleanProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setBooleanProperty ");
+ }
+ try {
+ messageReceived.setByteProperty("TESTBYTE", bValue);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setByteProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setByteProperty ");
+ }
+ try {
+ messageReceived.setShortProperty("TESTSHORT", nShort);
+ pass = false;
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setShortProperty");
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setShortProperty ");
+ }
+ try {
+ messageReceived.setIntProperty("TESTINT", nInt);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setIntProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setIntProperty ");
+ }
+ try {
+ messageReceived.setFloatProperty("TESTFLOAT", nFloat);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setFloatProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setFloatProperty ");
+ }
+ try {
+ messageReceived.setDoubleProperty("TESTDOUBLE", nDouble);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setDoubleProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setDoubleProperty ");
+ }
+ try {
+ messageReceived.setStringProperty("TESTSTRING", testString);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setStringProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setStringProperty ");
+ }
+ try {
+ messageReceived.setLongProperty("TESTLONG", nLong);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setLongProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setLongProperty ");
+ }
+ try {
+ messageReceived.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setObjectProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setObjectProperty ");
+ }
+
+ // --------------------------------------------------------------------------------
+ // read and verify the property values for primitive types in the received
+ // message
+ // --------------------------------------------------------------------------------
+ if (messageReceived.getBooleanProperty("TESTBOOLEAN") == bool) {
+ logger.log(Logger.Level.TRACE, "Pass: getBooleanProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getBooleanProperty");
+ pass = false;
+ }
+ if (messageReceived.getByteProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: getByteProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getByteProperty");
+ pass = false;
+ }
+ if (messageReceived.getLongProperty("TESTLONG") == nLong) {
+ logger.log(Logger.Level.TRACE, "Pass: getLongProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getLongProperty");
+ pass = false;
+ }
+ if (messageReceived.getStringProperty("TESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getStringProperty");
+ pass = false;
+ }
+ if (messageReceived.getDoubleProperty("TESTDOUBLE") == nDouble) {
+ logger.log(Logger.Level.TRACE, "Pass: getDoubleProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getDoubleProperty");
+ pass = false;
+ }
+ if (messageReceived.getFloatProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: getFloatProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getFloatProperty");
+ pass = false;
+ }
+ if (messageReceived.getIntProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: getIntProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getIntProperty");
+ pass = false;
+ }
+ if (messageReceived.getShortProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: getShortProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getShortProperty");
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------
+ // The other property get methods ( other than getStringProperty and
+ // getObjectProperty) must behave as if the property exists with a
+ // null value
+ // --------------------------------------------------------------------------------
+ try {
+ boolean b = messageReceived.getBooleanProperty("TESTDUMMY");
+ if (b != false) {
+ logger.log(Logger.Level.INFO, "Error: should havereceived false for getBooleanProperty");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ pass = false;
+ }
+ try {
+ byte value = messageReceived.getByteProperty("TESTDUMMY");
+
+ logger.log(Logger.Level.INFO, "Error: NumberFormatException should have occurred for getByteProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ short value = messageReceived.getShortProperty("TESTDUMMY");
+
+ logger.log(Logger.Level.INFO, "Error: NumberFormatException should have occurred for getShortProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ int value = messageReceived.getIntProperty("TESTDUMMY");
+
+ logger.log(Logger.Level.INFO, "Error: NumberFormatException should have occurred for getIntProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ long value = messageReceived.getLongProperty("TESTDUMMY");
+
+ logger.log(Logger.Level.INFO, "Error: NumberFormatException should have occurred for getLongProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ float value = messageReceived.getFloatProperty("TESTDUMMY");
+
+ logger.log(Logger.Level.INFO, "Error: NullPointerException should have occurred for getFloatProperty");
+ pass = false;
+ } catch (java.lang.NullPointerException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException as expected ");
+ }
+ try {
+ double value = messageReceived.getDoubleProperty("TESTDUMMY");
+
+ logger.log(Logger.Level.INFO, "Error: NullPointerException should have occurred for getDoubleProperty");
+ pass = false;
+ } catch (java.lang.NullPointerException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException as expected ");
+ }
+
+ // --------------------------------------------------------------------------------
+ // Getting a property value for a name which has not been set returns a
+ // null value.
+ // (For getStringProperty and getObjectProperty)
+ // --------------------------------------------------------------------------------
+ String value = messageReceived.getStringProperty("TESTDUMMY");
+
+ if (value == null) {
+ logger.log(Logger.Level.TRACE, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: expected a null return from getStringProperty for invalid property");
+ pass = false;
+ }
+ Boolean aBool = (Boolean) messageReceived.getObjectProperty("TESTDUMMY");
+
+ if (aBool == null) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Boolean");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: expected a null return from getObjectProperty for invalid property");
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------
+ // read and verify the property values for getObject in the received
+ // message
+ // --------------------------------------------------------------------------------
+ Boolean boolValue = (Boolean) messageReceived.getObjectProperty("OBJTESTBOOLEAN");
+
+ if (boolValue.booleanValue() == bool) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Boolean");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned for Boolean");
+ pass = false;
+ }
+ Byte byteValue = (Byte) messageReceived.getObjectProperty("OBJTESTBYTE");
+
+ if (byteValue.byteValue() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct Byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from Byte");
+ pass = false;
+ }
+ Long lValue = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
+
+ if (lValue.longValue() == nLong) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Long");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value returned for Long");
+ pass = false;
+ }
+
+ // String value =
+ // (String)messageReceived.getObjectProperty("OBJTESTSTRING");
+ if (messageReceived.getObjectProperty("OBJTESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for String");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for String");
+ pass = false;
+ }
+ Double dValue = (Double) messageReceived.getObjectProperty("OBJTESTDOUBLE");
+
+ if (dValue.doubleValue() == nDouble) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Double");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Double");
+ pass = false;
+ }
+ Float fValue = (Float) messageReceived.getObjectProperty("OBJTESTFLOAT");
+
+ if (fValue.floatValue() == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Float");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Float");
+ pass = false;
+ }
+ Integer iValue = (Integer) messageReceived.getObjectProperty("OBJTESTINT");
+
+ if (iValue.intValue() == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Integer");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Integer");
+ pass = false;
+ }
+ Short sValue = (Short) messageReceived.getObjectProperty("OBJTESTSHORT");
+
+ if (sValue.shortValue() == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Short");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Short");
+ pass = false;
+ }
+
+ // clear message properties
+ messageReceived.clearProperties();
+
+ // -------------------------------------------------------------------
+ // A message?s properties are deleted by the clearProperties method.
+ // This leaves the message with an empty set of properties.
+ // -------------------------------------------------------------------
+ Long aLong = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
+
+ if (aLong == null) {
+ logger.log(Logger.Level.TRACE, "Pass: property was cleared");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: getObjectProperty should have returned null for cleared property");
+ pass = false;
+ }
+ try {
+ short aShort = messageReceived.getShortProperty("TESTSHORT");
+
+ logger.log(Logger.Level.INFO, "Error: NumberFormatException should have occurred for getShortProperty");
+ logger.log(Logger.Level.INFO, "Properties have been cleared!");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+
+ // -------------------------------------------------------------------
+ // A message?s properties are deleted by the clearProperties method.
+ // This leaves the message with an empty set of properties.
+ // -------------------------------------------------------------------
+ aLong = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
+
+ if (aLong == null) {
+ logger.log(Logger.Level.TRACE, "Pass: property was cleared");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: getObjectProperty should have returned null for cleared property");
+ pass = false;
+ }
+ try {
+ short aShort = messageReceived.getShortProperty("TESTSHORT");
+
+ logger.log(Logger.Level.INFO, "Error: NumberFormatException should have occurred for getShortProperty");
+ logger.log(Logger.Level.INFO, "Properties have been cleared!");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+
+ // -------------------------------------------------------------------
+ // clearing the message property should not effect the message body.
+ // -------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Message body is : " + messageReceived.getText());
+ if (messageReceived.getText().equals(testMessageBody)) {
+ logger.log(Logger.Level.TRACE, "Pass: able to read message body after clearProperties");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unable to read message body after clearProperties");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // ConnectionMetaData.getJMSXPropertyNames() method returns the
+ // names of the JMSX properties supported by a connection.
+ // -------------------------------------------------------------------
+ try {
+ ConnectionMetaData data = tool.getDefaultQueueConnection().getMetaData();
+ Enumeration cmd = data.getJMSXPropertyNames();
+ String propName;
+
+ if (cmd == null) {
+ logger.log(Logger.Level.INFO, "Error: no JMSX property names were returned!");
+ logger.log(Logger.Level.INFO,
+ "expected JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount at a miniumum");
+ pass = false;
+ } else {
+ int iCount = 0;
+
+ do {
+ propName = (String) cmd.nextElement();
+ logger.log(Logger.Level.TRACE, propName);
+ if (propName.equals("JMSXGroupID") || propName.equals("JMSXGroupSeq")
+ || propName.equals("JMSXDeliveryCount")) {
+ iCount++;
+ }
+ } while (cmd.hasMoreElements());
+ if (iCount > 1) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: Expected property names not returned");
+ pass = false;
+ }
+ }
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, "attempting to read JMSX property names.");
+ logger.log(Logger.Level.INFO,
+ "Error: unexpected exception: " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during property tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgPropertiesQTest failed");
+ }
+ }
+
+ /*
+ * @testName: msgPropertiesConversionQTest
+ *
+ * @assertion_ids: JMS:SPEC:22.1; JMS:SPEC:22.2; JMS:SPEC:22.3; JMS:SPEC:22.4;
+ * JMS:SPEC:22.5; JMS:SPEC:22.6; JMS:SPEC:22.7; JMS:SPEC:22.8; JMS:SPEC:22.9;
+ * JMS:SPEC:22.10; JMS:SPEC:22.11; JMS:SPEC:22.12; JMS:SPEC:22.13;
+ * JMS:SPEC:22.14; JMS:SPEC:22.15; JMS:SPEC:22.16; JMS:JAVADOC:768;
+ * JMS:JAVADOC:769; JMS:JAVADOC:770; JMS:JAVADOC:771; JMS:JAVADOC:767;
+ * JMS:JAVADOC:772; JMS:JAVADOC:773; JMS:JAVADOC:774;
+ *
+ * @test_Strategy: create a message, set properties for all of the primitive
+ * types verify the conversion by getting the properties.
+ */
+ @Test
+ public void msgPropertiesConversionQTest() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ String testMessageBody = "Testing...";
+ int ntest = 0;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText(testMessageBody);
+
+ // ------------------------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ messageSent.setBooleanProperty("TESTBOOLEAN", bool);
+ messageSent.setByteProperty("TESTBYTE", bValue);
+ messageSent.setShortProperty("TESTSHORT", nShort);
+ messageSent.setIntProperty("TESTINT", nInt);
+ messageSent.setFloatProperty("TESTFLOAT", nFloat);
+ messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
+ messageSent.setStringProperty("TESTSTRING", "test");
+ messageSent.setLongProperty("TESTLONG", nLong);
+ messageSent.setStringProperty("TESTSTRINGTRUE", "true");
+ messageSent.setStringProperty("TESTSTRINGFALSE", "false");
+ messageSent.setStringProperty("TESTSTRING1", "1");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesConversionQTest");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // -------------------------------------------------------------------
+ // test conversions for property values
+ // -------------------------------------------------------------------
+ // property set as boolean can be read only as string or boolean
+ // -------------------------------------------------------------------
+ // valid - boolean to string
+ String myBool = messageReceived.getStringProperty("TESTBOOLEAN");
+
+ if (Boolean.valueOf(myBool).booleanValue() == bool) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from boolean to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from boolean to string failed");
+ pass = false;
+ }
+
+ // invalid - boolean to byte
+ try {
+ messageReceived.getByteProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+
+ // logger.log(Logger.Level.INFO,"Error: unexpected error " +
+ // ee.getClass().getName() + " was
+ // thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to byte");
+ pass = false;
+ }
+
+ // invalid - boolean to short
+ try {
+ messageReceived.getShortProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to short");
+ pass = false;
+ }
+
+ // invalid - boolean to int
+ try {
+ messageReceived.getIntProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception --boolean to int ");
+ pass = false;
+ }
+
+ // invalid - boolean to long
+ try {
+ messageReceived.getLongProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to long ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to long");
+ pass = false;
+ }
+
+ // invalid - boolean to float
+ try {
+ messageReceived.getFloatProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to float");
+ pass = false;
+ }
+
+ // invalid - boolean to double
+ try {
+ messageReceived.getDoubleProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as byte can be read as a byte,short,int,long or string
+ // valid - byte to string
+ String myByte = messageReceived.getStringProperty("TESTBYTE");
+
+ if (Byte.valueOf(myByte).byteValue() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from byte to string failed");
+ pass = false;
+ }
+
+ // valid - byte to short
+ if (messageReceived.getShortProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to short - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from byte to short failed");
+ pass = false;
+ }
+
+ // valid - byte to int
+ if (messageReceived.getIntProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from byte to int failed");
+ pass = false;
+ }
+
+ // valid - byte to long
+ if (messageReceived.getLongProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from byte to long failed");
+ pass = false;
+ }
+
+ // invalid - byte to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: byte to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- byte to boolean");
+ pass = false;
+ }
+
+ // invalid - byte to float
+ try {
+ messageReceived.getFloatProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: byte to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception --byte to float ");
+ pass = false;
+ }
+
+ // invalid - byte to double
+ try {
+ messageReceived.getDoubleProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: byte to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- byte to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------
+ // property set as short can be read as short,int,long or string
+ // valid - short to string
+ String myshort = messageReceived.getStringProperty("TESTSHORT");
+
+ if (Short.valueOf(myshort).shortValue() == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from short to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from short to string failed");
+ pass = false;
+ }
+
+ // valid - short to int
+ if (messageReceived.getIntProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from short to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from short to int failed");
+ pass = false;
+ }
+
+ // valid - short to long
+ if (messageReceived.getLongProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from short to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from short to long failed");
+ pass = false;
+ }
+
+ // invalid - short to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- short to boolean");
+ pass = false;
+ }
+
+ // invalid - short to byte
+ try {
+ messageReceived.getByteProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- short to byte");
+ pass = false;
+ }
+
+ // invalid - short to float
+ try {
+ messageReceived.getFloatProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- short to float");
+ pass = false;
+ }
+
+ // invalid - short to double
+ try {
+ messageReceived.getDoubleProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- short to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------
+ // property set as int can be read only as int, long or string
+ // valid - int to string
+ if (Integer.valueOf(messageReceived.getStringProperty("TESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from int to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from int to string failed");
+ pass = false;
+ }
+
+ // valid - int to long
+ if (messageReceived.getLongProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from int to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from int to long failed");
+ pass = false;
+ }
+
+ // invalid - int to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- int to boolean");
+ pass = false;
+ }
+
+ // invalid - int to byte
+ try {
+ messageReceived.getByteProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- int to byte");
+ pass = false;
+ }
+
+ // invalid - int to short
+ try {
+ messageReceived.getShortProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected -- int to short ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception ");
+ pass = false;
+ }
+
+ // invalid - int to float
+ try {
+ messageReceived.getFloatProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- int to float");
+ pass = false;
+ }
+
+ // invalid - int to double
+ try {
+ messageReceived.getDoubleProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- int to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as long can be read only as long,or a string
+ // valid - long to string
+ if (Long.valueOf(messageReceived.getStringProperty("TESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from long to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from long to string failed");
+ pass = false;
+ }
+
+ // invalid - long to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to boolean");
+ pass = false;
+ }
+
+ // invalid - long to byte
+ try {
+ messageReceived.getByteProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to byte");
+ pass = false;
+ }
+
+ // invalid - long to short
+ try {
+ messageReceived.getShortProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to short ");
+ pass = false;
+ }
+
+ // invalid - long to int
+ try {
+ messageReceived.getIntProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to int");
+ pass = false;
+ }
+
+ // invalid - long to float
+ try {
+ messageReceived.getFloatProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to float");
+ pass = false;
+ }
+
+ // invalid - long to double
+ try {
+ messageReceived.getDoubleProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as float can be read only as float,double or a string
+ // valid - float to string
+ if (Float.valueOf(messageReceived.getStringProperty("TESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from float to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from float to string failed");
+ pass = false;
+ }
+
+ // valid - float to double
+ if (messageReceived.getDoubleProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from long to double - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from long to double failed");
+ pass = false;
+ }
+
+ // invalid - float to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- float to boolean ");
+ pass = false;
+ }
+
+ // invalid - float to byte
+ try {
+ messageReceived.getByteProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- float to byte");
+ pass = false;
+ }
+
+ // invalid - float to short
+ try {
+ messageReceived.getShortProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception - float to short ");
+ pass = false;
+ }
+
+ // invalid - float to int
+ try {
+ messageReceived.getIntProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception --- float to int");
+ pass = false;
+ }
+
+ // invalid - float to long
+ try {
+ messageReceived.getLongProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to long ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- float to long");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as double can be read only as double or string
+ // valid - double to string
+ if (Double.valueOf(messageReceived.getStringProperty("TESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from double to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from double to string failed");
+ pass = false;
+ }
+
+ // invalid - double to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to boolean ");
+ pass = false;
+ }
+
+ // invalid - double to byte
+ try {
+ messageReceived.getByteProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to byte ");
+ pass = false;
+ }
+
+ // invalid - double to short
+ try {
+ messageReceived.getShortProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to short");
+ pass = false;
+ }
+
+ // invalid - double to int
+ try {
+ messageReceived.getIntProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception --- double to int ");
+ pass = false;
+ }
+
+ // invalid - double to long
+ try {
+ messageReceived.getLongProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to long ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to long");
+ pass = false;
+ }
+
+ // invalid - double to float
+ try {
+ messageReceived.getFloatProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to float");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as string can be read as boolean, byte, short,
+ // int, long, float, double, and String.
+ // valid - string to boolean
+ if ((messageReceived.getBooleanProperty("TESTSTRINGTRUE")) == true) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to boolean - expect true - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to boolean - expect true - failed");
+ pass = false;
+ }
+ if ((messageReceived.getBooleanProperty("TESTSTRINGFALSE")) == false) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to boolean expect false - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to boolean expect false - failed");
+ pass = false;
+ }
+
+ // valid - string to byte
+ if (messageReceived.getByteProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to byte - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to byte failed");
+ pass = false;
+ }
+
+ // valid - string to short
+ if (messageReceived.getShortProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to short - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to short failed");
+ pass = false;
+ }
+
+ // valid - string to int
+ if (messageReceived.getIntProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to int failed");
+ pass = false;
+ }
+
+ // valid - string to long
+ if (messageReceived.getLongProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to long failed");
+ pass = false;
+ }
+
+ // valid - string to float
+ if (messageReceived.getFloatProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to float - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to float failed");
+ pass = false;
+ }
+
+ // valid - string to double
+ if (messageReceived.getDoubleProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to double - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to double failed");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during property conversion tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgPropertiesConversionQTest failed");
+ }
+ }
+
+ /*
+ * @testName: msgPropertyExistTest
+ *
+ * @assertion_ids: JMS:JAVADOC:411; JMS:JAVADOC:413; JMS:JAVADOC:415;
+ * JMS:JAVADOC:417; JMS:JAVADOC:419; JMS:JAVADOC:421; JMS:JAVADOC:423;
+ * JMS:JAVADOC:425; JMS:JAVADOC:427; JMS:JAVADOC:389;
+ *
+ * @test_Strategy: Set and read properties for boolean, byte, short, int, long,
+ * float, double, and String. Verify expected results
+ */
+ @Test
+ public void msgPropertyExistTest() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ Enumeration propertyNames = null;
+ String testMessageBody = "Testing msgPropertyExistTest";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText(testMessageBody);
+
+ // ------------------------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ messageSent.setBooleanProperty("TESTBOOLEAN", bool);
+ messageSent.setByteProperty("TESTBYTE", bValue);
+ messageSent.setShortProperty("TESTSHORT", nShort);
+ messageSent.setIntProperty("TESTINT", nInt);
+ messageSent.setFloatProperty("TESTFLOAT", nFloat);
+ messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
+ messageSent.setStringProperty("TESTSTRING", "test");
+ messageSent.setLongProperty("TESTLONG", nLong);
+ messageSent.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // iterate thru the property names
+ int i = 0;
+ propertyNames = messageReceived.getPropertyNames();
+ do {
+ String tmp = (String) propertyNames.nextElement();
+
+ if (tmp.indexOf("JMS") != 0) {
+ i++;
+ if (tmp.equals("TESTBOOLEAN") || tmp.equals("TESTBYTE") || tmp.equals("TESTINT")
+ || tmp.equals("TESTSHORT") || tmp.equals("TESTFLOAT") || tmp.equals("TESTDOUBLE")
+ || tmp.equals("TESTSTRING") || tmp.equals("TESTLONG") || tmp.equals("OBJTESTBOOLEAN")) {
+ logger.log(Logger.Level.TRACE, "+++++++Appclication Property set by client is: " + tmp);
+ if (!messageReceived.propertyExists(tmp)) {
+ pass = messageReceived.propertyExists(tmp);
+ logger.log(Logger.Level.ERROR, "Positive propertyExists test failed for " + tmp);
+ } else if (messageReceived.propertyExists(tmp + "1")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Negative propertyExists test failed for " + tmp + "1");
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "+++++++Appclication Property not set by client: " + tmp);
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.TRACE, "+++++++ JMSProperty Name is: " + tmp);
+ }
+ } while (propertyNames.hasMoreElements());
+
+ if (!pass) {
+ throw new Exception("Error: failures occurred during propertyExists tests");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgPropertyExistTest failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/queuetests/QueueTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/queuetests/QueueTests.java
deleted file mode 100644
index f3c2f35c2b..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/queuetests/QueueTests.java
+++ /dev/null
@@ -1,1002 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.queuetests;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.Connection;
-import jakarta.jms.DeliveryMode;
-import jakarta.jms.JMSException;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.MessageConsumer;
-import jakarta.jms.MessageProducer;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueBrowser;
-import jakarta.jms.QueueConnection;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueSender;
-import jakarta.jms.QueueSession;
-import jakarta.jms.Session;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TemporaryQueue;
-import jakarta.jms.TextMessage;
-
-public class QueueTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.queuetests.QueueTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- QueueTests theTests = new QueueTests();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- TestUtil.logMsg("Didn't get expected exception");
- throw new Exception("Didn't catch expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(10);
- connections = new ArrayList(5);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Cleanup: Closing Queue Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- } catch (Exception e) {
- TestUtil.logErr("An error occurred while cleaning", e);
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /*
- * @testName: emptyMsgsQueueTest
- *
- * @assertion_ids: JMS:SPEC:85; JMS:SPEC:88; JMS:JAVADOC:198; JMS:JAVADOC:334;
- * JMS:JAVADOC:301; JMS:JAVADOC:209; JMS:JAVADOC:211; JMS:JAVADOC:213;
- * JMS:JAVADOC:215; JMS:JAVADOC:217; JMS:JAVADOC:219; JMS:JAVADOC:221;
- * JMS:JAVADOC:223;
- *
- * @test_Strategy: Send and receive empty messages of each type.
- *
- */
- public void emptyMsgsQueueTest() throws Exception {
- try {
-
- // create Queue Connection
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueSender().setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- tool.getDefaultQueueConnection().start();
-
- // send and receive simple message to Queue
- TestUtil.logMsg("Send generic Message to Queue.");
- Message msg = tool.getDefaultQueueSession().createMessage();
-
- msg.setStringProperty("COM_SUN_JMS_TESTNAME", "emptyMsgsQueueTest");
- tool.getDefaultQueueSender().send(msg);
- if (tool.getDefaultQueueReceiver().receive(timeout) == null) {
- throw new Exception("Did not receive message");
- }
-
- // send and receive bytes message to Queue
- TestUtil.logMsg("Send BytesMessage to Queue.");
- BytesMessage bMsg = tool.getDefaultQueueSession().createBytesMessage();
-
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "emptyMsgsQueueTest");
- tool.getDefaultQueueSender().send(bMsg);
- if (tool.getDefaultQueueReceiver().receive(timeout) == null) {
- throw new Exception("Did not receive message");
- }
-
- // send and receive map message to Queue
- TestUtil.logMsg("Send MapMessage to Queue.");
- MapMessage mMsg = tool.getDefaultQueueSession().createMapMessage();
-
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "emptyMsgsQueueTest");
- tool.getDefaultQueueSender().send(mMsg);
- if (tool.getDefaultQueueReceiver().receive(timeout) == null) {
- throw new Exception("Did not receive message");
- }
-
- // send and receive object message to Queue
- TestUtil.logMsg("Send ObjectMessage to Queue.");
- ObjectMessage oMsg = tool.getDefaultQueueSession().createObjectMessage();
-
- oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "emptyMsgsQueueTest");
- tool.getDefaultQueueSender().send(oMsg);
- if (tool.getDefaultQueueReceiver().receive(timeout) == null) {
- throw new Exception("Did not receive message");
- }
-
- // send and receive stream message to Queue
- TestUtil.logMsg("Send SreamMessage to Queue.");
- StreamMessage sMsg = tool.getDefaultQueueSession().createStreamMessage();
-
- sMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "emptyMsgsQueueTest");
- tool.getDefaultQueueSender().send(sMsg);
- if (tool.getDefaultQueueReceiver().receive(timeout) == null) {
- throw new Exception("Did not receive message");
- }
-
- // send and receive text message to Queue
- TestUtil.logMsg("Send TextMessage to Queue.");
- TextMessage tMsg = tool.getDefaultQueueSession().createTextMessage();
-
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "emptyMsgsQueueTest");
- tool.getDefaultQueueSender().send(tMsg);
- if (tool.getDefaultQueueReceiver().receive(timeout) == null) {
- throw new Exception("Did not receive message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("emptyMsgsQueueTest failed");
- }
- }
-
- /*
- * @testName: autoAckQueueTest
- *
- * @assertion_ids: JMS:SPEC:132; JMS:JAVADOC:198; JMS:JAVADOC:334;
- * JMS:JAVADOC:235;
- *
- * @test_Strategy: Send two messages to a queue. Receive the first message and
- * call session.recover(). Attempt to receive the second message.
- */
- public void autoAckQueueTest() throws Exception {
- try {
- Message messageSent = null;
- Message messageReceived = null;
-
- // create queue setup
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- // create and send messages
- messageSent = tool.getDefaultQueueSession().createMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "autoAckQueueTest");
-
- TestUtil.logTrace("send two messages");
- messageSent.setBooleanProperty("lastMessage", false);
- tool.getDefaultQueueSender().send(messageSent);
- messageSent.setBooleanProperty("lastMessage", true);
- tool.getDefaultQueueSender().send(messageSent);
-
- // receive message and call recover
- messageReceived = tool.getDefaultQueueReceiver().receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Did not receive message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
- throw new Exception("Error: received second message first");
- }
- TestUtil.logTrace("Message received. Call recover.");
- tool.getDefaultQueueSession().recover();
-
- // attempt to receive second message
- messageReceived = tool.getDefaultQueueReceiver().receive(timeout);
-
- // check message
- if (messageReceived == null) {
- throw new Exception("Did not receive second message as expected");
- } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
- throw new Exception("Received original message again");
- } else {
- TestUtil.logMsg("Did not receive message again - GOOD");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("autoAckQueueTest");
- }
- }
-
- /*
- * @testName: simpleSendReceiveQueueTest
- *
- * @assertion_ids: JMS:SPEC:138; JMS:JAVADOC:198; JMS:JAVADOC:334;
- * JMS:JAVADOC:122;
- *
- * @test_Strategy: Send and receive single message to verify that Queues are
- * working.
- */
- public void simpleSendReceiveQueueTest() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logMsg("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "simpleSendReceiveQueueTest");
- TestUtil.logMsg("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- TestUtil.logMsg("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logMsg("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("simpleSendReceiveQueueTest failed");
- }
- }
-
- /*
- * @testName: messageOrderQueueTest
- *
- * @assertion_ids: JMS:SPEC:146; JMS:SPEC:147; JMS:JAVADOC:198;
- * JMS:JAVADOC:122; JMS:JAVADOC:334;
- *
- * @test_Strategy: Send messages to a queue and receive them verify that the
- * text of each matches the order of the text in the sent messages.
- */
- public void messageOrderQueueTest() throws Exception {
- try {
- TextMessage tempMsg;
- String text[] = new String[numMessages];
-
- // set up tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- // create and send messages to queue
- for (int i = 0; i < numMessages; i++) {
- text[i] = "message order test " + i;
- tempMsg = tool.getDefaultQueueSession().createTextMessage();
- tempMsg.setText(text[i]);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "messageOrderQueueTest" + i);
- tool.getDefaultQueueSender().send(tempMsg);
- TestUtil.logTrace("Sent message: " + tempMsg.getText());
- }
-
- // receive messages and verify order
- for (int i = 0; i < numMessages; i++) {
- tempMsg = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
- if (tempMsg == null) {
- throw new Exception("cannot receive message");
- }
- TestUtil.logTrace("Received message: " + tempMsg.getText());
- if (!tempMsg.getText().equals(text[i])) {
- TestUtil.logMsg("Received message: " + tempMsg.getText());
- TestUtil.logMsg("Should have: " + text[i]);
- throw new Exception("received wrong message");
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("messageOrderQueueTest failed");
- }
- }
-
- /*
- * @testName: temporaryQueueNotConsumableTest
- *
- * @assertion_ids: JMS:SPEC:144; JMS:JAVADOC:194;
- *
- * @test_Strategy: Create temporary queue and a separate QueueSession. Try to
- * create a receiver for the temporary queue from the new session, which
- * should throw a JMSException. Also sends a blank message to verify that the
- * temporary queue is working.
- */
- public void temporaryQueueNotConsumableTest() throws Exception {
- boolean passed = false;
-
- try {
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- // create the TemporaryQueue
- TestUtil.logMsg("Creating TemporaryQueue");
- TemporaryQueue tempQ = tool.getDefaultQueueSession()
- .createTemporaryQueue();
-
- // open a new connection, create Session and Sender
- TestUtil.logMsg("Creating new Connection");
- QueueConnection newQConn = (QueueConnection) tool
- .getNewConnection(JmsTool.QUEUE, user, password);
- connections.add(newQConn);
-
- TestUtil.logMsg("Create new Session");
- QueueSession newQSess = newQConn.createQueueSession(false,
- Session.AUTO_ACKNOWLEDGE);
-
- TestUtil.logMsg("Create new sender for TemporaryQueue");
- QueueSender newQSender = newQSess.createSender(tempQ);
-
- // send message to verify TemporaryQueue
- TestUtil.logMsg("Send message to TemporaryQueue");
- Message msg = tool.getDefaultQueueSession().createMessage();
-
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "temporaryQueueNotConsumableTest");
- newQSender.send(msg);
-
- // try to create receiver for the TemporaryQueue
- TestUtil.logMsg(
- "Attempt to create receiver for TemporaryQueue from another Session");
- try {
- QueueReceiver newQReceiver = newQSess.createReceiver(tempQ);
- if (newQReceiver != null)
- TestUtil.logTrace("newQReceiver=" + newQReceiver);
- } catch (JMSException e) {
- TestUtil.logMsg("Received expected JMSException -- GOOD");
- passed = true;
- }
-
- // close new connection
- TestUtil.logTrace("Closing new QueueConnection");
- newQConn.close();
-
- // throw exception if test failed
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("temporaryQueueNotConsumableTest failed");
- }
- }
-
- /*
- * @testName: messageSelectorMsgRemainsOnQueueTest
- *
- * @assertion_ids: JMS:SPEC:146; JMS:SPEC:147; JMS:JAVADOC:186;
- *
- * @test_Strategy: Send two messages to a queue and receive the second one
- * using a message selector. Verify that the first message is still in the
- * queue by receiving with a different receiver.
- */
- public void messageSelectorMsgRemainsOnQueueTest() throws Exception {
- boolean pass = true;
-
- try {
- Message messageSent = null;
- Message messageReceived = null;
-
- // create Queue Connection
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
-
- // create receiver with message selector (close default receiver)
- TestUtil.logMsg("Creating receiver with message selector");
- tool.getDefaultQueueReceiver().close();
- QueueReceiver qSelectiveReceiver = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue(), "TEST = 'test'");
-
- // start connection
- tool.getDefaultQueueConnection().start();
-
- // send two messages
- TestUtil.logTrace("Sending two Messages");
- messageSent = tool.getDefaultQueueSession().createMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "messageSelectorMsgRemainsOnQueueTest");
-
- messageSent.setBooleanProperty("lastMessage", false);
- tool.getDefaultQueueSender().send(messageSent);
- messageSent.setStringProperty("TEST", "test");
- messageSent.setBooleanProperty("lastMessage", true);
- tool.getDefaultQueueSender().send(messageSent);
-
- // check selective receiver
- TestUtil.logTrace("Receiving message with selective receiver");
- messageReceived = qSelectiveReceiver.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- TestUtil.logErr("Did not receive any message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
- pass = false;
- TestUtil.logErr("Received incorrect message");
- } else {
- TestUtil.logMsg("Selective Receiver received correct message");
- }
-
- // receive original message with normal receiver
- qSelectiveReceiver.close();
- QueueReceiver qRec = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue());
- messageReceived = qRec.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- TestUtil.logErr("Un-received message did not remain on queue");
- } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
- pass = false;
- TestUtil.logErr("received incorrect message");
- } else {
- TestUtil.logMsg("Corrected Message left on Queue is received");
- }
-
- if (!pass)
- throw new Exception("messageSelectorMsgRemainsOnQueueTest Failed!!");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("messageSelectorMsgRemainsOnQueueTest failed");
- }
- }
-
- /*
- * @testName: msgSelectorMsgHeaderQueueTest
- *
- * @assertion_ids: JMS:SPEC:38; JMS:JAVADOC:186;
- *
- * @test_Strategy: Create receiver with a message selector that uses a message
- * header. Send two messages, one that has the proper header and one that
- * doesn't, and try to receive only matching message.
- */
- public void msgSelectorMsgHeaderQueueTest() throws Exception {
- boolean pass = true;
-
- try {
-
- // create Queue Connection
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
-
- // create receiver with message selector (close default receiver)
- TestUtil.logMsg("Creating receiver with message selector");
- tool.getDefaultQueueReceiver().close();
- QueueReceiver qSelectiveReceiver = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue(), "JMSType = 'test_message'");
-
- // start connection
- tool.getDefaultQueueConnection().start();
-
- // send messages
- Message m = tool.getDefaultQueueSession().createMessage();
- m.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgSelectorMsgHeaderQueueTest");
-
- TestUtil.logTrace("Sending message not matching selector");
- m.setJMSType("foo");
- m.setBooleanProperty("lastMessage", false);
- tool.getDefaultQueueSender().send(m);
-
- TestUtil.logTrace("Sending test message with header property JMSType");
- m.setJMSType("test_message");
- m.setBooleanProperty("lastMessage", true);
- tool.getDefaultQueueSender().send(m);
-
- // attempt to receive correct message
- TestUtil.logMsg("Attempt to receive 'good' message");
- Message msg1 = qSelectiveReceiver.receive(timeout);
- qSelectiveReceiver.close();
- if (msg1 == null) {
- pass = false;
- TestUtil.logErr("Did not receive any message");
- } else if (msg1.getBooleanProperty("lastMessage") == true) {
- TestUtil.logMsg("Received correct message -- GOOD");
- } else {
- pass = false;
- TestUtil.logErr("Received message not matching header");
- }
-
- // remove remaining message from queue
- QueueReceiver qRec = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue());
- msg1 = qRec.receive(timeout);
- if (msg1 == null) {
- pass = false;
- TestUtil.logErr("No message received.");
- } else if (msg1.getBooleanProperty("lastMessage") == false) {
- TestUtil.logMsg("Received correct message left");
- } else {
- pass = false;
- TestUtil.logErr("Received incorrect message");
- }
-
- if (!pass)
- throw new Exception("msgSelectorMsgHeaderQueueTest failed!!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgSelectorMsgHeaderQueueTest failed");
- }
- }
-
- /*
- * @testName: queueBrowserMsgsRemainOnQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:186; JMS:JAVADOC:221; JMS:JAVADOC:411;
- * JMS:JAVADOC:425; JMS:JAVADOC:120; JMS:JAVADOC:190; JMS:JAVADOC:282;
- * JMS:JAVADOC:284; JMS:SPEC:148; JMS:SPEC:149; JMS:JAVADOC:122;
- *
- * @test_Strategy: 1. Create a Queue and send x messages to it. 2. Create a
- * QueueReceiver with a message selector so that only last message received.
- * 3. Create a QueueBrowser to browse the queue. 4. Then create another
- * QueueReceiver to verify all x messages can be received from the Queue.
- */
- public void queueBrowserMsgsRemainOnQueueTest() throws Exception {
- try {
- TextMessage tempMsg = null;
- QueueReceiver lastMessageReceiver = null;
- QueueReceiver qRec = null;
- QueueBrowser qBrowser = null;
- Enumeration msgs = null;
-
- // create QueueConnection
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueReceiver().close();
- lastMessageReceiver = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue(), "lastMessage = TRUE");
- tool.getDefaultQueueConnection().start();
-
- // send "numMessages" messages to queue plus end of stream message
- for (int i = 0; i <= numMessages; i++) {
- tempMsg = tool.getDefaultQueueSession().createTextMessage();
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- tempMsg.setText("message" + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueBrowserMsgsRemainOnQueueTest" + i);
- tool.getDefaultQueueSender().send(tempMsg);
- TestUtil.logTrace("message " + i + " sent");
- }
-
- // receive final message, all messages now processed
- tempMsg = (TextMessage) lastMessageReceiver.receive(timeout);
- if (tempMsg == null) {
- throw new Exception("Did not receive expected message");
- } else {
- TestUtil.logTrace("Received last sent message, lastMessage="
- + tempMsg.getBooleanProperty("lastMessage"));
- }
- lastMessageReceiver.close();
-
- // create QueueBrowser
- TestUtil.logTrace("Creating QueueBrowser");
- qBrowser = tool.getDefaultQueueSession()
- .createBrowser(tool.getDefaultQueue());
-
- // check for messages
- TestUtil.logMsg(
- "Checking for " + numMessages + " messages with QueueBrowser");
- int msgCount = 0;
- msgs = qBrowser.getEnumeration();
- while (msgs.hasMoreElements()) {
- tempMsg = (TextMessage) msgs.nextElement();
- msgCount++;
- }
- TestUtil.logTrace("found " + msgCount + " messages total in browser");
-
- // check to see if all messages found
- if (msgCount != numMessages) {
-
- // not the test assertion, test can still pass
- TestUtil.logMsg("Warning: browser did not find all messages");
- }
- qBrowser.close();
-
- // continue and try to receive all messages
- qRec = tool.getDefaultQueueSession()
- .createReceiver(tool.getDefaultQueue());
- TestUtil
- .logMsg("Receive all remaining messages to verify still in queue");
- for (msgCount = 0; msgCount < numMessages; msgCount++) {
- tempMsg = (TextMessage) qRec.receive(timeout);
- if (tempMsg == null) {
- throw new Exception("Message " + msgCount + " missing from queue");
- } else {
- TestUtil.logTrace("received message: " + tempMsg.getText());
- }
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("queueBrowserMsgsRemainOnQueueTest failed");
- }
- }
-
- /*
- * @testName: inactiveClientReceiveQueueTest
- *
- * @assertion_ids: JMS:SPEC:150;
- *
- * @test_Strategy: Create a queue with no receiver and send messages to it.
- * Create a new session with a receiver for the queue and verify that the
- * messages can still be received.
- */
- public void inactiveClientReceiveQueueTest() throws Exception {
- try {
- TextMessage tempMsg;
- QueueSession qSession;
- QueueReceiver qReceiver;
-
- // create queue with no receiver
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueReceiver().close();
- tool.getDefaultQueueConnection().start();
-
- // create and send messages
- for (int i = 0; i < numMessages; i++) {
- tempMsg = tool.getDefaultQueueSession().createTextMessage();
- tempMsg.setText("message" + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "inactiveClientReceiveQueueTest" + i);
- tool.getDefaultQueueSender().send(tempMsg);
- TestUtil.logTrace("message " + i + " sent");
- }
-
- tool.getDefaultQueueSession().close();
-
- // create session with a receiver for the queue
- qSession = tool.getDefaultQueueConnection().createQueueSession(false,
- Session.AUTO_ACKNOWLEDGE);
- qReceiver = qSession.createReceiver(tool.getDefaultQueue());
-
- // attempt to receive all messages
- for (int i = 0; i < numMessages; i++) {
- tempMsg = (TextMessage) qReceiver.receive(timeout);
- if (tempMsg == null) {
- throw new Exception("Did not receive all messages");
- }
- TestUtil.logTrace("received message " + i);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("inactiveClientReceiveQueueTest failed");
- }
- }
-
- /*
- * @testName: msgProducerNullDestinationQueueTest
- *
- * @assertion_ids: JMS:SPEC:139; JMS:JAVADOC:188; JMS:JAVADOC:186;
- * JMS:JAVADOC:198;
- *
- * @test_Strategy: Create a q sender, specifying null for the destination send
- * the message to the default destination and then verify receiving it
- */
- public void msgProducerNullDestinationQueueTest() throws Exception {
- boolean pass = true;
- QueueSender qSender = null;
- Queue nullQ = null;
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- try {
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createTextMessage();
- messageSent.setText(
- "test creating a producer without specifying the destination");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgProducerNullDestinationQueueTest");
- TestUtil.logMsg("Test createSender(null) - This is valid");
- try {
- qSender = tool.getDefaultQueueSession().createSender(nullQ);
- TestUtil.logTrace("PASS: null allowed for unidentified producer");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- pass = false;
- }
-
- // publish to a queue and then get the message.
- TestUtil.logTrace("Send a message");
- qSender.send(tool.getDefaultQueue(), messageSent);
- TestUtil.logTrace("Receive a message");
- messageReceived = (TextMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- if (messageReceived == null) {
- pass = false;
- } else {
- TestUtil.logTrace("Got message - OK");
- }
- if (!pass) {
- throw new Exception(
- "Error: failures occurred during msgProducerNullDestinationQueueTest tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgProducerNullDestinationQueueTest failed");
- }
- }
-
- /*
- * @testName: multipleCloseQueueConnectionTest
- *
- * @assertion_ids: JMS:SPEC:108;
- *
- * @test_Strategy: Call close() twice on a connection and catch any exception.
- */
- public void multipleCloseQueueConnectionTest() throws Exception {
- try {
-
- // create Queue Connection
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- TestUtil.logTrace("Call close on a connection ");
- tool.getDefaultQueueConnection().close();
- TestUtil.logTrace("Call close on a connection a second time");
- tool.getDefaultQueueConnection().close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("multipleCloseQueueConnectionTest failed");
- }
- }
-
- /*
- * @testName: messageOrderDeliveryModeQueueTest
- *
- * @assertion_ids: JMS:SPEC:127; JMS:SPEC:128; JMS:JAVADOC:122;
- *
- * @test_Strategy: Send non persistent messages to a queue and receive them.
- * Verify that the text of each matches the order of the text in the sent
- * messages.
- */
- public void messageOrderDeliveryModeQueueTest() throws Exception {
- try {
- TextMessage tempMsg;
- String text[] = new String[numMessages];
-
- // set up tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
-
- // Persistent delivery is the default
- tool.getDefaultQueueSender().setDeliveryMode(DeliveryMode.NON_PERSISTENT);
-
- // create and send messages to queue
- for (int i = 0; i < numMessages; i++) {
- text[i] = "message order test " + i;
- tempMsg = tool.getDefaultQueueSession().createTextMessage();
- tempMsg.setText(text[i]);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "messageOrderDeliveryModeQueueTest" + i);
- tool.getDefaultQueueSender().send(tempMsg);
- TestUtil.logTrace("Sent message: " + tempMsg.getText());
- }
-
- // receive messages and verify order
- for (int i = 0; i < numMessages; i++) {
- tempMsg = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
- if (tempMsg == null) {
- throw new Exception("cannot receive message");
- }
- TestUtil.logTrace("Received message: " + tempMsg.getText());
- if (!tempMsg.getText().equals(text[i])) {
- TestUtil.logMsg("Received message: " + tempMsg.getText());
- TestUtil.logMsg("Should have: " + text[i]);
- throw new Exception("received wrong message");
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("messageOrderDeliveryModeQueueTest failed");
- }
- }
-
- /*
- * @testName: tempQueueTests
- *
- * @assertion_ids: JMS:SPEC:144; JMS:JAVADOC:262; JMS:JAVADOC:126;
- *
- * @test_Strategy: 1. Create a TemporaryQueue from a Session. Send a
- * TextMessage and Receive it using the TemporaryQueue. Verify the Message
- * received correctly. 2. Try to delete the TemporaryQueue without closing
- * MessageConsumer, verify that JMSException is thrown. 3. Close the
- * MessageConsumer, verify that the TemporaryQueue can be deleted. 4. Try to
- * create a MessageConsumer using Session from a different Connection, verify
- * that JMSException is thrown.
- */
- public void tempQueueTests() throws Exception {
- boolean pass = true;
- TextMessage msgSent;
- TextMessage msgReceived;
- String testName = "tempQueueTests";
- String message = "Just a test from tempQueueTests";
- TemporaryQueue tempQ = null;
- Connection newConn = null;
-
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- tool.getDefaultConsumer().close();
- tool.getDefaultConnection().start();
-
- // create the TemporaryQueue
- TestUtil.logMsg("Creating TemporaryQueue");
- tempQ = tool.getDefaultSession().createTemporaryQueue();
-
- // open a new connection, create Session and Sender
- TestUtil.logMsg("Create new sender for TemporaryQueue");
- MessageProducer sender = tool.getDefaultSession().createProducer(tempQ);
- MessageConsumer receiver = tool.getDefaultSession().createConsumer(tempQ);
-
- // send message to verify TemporaryQueue
- TestUtil.logMsg("Send message to TemporaryQueue");
- msgSent = tool.getDefaultSession().createTextMessage();
- msgSent.setText(message);
- msgSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- sender.send(msgSent);
-
- // try to create receiver for the TemporaryQueue
- msgReceived = (TextMessage) receiver.receive(timeout);
-
- if (msgReceived == null) {
- pass = false;
- TestUtil.logErr("didnot receive message");
- } else if (!msgReceived.getText().equals(message)) {
- pass = false;
- TestUtil.logErr("Received wrong message=" + msgReceived.getText());
- TestUtil.logErr("Should have: " + message);
- }
-
- try {
- tempQ.delete();
- pass = false;
- TestUtil.logErr(
- "Didn't throw expected JMSException calling TemporaryQueue.delete()");
- } catch (JMSException em) {
- TestUtil.logTrace("Received expected JMSException: ");
- }
- receiver.close();
-
- try {
- tempQ.delete();
- TestUtil.logTrace(
- "Succesfully calling TemporaryQueue.delete() after closing Receiver");
- } catch (Exception e) {
- pass = false;
- TestUtil.logErr("Received unexpected Exception: ", e);
- }
-
- tempQ = tool.getDefaultSession().createTemporaryQueue();
- newConn = (Connection) tool.getNewConnection(JmsTool.COMMON_Q, user,
- password);
- connections.add(newConn);
- Session newSess = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- // try to create receiver for the TemporaryQueue
- TestUtil.logMsg(
- "Attempt to create MessageConsumer for TemporaryQueue from another Connection");
- try {
- MessageConsumer newReceiver = newSess.createConsumer(tempQ);
- if (newReceiver != null)
- TestUtil.logTrace("newReceiver=" + newReceiver);
- logTrace("FAIL: expected IllegalStateException");
- TestUtil.logErr(
- "Didn't throw expected JMSException calling Session.createConsumer(TemporaryQueue)");
- } catch (JMSException e) {
- TestUtil
- .logTrace("Received expected JMSException from createConsumer.");
- }
-
- if (!pass)
- throw new Exception(testName + " failed");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/queuetests/QueueTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/queuetests/QueueTestsIT.java
new file mode 100644
index 0000000000..94df4ec3ba
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/queuetests/QueueTestsIT.java
@@ -0,0 +1,980 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.queuetests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.Connection;
+import jakarta.jms.DeliveryMode;
+import jakarta.jms.JMSException;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueBrowser;
+import jakarta.jms.QueueConnection;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueSender;
+import jakarta.jms.QueueSession;
+import jakarta.jms.Session;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TemporaryQueue;
+import jakarta.jms.TextMessage;
+
+
+public class QueueTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.queuetests.QueueTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(QueueTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ /* Utility methods for tests */
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't catch expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(10);
+ connections = new ArrayList(5);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning", e);
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: emptyMsgsQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:85; JMS:SPEC:88; JMS:JAVADOC:198; JMS:JAVADOC:334;
+ * JMS:JAVADOC:301; JMS:JAVADOC:209; JMS:JAVADOC:211; JMS:JAVADOC:213;
+ * JMS:JAVADOC:215; JMS:JAVADOC:217; JMS:JAVADOC:219; JMS:JAVADOC:221;
+ * JMS:JAVADOC:223;
+ *
+ * @test_Strategy: Send and receive empty messages of each type.
+ *
+ */
+ @Test
+ public void emptyMsgsQueueTest() throws Exception {
+ try {
+
+ // create Queue Connection
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueSender().setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ tool.getDefaultQueueConnection().start();
+
+ // send and receive simple message to Queue
+ logger.log(Logger.Level.INFO, "Send generic Message to Queue.");
+ Message msg = tool.getDefaultQueueSession().createMessage();
+
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "emptyMsgsQueueTest");
+ tool.getDefaultQueueSender().send(msg);
+ if (tool.getDefaultQueueReceiver().receive(timeout) == null) {
+ throw new Exception("Did not receive message");
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.INFO, "Send BytesMessage to Queue.");
+ BytesMessage bMsg = tool.getDefaultQueueSession().createBytesMessage();
+
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "emptyMsgsQueueTest");
+ tool.getDefaultQueueSender().send(bMsg);
+ if (tool.getDefaultQueueReceiver().receive(timeout) == null) {
+ throw new Exception("Did not receive message");
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.INFO, "Send MapMessage to Queue.");
+ MapMessage mMsg = tool.getDefaultQueueSession().createMapMessage();
+
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "emptyMsgsQueueTest");
+ tool.getDefaultQueueSender().send(mMsg);
+ if (tool.getDefaultQueueReceiver().receive(timeout) == null) {
+ throw new Exception("Did not receive message");
+ }
+
+ // send and receive object message to Queue
+ logger.log(Logger.Level.INFO, "Send ObjectMessage to Queue.");
+ ObjectMessage oMsg = tool.getDefaultQueueSession().createObjectMessage();
+
+ oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "emptyMsgsQueueTest");
+ tool.getDefaultQueueSender().send(oMsg);
+ if (tool.getDefaultQueueReceiver().receive(timeout) == null) {
+ throw new Exception("Did not receive message");
+ }
+
+ // send and receive stream message to Queue
+ logger.log(Logger.Level.INFO, "Send SreamMessage to Queue.");
+ StreamMessage sMsg = tool.getDefaultQueueSession().createStreamMessage();
+
+ sMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "emptyMsgsQueueTest");
+ tool.getDefaultQueueSender().send(sMsg);
+ if (tool.getDefaultQueueReceiver().receive(timeout) == null) {
+ throw new Exception("Did not receive message");
+ }
+
+ // send and receive text message to Queue
+ logger.log(Logger.Level.INFO, "Send TextMessage to Queue.");
+ TextMessage tMsg = tool.getDefaultQueueSession().createTextMessage();
+
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "emptyMsgsQueueTest");
+ tool.getDefaultQueueSender().send(tMsg);
+ if (tool.getDefaultQueueReceiver().receive(timeout) == null) {
+ throw new Exception("Did not receive message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("emptyMsgsQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: autoAckQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:132; JMS:JAVADOC:198; JMS:JAVADOC:334;
+ * JMS:JAVADOC:235;
+ *
+ * @test_Strategy: Send two messages to a queue. Receive the first message and
+ * call session.recover(). Attempt to receive the second message.
+ */
+ @Test
+ public void autoAckQueueTest() throws Exception {
+ try {
+ Message messageSent = null;
+ Message messageReceived = null;
+
+ // create queue setup
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ // create and send messages
+ messageSent = tool.getDefaultQueueSession().createMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "autoAckQueueTest");
+
+ logger.log(Logger.Level.TRACE, "send two messages");
+ messageSent.setBooleanProperty("lastMessage", false);
+ tool.getDefaultQueueSender().send(messageSent);
+ messageSent.setBooleanProperty("lastMessage", true);
+ tool.getDefaultQueueSender().send(messageSent);
+
+ // receive message and call recover
+ messageReceived = tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Did not receive message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
+ throw new Exception("Error: received second message first");
+ }
+ logger.log(Logger.Level.TRACE, "Message received. Call recover.");
+ tool.getDefaultQueueSession().recover();
+
+ // attempt to receive second message
+ messageReceived = tool.getDefaultQueueReceiver().receive(timeout);
+
+ // check message
+ if (messageReceived == null) {
+ throw new Exception("Did not receive second message as expected");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
+ throw new Exception("Received original message again");
+ } else {
+ logger.log(Logger.Level.INFO, "Did not receive message again - GOOD");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("autoAckQueueTest");
+ }
+ }
+
+ /*
+ * @testName: simpleSendReceiveQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:138; JMS:JAVADOC:198; JMS:JAVADOC:334;
+ * JMS:JAVADOC:122;
+ *
+ * @test_Strategy: Send and receive single message to verify that Queues are
+ * working.
+ */
+ @Test
+ public void simpleSendReceiveQueueTest() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "simpleSendReceiveQueueTest");
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("simpleSendReceiveQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: messageOrderQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:146; JMS:SPEC:147; JMS:JAVADOC:198; JMS:JAVADOC:122;
+ * JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Send messages to a queue and receive them verify that the
+ * text of each matches the order of the text in the sent messages.
+ */
+ @Test
+ public void messageOrderQueueTest() throws Exception {
+ try {
+ TextMessage tempMsg;
+ String text[] = new String[numMessages];
+
+ // set up tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ // create and send messages to queue
+ for (int i = 0; i < numMessages; i++) {
+ text[i] = "message order test " + i;
+ tempMsg = tool.getDefaultQueueSession().createTextMessage();
+ tempMsg.setText(text[i]);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "messageOrderQueueTest" + i);
+ tool.getDefaultQueueSender().send(tempMsg);
+ logger.log(Logger.Level.TRACE, "Sent message: " + tempMsg.getText());
+ }
+
+ // receive messages and verify order
+ for (int i = 0; i < numMessages; i++) {
+ tempMsg = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (tempMsg == null) {
+ throw new Exception("cannot receive message");
+ }
+ logger.log(Logger.Level.TRACE, "Received message: " + tempMsg.getText());
+ if (!tempMsg.getText().equals(text[i])) {
+ logger.log(Logger.Level.INFO, "Received message: " + tempMsg.getText());
+ logger.log(Logger.Level.INFO, "Should have: " + text[i]);
+ throw new Exception("received wrong message");
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("messageOrderQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: temporaryQueueNotConsumableTest
+ *
+ * @assertion_ids: JMS:SPEC:144; JMS:JAVADOC:194;
+ *
+ * @test_Strategy: Create temporary queue and a separate QueueSession. Try to
+ * create a receiver for the temporary queue from the new session, which should
+ * throw a JMSException. Also sends a blank message to verify that the temporary
+ * queue is working.
+ */
+ @Test
+ public void temporaryQueueNotConsumableTest() throws Exception {
+ boolean passed = false;
+
+ try {
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ // create the TemporaryQueue
+ logger.log(Logger.Level.INFO, "Creating TemporaryQueue");
+ TemporaryQueue tempQ = tool.getDefaultQueueSession().createTemporaryQueue();
+
+ // open a new connection, create Session and Sender
+ logger.log(Logger.Level.INFO, "Creating new Connection");
+ QueueConnection newQConn = (QueueConnection) tool.getNewConnection(JmsTool.QUEUE, user, password);
+ connections.add(newQConn);
+
+ logger.log(Logger.Level.INFO, "Create new Session");
+ QueueSession newQSess = newQConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ logger.log(Logger.Level.INFO, "Create new sender for TemporaryQueue");
+ QueueSender newQSender = newQSess.createSender(tempQ);
+
+ // send message to verify TemporaryQueue
+ logger.log(Logger.Level.INFO, "Send message to TemporaryQueue");
+ Message msg = tool.getDefaultQueueSession().createMessage();
+
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "temporaryQueueNotConsumableTest");
+ newQSender.send(msg);
+
+ // try to create receiver for the TemporaryQueue
+ logger.log(Logger.Level.INFO, "Attempt to create receiver for TemporaryQueue from another Session");
+ try {
+ QueueReceiver newQReceiver = newQSess.createReceiver(tempQ);
+ if (newQReceiver != null)
+ logger.log(Logger.Level.TRACE, "newQReceiver=" + newQReceiver);
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Received expected JMSException -- GOOD");
+ passed = true;
+ }
+
+ // close new connection
+ logger.log(Logger.Level.TRACE, "Closing new QueueConnection");
+ newQConn.close();
+
+ // throw exception if test failed
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("temporaryQueueNotConsumableTest failed");
+ }
+ }
+
+ /*
+ * @testName: messageSelectorMsgRemainsOnQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:146; JMS:SPEC:147; JMS:JAVADOC:186;
+ *
+ * @test_Strategy: Send two messages to a queue and receive the second one using
+ * a message selector. Verify that the first message is still in the queue by
+ * receiving with a different receiver.
+ */
+ @Test
+ public void messageSelectorMsgRemainsOnQueueTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ Message messageSent = null;
+ Message messageReceived = null;
+
+ // create Queue Connection
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+
+ // create receiver with message selector (close default receiver)
+ logger.log(Logger.Level.INFO, "Creating receiver with message selector");
+ tool.getDefaultQueueReceiver().close();
+ QueueReceiver qSelectiveReceiver = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue(),
+ "TEST = 'test'");
+
+ // start connection
+ tool.getDefaultQueueConnection().start();
+
+ // send two messages
+ logger.log(Logger.Level.TRACE, "Sending two Messages");
+ messageSent = tool.getDefaultQueueSession().createMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "messageSelectorMsgRemainsOnQueueTest");
+
+ messageSent.setBooleanProperty("lastMessage", false);
+ tool.getDefaultQueueSender().send(messageSent);
+ messageSent.setStringProperty("TEST", "test");
+ messageSent.setBooleanProperty("lastMessage", true);
+ tool.getDefaultQueueSender().send(messageSent);
+
+ // check selective receiver
+ logger.log(Logger.Level.TRACE, "Receiving message with selective receiver");
+ messageReceived = qSelectiveReceiver.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Did not receive any message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ } else {
+ logger.log(Logger.Level.INFO, "Selective Receiver received correct message");
+ }
+
+ // receive original message with normal receiver
+ qSelectiveReceiver.close();
+ QueueReceiver qRec = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue());
+ messageReceived = qRec.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Un-received message did not remain on queue");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "received incorrect message");
+ } else {
+ logger.log(Logger.Level.INFO, "Corrected Message left on Queue is received");
+ }
+
+ if (!pass)
+ throw new Exception("messageSelectorMsgRemainsOnQueueTest Failed!!");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("messageSelectorMsgRemainsOnQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: msgSelectorMsgHeaderQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:38; JMS:JAVADOC:186;
+ *
+ * @test_Strategy: Create receiver with a message selector that uses a message
+ * header. Send two messages, one that has the proper header and one that
+ * doesn't, and try to receive only matching message.
+ */
+ @Test
+ public void msgSelectorMsgHeaderQueueTest() throws Exception {
+ boolean pass = true;
+
+ try {
+
+ // create Queue Connection
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+
+ // create receiver with message selector (close default receiver)
+ logger.log(Logger.Level.INFO, "Creating receiver with message selector");
+ tool.getDefaultQueueReceiver().close();
+ QueueReceiver qSelectiveReceiver = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue(),
+ "JMSType = 'test_message'");
+
+ // start connection
+ tool.getDefaultQueueConnection().start();
+
+ // send messages
+ Message m = tool.getDefaultQueueSession().createMessage();
+ m.setStringProperty("COM_SUN_JMS_TESTNAME", "msgSelectorMsgHeaderQueueTest");
+
+ logger.log(Logger.Level.TRACE, "Sending message not matching selector");
+ m.setJMSType("foo");
+ m.setBooleanProperty("lastMessage", false);
+ tool.getDefaultQueueSender().send(m);
+
+ logger.log(Logger.Level.TRACE, "Sending test message with header property JMSType");
+ m.setJMSType("test_message");
+ m.setBooleanProperty("lastMessage", true);
+ tool.getDefaultQueueSender().send(m);
+
+ // attempt to receive correct message
+ logger.log(Logger.Level.INFO, "Attempt to receive 'good' message");
+ Message msg1 = qSelectiveReceiver.receive(timeout);
+ qSelectiveReceiver.close();
+ if (msg1 == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Did not receive any message");
+ } else if (msg1.getBooleanProperty("lastMessage") == true) {
+ logger.log(Logger.Level.INFO, "Received correct message -- GOOD");
+ } else {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received message not matching header");
+ }
+
+ // remove remaining message from queue
+ QueueReceiver qRec = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue());
+ msg1 = qRec.receive(timeout);
+ if (msg1 == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "No message received.");
+ } else if (msg1.getBooleanProperty("lastMessage") == false) {
+ logger.log(Logger.Level.INFO, "Received correct message left");
+ } else {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ }
+
+ if (!pass)
+ throw new Exception("msgSelectorMsgHeaderQueueTest failed!!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgSelectorMsgHeaderQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: queueBrowserMsgsRemainOnQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:186; JMS:JAVADOC:221; JMS:JAVADOC:411;
+ * JMS:JAVADOC:425; JMS:JAVADOC:120; JMS:JAVADOC:190; JMS:JAVADOC:282;
+ * JMS:JAVADOC:284; JMS:SPEC:148; JMS:SPEC:149; JMS:JAVADOC:122;
+ *
+ * @test_Strategy: 1. Create a Queue and send x messages to it. 2. Create a
+ * QueueReceiver with a message selector so that only last message received. 3.
+ * Create a QueueBrowser to browse the queue. 4. Then create another
+ * QueueReceiver to verify all x messages can be received from the Queue.
+ */
+ @Test
+ public void queueBrowserMsgsRemainOnQueueTest() throws Exception {
+ try {
+ TextMessage tempMsg = null;
+ QueueReceiver lastMessageReceiver = null;
+ QueueReceiver qRec = null;
+ QueueBrowser qBrowser = null;
+ Enumeration msgs = null;
+
+ // create QueueConnection
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueReceiver().close();
+ lastMessageReceiver = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue(),
+ "lastMessage = TRUE");
+ tool.getDefaultQueueConnection().start();
+
+ // send "numMessages" messages to queue plus end of stream message
+ for (int i = 0; i <= numMessages; i++) {
+ tempMsg = tool.getDefaultQueueSession().createTextMessage();
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ tempMsg.setText("message" + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "queueBrowserMsgsRemainOnQueueTest" + i);
+ tool.getDefaultQueueSender().send(tempMsg);
+ logger.log(Logger.Level.TRACE, "message " + i + " sent");
+ }
+
+ // receive final message, all messages now processed
+ tempMsg = (TextMessage) lastMessageReceiver.receive(timeout);
+ if (tempMsg == null) {
+ throw new Exception("Did not receive expected message");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Received last sent message, lastMessage=" + tempMsg.getBooleanProperty("lastMessage"));
+ }
+ lastMessageReceiver.close();
+
+ // create QueueBrowser
+ logger.log(Logger.Level.TRACE, "Creating QueueBrowser");
+ qBrowser = tool.getDefaultQueueSession().createBrowser(tool.getDefaultQueue());
+
+ // check for messages
+ logger.log(Logger.Level.INFO, "Checking for " + numMessages + " messages with QueueBrowser");
+ int msgCount = 0;
+ msgs = qBrowser.getEnumeration();
+ while (msgs.hasMoreElements()) {
+ tempMsg = (TextMessage) msgs.nextElement();
+ msgCount++;
+ }
+ logger.log(Logger.Level.TRACE, "found " + msgCount + " messages total in browser");
+
+ // check to see if all messages found
+ if (msgCount != numMessages) {
+
+ // not the test assertion, test can still pass
+ logger.log(Logger.Level.INFO, "Warning: browser did not find all messages");
+ }
+ qBrowser.close();
+
+ // continue and try to receive all messages
+ qRec = tool.getDefaultQueueSession().createReceiver(tool.getDefaultQueue());
+ logger.log(Logger.Level.INFO, "Receive all remaining messages to verify still in queue");
+ for (msgCount = 0; msgCount < numMessages; msgCount++) {
+ tempMsg = (TextMessage) qRec.receive(timeout);
+ if (tempMsg == null) {
+ throw new Exception("Message " + msgCount + " missing from queue");
+ } else {
+ logger.log(Logger.Level.TRACE, "received message: " + tempMsg.getText());
+ }
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueBrowserMsgsRemainOnQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: inactiveClientReceiveQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:150;
+ *
+ * @test_Strategy: Create a queue with no receiver and send messages to it.
+ * Create a new session with a receiver for the queue and verify that the
+ * messages can still be received.
+ */
+ @Test
+ public void inactiveClientReceiveQueueTest() throws Exception {
+ try {
+ TextMessage tempMsg;
+ QueueSession qSession;
+ QueueReceiver qReceiver;
+
+ // create queue with no receiver
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueReceiver().close();
+ tool.getDefaultQueueConnection().start();
+
+ // create and send messages
+ for (int i = 0; i < numMessages; i++) {
+ tempMsg = tool.getDefaultQueueSession().createTextMessage();
+ tempMsg.setText("message" + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "inactiveClientReceiveQueueTest" + i);
+ tool.getDefaultQueueSender().send(tempMsg);
+ logger.log(Logger.Level.TRACE, "message " + i + " sent");
+ }
+
+ tool.getDefaultQueueSession().close();
+
+ // create session with a receiver for the queue
+ qSession = tool.getDefaultQueueConnection().createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ qReceiver = qSession.createReceiver(tool.getDefaultQueue());
+
+ // attempt to receive all messages
+ for (int i = 0; i < numMessages; i++) {
+ tempMsg = (TextMessage) qReceiver.receive(timeout);
+ if (tempMsg == null) {
+ throw new Exception("Did not receive all messages");
+ }
+ logger.log(Logger.Level.TRACE, "received message " + i);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("inactiveClientReceiveQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: msgProducerNullDestinationQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:139; JMS:JAVADOC:188; JMS:JAVADOC:186;
+ * JMS:JAVADOC:198;
+ *
+ * @test_Strategy: Create a q sender, specifying null for the destination send
+ * the message to the default destination and then verify receiving it
+ */
+ @Test
+ public void msgProducerNullDestinationQueueTest() throws Exception {
+ boolean pass = true;
+ QueueSender qSender = null;
+ Queue nullQ = null;
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ try {
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createTextMessage();
+ messageSent.setText("test creating a producer without specifying the destination");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgProducerNullDestinationQueueTest");
+ logger.log(Logger.Level.INFO, "Test createSender(null) - This is valid");
+ try {
+ qSender = tool.getDefaultQueueSession().createSender(nullQ);
+ logger.log(Logger.Level.TRACE, "PASS: null allowed for unidentified producer");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // publish to a queue and then get the message.
+ logger.log(Logger.Level.TRACE, "Send a message");
+ qSender.send(tool.getDefaultQueue(), messageSent);
+ logger.log(Logger.Level.TRACE, "Receive a message");
+ messageReceived = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Got message - OK");
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during msgProducerNullDestinationQueueTest tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgProducerNullDestinationQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: multipleCloseQueueConnectionTest
+ *
+ * @assertion_ids: JMS:SPEC:108;
+ *
+ * @test_Strategy: Call close() twice on a connection and catch any exception.
+ */
+ @Test
+ public void multipleCloseQueueConnectionTest() throws Exception {
+ try {
+
+ // create Queue Connection
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Call close on a connection ");
+ tool.getDefaultQueueConnection().close();
+ logger.log(Logger.Level.TRACE, "Call close on a connection a second time");
+ tool.getDefaultQueueConnection().close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("multipleCloseQueueConnectionTest failed");
+ }
+ }
+
+ /*
+ * @testName: messageOrderDeliveryModeQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:127; JMS:SPEC:128; JMS:JAVADOC:122;
+ *
+ * @test_Strategy: Send non persistent messages to a queue and receive them.
+ * Verify that the text of each matches the order of the text in the sent
+ * messages.
+ */
+ @Test
+ public void messageOrderDeliveryModeQueueTest() throws Exception {
+ try {
+ TextMessage tempMsg;
+ String text[] = new String[numMessages];
+
+ // set up tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+
+ // Persistent delivery is the default
+ tool.getDefaultQueueSender().setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+
+ // create and send messages to queue
+ for (int i = 0; i < numMessages; i++) {
+ text[i] = "message order test " + i;
+ tempMsg = tool.getDefaultQueueSession().createTextMessage();
+ tempMsg.setText(text[i]);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "messageOrderDeliveryModeQueueTest" + i);
+ tool.getDefaultQueueSender().send(tempMsg);
+ logger.log(Logger.Level.TRACE, "Sent message: " + tempMsg.getText());
+ }
+
+ // receive messages and verify order
+ for (int i = 0; i < numMessages; i++) {
+ tempMsg = (TextMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ if (tempMsg == null) {
+ throw new Exception("cannot receive message");
+ }
+ logger.log(Logger.Level.TRACE, "Received message: " + tempMsg.getText());
+ if (!tempMsg.getText().equals(text[i])) {
+ logger.log(Logger.Level.INFO, "Received message: " + tempMsg.getText());
+ logger.log(Logger.Level.INFO, "Should have: " + text[i]);
+ throw new Exception("received wrong message");
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("messageOrderDeliveryModeQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: tempQueueTests
+ *
+ * @assertion_ids: JMS:SPEC:144; JMS:JAVADOC:262; JMS:JAVADOC:126;
+ *
+ * @test_Strategy: 1. Create a TemporaryQueue from a Session. Send a TextMessage
+ * and Receive it using the TemporaryQueue. Verify the Message received
+ * correctly. 2. Try to delete the TemporaryQueue without closing
+ * MessageConsumer, verify that JMSException is thrown. 3. Close the
+ * MessageConsumer, verify that the TemporaryQueue can be deleted. 4. Try to
+ * create a MessageConsumer using Session from a different Connection, verify
+ * that JMSException is thrown.
+ */
+ @Test
+ public void tempQueueTests() throws Exception {
+ boolean pass = true;
+ TextMessage msgSent;
+ TextMessage msgReceived;
+ String testName = "tempQueueTests";
+ String message = "Just a test from tempQueueTests";
+ TemporaryQueue tempQ = null;
+ Connection newConn = null;
+
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ tool.getDefaultConsumer().close();
+ tool.getDefaultConnection().start();
+
+ // create the TemporaryQueue
+ logger.log(Logger.Level.INFO, "Creating TemporaryQueue");
+ tempQ = tool.getDefaultSession().createTemporaryQueue();
+
+ // open a new connection, create Session and Sender
+ logger.log(Logger.Level.INFO, "Create new sender for TemporaryQueue");
+ MessageProducer sender = tool.getDefaultSession().createProducer(tempQ);
+ MessageConsumer receiver = tool.getDefaultSession().createConsumer(tempQ);
+
+ // send message to verify TemporaryQueue
+ logger.log(Logger.Level.INFO, "Send message to TemporaryQueue");
+ msgSent = tool.getDefaultSession().createTextMessage();
+ msgSent.setText(message);
+ msgSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ sender.send(msgSent);
+
+ // try to create receiver for the TemporaryQueue
+ msgReceived = (TextMessage) receiver.receive(timeout);
+
+ if (msgReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "didnot receive message");
+ } else if (!msgReceived.getText().equals(message)) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received wrong message=" + msgReceived.getText());
+ logger.log(Logger.Level.ERROR, "Should have: " + message);
+ }
+
+ try {
+ tempQ.delete();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSException calling TemporaryQueue.delete()");
+ } catch (JMSException em) {
+ logger.log(Logger.Level.TRACE, "Received expected JMSException: ");
+ }
+ receiver.close();
+
+ try {
+ tempQ.delete();
+ logger.log(Logger.Level.TRACE, "Succesfully calling TemporaryQueue.delete() after closing Receiver");
+ } catch (Exception e) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received unexpected Exception: ", e);
+ }
+
+ tempQ = tool.getDefaultSession().createTemporaryQueue();
+ newConn = (Connection) tool.getNewConnection(JmsTool.COMMON_Q, user, password);
+ connections.add(newConn);
+ Session newSess = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // try to create receiver for the TemporaryQueue
+ logger.log(Logger.Level.INFO,
+ "Attempt to create MessageConsumer for TemporaryQueue from another Connection");
+ try {
+ MessageConsumer newReceiver = newSess.createConsumer(tempQ);
+ if (newReceiver != null)
+ logger.log(Logger.Level.TRACE, "newReceiver=" + newReceiver);
+ logger.log(Logger.Level.TRACE, "FAIL: expected IllegalStateException");
+ logger.log(Logger.Level.ERROR,
+ "Didn't throw expected JMSException calling Session.createConsumer(TemporaryQueue)");
+ } catch (JMSException e) {
+ logger.log(Logger.Level.TRACE, "Received expected JMSException from createConsumer.");
+ }
+
+ if (!pass)
+ throw new Exception(testName + " failed");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/selectorQueue/MsgSelectorQueueTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/selectorQueue/MsgSelectorQueueTests.java
deleted file mode 100644
index 4a0e2cbfbe..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/selectorQueue/MsgSelectorQueueTests.java
+++ /dev/null
@@ -1,2880 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.selectorQueue;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.InvalidSelectorException;
-import jakarta.jms.JMSException;
-import jakarta.jms.Message;
-import jakarta.jms.QueueConnection;
-import jakarta.jms.QueueConnectionFactory;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueSender;
-import jakarta.jms.QueueSession;
-import jakarta.jms.Session;
-import jakarta.jms.TemporaryQueue;
-
-public class MsgSelectorQueueTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.ee.selectorQueue.MsgSelectorQueueTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient Message msg = null;
-
- private transient QueueReceiver qReceiver = null;
-
- private transient TemporaryQueue tempQ = null;
-
- private transient QueueSender qSender = null;
-
- private transient QueueConnection qConnect;
-
- private transient QueueSession session;
-
- private transient QueueConnectionFactory qFactory;
-
- private boolean transacted = false;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- private long jms_timeout;
-
- private String jmsUser = null;
-
- private String jmsPassword = null;
-
- private String mode = null;
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- MsgSelectorQueueTests theTests = new MsgSelectorQueueTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * The beginning of the test creates receiver and message. This is broken
- * apart from the rest of the test so that the user can specify message
- * properties before sending the message.
- */
- private void startTest(String selector, String headerValue) throws Exception {
- logTrace("startTest(): Creating receiver with message selector");
-
- tempQ = session.createTemporaryQueue();
- qReceiver = session.createReceiver(tempQ, selector);
-
- logTrace("Creating message");
- msg = session.createMessage();
- msg.setStringProperty("COM_SUN_JMS_TESTNAME", "MsgSelectorQueueTests");
- msg.setJMSType(headerValue);
- }
-
- /*
- * Send the message and try to receive it. Check the result against the
- * expectation.
- */
- private void finishTestReceive() throws Exception {
- logTrace("finishTestReceive(): Sending test message");
- msg.setBooleanProperty("first_message", true);
- qSender = session.createSender(tempQ);
-
- qSender.send(msg);
- logTrace("Attempt to receive message");
- Message msg1 = qReceiver.receive(jms_timeout);
- logTrace("Received message: " + msg1);
-
- // check result
- if (msg1 == null) {
- throw new Exception("Did not receive message!");
- } else if (msg1.getBooleanProperty("first_message") == true) {
- logTrace("test passed");
- } else {
- logMsg("Received completely unexpected message.");
- throw new Exception("Received unexpected message -- not part of test");
- }
- }
-
- /*
- * Send the message. Used with finishTest() to send a second message and make
- * sure that the first is not received my the message consumer.
- */
- private void sendFirstMessage() throws JMSException {
- logTrace(
- "sendFirstMessage(): Sending message that does not match selector");
- msg.setBooleanProperty("second_message", false);
- // ii
- qSender = session.createSender(tempQ);
- qSender.send(msg);
-
- msg = session.createMessage();
- msg.setStringProperty("COM_SUN_JMS_TESTNAME", "MsgSelectorQueueTests_2");
- }
-
- /*
- * Send the second message which does match the selector. Receive() and verify
- * that only this second message is received.
- */
- private void finishTest() throws Exception {
- TestUtil.logTrace("time_out is " + jms_timeout);
- logTrace("finishTest: Sending message that should match selector");
- msg.setBooleanProperty("second_message", true);
- qSender = session.createSender(tempQ);
- qSender.send(msg);
-
- logTrace("Attempt to receive message. Should receive second message only.");
- Message msg1 = qReceiver.receive(jms_timeout);
- logTrace("Received message: " + msg1);
-
- // check result
- if (msg1 == null) {
- throw new Exception("Did not receive message!");
- } else if (msg1.getBooleanProperty("second_message") == true) {
- logTrace("test passed");
- } else if (msg1.getBooleanProperty("second_message") == false) {
- throw new Exception("Incorrectly received non-matching message!");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Individual tests create a temporary Queue
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- props = p;
- jms_timeout = Long.parseLong(props.getProperty("jms_timeout"));
- // check props for errors
- if (jms_timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- jmsUser = props.getProperty("user");
- jmsPassword = props.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- JmsTool tool = new JmsTool(JmsTool.QUEUE_FACTORY, jmsUser, jmsPassword,
- mode);
- qFactory = tool.getQueueConnectionFactory();
- qConnect = qFactory.createQueueConnection(jmsUser, jmsPassword);
- qConnect.start();
-
- session = qConnect.createQueueSession(transacted,
- Session.AUTO_ACKNOWLEDGE);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- logTrace(" closing connection");
- qConnect.close();
- tempQ = null;
- session.close();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: selectorTest01
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:39;
- *
- * @test_Strategy: create receiver with selector set msg header to include
- * string send message check receipt of message
- */
- public void selectorTest01() throws Exception {
- try {
- String selector = "JMSType='literal'";
- String value = "literal"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: selectorTest02
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:39;
- *
- * @test_Strategy: create receiver with selector set msg header to include '
- * character send message check receipt of message
- */
- public void selectorTest02() throws Exception {
- try {
- String selector = "JMSType='literal''s'";
- String value = "literal's"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: selectorTest03
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:63; JMS:SPEC:55; JMS:SPEC:49;
- * JMS:SPEC:40;
- *
- * @test_Strategy: create receiver with selector set msg properties to include
- * values at ends of long range send message check receipt of message
- */
- public void selectorTest03() throws Exception {
- try {
- String selector = "myProp0=" + Long.MIN_VALUE + "L AND myProp1="
- + Long.MAX_VALUE + "L";
- String value = ""; // set for JMSType automatically
- TestUtil.logTrace(selector);
-
- startTest(selector, value);
- msg.setLongProperty("myProp0", Long.MIN_VALUE);
- msg.setLongProperty("myProp1", Long.MAX_VALUE);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: selectorTest04
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:63; JMS:SPEC:55; JMS:SPEC:56;
- * JMS:SPEC:49; JMS:SPEC:40;
- *
- * @test_Strategy: create receiver with selector set msg properties to include
- * numeric value send message check receipt of message
- */
- public void selectorTest04() throws Exception {
- try {
- String selector = "myProp0=-957 AND myProp1=+62";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setLongProperty("myProp0", -957);
- msg.setLongProperty("myProp1", 62);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: selectorTest05
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:40;
- *
- * @test_Strategy: create receiver with selector containing octal set msg
- * properties to include numeric value send message check receipt of message
- */
- public void selectorTest05() throws Exception {
- try {
- String selector = "myProp=035"; // 29 in octal is 035
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setLongProperty("myProp", 29);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: selectorTest06
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:40;
- *
- * @test_Strategy: create receiver with selector containing hexadecimal set
- * msg properties to include numeric value send message check receipt of
- * message
- */
- public void selectorTest06() throws Exception {
- try {
- String selector = "myProp=0x1d";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setLongProperty("myProp", 29); // 29 in hex is 0x1d
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: selectorTest07
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:56; JMS:SPEC:49;
- * JMS:SPEC:41;
- *
- * @test_Strategy: create receiver with selector set msg properties to include
- * numeric value send message check receipt of message
- */
- public void selectorTest07() throws Exception {
- try {
- String selector = "myProp0=7E3 AND myProp1=-57.9E3";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setDoubleProperty("myProp0", 7000.0);
- msg.setDoubleProperty("myProp1", -57900.0);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: selectorTest08
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:41;
- *
- * @test_Strategy: create receiver with selector set msg properties to include
- * numeric value send message check receipt of message
- */
- public void selectorTest08() throws Exception {
- try {
- String selector = "myProp=7000.";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setDoubleProperty("myProp", 7000.0);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: selectorTest09
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:41;
- *
- * @test_Strategy: create receiver with selector set msg properties to include
- * numeric value send message check receipt of message
- */
- public void selectorTest09() throws Exception {
- try {
- String selector = "myProp0=.7e4";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setDoubleProperty("myProp0", 7000.0);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: selectorTest11
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:56; JMS:SPEC:49;
- * JMS:SPEC:42;
- *
- * @test_Strategy: create receiver with selector send message with header
- * including TRUE/FALSE check receipt of message
- */
- public void selectorTest11() throws Exception {
- try {
- String selector = "myProp0=TRUE AND myProp1=FALSE";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myProp0", true);
- msg.setBooleanProperty("myProp1", false);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: selectorTest12
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:42;
- *
- * @test_Strategy: create receiver with selector send message with header
- * including TRUE/FALSE check receipt of message
- */
- public void selectorTest12() throws Exception {
- try {
- String selector = "myProp0=false AND myProp1=true";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myProp0", false);
- msg.setBooleanProperty("myProp1", true);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest01
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:43;
- *
- * @test_Strategy: create receiver with selector send message with identifiers
- * including '_' and '$' check receipt of message
- */
- public void identifierTest01() throws Exception {
- try {
- String selector = "$myProp=TRUE AND _myProp=FALSE";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("$myProp", true);
- msg.setBooleanProperty("_myProp", false);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest02
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:44;
- * JMS:SPEC:175;
- *
- * @test_Strategy: create receiver with selector containing 'NULL' check for
- * proper exception
- */
- public void identifierTest02() throws Exception {
- try {
- String selector = "NULL = 0";
- String value = "";
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest03
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:44; JMS:SPEC:175;
- *
- * @test_Strategy: create receiver with selector containing 'TRUE' check for
- * proper exception
- */
- public void identifierTest03() throws Exception {
- try {
- String selector = "TRUE = 0";
- String value = "";
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest04
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:44; JMS:SPEC:175;
- *
- * @test_Strategy: create receiver with selector containing 'FALSE' check for
- * proper exception
- */
- public void identifierTest04() throws Exception {
- try {
- String selector = "FALSE = 0";
- String value = "";
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest05
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45; JMS:SPEC:175;
- *
- * @test_Strategy: create receiver with selector containing 'NOT' check for
- * proper exception
- */
- public void identifierTest05() throws Exception {
- try {
- String selector = "NOT = 0";
- String value = "";
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest06
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
- *
- * @test_Strategy: create receiver with selector containing 'AND' check for
- * proper exception
- */
- public void identifierTest06() throws Exception {
- try {
- String selector = "AND = 0";
- String value = "";
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest07
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
- *
- * @test_Strategy: create receiver with selector containing 'OR' check for
- * proper exception
- */
- public void identifierTest07() throws Exception {
- try {
- String selector = "OR = 0";
- String value = "";
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest08
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
- *
- * @test_Strategy: create receiver with selector containing 'BETWEEN' check
- * for proper exception
- */
- public void identifierTest08() throws Exception {
- try {
- String selector = "BETWEEN = 0";
- String value = "";
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest09
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
- *
- * @test_Strategy: create receiver with selector containing 'LIKE' check for
- * proper exception
- */
- public void identifierTest09() throws Exception {
- try {
- String selector = "LIKE = 0";
- String value = "";
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest10
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
- *
- * @test_Strategy: create receiver with selector containing 'IN' check for
- * proper exception
- */
- public void identifierTest10() throws Exception {
- try {
- String selector = "IN = 0";
- String value = "";
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest11
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
- *
- * @test_Strategy: create receiver with selector containing 'IS' check for
- * proper exception
- */
- public void identifierTest11() throws Exception {
- try {
- String selector = "IS = 0";
- String value = "";
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest12
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:48;
- *
- * @test_Strategy: create receiver with selector set two msg properties with
- * names differing in case send message check receipt of message
- */
- public void identifierTest12() throws Exception {
- try {
- String selector = "myProp=TRUE AND MYpROP=FALSE";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myProp", true);
- msg.setBooleanProperty("MYpROP", false);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest13
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:46;
- *
- * @test_Strategy: create receiver with selector send message check that
- * message is not received
- */
- public void identifierTest13() throws Exception {
- try {
- String selector = "myProp ='foo'";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setStringProperty("myProp", "foo");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest14
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
- *
- * @test_Strategy: create receiver with selector containing 'ESCAPE' check for
- * proper exception
- */
- public void identifierTest14() throws Exception {
- try {
- String selector = "ESCAPE = 0";
- String value = "";
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: whitespaceTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:53;
- *
- * @test_Strategy: create receiver with selector containing extra spaces send
- * message with header set check receipt of message
- */
- public void whitespaceTest1() throws Exception {
- try {
- String selector = "JMSType = 'foo'";
- String value = "foo"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: whitespaceTest2
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:53;
- *
- * @test_Strategy: create receiver with selector containing tabs send message
- * with header set check receipt of message
- */
- public void whitespaceTest2() throws Exception {
- try {
- String selector = "JMSType\t=\t'foo'";
- String value = "foo"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: whitespaceTest3
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:53;
- *
- * @test_Strategy: create receiver with selector containing form feeds send
- * message with header set check receipt of message
- */
- public void whitespaceTest3() throws Exception {
- try {
- String selector = "JMSType\f=\f'foo'";
- String value = "foo"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: whitespaceTest4
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:53;
- *
- * @test_Strategy: create receiver with selector containing line terminators
- * send message with header set check receipt of message
- */
- public void whitespaceTest4() throws Exception {
- try {
- String selector = "JMSType\n= \n'foo'";
- String value = "foo"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: expressionTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:54;
- *
- * @test_Strategy: create receiver with selector send message with TRUE
- * boolean property check receipt of message
- */
- public void expressionTest1() throws Exception {
- try {
- String selector = "myProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myProp", true);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: expressionTest2
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:54;
- *
- * @test_Strategy: create receiver with selector send message with FALSE
- * boolean property check that message is not received
- */
- public void expressionTest2() throws Exception {
- try {
- String selector = "myProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myProp", false);
- sendFirstMessage();
- msg.setBooleanProperty("myProp", true);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: expressionTest3
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:54;
- *
- * @test_Strategy: create receiver with selector referenceing null property
- * send message check that message is not received
- */
- public void expressionTest3() throws Exception {
- try {
- String selector = "myNullProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setBooleanProperty("myNullProp", true);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: bracketingTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:57;
- *
- * @test_Strategy: create receiver with selector that should evaluate to FALSE
- * send message check that message is not received
- */
- public void bracketingTest1() throws Exception {
- try {
- String selector = "(myTrueProp OR myFalseProp) AND myFalseProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myTrueProp", true);
- msg.setBooleanProperty("myFalseProp", false);
- sendFirstMessage();
- msg.setBooleanProperty("myTrueProp", true);
- msg.setBooleanProperty("myFalseProp", true);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: bracketingTest2
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:57;
- *
- * @test_Strategy: create receiver with selector that should evaluate to TRUE
- * send message check receipt of message
- */
- public void bracketingTest2() throws Exception {
- try {
- String selector = "TRUE OR (FALSE AND FALSE)";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: bracketingTest3
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:57;
- *
- * @test_Strategy: create receiver with selector that should evaluate to FALSE
- * send message check that message is not received
- */
- public void bracketingTest3() throws Exception {
- try {
- String selector = "(myProp0 = true OR myProp1 = true) AND JMSType = 'not_foo'";
- String value = "foo"; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myProp0", true);
- msg.setBooleanProperty("myProp1", false);
- sendFirstMessage();
- msg.setJMSType("not_foo");
- msg.setBooleanProperty("myProp0", true);
- msg.setBooleanProperty("myProp1", false);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: bracketingTest4
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:57;
- *
- * @test_Strategy: create receiver with selector that should evaluate to TRUE
- * send message check receipt of message
- */
- public void bracketingTest4() throws Exception {
- try {
- String selector = "(myProp1 = true AND JMSType = 'not_foo') OR myProp0 = true";
- String value = "foo"; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myProp0", true);
- msg.setBooleanProperty("myProp1", false);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest01
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:59;
- *
- * @test_Strategy: create receiver with selector containing operators send
- * message with properties matching selector check receipt of message
- */
- public void comparisonTest01() throws Exception {
- try {
- String selector = "myProp0 = 'foo' AND " + "myProp1 > 0 AND "
- + "myProp2 >= 2 AND " + "myProp3 >= 2 AND " + "myProp4 < 5 AND "
- + "myProp5 <= 6 AND " + "myProp6 <= 6 AND " + "myProp7 <> 7";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp0", "foo");
- msg.setIntProperty("myProp1", 1);
- msg.setFloatProperty("myProp2", 2.0f);
- msg.setIntProperty("myProp3", 3);
- msg.setDoubleProperty("myProp4", 4.0);
- msg.setIntProperty("myProp5", 5);
- msg.setIntProperty("myProp6", 6);
- msg.setFloatProperty("myProp7", 0f);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest02
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:59;
- *
- * @test_Strategy: create receiver with selector containing operators send
- * message with properties not matching selector check that message is not
- * received
- */
- public void comparisonTest02() throws Exception {
- try {
- String selector = "myProp0 = 'foo' OR " + "myProp1 > 0 OR "
- + "myProp2 >= 2 OR " + "myProp3 < 5 OR " + "myProp4 <= 6 OR "
- + "myProp5 <> 7";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp0", "not_foo");
- msg.setIntProperty("myProp1", 0);
- msg.setFloatProperty("myProp2", 1.5f);
- msg.setDoubleProperty("myProp3", 5.0);
- msg.setIntProperty("myProp4", 7);
- msg.setFloatProperty("myProp5", 7f);
- sendFirstMessage();
- msg.setStringProperty("myProp0", "foo");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest03
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:60;
- *
- * @test_Strategy: create receiver with selector send message with exact and
- * approximate numeric values check receipt of message
- */
- public void comparisonTest03() throws Exception {
- try {
- String selector = "myProp0 < myProp1";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setIntProperty("myProp0", 0);
- msg.setDoubleProperty("myProp1", 1.5);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest04
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:61;
- *
- * @test_Strategy: create receiver with selector containing > and string
- * should throw InvalidSelectorException
- */
- public void comparisonTest04() throws Exception {
- try {
- String selector = "myProp > 'foo'";
- String value = "";
-
- startTest(selector, value);
-
- // did not get exception
- throw new Exception(
- "Did not receive InvalidSelectorException " + "as expected.");
- } catch (InvalidSelectorException ise) {
- logTrace("Test passed. Received expected exception.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest05
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
- *
- * @test_Strategy: create receiver with selector containing >= and string
- * should throw InvalidSelectorException
- */
- public void comparisonTest05() throws Exception {
- try {
- String selector = "myProp >= 'foo'";
- String value = "";
-
- startTest(selector, value);
-
- // did not get exception
- throw new Exception(
- "Did not receive InvalidSelectorException " + "as expected.");
- } catch (InvalidSelectorException ise) {
- logTrace("Test passed. Received expected exception.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest06
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
- *
- * @test_Strategy: create receiver with selector containing < and string
- * should throw InvalidSelectorException
- */
- public void comparisonTest06() throws Exception {
- try {
- String selector = "myProp < 'foo'";
- String value = "";
-
- startTest(selector, value);
-
- // did not get exception
- throw new Exception(
- "Did not receive InvalidSelectorException " + "as expected.");
- } catch (InvalidSelectorException ise) {
- logTrace("Test passed. Received expected exception.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest07
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
- *
- * @test_Strategy: create receiver with selector containing <= and string
- * should throw InvalidSelectorException
- */
- public void comparisonTest07() throws Exception {
- try {
- String selector = "myProp <= 'foo'";
- String value = "";
-
- startTest(selector, value);
-
- // did not get exception
- throw new Exception(
- "Did not receive InvalidSelectorException " + "as expected.");
- } catch (InvalidSelectorException ise) {
- logTrace("Test passed. Received expected exception.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest08
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
- *
- * @test_Strategy: create receiver with valid selector send matching message
- * check for receipt of message
- */
- public void comparisonTest08() throws Exception {
- try {
- String selector = "JMSType = 'foo' AND myProp <> 'not_foo'";
- String value = "foo";
-
- startTest(selector, value);
- msg.setStringProperty("myProp", "foo");
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest09
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
- *
- * @test_Strategy: create receiver with selector comparing TRUE with > should
- * throw InvalidSelectorException
- */
- public void comparisonTest09() throws Exception {
- try {
- String selector = "'foo' > TRUE ";
- String value = "";
-
- startTest(selector, value);
-
- // did not get exception
- throw new Exception(
- "Did not receive InvalidSelectorException " + "as expected.");
- } catch (InvalidSelectorException ise) {
- logTrace("Test passed. Received expected exception.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest10
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
- *
- * @test_Strategy: create receiver with selector comparing TRUE with >= should
- * throw InvalidSelectorException
- */
- public void comparisonTest10() throws Exception {
- try {
- String selector = "'foo' >= TRUE ";
- String value = "";
-
- startTest(selector, value);
-
- // did not get exception
- throw new Exception(
- "Did not receive InvalidSelectorException " + "as expected.");
- } catch (InvalidSelectorException ise) {
- logTrace("Test passed. Received expected exception.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest11
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
- *
- * @test_Strategy: create receiver with selector comparing TRUE with < should
- * throw InvalidSelectorException
- */
- public void comparisonTest11() throws Exception {
- try {
- String selector = "'foo' < TRUE ";
- String value = "";
-
- startTest(selector, value);
-
- // did not get exception
- throw new Exception(
- "Did not receive InvalidSelectorException " + "as expected.");
- } catch (InvalidSelectorException ise) {
- logTrace("Test passed. Received expected exception.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest12
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
- *
- * @test_Strategy: create receiver with selector comparing TRUE with <= should
- * throw InvalidSelectorException
- */
- public void comparisonTest12() throws Exception {
- try {
- String selector = "'foo' <= TRUE ";
- String value = "";
-
- startTest(selector, value);
-
- // did not get exception
- throw new Exception(
- "Did not receive InvalidSelectorException " + "as expected.");
- } catch (InvalidSelectorException ise) {
- logTrace("Test passed. Received expected exception.");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest13
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:61;
- *
- * @test_Strategy: create receiver with valid selector send matching message
- * check for receipt of message
- */
- public void comparisonTest13() throws Exception {
- try {
- String selector = "myProp0 = TRUE AND myProp1 <> FALSE";
- String value = "";
-
- startTest(selector, value);
- msg.setBooleanProperty("myProp0", true);
- msg.setBooleanProperty("myProp1", true);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: operatorTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:62;
- *
- * @test_Strategy: create receiver with selector containing +,- send message
- * with numeric properties check receipt of message
- */
- public void operatorTest1() throws Exception {
- try {
- String selector = "-myProp0 < 0 AND +myProp1 < 0";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setIntProperty("myProp0", 5);
- msg.setIntProperty("myProp1", -5);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: operatorTest2
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:62;
- *
- * @test_Strategy: create receiver with selector containing *,/ send message
- * with numeric properties check receipt of message
- */
- public void operatorTest2() throws Exception {
- try {
- String selector = "myProp0*2 = 10 AND myProp1/2 = -5";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setIntProperty("myProp0", 5);
- msg.setIntProperty("myProp1", -10);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: operatorTest3
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:62;
- *
- * @test_Strategy: create receiver with selector containing +,- send message
- * with numeric properties check receipt of message
- */
- public void operatorTest3() throws Exception {
- try {
- String selector = "myProp0+5 = 0 AND myProp1-5 = 5";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setIntProperty("myProp0", -5);
- msg.setIntProperty("myProp1", 10);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: betweenTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
- *
- * @test_Strategy: create receiver with selector containing BETWEEN send
- * message matching selector check receipt of message
- */
- public void betweenTest1() throws Exception {
- try {
- String selector = "myProp0 BETWEEN 5 and 10 AND "
- + "myProp1 BETWEEN -1 and 1 AND " + "myProp2 BETWEEN 0 and 2";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setIntProperty("myProp0", 7);
- msg.setIntProperty("myProp1", -1);
- msg.setIntProperty("myProp2", 2);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: betweenTest2
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
- *
- * @test_Strategy: create receiver with selector containing BETWEEN send
- * message not matching selector check that message is not received
- */
- public void betweenTest2() throws Exception {
- try {
- String selector = "myProp0 BETWEEN -4 and 5 OR "
- + "myProp1 BETWEEN -5 and 4";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setIntProperty("myProp0", -5);
- msg.setIntProperty("myProp1", 5);
- sendFirstMessage();
- msg.setIntProperty("myProp0", 0);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: betweenTest3
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
- *
- * @test_Strategy: create receiver with selector containing NOT BETWEEN send
- * message matching selector check receipt of message
- */
- public void betweenTest3() throws Exception {
- try {
- String selector = "myProp0 NOT BETWEEN -4 and 5 AND "
- + "myProp1 NOT BETWEEN -5 and 4";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setIntProperty("myProp0", -5);
- msg.setIntProperty("myProp1", 5);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: betweenTest4
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
- *
- * @test_Strategy: create receiver with selector containing NOT BETWEEN send
- * message not matching selector check that message is not received
- */
- public void betweenTest4() throws Exception {
- try {
- String selector = "myProp0 NOT BETWEEN 5 and 10 OR "
- + "myProp1 NOT BETWEEN -1 and 1 OR " + "myProp2 NOT BETWEEN 0 and 2";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setIntProperty("myProp0", 7);
- msg.setIntProperty("myProp1", -1);
- msg.setIntProperty("myProp2", 2);
- sendFirstMessage();
- msg.setIntProperty("myProp0", 0);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: betweenTest5
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
- *
- * @test_Strategy: create receiver with selector containing BETWEEN send
- * message with property that is not arithmetic check that message is not
- * received
- */
- public void betweenTest5() throws Exception {
- try {
- String selector = "myProp BETWEEN 5 and 10";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
-
- // not a number. should not be received
- msg.setStringProperty("myProp", "7");
- sendFirstMessage();
- msg.setIntProperty("myProp", 7);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: betweenTest6
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
- *
- * @test_Strategy: create receiver with selector containing BETWEEN send
- * message with property that is not arithmetic check that message is not
- * received
- */
- public void betweenTest6() throws Exception {
- try {
- String selector = "myProp BETWEEN 5 and 10";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
-
- // not number, so message shouldn't be received
- msg.setStringProperty("myProp", "seven");
- sendFirstMessage();
- msg.setIntProperty("myProp", 7);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: betweenTest7
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
- *
- * @test_Strategy: create receiver with syntactically incorrect selector check
- * for proper excepion
- */
- public void betweenTest7() throws Exception {
- try {
- String selector = "myProp BETWEEN 'foo' and 'test'";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: inTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
- *
- * @test_Strategy: create receiver with selector containing IN send message
- * matching selector check receipt of message
- */
- public void inTest1() throws Exception {
- try {
- String selector = "JMSType IN ('foo','jms','test')";
- String value = "jms"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: inTest2
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
- *
- * @test_Strategy: create receiver with selector containing IN send message
- * not matching selector check that message is not received
- */
- public void inTest2() throws Exception {
- try {
- String selector = "JMSType IN ('foo','jms','test')";
- String value = "JMS"; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setJMSType("jms");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: inTest3
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
- *
- * @test_Strategy: create receiver with selector containing NOT IT send
- * message matching selector check receipt of message
- */
- public void inTest3() throws Exception {
- try {
- String selector = "JMSType NOT IN ('foo','jms','test')";
- String value = "FOO"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: inTest4
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
- *
- * @test_Strategy: create receiver with selector containing NOT IN send
- * message not matching selector check that message is not received
- */
- public void inTest4() throws Exception {
- try {
- String selector = "JMSType NOT IN ('foo','jms','test')";
- String value = "foo"; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setJMSType("FOO");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: inTest5
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
- *
- * @test_Strategy: create receiver with selector containing IN msg selector
- * references an unknown property send message check that message is not
- * received
- */
- public void inTest5() throws Exception {
- try {
- String selector = "myNullProp IN ('foo','jms','test')";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setStringProperty("myNullProp", "jms");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: inTest6
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
- *
- * @test_Strategy: create receiver with selector containing NOT IN msg
- * selector references an unknown property send message check that message is
- * not received
- */
- public void inTest6() throws Exception {
- try {
- String selector = "myNullProp NOT IN ('foo','jms','test')";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setStringProperty("myNullProp", "JMS");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: inTest7
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
- *
- * @test_Strategy: create receiver with selector containing NOT IN set msg
- * property of integer type send message check that message is not received
- */
- public void inTest7() throws Exception {
- try {
- String selector = "myProp NOT IN ('foo','jms','test')";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
-
- // property is not a string
- msg.setIntProperty("myProp", 0);
- sendFirstMessage();
- msg.setStringProperty("myProp", "zero");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: inTest8
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
- *
- * @test_Strategy: create receiver with syntactically incorrect selector check
- * for proper exception
- */
- public void inTest8() throws Exception {
- try {
- String selector = "myProp NOT IN (1,2,3)";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest01
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector containing LIKE send
- * message matching selector check receipt of message
- */
- public void likeTest01() throws Exception {
- try {
- String selector = "JMSType LIKE 'jms'";
- String value = "jms"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest02
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains
- * LIKE statement using '_' send message matching selector check receipt of
- * message
- */
- public void likeTest02() throws Exception {
- try {
- String selector = "JMSType LIKE 's_lector' AND "
- + "myProp0 LIKE '_bcd' AND " + "myProp1 LIKE '123_'";
- String value = "selector"; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp0", "abcd");
- msg.setStringProperty("myProp1", "1234");
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest03
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains
- * LIKE statement using '%' send message matching selector check receipt of
- * message
- */
- public void likeTest03() throws Exception {
- try {
- String selector = "JMSType LIKE 's%tor' AND " + "myProp0 LIKE '%cd' AND "
- + "myProp1 LIKE '1%' AND " + "myProp2 LIKE 'AB%CD' AND "
- + "myProp3 LIKE '%'";
- String value = "selector"; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp0", "abcd");
- msg.setStringProperty("myProp1", "1234");
- msg.setStringProperty("myProp2", "ABCD");
- msg.setStringProperty("myProp3", "foo");
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest04
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains
- * LIKE statement using ESCAPE character send message matching selector check
- * receipt of message
- */
- public void likeTest04() throws Exception {
- try {
- String selector = "JMSType LIKE 'A_fo_A%f%' " + "ESCAPE 'A'";
- String value = "_foo%foo"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest05
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector containing LIKE send
- * message not matching selector check that message is not received
- */
- public void likeTest05() throws Exception {
- try {
- String selector = "JMSType LIKE '123' OR " + "myProp LIKE 'jms0'";
- String value = "1234"; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp", "jms");
- sendFirstMessage();
- msg.setStringProperty("myProp", "jms0");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest06
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains
- * LIKE statement using '_' send message not matching selector check that
- * message is not received
- */
- public void likeTest06() throws Exception {
- try {
- String selector = "JMSType LIKE 'se_ector' OR " + "myProp0 LIKE '_cd' OR "
- + "myProp1 LIKE '12_'";
- String value = "seleector"; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp0", "abcd");
- msg.setStringProperty("myProp1", "1234");
- sendFirstMessage();
- msg.setJMSType("selector");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest07
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains
- * LIKE statement using '%' send message not matching selector check that
- * message is not received
- */
- public void likeTest07() throws Exception {
- try {
- String selector = "JMSType LIKE '12%3'";
- String value = "1234";
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setJMSType("12333");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest08
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains
- * LIKE statement using ESCAPE character send message not matching selector
- * check that message is not received
- */
- public void likeTest08() throws Exception {
- try {
- String selector = "JMSType LIKE 'A%fooA_' " + "ESCAPE 'A'";
- String value = "_foo%"; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setJMSType("%foo_");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest09
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector containing NOT LIKE
- * send message matching selector check receipt of message
- */
- public void likeTest09() throws Exception {
- try {
- String selector = "JMSType NOT LIKE 'jms_foo'";
- String value = "jms"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest10
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains NOT
- * LIKE statement using '_' send message matching selector check receipt of
- * message
- */
- public void likeTest10() throws Exception {
- try {
- String selector = "JMSType NOT LIKE 's_ector' AND "
- + "myProp0 NOT LIKE '_cd' AND " + "myProp1 NOT LIKE '12_'";
- String value = "selector"; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp0", "abcd");
- msg.setStringProperty("myProp1", "1234");
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest11
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains NOT
- * LIKE statement using '%' send message matching selector check receipt of
- * message
- */
- public void likeTest11() throws Exception {
- try {
- String selector = "myProp0 NOT LIKE '%cde' AND "
- + "myProp1 NOT LIKE '01%' AND " + "myProp2 NOT LIKE 'A%x%D'";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp0", "abcd");
- msg.setStringProperty("myProp1", "1234");
- msg.setStringProperty("myProp2", "ABCD");
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest12
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains NOT
- * LIKE statement using ESCAPE character send message matching selector check
- * receipt of message
- */
- public void likeTest12() throws Exception {
- try {
- String selector = "JMSType NOT LIKE 'A_A_' " + "ESCAPE 'A'";
- String value = "_A"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest13
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector containing NOT LIKE
- * send message not matching selector check that message is not received
- */
- public void likeTest13() throws Exception {
- try {
- String selector = "JMSType NOT LIKE '1234' OR " + "myProp NOT LIKE 'jms'";
- String value = "1234"; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp", "jms");
- sendFirstMessage();
- msg.setJMSType("foo");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest14
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains NOT
- * LIKE statement using '_' send message not matching selector check that
- * message is not received
- */
- public void likeTest14() throws Exception {
- try {
- String selector = "JMSType NOT LIKE 'se_ector' OR "
- + "myProp0 NOT LIKE '_bcd' OR " + "myProp1 NOT LIKE '123_'";
- String value = "selector"; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp0", "abcd");
- msg.setStringProperty("myProp1", "1234");
- sendFirstMessage();
- msg.setJMSType("foo");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest15
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains NOT
- * LIKE statement using '%' send message not matching selector check that
- * message is not received
- */
- public void likeTest15() throws Exception {
- try {
- String selector = "JMSType NOT LIKE '12%'";
- String value = "1234";
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setJMSType("foo");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest16
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains NOT
- * LIKE statement using ESCAPE character send message not matching selector
- * check that message is not received
- */
- public void likeTest16() throws Exception {
- try {
- String selector = "JMSType NOT LIKE 'A_fooA%' " + "ESCAPE 'A'";
- String value = "_foo%"; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setJMSType("jms");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest17
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector selector contains NOT
- * LIKE statement using ESCAPE character '\' send message not matching
- * selector check receipt of message
- */
- public void likeTest17() throws Exception {
- try {
- String selector = "JMSType LIKE '\\__\\%%' ESCAPE '\\'";
- String value = "_a%b"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest18
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:60; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector using LIKE selector
- * references unknown property send message check that message is not received
- */
- public void likeTest18() throws Exception {
- try {
- String selector = "myNullProp LIKE '1_3'";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setStringProperty("myNullProp", "123");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest19
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:60; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector using NOT LIKE
- * selector references unknown property send message check that message is not
- * received
- */
- public void likeTest19() throws Exception {
- try {
- String selector = "myNullProp NOT LIKE '1_3'";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setStringProperty("myNullProp", "foo");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest20
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector using LIKE send
- * message with non-string property check that message is not received
- */
- public void likeTest20() throws Exception {
- try {
- String selector = "myProp LIKE '1_3'";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
-
- // not a string
- msg.setIntProperty("myProp", 123);
- sendFirstMessage();
- msg.setStringProperty("myProp", "123");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest21
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with invalid selector check for proper
- * exception
- */
- public void likeTest21() throws Exception {
- try {
- String selector = "myProp LIKE 7";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
-
- // should have received exception
- throw new Exception("Did not receive InvalidSelectorException");
- } catch (InvalidSelectorException ise) {
- logTrace("Caught expected exception");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: isNullTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:67;
- *
- * @test_Strategy: create receiver with message selector containing IS NULL
- * selector references unknown property send message check receipt of message
- */
- public void isNullTest1() throws Exception {
- try {
- String selector = "myNullProp IS NULL";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: isNullTest2
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:67;
- *
- * @test_Strategy: create receiver with message selector containing IS NULL
- * selector references existing property send message check that message is
- * not received
- */
- public void isNullTest2() throws Exception {
- try {
- String selector = "myProp IS NULL";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp", "foo");
- sendFirstMessage();
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: isNullTest3
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:68;
- *
- * @test_Strategy: create receiver with message selector containing IS NOT
- * NULL selector references existing property send message check receipt of
- * message
- */
- public void isNullTest3() throws Exception {
- try {
- String selector = "myProp IS NOT NULL";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setFloatProperty("myProp", 10f);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: isNullTest4
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:68;
- *
- * @test_Strategy: create receiver with message selector containing IS NOT
- * NULL selector references unknown property send message check that message
- * is not received
- */
- public void isNullTest4() throws Exception {
- try {
- String selector = "myNullProp IS NOT NULL";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setStringProperty("myNullProp", "foo");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: caseTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:247;
- *
- * @test_Strategy: create receiver with message selector selector contains
- * lower case versions of selector operators send message matching selector
- * check receipt of message
- */
- public void caseTest1() throws Exception {
- try {
- String selector = "myProp0 is null and "
- + "myProp1 like 'fooG_%' escape 'G' and "
- + "myProp2 in ('a', 'b') and " + "myProp3 not between 0 and 10 and "
- + "(myProp4 or false)";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp1", "foo_test");
- msg.setStringProperty("myProp2", "a");
- msg.setIntProperty("myProp3", 20);
- msg.setBooleanProperty("myProp4", true);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: precedenceTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:58;
- *
- * @test_Strategy: create receiver with message selector containing AND and OR
- * send message not matching selector check that message is not received !F&F
- * = (!F)&F = T&F = F incorrect order would be !F&F -> !(F&F) = !F = T
- */
- public void precedenceTest1() throws Exception {
- try {
- String selector = "NOT myTrueProp AND myFalseProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myTrueProp", true);
- msg.setBooleanProperty("myFalseProp", false);
- sendFirstMessage();
- msg.setBooleanProperty("myTrueProp", false);
- msg.setBooleanProperty("myFalseProp", true);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: precedenceTest2
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:58;
- *
- * @test_Strategy: create receiver with message selector containing AND and
- * NOT send message matching selector check receipt of message
- */
- public void precedenceTest2() throws Exception {
- try {
- String selector = "myTrueProp AND NOT myFalseProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myTrueProp", true);
- msg.setBooleanProperty("myFalseProp", false);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: precedenceTest3
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:58;
- *
- * @test_Strategy: create receiver with message selector containing AND and OR
- * send message matching selector check receipt of message TvT&F = Tv(T&F) =
- * TvF = T incorrect order would be TvT&F -> (TvT)&F = T&F = F
- */
- public void precedenceTest3() throws Exception {
- try {
- String selector = "myTrueProp OR myTrueProp AND myFalseProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myTrueProp", true);
- msg.setBooleanProperty("myFalseProp", false);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: precedenceTest4
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:62;
- *
- * @test_Strategy: create receiver with message selector send message check
- * receipt of message
- */
- public void precedenceTest4() throws Exception {
- try {
- String selector = "- myProp0 + myProp1 = 0";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setIntProperty("myProp0", 5);
- msg.setIntProperty("myProp1", 5);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: precedenceTest5
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:62;
- *
- * @test_Strategy: create receiver with message selector send message matching
- * selector check receipt of message
- */
- public void precedenceTest5() throws Exception {
- try {
- String selector = "myProp0+myProp1*myProp2-myProp3/myProp4 = 6";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setFloatProperty("myProp0", 1f);
- msg.setFloatProperty("myProp1", 2f);
- msg.setFloatProperty("myProp2", 3f);
- msg.setFloatProperty("myProp3", 4f);
- msg.setFloatProperty("myProp4", 4f);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest01
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:60;
- *
- * @test_Strategy: create receiver with selector referencing unknown property
- * send message check that message is not received
- */
- public void nullTest01() throws Exception {
- try {
- String selector = "myProp + 2 < 10";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setIntProperty("myProp", 0);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest02
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:60;
- *
- * @test_Strategy: create receiver with selector referencing unknown property
- * send message check that message is not received
- */
- public void nullTest02() throws Exception {
- try {
- String selector = "myProp = 'foo'";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setStringProperty("myProp", "foo");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest03
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:60;
- *
- * @test_Strategy: create receiver with selector referencing unknown property
- * send message check that message is not received
- */
- public void nullTest03() throws Exception {
- try {
- String selector = "myProp NOT IN ('a', 'b')";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setStringProperty("myProp", "foo");
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest04
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:248.1;
- *
- * @test_Strategy: create receiver with selector containing AND send message
- * matching selector check receipt of message
- */
- public void nullTest04() throws Exception {
- try {
- String selector = "myTrueProp AND myTrueProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myTrueProp", true);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest05
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:248.2; JMS:SPEC:248.3;
- * JMS:SPEC:248.4; JMS:SPEC:248.5; JMS:SPEC:248.6; JMS:SPEC:248.7;
- * JMS:SPEC:248.8; JMS:SPEC:248.9;
- *
- * @test_Strategy: create receiver with selector containing AND each
- * comparison should evaluate to FALSE send message check that message is not
- * received
- */
- public void nullTest05() throws Exception {
- try {
- String selector = "(myTrueProp AND myFalseProp) OR "
- + "(myTrueProp AND myNullProp) OR "
- + "(myFalseProp AND myTrueProp) OR "
- + "(myFalseProp AND myFalseProp) OR "
- + "(myFalseProp AND myNullProp) OR "
- + "(MyNullProp AND myTrueProp) OR "
- + "(MyNullProp AND myFalseProp) OR " + "(MyNullProp AND myNullProp)";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myTrueProp", true);
- msg.setBooleanProperty("myFalseProp", false);
- sendFirstMessage();
- msg.setBooleanProperty("myTrueProp", true);
- msg.setBooleanProperty("myFalseProp", true);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest06
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:249.1; JMS:SPEC:249.2;
- * JMS:SPEC:249.3; JMS:SPEC:249.4; JMS:SPEC:249.7;
- *
- * @test_Strategy: create receiver with selector containing OR each comparison
- * should evaluate to TRUE send message check receipt of message
- */
- public void nullTest06() throws Exception {
- try {
- String selector = "(myTrueProp OR myTrueProp) AND "
- + "(myTrueProp OR myFalseProp) AND "
- + "(myTrueProp OR myNullProp) AND "
- + "(myFalseProp OR myTrueProp) AND " + "(myNullProp OR myTrueProp)";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myTrueProp", true);
- msg.setBooleanProperty("myFalseProp", false);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest07
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:249.5; JMS:SPEC:249.6;
- * JMS:SPEC:249.8; JMS:SPEC:249.9;
- *
- * @test_Strategy: create receiver with selector containing OR each comparison
- * should evaluate to FALSE send message check that message is not received
- */
- public void nullTest07() throws Exception {
- try {
- String selector = "(myFalseProp OR myFalseProp) OR "
- + "(myFalseProp OR myNullProp) OR "
- + "(myNullProp OR myFalseProp) OR " + "(myNullProp OR myNullProp)";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myFalseProp", false);
- sendFirstMessage();
- msg.setBooleanProperty("myFalseProp", true);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest08
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:250.2;
- *
- * @test_Strategy: create receiver with selector containing NOT send message
- * matching selector check receipt of message
- */
- public void nullTest08() throws Exception {
- try {
- String selector = "NOT myFalseProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myFalseProp", false);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest09
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:250.1;
- *
- * @test_Strategy: create receiver with selector containing NOT send message
- * not matching selector check that message is not received
- */
- public void nullTest09() throws Exception {
- try {
- String selector = "NOT myTrueProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myTrueProp", true);
- sendFirstMessage();
- msg.setBooleanProperty("myTrueProp", false);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest10
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:250.3;
- *
- * @test_Strategy: create receiver with selector containing NOT selector
- * references an unknown property send message check receipt of message
- */
- public void nullTest10() throws Exception {
- try {
- String selector = "NOT myNullProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setBooleanProperty("myNullProp", false);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest11
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:37;
- *
- * @test_Strategy: create receiver with null selector. check receipt of
- * message
- */
- public void nullTest11() throws Exception {
- try {
- String selector = null;
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myNullProp", false);
- finishTest();
- } catch (Exception e) {
- throw new Exception("test failed", e);
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/selectorQueue/MsgSelectorQueueTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/selectorQueue/MsgSelectorQueueTestsIT.java
new file mode 100644
index 0000000000..647e64aa51
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/selectorQueue/MsgSelectorQueueTestsIT.java
@@ -0,0 +1,2949 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.selectorQueue;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.InvalidSelectorException;
+import jakarta.jms.JMSException;
+import jakarta.jms.Message;
+import jakarta.jms.QueueConnection;
+import jakarta.jms.QueueConnectionFactory;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueSender;
+import jakarta.jms.QueueSession;
+import jakarta.jms.Session;
+import jakarta.jms.TemporaryQueue;
+
+
+public class MsgSelectorQueueTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.ee.selectorQueue.MsgSelectorQueueTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgSelectorQueueTestsIT.class.getName());
+
+ // JMS objects
+ private transient Message msg = null;
+
+ private transient QueueReceiver qReceiver = null;
+
+ private transient TemporaryQueue tempQ = null;
+
+ private transient QueueSender qSender = null;
+
+ private transient QueueConnection qConnect;
+
+ private transient QueueSession session;
+
+ private transient QueueConnectionFactory qFactory;
+
+ private boolean transacted = false;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ private long jms_timeout;
+
+ private String jmsUser = null;
+
+ private String jmsPassword = null;
+
+ private String mode = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * The beginning of the test creates receiver and message. This is broken apart
+ * from the rest of the test so that the user can specify message properties
+ * before sending the message.
+ */
+ private void startTest(String selector, String headerValue) throws Exception {
+ logger.log(Logger.Level.TRACE, "startTest(): Creating receiver with message selector");
+
+ tempQ = session.createTemporaryQueue();
+ qReceiver = session.createReceiver(tempQ, selector);
+
+ logger.log(Logger.Level.TRACE, "Creating message");
+ msg = session.createMessage();
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "MsgSelectorQueueTests");
+ msg.setJMSType(headerValue);
+ }
+
+ /*
+ * Send the message and try to receive it. Check the result against the
+ * expectation.
+ */
+ private void finishTestReceive() throws Exception {
+ logger.log(Logger.Level.TRACE, "finishTestReceive(): Sending test message");
+ msg.setBooleanProperty("first_message", true);
+ qSender = session.createSender(tempQ);
+
+ qSender.send(msg);
+ logger.log(Logger.Level.TRACE, "Attempt to receive message");
+ Message msg1 = qReceiver.receive(jms_timeout);
+ logger.log(Logger.Level.TRACE, "Received message: " + msg1);
+
+ // check result
+ if (msg1 == null) {
+ throw new Exception("Did not receive message!");
+ } else if (msg1.getBooleanProperty("first_message") == true) {
+ logger.log(Logger.Level.TRACE, "test passed");
+ } else {
+ logger.log(Logger.Level.INFO, "Received completely unexpected message.");
+ throw new Exception("Received unexpected message -- not part of test");
+ }
+ }
+
+ /*
+ * Send the message. Used with finishTest() to send a second message and make
+ * sure that the first is not received my the message consumer.
+ */
+ private void sendFirstMessage() throws JMSException {
+ logger.log(Logger.Level.TRACE, "sendFirstMessage(): Sending message that does not match selector");
+ msg.setBooleanProperty("second_message", false);
+ // ii
+ qSender = session.createSender(tempQ);
+ qSender.send(msg);
+
+ msg = session.createMessage();
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "MsgSelectorQueueTests_2");
+ }
+
+ /*
+ * Send the second message which does match the selector. Receive() and verify
+ * that only this second message is received.
+ */
+ private void finishTest() throws Exception {
+ logger.log(Logger.Level.TRACE, "time_out is " + jms_timeout);
+ logger.log(Logger.Level.TRACE, "finishTest: Sending message that should match selector");
+ msg.setBooleanProperty("second_message", true);
+ qSender = session.createSender(tempQ);
+ qSender.send(msg);
+
+ logger.log(Logger.Level.TRACE, "Attempt to receive message. Should receive second message only.");
+ Message msg1 = qReceiver.receive(jms_timeout);
+ logger.log(Logger.Level.TRACE, "Received message: " + msg1);
+
+ // check result
+ if (msg1 == null) {
+ throw new Exception("Did not receive message!");
+ } else if (msg1.getBooleanProperty("second_message") == true) {
+ logger.log(Logger.Level.TRACE, "test passed");
+ } else if (msg1.getBooleanProperty("second_message") == false) {
+ throw new Exception("Incorrectly received non-matching message!");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Individual tests create a temporary Queue
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ jms_timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ // check props for errors
+ if (jms_timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ JmsTool tool = new JmsTool(JmsTool.QUEUE_FACTORY, jmsUser, jmsPassword, mode);
+ qFactory = tool.getQueueConnectionFactory();
+ qConnect = qFactory.createQueueConnection(jmsUser, jmsPassword);
+ qConnect.start();
+
+ session = qConnect.createQueueSession(transacted, Session.AUTO_ACKNOWLEDGE);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, " closing connection");
+ qConnect.close();
+ tempQ = null;
+ session.close();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: selectorTest01
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:39;
+ *
+ * @test_Strategy: create receiver with selector set msg header to include
+ * string send message check receipt of message
+ */
+ @Test
+ public void selectorTest01() throws Exception {
+ try {
+ String selector = "JMSType='literal'";
+ String value = "literal"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: selectorTest02
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:39;
+ *
+ * @test_Strategy: create receiver with selector set msg header to include '
+ * character send message check receipt of message
+ */
+ @Test
+ public void selectorTest02() throws Exception {
+ try {
+ String selector = "JMSType='literal''s'";
+ String value = "literal's"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: selectorTest03
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:63; JMS:SPEC:55; JMS:SPEC:49;
+ * JMS:SPEC:40;
+ *
+ * @test_Strategy: create receiver with selector set msg properties to include
+ * values at ends of long range send message check receipt of message
+ */
+ @Test
+ public void selectorTest03() throws Exception {
+ try {
+ String selector = "myProp0=" + Long.MIN_VALUE + "L AND myProp1=" + Long.MAX_VALUE + "L";
+ String value = ""; // set for JMSType automatically
+ logger.log(Logger.Level.TRACE, selector);
+
+ startTest(selector, value);
+ msg.setLongProperty("myProp0", Long.MIN_VALUE);
+ msg.setLongProperty("myProp1", Long.MAX_VALUE);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: selectorTest04
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:63; JMS:SPEC:55; JMS:SPEC:56;
+ * JMS:SPEC:49; JMS:SPEC:40;
+ *
+ * @test_Strategy: create receiver with selector set msg properties to include
+ * numeric value send message check receipt of message
+ */
+ @Test
+ public void selectorTest04() throws Exception {
+ try {
+ String selector = "myProp0=-957 AND myProp1=+62";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setLongProperty("myProp0", -957);
+ msg.setLongProperty("myProp1", 62);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: selectorTest05
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:40;
+ *
+ * @test_Strategy: create receiver with selector containing octal set msg
+ * properties to include numeric value send message check receipt of message
+ */
+ @Test
+ public void selectorTest05() throws Exception {
+ try {
+ String selector = "myProp=035"; // 29 in octal is 035
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setLongProperty("myProp", 29);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: selectorTest06
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:40;
+ *
+ * @test_Strategy: create receiver with selector containing hexadecimal set msg
+ * properties to include numeric value send message check receipt of message
+ */
+ @Test
+ public void selectorTest06() throws Exception {
+ try {
+ String selector = "myProp=0x1d";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setLongProperty("myProp", 29); // 29 in hex is 0x1d
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: selectorTest07
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:56; JMS:SPEC:49;
+ * JMS:SPEC:41;
+ *
+ * @test_Strategy: create receiver with selector set msg properties to include
+ * numeric value send message check receipt of message
+ */
+ @Test
+ public void selectorTest07() throws Exception {
+ try {
+ String selector = "myProp0=7E3 AND myProp1=-57.9E3";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setDoubleProperty("myProp0", 7000.0);
+ msg.setDoubleProperty("myProp1", -57900.0);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: selectorTest08
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:41;
+ *
+ * @test_Strategy: create receiver with selector set msg properties to include
+ * numeric value send message check receipt of message
+ */
+ @Test
+ public void selectorTest08() throws Exception {
+ try {
+ String selector = "myProp=7000.";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setDoubleProperty("myProp", 7000.0);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: selectorTest09
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:41;
+ *
+ * @test_Strategy: create receiver with selector set msg properties to include
+ * numeric value send message check receipt of message
+ */
+ @Test
+ public void selectorTest09() throws Exception {
+ try {
+ String selector = "myProp0=.7e4";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setDoubleProperty("myProp0", 7000.0);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: selectorTest11
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:56; JMS:SPEC:49;
+ * JMS:SPEC:42;
+ *
+ * @test_Strategy: create receiver with selector send message with header
+ * including TRUE/FALSE check receipt of message
+ */
+ @Test
+ public void selectorTest11() throws Exception {
+ try {
+ String selector = "myProp0=TRUE AND myProp1=FALSE";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myProp0", true);
+ msg.setBooleanProperty("myProp1", false);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: selectorTest12
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:42;
+ *
+ * @test_Strategy: create receiver with selector send message with header
+ * including TRUE/FALSE check receipt of message
+ */
+ @Test
+ public void selectorTest12() throws Exception {
+ try {
+ String selector = "myProp0=false AND myProp1=true";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myProp0", false);
+ msg.setBooleanProperty("myProp1", true);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest01
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:43;
+ *
+ * @test_Strategy: create receiver with selector send message with identifiers
+ * including '_' and '$' check receipt of message
+ */
+ @Test
+ public void identifierTest01() throws Exception {
+ try {
+ String selector = "$myProp=TRUE AND _myProp=FALSE";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("$myProp", true);
+ msg.setBooleanProperty("_myProp", false);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest02
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:44;
+ * JMS:SPEC:175;
+ *
+ * @test_Strategy: create receiver with selector containing 'NULL' check for
+ * proper exception
+ */
+ @Test
+ public void identifierTest02() throws Exception {
+ try {
+ String selector = "NULL = 0";
+ String value = "";
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest03
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:44; JMS:SPEC:175;
+ *
+ * @test_Strategy: create receiver with selector containing 'TRUE' check for
+ * proper exception
+ */
+ @Test
+ public void identifierTest03() throws Exception {
+ try {
+ String selector = "TRUE = 0";
+ String value = "";
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest04
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:44; JMS:SPEC:175;
+ *
+ * @test_Strategy: create receiver with selector containing 'FALSE' check for
+ * proper exception
+ */
+ @Test
+ public void identifierTest04() throws Exception {
+ try {
+ String selector = "FALSE = 0";
+ String value = "";
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest05
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45; JMS:SPEC:175;
+ *
+ * @test_Strategy: create receiver with selector containing 'NOT' check for
+ * proper exception
+ */
+ @Test
+ public void identifierTest05() throws Exception {
+ try {
+ String selector = "NOT = 0";
+ String value = "";
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest06
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
+ *
+ * @test_Strategy: create receiver with selector containing 'AND' check for
+ * proper exception
+ */
+ @Test
+ public void identifierTest06() throws Exception {
+ try {
+ String selector = "AND = 0";
+ String value = "";
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest07
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
+ *
+ * @test_Strategy: create receiver with selector containing 'OR' check for
+ * proper exception
+ */
+ @Test
+ public void identifierTest07() throws Exception {
+ try {
+ String selector = "OR = 0";
+ String value = "";
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest08
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
+ *
+ * @test_Strategy: create receiver with selector containing 'BETWEEN' check for
+ * proper exception
+ */
+ @Test
+ public void identifierTest08() throws Exception {
+ try {
+ String selector = "BETWEEN = 0";
+ String value = "";
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest09
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
+ *
+ * @test_Strategy: create receiver with selector containing 'LIKE' check for
+ * proper exception
+ */
+ @Test
+ public void identifierTest09() throws Exception {
+ try {
+ String selector = "LIKE = 0";
+ String value = "";
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest10
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
+ *
+ * @test_Strategy: create receiver with selector containing 'IN' check for
+ * proper exception
+ */
+ @Test
+ public void identifierTest10() throws Exception {
+ try {
+ String selector = "IN = 0";
+ String value = "";
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest11
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
+ *
+ * @test_Strategy: create receiver with selector containing 'IS' check for
+ * proper exception
+ */
+ @Test
+ public void identifierTest11() throws Exception {
+ try {
+ String selector = "IS = 0";
+ String value = "";
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest12
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:48;
+ *
+ * @test_Strategy: create receiver with selector set two msg properties with
+ * names differing in case send message check receipt of message
+ */
+ @Test
+ public void identifierTest12() throws Exception {
+ try {
+ String selector = "myProp=TRUE AND MYpROP=FALSE";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myProp", true);
+ msg.setBooleanProperty("MYpROP", false);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest13
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:46;
+ *
+ * @test_Strategy: create receiver with selector send message check that message
+ * is not received
+ */
+ @Test
+ public void identifierTest13() throws Exception {
+ try {
+ String selector = "myProp ='foo'";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setStringProperty("myProp", "foo");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest14
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:45;
+ *
+ * @test_Strategy: create receiver with selector containing 'ESCAPE' check for
+ * proper exception
+ */
+ @Test
+ public void identifierTest14() throws Exception {
+ try {
+ String selector = "ESCAPE = 0";
+ String value = "";
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: whitespaceTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:53;
+ *
+ * @test_Strategy: create receiver with selector containing extra spaces send
+ * message with header set check receipt of message
+ */
+ @Test
+ public void whitespaceTest1() throws Exception {
+ try {
+ String selector = "JMSType = 'foo'";
+ String value = "foo"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: whitespaceTest2
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:53;
+ *
+ * @test_Strategy: create receiver with selector containing tabs send message
+ * with header set check receipt of message
+ */
+ @Test
+ public void whitespaceTest2() throws Exception {
+ try {
+ String selector = "JMSType\t=\t'foo'";
+ String value = "foo"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: whitespaceTest3
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:53;
+ *
+ * @test_Strategy: create receiver with selector containing form feeds send
+ * message with header set check receipt of message
+ */
+ @Test
+ public void whitespaceTest3() throws Exception {
+ try {
+ String selector = "JMSType\f=\f'foo'";
+ String value = "foo"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: whitespaceTest4
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:53;
+ *
+ * @test_Strategy: create receiver with selector containing line terminators
+ * send message with header set check receipt of message
+ */
+ @Test
+ public void whitespaceTest4() throws Exception {
+ try {
+ String selector = "JMSType\n= \n'foo'";
+ String value = "foo"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: expressionTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:54;
+ *
+ * @test_Strategy: create receiver with selector send message with TRUE boolean
+ * property check receipt of message
+ */
+ @Test
+ public void expressionTest1() throws Exception {
+ try {
+ String selector = "myProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myProp", true);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: expressionTest2
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:54;
+ *
+ * @test_Strategy: create receiver with selector send message with FALSE boolean
+ * property check that message is not received
+ */
+ @Test
+ public void expressionTest2() throws Exception {
+ try {
+ String selector = "myProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myProp", false);
+ sendFirstMessage();
+ msg.setBooleanProperty("myProp", true);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: expressionTest3
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:54;
+ *
+ * @test_Strategy: create receiver with selector referenceing null property send
+ * message check that message is not received
+ */
+ @Test
+ public void expressionTest3() throws Exception {
+ try {
+ String selector = "myNullProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setBooleanProperty("myNullProp", true);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: bracketingTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:57;
+ *
+ * @test_Strategy: create receiver with selector that should evaluate to FALSE
+ * send message check that message is not received
+ */
+ @Test
+ public void bracketingTest1() throws Exception {
+ try {
+ String selector = "(myTrueProp OR myFalseProp) AND myFalseProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myTrueProp", true);
+ msg.setBooleanProperty("myFalseProp", false);
+ sendFirstMessage();
+ msg.setBooleanProperty("myTrueProp", true);
+ msg.setBooleanProperty("myFalseProp", true);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: bracketingTest2
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:57;
+ *
+ * @test_Strategy: create receiver with selector that should evaluate to TRUE
+ * send message check receipt of message
+ */
+ @Test
+ public void bracketingTest2() throws Exception {
+ try {
+ String selector = "TRUE OR (FALSE AND FALSE)";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: bracketingTest3
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:57;
+ *
+ * @test_Strategy: create receiver with selector that should evaluate to FALSE
+ * send message check that message is not received
+ */
+ @Test
+ public void bracketingTest3() throws Exception {
+ try {
+ String selector = "(myProp0 = true OR myProp1 = true) AND JMSType = 'not_foo'";
+ String value = "foo"; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myProp0", true);
+ msg.setBooleanProperty("myProp1", false);
+ sendFirstMessage();
+ msg.setJMSType("not_foo");
+ msg.setBooleanProperty("myProp0", true);
+ msg.setBooleanProperty("myProp1", false);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: bracketingTest4
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:57;
+ *
+ * @test_Strategy: create receiver with selector that should evaluate to TRUE
+ * send message check receipt of message
+ */
+ @Test
+ public void bracketingTest4() throws Exception {
+ try {
+ String selector = "(myProp1 = true AND JMSType = 'not_foo') OR myProp0 = true";
+ String value = "foo"; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myProp0", true);
+ msg.setBooleanProperty("myProp1", false);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest01
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:59;
+ *
+ * @test_Strategy: create receiver with selector containing operators send
+ * message with properties matching selector check receipt of message
+ */
+ @Test
+ public void comparisonTest01() throws Exception {
+ try {
+ String selector = "myProp0 = 'foo' AND " + "myProp1 > 0 AND " + "myProp2 >= 2 AND " + "myProp3 >= 2 AND "
+ + "myProp4 < 5 AND " + "myProp5 <= 6 AND " + "myProp6 <= 6 AND " + "myProp7 <> 7";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp0", "foo");
+ msg.setIntProperty("myProp1", 1);
+ msg.setFloatProperty("myProp2", 2.0f);
+ msg.setIntProperty("myProp3", 3);
+ msg.setDoubleProperty("myProp4", 4.0);
+ msg.setIntProperty("myProp5", 5);
+ msg.setIntProperty("myProp6", 6);
+ msg.setFloatProperty("myProp7", 0f);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest02
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:59;
+ *
+ * @test_Strategy: create receiver with selector containing operators send
+ * message with properties not matching selector check that message is not
+ * received
+ */
+ @Test
+ public void comparisonTest02() throws Exception {
+ try {
+ String selector = "myProp0 = 'foo' OR " + "myProp1 > 0 OR " + "myProp2 >= 2 OR " + "myProp3 < 5 OR "
+ + "myProp4 <= 6 OR " + "myProp5 <> 7";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp0", "not_foo");
+ msg.setIntProperty("myProp1", 0);
+ msg.setFloatProperty("myProp2", 1.5f);
+ msg.setDoubleProperty("myProp3", 5.0);
+ msg.setIntProperty("myProp4", 7);
+ msg.setFloatProperty("myProp5", 7f);
+ sendFirstMessage();
+ msg.setStringProperty("myProp0", "foo");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest03
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:60;
+ *
+ * @test_Strategy: create receiver with selector send message with exact and
+ * approximate numeric values check receipt of message
+ */
+ @Test
+ public void comparisonTest03() throws Exception {
+ try {
+ String selector = "myProp0 < myProp1";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setIntProperty("myProp0", 0);
+ msg.setDoubleProperty("myProp1", 1.5);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest04
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:61;
+ *
+ * @test_Strategy: create receiver with selector containing > and string should
+ * throw InvalidSelectorException
+ */
+ @Test
+ public void comparisonTest04() throws Exception {
+ try {
+ String selector = "myProp > 'foo'";
+ String value = "";
+
+ startTest(selector, value);
+
+ // did not get exception
+ throw new Exception("Did not receive InvalidSelectorException " + "as expected.");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Test passed. Received expected exception.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest05
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
+ *
+ * @test_Strategy: create receiver with selector containing >= and string should
+ * throw InvalidSelectorException
+ */
+ @Test
+ public void comparisonTest05() throws Exception {
+ try {
+ String selector = "myProp >= 'foo'";
+ String value = "";
+
+ startTest(selector, value);
+
+ // did not get exception
+ throw new Exception("Did not receive InvalidSelectorException " + "as expected.");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Test passed. Received expected exception.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest06
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
+ *
+ * @test_Strategy: create receiver with selector containing < and string should
+ * throw InvalidSelectorException
+ */
+ @Test
+ public void comparisonTest06() throws Exception {
+ try {
+ String selector = "myProp < 'foo'";
+ String value = "";
+
+ startTest(selector, value);
+
+ // did not get exception
+ throw new Exception("Did not receive InvalidSelectorException " + "as expected.");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Test passed. Received expected exception.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest07
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
+ *
+ * @test_Strategy: create receiver with selector containing <= and string should
+ * throw InvalidSelectorException
+ */
+ @Test
+ public void comparisonTest07() throws Exception {
+ try {
+ String selector = "myProp <= 'foo'";
+ String value = "";
+
+ startTest(selector, value);
+
+ // did not get exception
+ throw new Exception("Did not receive InvalidSelectorException " + "as expected.");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Test passed. Received expected exception.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest08
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
+ *
+ * @test_Strategy: create receiver with valid selector send matching message
+ * check for receipt of message
+ */
+ @Test
+ public void comparisonTest08() throws Exception {
+ try {
+ String selector = "JMSType = 'foo' AND myProp <> 'not_foo'";
+ String value = "foo";
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp", "foo");
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest09
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
+ *
+ * @test_Strategy: create receiver with selector comparing TRUE with > should
+ * throw InvalidSelectorException
+ */
+ @Test
+ public void comparisonTest09() throws Exception {
+ try {
+ String selector = "'foo' > TRUE ";
+ String value = "";
+
+ startTest(selector, value);
+
+ // did not get exception
+ throw new Exception("Did not receive InvalidSelectorException " + "as expected.");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Test passed. Received expected exception.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest10
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
+ *
+ * @test_Strategy: create receiver with selector comparing TRUE with >= should
+ * throw InvalidSelectorException
+ */
+ @Test
+ public void comparisonTest10() throws Exception {
+ try {
+ String selector = "'foo' >= TRUE ";
+ String value = "";
+
+ startTest(selector, value);
+
+ // did not get exception
+ throw new Exception("Did not receive InvalidSelectorException " + "as expected.");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Test passed. Received expected exception.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest11
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
+ *
+ * @test_Strategy: create receiver with selector comparing TRUE with < should
+ * throw InvalidSelectorException
+ */
+ @Test
+ public void comparisonTest11() throws Exception {
+ try {
+ String selector = "'foo' < TRUE ";
+ String value = "";
+
+ startTest(selector, value);
+
+ // did not get exception
+ throw new Exception("Did not receive InvalidSelectorException " + "as expected.");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Test passed. Received expected exception.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest12
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:61;
+ *
+ * @test_Strategy: create receiver with selector comparing TRUE with <= should
+ * throw InvalidSelectorException
+ */
+ @Test
+ public void comparisonTest12() throws Exception {
+ try {
+ String selector = "'foo' <= TRUE ";
+ String value = "";
+
+ startTest(selector, value);
+
+ // did not get exception
+ throw new Exception("Did not receive InvalidSelectorException " + "as expected.");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Test passed. Received expected exception.");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest13
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:61;
+ *
+ * @test_Strategy: create receiver with valid selector send matching message
+ * check for receipt of message
+ */
+ @Test
+ public void comparisonTest13() throws Exception {
+ try {
+ String selector = "myProp0 = TRUE AND myProp1 <> FALSE";
+ String value = "";
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myProp0", true);
+ msg.setBooleanProperty("myProp1", true);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: operatorTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:62;
+ *
+ * @test_Strategy: create receiver with selector containing +,- send message
+ * with numeric properties check receipt of message
+ */
+ @Test
+ public void operatorTest1() throws Exception {
+ try {
+ String selector = "-myProp0 < 0 AND +myProp1 < 0";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setIntProperty("myProp0", 5);
+ msg.setIntProperty("myProp1", -5);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: operatorTest2
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:62;
+ *
+ * @test_Strategy: create receiver with selector containing *,/ send message
+ * with numeric properties check receipt of message
+ */
+ @Test
+ public void operatorTest2() throws Exception {
+ try {
+ String selector = "myProp0*2 = 10 AND myProp1/2 = -5";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setIntProperty("myProp0", 5);
+ msg.setIntProperty("myProp1", -10);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: operatorTest3
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:62;
+ *
+ * @test_Strategy: create receiver with selector containing +,- send message
+ * with numeric properties check receipt of message
+ */
+ @Test
+ public void operatorTest3() throws Exception {
+ try {
+ String selector = "myProp0+5 = 0 AND myProp1-5 = 5";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setIntProperty("myProp0", -5);
+ msg.setIntProperty("myProp1", 10);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: betweenTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
+ *
+ * @test_Strategy: create receiver with selector containing BETWEEN send message
+ * matching selector check receipt of message
+ */
+ @Test
+ public void betweenTest1() throws Exception {
+ try {
+ String selector = "myProp0 BETWEEN 5 and 10 AND " + "myProp1 BETWEEN -1 and 1 AND "
+ + "myProp2 BETWEEN 0 and 2";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setIntProperty("myProp0", 7);
+ msg.setIntProperty("myProp1", -1);
+ msg.setIntProperty("myProp2", 2);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: betweenTest2
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
+ *
+ * @test_Strategy: create receiver with selector containing BETWEEN send message
+ * not matching selector check that message is not received
+ */
+ @Test
+ public void betweenTest2() throws Exception {
+ try {
+ String selector = "myProp0 BETWEEN -4 and 5 OR " + "myProp1 BETWEEN -5 and 4";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setIntProperty("myProp0", -5);
+ msg.setIntProperty("myProp1", 5);
+ sendFirstMessage();
+ msg.setIntProperty("myProp0", 0);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: betweenTest3
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
+ *
+ * @test_Strategy: create receiver with selector containing NOT BETWEEN send
+ * message matching selector check receipt of message
+ */
+ @Test
+ public void betweenTest3() throws Exception {
+ try {
+ String selector = "myProp0 NOT BETWEEN -4 and 5 AND " + "myProp1 NOT BETWEEN -5 and 4";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setIntProperty("myProp0", -5);
+ msg.setIntProperty("myProp1", 5);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: betweenTest4
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
+ *
+ * @test_Strategy: create receiver with selector containing NOT BETWEEN send
+ * message not matching selector check that message is not received
+ */
+ @Test
+ public void betweenTest4() throws Exception {
+ try {
+ String selector = "myProp0 NOT BETWEEN 5 and 10 OR " + "myProp1 NOT BETWEEN -1 and 1 OR "
+ + "myProp2 NOT BETWEEN 0 and 2";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setIntProperty("myProp0", 7);
+ msg.setIntProperty("myProp1", -1);
+ msg.setIntProperty("myProp2", 2);
+ sendFirstMessage();
+ msg.setIntProperty("myProp0", 0);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: betweenTest5
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
+ *
+ * @test_Strategy: create receiver with selector containing BETWEEN send message
+ * with property that is not arithmetic check that message is not received
+ */
+ @Test
+ public void betweenTest5() throws Exception {
+ try {
+ String selector = "myProp BETWEEN 5 and 10";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+
+ // not a number. should not be received
+ msg.setStringProperty("myProp", "7");
+ sendFirstMessage();
+ msg.setIntProperty("myProp", 7);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: betweenTest6
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
+ *
+ * @test_Strategy: create receiver with selector containing BETWEEN send message
+ * with property that is not arithmetic check that message is not received
+ */
+ @Test
+ public void betweenTest6() throws Exception {
+ try {
+ String selector = "myProp BETWEEN 5 and 10";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+
+ // not number, so message shouldn't be received
+ msg.setStringProperty("myProp", "seven");
+ sendFirstMessage();
+ msg.setIntProperty("myProp", 7);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: betweenTest7
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
+ *
+ * @test_Strategy: create receiver with syntactically incorrect selector check
+ * for proper excepion
+ */
+ @Test
+ public void betweenTest7() throws Exception {
+ try {
+ String selector = "myProp BETWEEN 'foo' and 'test'";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: inTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
+ *
+ * @test_Strategy: create receiver with selector containing IN send message
+ * matching selector check receipt of message
+ */
+ @Test
+ public void inTest1() throws Exception {
+ try {
+ String selector = "JMSType IN ('foo','jms','test')";
+ String value = "jms"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: inTest2
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
+ *
+ * @test_Strategy: create receiver with selector containing IN send message not
+ * matching selector check that message is not received
+ */
+ @Test
+ public void inTest2() throws Exception {
+ try {
+ String selector = "JMSType IN ('foo','jms','test')";
+ String value = "JMS"; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setJMSType("jms");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: inTest3
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
+ *
+ * @test_Strategy: create receiver with selector containing NOT IT send message
+ * matching selector check receipt of message
+ */
+ @Test
+ public void inTest3() throws Exception {
+ try {
+ String selector = "JMSType NOT IN ('foo','jms','test')";
+ String value = "FOO"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: inTest4
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
+ *
+ * @test_Strategy: create receiver with selector containing NOT IN send message
+ * not matching selector check that message is not received
+ */
+ @Test
+ public void inTest4() throws Exception {
+ try {
+ String selector = "JMSType NOT IN ('foo','jms','test')";
+ String value = "foo"; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setJMSType("FOO");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: inTest5
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
+ *
+ * @test_Strategy: create receiver with selector containing IN msg selector
+ * references an unknown property send message check that message is not
+ * received
+ */
+ @Test
+ public void inTest5() throws Exception {
+ try {
+ String selector = "myNullProp IN ('foo','jms','test')";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setStringProperty("myNullProp", "jms");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: inTest6
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
+ *
+ * @test_Strategy: create receiver with selector containing NOT IN msg selector
+ * references an unknown property send message check that message is not
+ * received
+ */
+ @Test
+ public void inTest6() throws Exception {
+ try {
+ String selector = "myNullProp NOT IN ('foo','jms','test')";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setStringProperty("myNullProp", "JMS");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: inTest7
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
+ *
+ * @test_Strategy: create receiver with selector containing NOT IN set msg
+ * property of integer type send message check that message is not received
+ */
+ @Test
+ public void inTest7() throws Exception {
+ try {
+ String selector = "myProp NOT IN ('foo','jms','test')";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+
+ // property is not a string
+ msg.setIntProperty("myProp", 0);
+ sendFirstMessage();
+ msg.setStringProperty("myProp", "zero");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: inTest8
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
+ *
+ * @test_Strategy: create receiver with syntactically incorrect selector check
+ * for proper exception
+ */
+ @Test
+ public void inTest8() throws Exception {
+ try {
+ String selector = "myProp NOT IN (1,2,3)";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest01
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector containing LIKE send
+ * message matching selector check receipt of message
+ */
+ @Test
+ public void likeTest01() throws Exception {
+ try {
+ String selector = "JMSType LIKE 'jms'";
+ String value = "jms"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest02
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains LIKE
+ * statement using '_' send message matching selector check receipt of message
+ */
+ @Test
+ public void likeTest02() throws Exception {
+ try {
+ String selector = "JMSType LIKE 's_lector' AND " + "myProp0 LIKE '_bcd' AND " + "myProp1 LIKE '123_'";
+ String value = "selector"; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp0", "abcd");
+ msg.setStringProperty("myProp1", "1234");
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest03
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains LIKE
+ * statement using '%' send message matching selector check receipt of message
+ */
+ @Test
+ public void likeTest03() throws Exception {
+ try {
+ String selector = "JMSType LIKE 's%tor' AND " + "myProp0 LIKE '%cd' AND " + "myProp1 LIKE '1%' AND "
+ + "myProp2 LIKE 'AB%CD' AND " + "myProp3 LIKE '%'";
+ String value = "selector"; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp0", "abcd");
+ msg.setStringProperty("myProp1", "1234");
+ msg.setStringProperty("myProp2", "ABCD");
+ msg.setStringProperty("myProp3", "foo");
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest04
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains LIKE
+ * statement using ESCAPE character send message matching selector check receipt
+ * of message
+ */
+ @Test
+ public void likeTest04() throws Exception {
+ try {
+ String selector = "JMSType LIKE 'A_fo_A%f%' " + "ESCAPE 'A'";
+ String value = "_foo%foo"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest05
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector containing LIKE send
+ * message not matching selector check that message is not received
+ */
+ @Test
+ public void likeTest05() throws Exception {
+ try {
+ String selector = "JMSType LIKE '123' OR " + "myProp LIKE 'jms0'";
+ String value = "1234"; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp", "jms");
+ sendFirstMessage();
+ msg.setStringProperty("myProp", "jms0");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest06
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains LIKE
+ * statement using '_' send message not matching selector check that message is
+ * not received
+ */
+ @Test
+ public void likeTest06() throws Exception {
+ try {
+ String selector = "JMSType LIKE 'se_ector' OR " + "myProp0 LIKE '_cd' OR " + "myProp1 LIKE '12_'";
+ String value = "seleector"; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp0", "abcd");
+ msg.setStringProperty("myProp1", "1234");
+ sendFirstMessage();
+ msg.setJMSType("selector");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest07
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains LIKE
+ * statement using '%' send message not matching selector check that message is
+ * not received
+ */
+ @Test
+ public void likeTest07() throws Exception {
+ try {
+ String selector = "JMSType LIKE '12%3'";
+ String value = "1234";
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setJMSType("12333");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest08
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains LIKE
+ * statement using ESCAPE character send message not matching selector check
+ * that message is not received
+ */
+ @Test
+ public void likeTest08() throws Exception {
+ try {
+ String selector = "JMSType LIKE 'A%fooA_' " + "ESCAPE 'A'";
+ String value = "_foo%"; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setJMSType("%foo_");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest09
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector containing NOT LIKE
+ * send message matching selector check receipt of message
+ */
+ @Test
+ public void likeTest09() throws Exception {
+ try {
+ String selector = "JMSType NOT LIKE 'jms_foo'";
+ String value = "jms"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest10
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains NOT
+ * LIKE statement using '_' send message matching selector check receipt of
+ * message
+ */
+ @Test
+ public void likeTest10() throws Exception {
+ try {
+ String selector = "JMSType NOT LIKE 's_ector' AND " + "myProp0 NOT LIKE '_cd' AND "
+ + "myProp1 NOT LIKE '12_'";
+ String value = "selector"; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp0", "abcd");
+ msg.setStringProperty("myProp1", "1234");
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest11
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains NOT
+ * LIKE statement using '%' send message matching selector check receipt of
+ * message
+ */
+ @Test
+ public void likeTest11() throws Exception {
+ try {
+ String selector = "myProp0 NOT LIKE '%cde' AND " + "myProp1 NOT LIKE '01%' AND "
+ + "myProp2 NOT LIKE 'A%x%D'";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp0", "abcd");
+ msg.setStringProperty("myProp1", "1234");
+ msg.setStringProperty("myProp2", "ABCD");
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest12
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains NOT
+ * LIKE statement using ESCAPE character send message matching selector check
+ * receipt of message
+ */
+ @Test
+ public void likeTest12() throws Exception {
+ try {
+ String selector = "JMSType NOT LIKE 'A_A_' " + "ESCAPE 'A'";
+ String value = "_A"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest13
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector containing NOT LIKE
+ * send message not matching selector check that message is not received
+ */
+ @Test
+ public void likeTest13() throws Exception {
+ try {
+ String selector = "JMSType NOT LIKE '1234' OR " + "myProp NOT LIKE 'jms'";
+ String value = "1234"; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp", "jms");
+ sendFirstMessage();
+ msg.setJMSType("foo");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest14
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains NOT
+ * LIKE statement using '_' send message not matching selector check that
+ * message is not received
+ */
+ @Test
+ public void likeTest14() throws Exception {
+ try {
+ String selector = "JMSType NOT LIKE 'se_ector' OR " + "myProp0 NOT LIKE '_bcd' OR "
+ + "myProp1 NOT LIKE '123_'";
+ String value = "selector"; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp0", "abcd");
+ msg.setStringProperty("myProp1", "1234");
+ sendFirstMessage();
+ msg.setJMSType("foo");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest15
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains NOT
+ * LIKE statement using '%' send message not matching selector check that
+ * message is not received
+ */
+ @Test
+ public void likeTest15() throws Exception {
+ try {
+ String selector = "JMSType NOT LIKE '12%'";
+ String value = "1234";
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setJMSType("foo");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest16
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains NOT
+ * LIKE statement using ESCAPE character send message not matching selector
+ * check that message is not received
+ */
+ @Test
+ public void likeTest16() throws Exception {
+ try {
+ String selector = "JMSType NOT LIKE 'A_fooA%' " + "ESCAPE 'A'";
+ String value = "_foo%"; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setJMSType("jms");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest17
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector selector contains NOT
+ * LIKE statement using ESCAPE character '\' send message not matching selector
+ * check receipt of message
+ */
+ @Test
+ public void likeTest17() throws Exception {
+ try {
+ String selector = "JMSType LIKE '\\__\\%%' ESCAPE '\\'";
+ String value = "_a%b"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest18
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:60; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector using LIKE selector
+ * references unknown property send message check that message is not received
+ */
+ @Test
+ public void likeTest18() throws Exception {
+ try {
+ String selector = "myNullProp LIKE '1_3'";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setStringProperty("myNullProp", "123");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest19
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:60; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector using NOT LIKE selector
+ * references unknown property send message check that message is not received
+ */
+ @Test
+ public void likeTest19() throws Exception {
+ try {
+ String selector = "myNullProp NOT LIKE '1_3'";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setStringProperty("myNullProp", "foo");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest20
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector using LIKE send message
+ * with non-string property check that message is not received
+ */
+ @Test
+ public void likeTest20() throws Exception {
+ try {
+ String selector = "myProp LIKE '1_3'";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+
+ // not a string
+ msg.setIntProperty("myProp", 123);
+ sendFirstMessage();
+ msg.setStringProperty("myProp", "123");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest21
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with invalid selector check for proper
+ * exception
+ */
+ @Test
+ public void likeTest21() throws Exception {
+ try {
+ String selector = "myProp LIKE 7";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+
+ // should have received exception
+ throw new Exception("Did not receive InvalidSelectorException");
+ } catch (InvalidSelectorException ise) {
+ logger.log(Logger.Level.TRACE, "Caught expected exception");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: isNullTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:67;
+ *
+ * @test_Strategy: create receiver with message selector containing IS NULL
+ * selector references unknown property send message check receipt of message
+ */
+ @Test
+ public void isNullTest1() throws Exception {
+ try {
+ String selector = "myNullProp IS NULL";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: isNullTest2
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:67;
+ *
+ * @test_Strategy: create receiver with message selector containing IS NULL
+ * selector references existing property send message check that message is not
+ * received
+ */
+ @Test
+ public void isNullTest2() throws Exception {
+ try {
+ String selector = "myProp IS NULL";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp", "foo");
+ sendFirstMessage();
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: isNullTest3
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:68;
+ *
+ * @test_Strategy: create receiver with message selector containing IS NOT NULL
+ * selector references existing property send message check receipt of message
+ */
+ @Test
+ public void isNullTest3() throws Exception {
+ try {
+ String selector = "myProp IS NOT NULL";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setFloatProperty("myProp", 10f);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: isNullTest4
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:68;
+ *
+ * @test_Strategy: create receiver with message selector containing IS NOT NULL
+ * selector references unknown property send message check that message is not
+ * received
+ */
+ @Test
+ public void isNullTest4() throws Exception {
+ try {
+ String selector = "myNullProp IS NOT NULL";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setStringProperty("myNullProp", "foo");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: caseTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:247;
+ *
+ * @test_Strategy: create receiver with message selector selector contains lower
+ * case versions of selector operators send message matching selector check
+ * receipt of message
+ */
+ @Test
+ public void caseTest1() throws Exception {
+ try {
+ String selector = "myProp0 is null and " + "myProp1 like 'fooG_%' escape 'G' and "
+ + "myProp2 in ('a', 'b') and " + "myProp3 not between 0 and 10 and " + "(myProp4 or false)";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp1", "foo_test");
+ msg.setStringProperty("myProp2", "a");
+ msg.setIntProperty("myProp3", 20);
+ msg.setBooleanProperty("myProp4", true);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: precedenceTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:58;
+ *
+ * @test_Strategy: create receiver with message selector containing AND and OR
+ * send message not matching selector check that message is not received !F&F =
+ * (!F)&F = T&F = F incorrect order would be !F&F -> !(F&F) = !F = T
+ */
+ @Test
+ public void precedenceTest1() throws Exception {
+ try {
+ String selector = "NOT myTrueProp AND myFalseProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myTrueProp", true);
+ msg.setBooleanProperty("myFalseProp", false);
+ sendFirstMessage();
+ msg.setBooleanProperty("myTrueProp", false);
+ msg.setBooleanProperty("myFalseProp", true);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: precedenceTest2
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:58;
+ *
+ * @test_Strategy: create receiver with message selector containing AND and NOT
+ * send message matching selector check receipt of message
+ */
+ @Test
+ public void precedenceTest2() throws Exception {
+ try {
+ String selector = "myTrueProp AND NOT myFalseProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myTrueProp", true);
+ msg.setBooleanProperty("myFalseProp", false);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: precedenceTest3
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:58;
+ *
+ * @test_Strategy: create receiver with message selector containing AND and OR
+ * send message matching selector check receipt of message TvT&F = Tv(T&F) = TvF
+ * = T incorrect order would be TvT&F -> (TvT)&F = T&F = F
+ */
+ @Test
+ public void precedenceTest3() throws Exception {
+ try {
+ String selector = "myTrueProp OR myTrueProp AND myFalseProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myTrueProp", true);
+ msg.setBooleanProperty("myFalseProp", false);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: precedenceTest4
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:62;
+ *
+ * @test_Strategy: create receiver with message selector send message check
+ * receipt of message
+ */
+ @Test
+ public void precedenceTest4() throws Exception {
+ try {
+ String selector = "- myProp0 + myProp1 = 0";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setIntProperty("myProp0", 5);
+ msg.setIntProperty("myProp1", 5);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: precedenceTest5
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:62;
+ *
+ * @test_Strategy: create receiver with message selector send message matching
+ * selector check receipt of message
+ */
+ @Test
+ public void precedenceTest5() throws Exception {
+ try {
+ String selector = "myProp0+myProp1*myProp2-myProp3/myProp4 = 6";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setFloatProperty("myProp0", 1f);
+ msg.setFloatProperty("myProp1", 2f);
+ msg.setFloatProperty("myProp2", 3f);
+ msg.setFloatProperty("myProp3", 4f);
+ msg.setFloatProperty("myProp4", 4f);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest01
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:60;
+ *
+ * @test_Strategy: create receiver with selector referencing unknown property
+ * send message check that message is not received
+ */
+ @Test
+ public void nullTest01() throws Exception {
+ try {
+ String selector = "myProp + 2 < 10";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setIntProperty("myProp", 0);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest02
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:60;
+ *
+ * @test_Strategy: create receiver with selector referencing unknown property
+ * send message check that message is not received
+ */
+ @Test
+ public void nullTest02() throws Exception {
+ try {
+ String selector = "myProp = 'foo'";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setStringProperty("myProp", "foo");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest03
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:60;
+ *
+ * @test_Strategy: create receiver with selector referencing unknown property
+ * send message check that message is not received
+ */
+ @Test
+ public void nullTest03() throws Exception {
+ try {
+ String selector = "myProp NOT IN ('a', 'b')";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setStringProperty("myProp", "foo");
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest04
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:248.1;
+ *
+ * @test_Strategy: create receiver with selector containing AND send message
+ * matching selector check receipt of message
+ */
+ @Test
+ public void nullTest04() throws Exception {
+ try {
+ String selector = "myTrueProp AND myTrueProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myTrueProp", true);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest05
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:248.2; JMS:SPEC:248.3;
+ * JMS:SPEC:248.4; JMS:SPEC:248.5; JMS:SPEC:248.6; JMS:SPEC:248.7;
+ * JMS:SPEC:248.8; JMS:SPEC:248.9;
+ *
+ * @test_Strategy: create receiver with selector containing AND each comparison
+ * should evaluate to FALSE send message check that message is not received
+ */
+ @Test
+ public void nullTest05() throws Exception {
+ try {
+ String selector = "(myTrueProp AND myFalseProp) OR " + "(myTrueProp AND myNullProp) OR "
+ + "(myFalseProp AND myTrueProp) OR " + "(myFalseProp AND myFalseProp) OR "
+ + "(myFalseProp AND myNullProp) OR " + "(MyNullProp AND myTrueProp) OR "
+ + "(MyNullProp AND myFalseProp) OR " + "(MyNullProp AND myNullProp)";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myTrueProp", true);
+ msg.setBooleanProperty("myFalseProp", false);
+ sendFirstMessage();
+ msg.setBooleanProperty("myTrueProp", true);
+ msg.setBooleanProperty("myFalseProp", true);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest06
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:249.1; JMS:SPEC:249.2;
+ * JMS:SPEC:249.3; JMS:SPEC:249.4; JMS:SPEC:249.7;
+ *
+ * @test_Strategy: create receiver with selector containing OR each comparison
+ * should evaluate to TRUE send message check receipt of message
+ */
+ @Test
+ public void nullTest06() throws Exception {
+ try {
+ String selector = "(myTrueProp OR myTrueProp) AND " + "(myTrueProp OR myFalseProp) AND "
+ + "(myTrueProp OR myNullProp) AND " + "(myFalseProp OR myTrueProp) AND "
+ + "(myNullProp OR myTrueProp)";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myTrueProp", true);
+ msg.setBooleanProperty("myFalseProp", false);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest07
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:249.5; JMS:SPEC:249.6;
+ * JMS:SPEC:249.8; JMS:SPEC:249.9;
+ *
+ * @test_Strategy: create receiver with selector containing OR each comparison
+ * should evaluate to FALSE send message check that message is not received
+ */
+ @Test
+ public void nullTest07() throws Exception {
+ try {
+ String selector = "(myFalseProp OR myFalseProp) OR " + "(myFalseProp OR myNullProp) OR "
+ + "(myNullProp OR myFalseProp) OR " + "(myNullProp OR myNullProp)";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myFalseProp", false);
+ sendFirstMessage();
+ msg.setBooleanProperty("myFalseProp", true);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest08
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:250.2;
+ *
+ * @test_Strategy: create receiver with selector containing NOT send message
+ * matching selector check receipt of message
+ */
+ @Test
+ public void nullTest08() throws Exception {
+ try {
+ String selector = "NOT myFalseProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myFalseProp", false);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest09
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:250.1;
+ *
+ * @test_Strategy: create receiver with selector containing NOT send message not
+ * matching selector check that message is not received
+ */
+ @Test
+ public void nullTest09() throws Exception {
+ try {
+ String selector = "NOT myTrueProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myTrueProp", true);
+ sendFirstMessage();
+ msg.setBooleanProperty("myTrueProp", false);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest10
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:250.3;
+ *
+ * @test_Strategy: create receiver with selector containing NOT selector
+ * references an unknown property send message check receipt of message
+ */
+ @Test
+ public void nullTest10() throws Exception {
+ try {
+ String selector = "NOT myNullProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setBooleanProperty("myNullProp", false);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest11
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:37;
+ *
+ * @test_Strategy: create receiver with null selector. check receipt of message
+ */
+ @Test
+ public void nullTest11() throws Exception {
+ try {
+ String selector = null;
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myNullProp", false);
+ finishTest();
+ } catch (Exception e) {
+ throw new Exception("test failed", e);
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/selectorTopic/MsgSelectorTopicTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/selectorTopic/MsgSelectorTopicTests.java
deleted file mode 100644
index 1d269e668b..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/selectorTopic/MsgSelectorTopicTests.java
+++ /dev/null
@@ -1,895 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.selectorTopic;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.JMSException;
-import jakarta.jms.Message;
-import jakarta.jms.Session;
-import jakarta.jms.TemporaryTopic;
-import jakarta.jms.TextMessage;
-import jakarta.jms.TopicConnection;
-import jakarta.jms.TopicConnectionFactory;
-import jakarta.jms.TopicPublisher;
-import jakarta.jms.TopicSession;
-import jakarta.jms.TopicSubscriber;
-
-public class MsgSelectorTopicTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.selectorTopic.MsgSelectorTopicTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- private transient Message msg = null;
-
- private transient TopicSubscriber subscriber = null;
-
- private transient TemporaryTopic tempT = null;
-
- private transient TopicPublisher publisher = null;
-
- private transient TopicConnection tConnect;
-
- private transient TopicSession session;
-
- private transient TopicConnectionFactory tFactory;
-
- private boolean transacted = false;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- private long jms_timeout;
-
- private String jmsUser = null;
-
- private String jmsPassword = null;
-
- private String mode = null;
-
- private boolean noLocal = false;
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- MsgSelectorTopicTests theTests = new MsgSelectorTopicTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * The beginning of the test creates receiver and message. This is broken
- * apart from the rest of the test so that the user can specify message
- * properties before sending the message.
- */
- private void startTest(String selector, String headerValue) throws Exception {
- logTrace("startTest(): Creating receiver with message selector");
-
- tempT = session.createTemporaryTopic();
- subscriber = session.createSubscriber(tempT, selector, noLocal);
-
- logTrace("Creating message");
- msg = session.createMessage();
- msg.setStringProperty("COM_SUN_JMS_TESTNAME", "MsgSelectorTopicTests");
- msg.setJMSType(headerValue);
- }
-
- /*
- * Send the message and try to receive it. Check the result against the
- * expectation.
- */
- private void finishTestReceive() throws Exception {
- logTrace("finishTestReceive(): Sending test message");
- msg.setBooleanProperty("first_message", true);
- // ii
- publisher = session.createPublisher(tempT);
-
- publisher.publish(msg);
- logTrace("Attempt to receive message");
- Message msg1 = subscriber.receive(jms_timeout);
- logTrace("Received message: " + msg1);
-
- // check result
- if (msg1 == null) {
- throw new Exception("Did not receive message!");
- } else if (msg1.getBooleanProperty("first_message") == true) {
- logTrace("test passed");
- } else {
- logMsg("Received completely unexpected message.");
- throw new Exception("Received unexpected message -- not part of test");
- }
- }
-
- /*
- * Send the message. Used with finishTest() to send a second message and make
- * sure that the first is not received my the message consumer.
- */
- private void sendFirstMessage() throws JMSException {
- logTrace(
- "sendFirstMessage(): Sending message that does not match selector");
- msg.setBooleanProperty("second_message", false);
- // ii
- publisher = session.createPublisher(tempT);
- publisher.publish(msg);
-
- msg = session.createMessage();
- msg.setStringProperty("COM_SUN_JMS_TESTNAME", "MsgSelectorTopicTests_2");
- }
-
- /*
- * Send the second message which does match the selector. Receive() and verify
- * that only this second message is received.
- */
- private void finishTest() throws Exception {
-
- logTrace("finishTest: Sending message that should match selector");
- msg.setBooleanProperty("second_message", true);
- publisher = session.createPublisher(tempT);
- publisher.publish(msg);
-
- logTrace("Attempt to receive message. Should receive second message only.");
- Message msg1 = subscriber.receive(jms_timeout);
- logTrace("Received message: " + msg1);
-
- // check result
- if (msg1 == null) {
- throw new Exception("Did not receive message!");
- } else if (msg1.getBooleanProperty("second_message") == true) {
- logTrace("test passed");
- } else if (msg1.getBooleanProperty("second_message") == false) {
- throw new Exception("Incorrectly received non-matching message!");
- }
- }
-
- /*
- * Cleanup method for tests that use durable subscriptions
- */
- private void cleanupSubscription(TopicSubscriber sub, TopicSession session,
- String subName) {
- if (sub != null) {
- try {
- TestUtil.logTrace("Closing durable subscriber: " + sub);
- sub.close();
- } catch (Exception e) {
- TestUtil.logErr("exception during close: ", e);
- }
- }
-
- if (session != null) {
- try {
- TestUtil.logTrace("Unsubscribing \"" + subName + "\"");
- session.unsubscribe(subName);
- } catch (Exception e) {
- TestUtil.logErr("exception during unsubscribe: ", e);
- }
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Individual tests create a temporary Topic
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- props = p;
- // get props
- jms_timeout = Long.parseLong(props.getProperty("jms_timeout"));
- // check props for errors
- if (jms_timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- jmsUser = props.getProperty("user");
- jmsPassword = props.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- tool = new JmsTool(JmsTool.TOPIC_FACTORY, jmsUser, jmsPassword, mode);
- tFactory = tool.getTopicConnectionFactory();
- tConnect = tFactory.createTopicConnection(jmsUser, jmsPassword);
- tConnect.start();
-
- session = tConnect.createTopicSession(transacted,
- Session.AUTO_ACKNOWLEDGE);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- logTrace(" closing connection");
- tConnect.close();
- tempT = null;
- session.close();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: selectorTest01
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:39;
- *
- * @test_Strategy: create receiver with selector set msg header to include
- * string send message check receipt of message
- */
- public void selectorTest01() throws Exception {
- try {
- String selector = "JMSType='literal'";
- String value = "literal"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: identifierTest01
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:43;
- *
- * @test_Strategy: create receiver with selector send message with identifiers
- * including '_' and '$' check receipt of message
- */
- public void identifierTest01() throws Exception {
- try {
- String selector = "$myProp=TRUE AND _myProp=FALSE";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("$myProp", true);
- msg.setBooleanProperty("_myProp", false);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: whitespaceTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:53;
- *
- * @test_Strategy: create receiver with selector containing extra spaces send
- * message with header set check receipt of message
- */
- public void whitespaceTest1() throws Exception {
- try {
- String selector = "JMSType = 'foo'";
- String value = "foo"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: expressionTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:54;
- *
- * @test_Strategy: create receiver with selector send message with TRUE
- * boolean property check receipt of message
- */
- public void expressionTest1() throws Exception {
- try {
- String selector = "myProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myProp", true);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: bracketingTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:57;
- *
- * @test_Strategy: create receiver with selector that should evaluate to FALSE
- * send message check that message is not received
- */
- public void bracketingTest1() throws Exception {
- try {
- String selector = "(myTrueProp OR myFalseProp) AND myFalseProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myTrueProp", true);
- msg.setBooleanProperty("myFalseProp", false);
- sendFirstMessage();
- msg.setBooleanProperty("myTrueProp", true);
- msg.setBooleanProperty("myFalseProp", true);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: comparisonTest01
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:59;
- *
- * @test_Strategy: create receiver with selector containing operators send
- * message with properties matching selector check receipt of message
- */
- public void comparisonTest01() throws Exception {
- try {
- String selector = "myProp0 = 'foo' AND " + "myProp1 > 0 AND "
- + "myProp2 >= 2 AND " + "myProp3 >= 2 AND " + "myProp4 < 5 AND "
- + "myProp5 <= 6 AND " + "myProp6 <= 6 AND " + "myProp7 <> 7";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp0", "foo");
- msg.setIntProperty("myProp1", 1);
- msg.setFloatProperty("myProp2", 2.0f);
- msg.setIntProperty("myProp3", 3);
- msg.setDoubleProperty("myProp4", 4.0);
- msg.setIntProperty("myProp5", 5);
- msg.setIntProperty("myProp6", 6);
- msg.setFloatProperty("myProp7", 0f);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: operatorTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:62;
- *
- * @test_Strategy: create receiver with selector containing +,- send message
- * with numeric properties check receipt of message
- */
- public void operatorTest1() throws Exception {
- try {
- String selector = "-myProp0 < 0 AND +myProp1 < 0";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setIntProperty("myProp0", 5);
- msg.setIntProperty("myProp1", -5);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: betweenTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
- *
- * @test_Strategy: create receiver with selector containing BETWEEN send
- * message matching selector check receipt of message
- */
- public void betweenTest1() throws Exception {
- try {
- String selector = "myProp0 BETWEEN 5 and 10 AND "
- + "myProp1 BETWEEN -1 and 1 AND " + "myProp2 BETWEEN 0 and 2";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setIntProperty("myProp0", 7);
- msg.setIntProperty("myProp1", -1);
- msg.setIntProperty("myProp2", 2);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: inTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
- *
- * @test_Strategy: create receiver with selector containing IN send message
- * matching selector check receipt of message
- */
- public void inTest1() throws Exception {
- try {
- String selector = "JMSType IN ('foo','jms','test')";
- String value = "jms"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: likeTest01
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
- *
- * @test_Strategy: create receiver with message selector containing LIKE send
- * message matching selector check receipt of message
- */
- public void likeTest01() throws Exception {
- try {
- String selector = "JMSType LIKE 'jms'";
- String value = "jms"; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: isNullTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:67;
- *
- * @test_Strategy: create receiver with message selector containing IS NULL
- * selector references unknown property send message check receipt of message
- */
- public void isNullTest1() throws Exception {
- try {
- String selector = "myNullProp IS NULL";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: caseTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:247;
- *
- * @test_Strategy: create receiver with message selector selector contains
- * lower case versions of selector operators send message matching selector
- * check receipt of message
- */
- public void caseTest1() throws Exception {
- try {
- String selector = "myProp0 is null and "
- + "myProp1 like 'fooG_%' escape 'G' and "
- + "myProp2 in ('a', 'b') and " + "myProp3 not between 0 and 10 and "
- + "(myProp4 or false)";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setStringProperty("myProp1", "foo_test");
- msg.setStringProperty("myProp2", "a");
- msg.setIntProperty("myProp3", 20);
- msg.setBooleanProperty("myProp4", true);
- finishTestReceive();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: precedenceTest1
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:58;
- *
- * @test_Strategy: create receiver with message selector containing AND and OR
- * send message not matching selector check that message is not received !F&F
- * = (!F)&F = T&F = F incorrect order would be !F&F -> !(F&F) = !F = T
- */
- public void precedenceTest1() throws Exception {
- try {
- String selector = "NOT myTrueProp AND myFalseProp";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myTrueProp", true);
- msg.setBooleanProperty("myFalseProp", false);
- sendFirstMessage();
- msg.setBooleanProperty("myTrueProp", false);
- msg.setBooleanProperty("myFalseProp", true);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest01
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:60;
- *
- * @test_Strategy: create receiver with selector referencing unknown property
- * send message check that message is not received
- */
- public void nullTest01() throws Exception {
- try {
- String selector = "myProp + 2 < 10";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- sendFirstMessage();
- msg.setIntProperty("myProp", 0);
- finishTest();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("test failed");
- }
- }
-
- /*
- * @testName: nullTest11
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:37;
- *
- * @test_Strategy: create receiver with null selector. check receipt of
- * message
- */
- public void nullTest11() throws Exception {
- try {
- String selector = null;
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myNullProp", false);
- finishTest();
- } catch (Exception e) {
- throw new Exception("test failed", e);
- }
- }
-
- /*
- * @testName: emptyTest
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:37;
- *
- * @test_Strategy: create receiver with empty selector. check receipt of
- * message
- */
- public void emptyTest() throws Exception {
- try {
- String selector = "";
- String value = ""; // set for JMSType automatically
-
- startTest(selector, value);
- msg.setBooleanProperty("myEmptyProp", false);
- finishTest();
- } catch (Exception e) {
- throw new Exception("test failed", e);
- }
- }
-
- /*
- * @testName: durableTopicEmptyStringSelTest
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:37;
- *
- * @test_Strategy: The javadoc documents the messageSelector parameter as
- * follows: A value of null or an empty string indicates that there is no
- * message selector for the message consumer.
- *
- * Test Case: Test with messageSelector = empty string.
- *
- * 1) Lookup durable connection factory (clientid set), topic, and create a
- * durable subscription with an empty string message selector for that topic
- * then close the connection. 2) Lookup non durable connection factory (no
- * clientid set), topic, send a TextMessage, then close the connection. 3)
- * Lookup durable connection factory (clientid set), topic and reactivate the
- * durable subscription created in step 1 above but this time not specifying a
- * message selector. Try and receive the message that was sent in step 2. The
- * message should be received. If message received then test passes. If no
- * message recevied then test failed.
- *
- */
- public void durableTopicEmptyStringSelTest() throws Exception {
- String lookupDurable = "DURABLE_SUB_CONNECTION_FACTORY";
- String lookupNonDurable = "MyTopicConnectionFactory";
- String msgSelectorEmptyString = "";
- TopicSubscriber durableTS = null;
- boolean noLocal = false;
- boolean pass = true;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Topic
- TestUtil.logMsg("TEST CASE [message selector=empty string] test case");
- TestUtil.logMsg("BEGIN STEP1");
- TestUtil.logMsg(
- "Setup JmsTool for TOPIC using connection factory with ClientID set");
- tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword,
- lookupDurable, mode);
-
- // create durable subscription with empty string message selector
- TestUtil
- .logMsg("Create durable subscription subname=mySubTestEmptyString,"
- + " msgSelector=\"\" and noLocal=false");
- tool.getDefaultTopicSubscriber().close();
- durableTS = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), "mySubTestEmptyString",
- msgSelectorEmptyString, noLocal);
- TestUtil.logMsg("Close connection and resources");
- durableTS.close();
- tool.closeAllResources();
- tool.getDefaultTopicConnection().close();
- TestUtil.logMsg("END STEP1");
-
- // set up test tool for Topic
- TestUtil.logMsg("BEGIN STEP2");
- TestUtil.logMsg(
- "Setup JmsTool for TOPIC using connection factory with no ClientID set");
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookupNonDurable,
- mode);
- tool.getDefaultTopicConnection().start();
-
- TestUtil.logMsg("Create a message and publish the message");
- messageSent = tool.getDefaultTopicSession()
- .createTextMessage("Hello There!");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableTopicEmptyStringSelTest");
- tool.getDefaultTopicPublisher().publish(messageSent);
-
- TestUtil.logMsg("Close connection and resources");
- tool.closeAllResources();
- tool.getDefaultTopicConnection().close();
- TestUtil.logMsg("END STEP2");
-
- // set up test tool for Topic
- TestUtil.logMsg("BEGIN STEP3");
- TestUtil.logMsg(
- "Setup JmsTool for TOPIC using connection factory with ClientID set");
- tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword,
- lookupDurable, mode);
-
- // Reactivate durable subscription created in step 1
- TestUtil.logMsg(
- "Reactivate durable subscription subname=mySubTestEmptyString in STEP1");
- tool.getDefaultTopicSubscriber().close();
- durableTS = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), "mySubTestEmptyString");
- tool.getDefaultTopicConnection().start();
-
- TestUtil.logMsg("Receive the message that was sent in STEP2");
- messageReceived = (TextMessage) durableTS.receive(jms_timeout);
- if (messageReceived == null) {
- TestUtil.logErr("didn't get the message");
- TestUtil.logErr("TEST CASE [message selector=empty string] failed");
- pass = false;
- } else if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message: text=["
- + messageReceived.getText() + "]");
- TestUtil.logMsg("TEST CASE [message selector=empty string] passed");
- } else {
- TestUtil.logErr("Received incorrect message: text=["
- + messageReceived.getText() + "] expected=[Hello There!]");
- TestUtil.logErr("didn't get the right message");
- TestUtil.logErr("TEST CASE [message selector=empty string] failed");
- pass = false;
- }
- TestUtil.logMsg("END STEP3");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("durableTopicEmptyStringSelTest failed");
- } finally {
- try {
- cleanupSubscription(durableTS, tool.getDefaultTopicSession(),
- "mySubTestEmptyString");
- tool.closeAllResources();
- tool.getDefaultTopicConnection().close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("durableTopicEmptyStringSelTest during cleanup");
- }
- }
-
- if (!pass)
- throw new Exception("durableTopicEmptyStringSelTest failed");
- }
-
- /*
- * @testName: durableTopicNullSelTest
- *
- * @assertion_ids: JMS:SPEC:36; JMS:SPEC:37;
- *
- * @test_Strategy: The javadoc documents the messageSelector parameter as
- * follows: A value of null or an empty string indicates that there is no
- * message selector for the message consumer.
- *
- * Test Case: Test with messageSelector = null.
- *
- * 1) Lookup durable connection factory (clientid set), topic, and create a
- * durable subscription with an empty string message selector for that topic
- * then close the connection. 2) Lookup non durable connection factory (no
- * clientid set), topic, send a TextMessage, then close the connection. 3)
- * Lookup durable connection factory (clientid set), topic and reactivate the
- * durable subscription created in step 1 above but this time not specifying a
- * message selector. Try and receive the message that was sent in step 2. The
- * message should be received. If message received then test passes. If no
- * message recevied then test failed.
- *
- */
- public void durableTopicNullSelTest() throws Exception {
- String lookupDurable = "DURABLE_SUB_CONNECTION_FACTORY";
- String lookupNonDurable = "MyTopicConnectionFactory";
- String msgSelectorNull = null;
- TopicSubscriber durableTS = null;
- boolean noLocal = false;
- boolean pass = true;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Topic
- TestUtil.logMsg("TEST CASE [message selector=null] test case");
- TestUtil.logMsg("BEGIN STEP1");
- TestUtil.logMsg(
- "Setup JmsTool for TOPIC using connection factory with ClientID set");
- tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword,
- lookupDurable, mode);
-
- // create durable subscription with null message selector
- TestUtil.logMsg("Create durable subscription subname=mySubTestNull,"
- + " msgSelector=null and noLocal=false");
- tool.getDefaultTopicSubscriber().close();
- durableTS = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), "mySubTestNull", msgSelectorNull, noLocal);
- TestUtil.logMsg("Close connection and resources");
- durableTS.close();
- tool.closeAllResources();
- tool.getDefaultTopicConnection().close();
- TestUtil.logMsg("END STEP1");
-
- // set up test tool for Topic
- TestUtil.logMsg("BEGIN STEP2");
- TestUtil.logMsg(
- "Setup JmsTool for TOPIC using connection factory with no ClientID set");
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookupNonDurable,
- mode);
- tool.getDefaultTopicConnection().start();
-
- TestUtil.logMsg("Create a message and publish the message");
- messageSent = tool.getDefaultTopicSession()
- .createTextMessage("Hello There!");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableTopicNullSelTest");
- tool.getDefaultTopicPublisher().publish(messageSent);
-
- TestUtil.logMsg("Close connection and resources");
- tool.closeAllResources();
- tool.getDefaultTopicConnection().close();
- TestUtil.logMsg("END STEP2");
-
- // set up test tool for Topic
- TestUtil.logMsg("BEGIN STEP3");
- TestUtil.logMsg(
- "Setup JmsTool for TOPIC using connection factory with ClientID set");
- tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword,
- lookupDurable, mode);
-
- // Reactivate durable subscription created in step 1
- TestUtil.logMsg(
- "Reactivate durable subscription subname=mySubTestNull in STEP1");
- tool.getDefaultTopicSubscriber().close();
- durableTS = tool.getDefaultTopicSession()
- .createDurableSubscriber(tool.getDefaultTopic(), "mySubTestNull");
- tool.getDefaultTopicConnection().start();
-
- TestUtil.logMsg("Receive the message that was sent in STEP2");
- messageReceived = (TextMessage) durableTS.receive(jms_timeout);
- if (messageReceived == null) {
- TestUtil.logErr("didn't get the message");
- TestUtil.logErr("TEST CASE [message selector=null] failed");
- pass = false;
- } else if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message: text=["
- + messageReceived.getText() + "]");
- TestUtil.logMsg("TEST CASE [message selector=null] passed");
- } else {
- TestUtil.logErr("Received incorrect message: text=["
- + messageReceived.getText() + "] expected=[Hello There!]");
- TestUtil.logErr("didn't get the right message");
- TestUtil.logErr("TEST CASE [message selector=null] failed");
- pass = false;
- }
- TestUtil.logMsg("END STEP3");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("durableTopicNullSelTest failed");
- } finally {
- try {
- cleanupSubscription(durableTS, tool.getDefaultTopicSession(),
- "mySubTestNull");
- tool.closeAllResources();
- tool.getDefaultTopicConnection().close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("durableTopicNullSelTest during cleanup");
- }
- }
-
- if (!pass)
- throw new Exception("durableTopicNullSelTest failed");
- }
-
-}// The End......
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/selectorTopic/MsgSelectorTopicTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/selectorTopic/MsgSelectorTopicTestsIT.java
new file mode 100644
index 0000000000..19eef73e46
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/selectorTopic/MsgSelectorTopicTestsIT.java
@@ -0,0 +1,874 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.selectorTopic;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.JMSException;
+import jakarta.jms.Message;
+import jakarta.jms.Session;
+import jakarta.jms.TemporaryTopic;
+import jakarta.jms.TextMessage;
+import jakarta.jms.TopicConnection;
+import jakarta.jms.TopicConnectionFactory;
+import jakarta.jms.TopicPublisher;
+import jakarta.jms.TopicSession;
+import jakarta.jms.TopicSubscriber;
+
+
+public class MsgSelectorTopicTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.selectorTopic.MsgSelectorTopicTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgSelectorTopicTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ private transient Message msg = null;
+
+ private transient TopicSubscriber subscriber = null;
+
+ private transient TemporaryTopic tempT = null;
+
+ private transient TopicPublisher publisher = null;
+
+ private transient TopicConnection tConnect;
+
+ private transient TopicSession session;
+
+ private transient TopicConnectionFactory tFactory;
+
+ private boolean transacted = false;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ private long jms_timeout;
+
+ private String jmsUser = null;
+
+ private String jmsPassword = null;
+
+ private String mode = null;
+
+ private boolean noLocal = false;
+
+ /* Utility methods for tests */
+
+ /*
+ * The beginning of the test creates receiver and message. This is broken apart
+ * from the rest of the test so that the user can specify message properties
+ * before sending the message.
+ */
+ private void startTest(String selector, String headerValue) throws Exception {
+ logger.log(Logger.Level.TRACE, "startTest(): Creating receiver with message selector");
+
+ tempT = session.createTemporaryTopic();
+ subscriber = session.createSubscriber(tempT, selector, noLocal);
+
+ logger.log(Logger.Level.TRACE, "Creating message");
+ msg = session.createMessage();
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "MsgSelectorTopicTests");
+ msg.setJMSType(headerValue);
+ }
+
+ /*
+ * Send the message and try to receive it. Check the result against the
+ * expectation.
+ */
+ private void finishTestReceive() throws Exception {
+ logger.log(Logger.Level.TRACE, "finishTestReceive(): Sending test message");
+ msg.setBooleanProperty("first_message", true);
+ // ii
+ publisher = session.createPublisher(tempT);
+
+ publisher.publish(msg);
+ logger.log(Logger.Level.TRACE, "Attempt to receive message");
+ Message msg1 = subscriber.receive(jms_timeout);
+ logger.log(Logger.Level.TRACE, "Received message: " + msg1);
+
+ // check result
+ if (msg1 == null) {
+ throw new Exception("Did not receive message!");
+ } else if (msg1.getBooleanProperty("first_message") == true) {
+ logger.log(Logger.Level.TRACE, "test passed");
+ } else {
+ logger.log(Logger.Level.INFO, "Received completely unexpected message.");
+ throw new Exception("Received unexpected message -- not part of test");
+ }
+ }
+
+ /*
+ * Send the message. Used with finishTest() to send a second message and make
+ * sure that the first is not received my the message consumer.
+ */
+ private void sendFirstMessage() throws JMSException {
+ logger.log(Logger.Level.TRACE, "sendFirstMessage(): Sending message that does not match selector");
+ msg.setBooleanProperty("second_message", false);
+ // ii
+ publisher = session.createPublisher(tempT);
+ publisher.publish(msg);
+
+ msg = session.createMessage();
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "MsgSelectorTopicTests_2");
+ }
+
+ /*
+ * Send the second message which does match the selector. Receive() and verify
+ * that only this second message is received.
+ */
+ private void finishTest() throws Exception {
+
+ logger.log(Logger.Level.TRACE, "finishTest: Sending message that should match selector");
+ msg.setBooleanProperty("second_message", true);
+ publisher = session.createPublisher(tempT);
+ publisher.publish(msg);
+
+ logger.log(Logger.Level.TRACE, "Attempt to receive message. Should receive second message only.");
+ Message msg1 = subscriber.receive(jms_timeout);
+ logger.log(Logger.Level.TRACE, "Received message: " + msg1);
+
+ // check result
+ if (msg1 == null) {
+ throw new Exception("Did not receive message!");
+ } else if (msg1.getBooleanProperty("second_message") == true) {
+ logger.log(Logger.Level.TRACE, "test passed");
+ } else if (msg1.getBooleanProperty("second_message") == false) {
+ throw new Exception("Incorrectly received non-matching message!");
+ }
+ }
+
+ /*
+ * Cleanup method for tests that use durable subscriptions
+ */
+ private void cleanupSubscription(TopicSubscriber sub, TopicSession session, String subName) {
+ if (sub != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Closing durable subscriber: " + sub);
+ sub.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "exception during close: ", e);
+ }
+ }
+
+ if (session != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Unsubscribing \"" + subName + "\"");
+ session.unsubscribe(subName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "exception during unsubscribe: ", e);
+ }
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Individual tests create a temporary Topic
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ jms_timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ // check props for errors
+ if (jms_timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ tool = new JmsTool(JmsTool.TOPIC_FACTORY, jmsUser, jmsPassword, mode);
+ tFactory = tool.getTopicConnectionFactory();
+ tConnect = tFactory.createTopicConnection(jmsUser, jmsPassword);
+ tConnect.start();
+
+ session = tConnect.createTopicSession(transacted, Session.AUTO_ACKNOWLEDGE);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, " closing connection");
+ tConnect.close();
+ tempT = null;
+ session.close();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: selectorTest01
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:55; JMS:SPEC:49; JMS:SPEC:39;
+ *
+ * @test_Strategy: create receiver with selector set msg header to include
+ * string send message check receipt of message
+ */
+ @Test
+ public void selectorTest01() throws Exception {
+ try {
+ String selector = "JMSType='literal'";
+ String value = "literal"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: identifierTest01
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:56; JMS:SPEC:49; JMS:SPEC:43;
+ *
+ * @test_Strategy: create receiver with selector send message with identifiers
+ * including '_' and '$' check receipt of message
+ */
+ @Test
+ public void identifierTest01() throws Exception {
+ try {
+ String selector = "$myProp=TRUE AND _myProp=FALSE";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("$myProp", true);
+ msg.setBooleanProperty("_myProp", false);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: whitespaceTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:53;
+ *
+ * @test_Strategy: create receiver with selector containing extra spaces send
+ * message with header set check receipt of message
+ */
+ @Test
+ public void whitespaceTest1() throws Exception {
+ try {
+ String selector = "JMSType = 'foo'";
+ String value = "foo"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: expressionTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:54;
+ *
+ * @test_Strategy: create receiver with selector send message with TRUE boolean
+ * property check receipt of message
+ */
+ @Test
+ public void expressionTest1() throws Exception {
+ try {
+ String selector = "myProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myProp", true);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: bracketingTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:57;
+ *
+ * @test_Strategy: create receiver with selector that should evaluate to FALSE
+ * send message check that message is not received
+ */
+ @Test
+ public void bracketingTest1() throws Exception {
+ try {
+ String selector = "(myTrueProp OR myFalseProp) AND myFalseProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myTrueProp", true);
+ msg.setBooleanProperty("myFalseProp", false);
+ sendFirstMessage();
+ msg.setBooleanProperty("myTrueProp", true);
+ msg.setBooleanProperty("myFalseProp", true);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: comparisonTest01
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:59;
+ *
+ * @test_Strategy: create receiver with selector containing operators send
+ * message with properties matching selector check receipt of message
+ */
+ @Test
+ public void comparisonTest01() throws Exception {
+ try {
+ String selector = "myProp0 = 'foo' AND " + "myProp1 > 0 AND " + "myProp2 >= 2 AND " + "myProp3 >= 2 AND "
+ + "myProp4 < 5 AND " + "myProp5 <= 6 AND " + "myProp6 <= 6 AND " + "myProp7 <> 7";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp0", "foo");
+ msg.setIntProperty("myProp1", 1);
+ msg.setFloatProperty("myProp2", 2.0f);
+ msg.setIntProperty("myProp3", 3);
+ msg.setDoubleProperty("myProp4", 4.0);
+ msg.setIntProperty("myProp5", 5);
+ msg.setIntProperty("myProp6", 6);
+ msg.setFloatProperty("myProp7", 0f);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: operatorTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:62;
+ *
+ * @test_Strategy: create receiver with selector containing +,- send message
+ * with numeric properties check receipt of message
+ */
+ @Test
+ public void operatorTest1() throws Exception {
+ try {
+ String selector = "-myProp0 < 0 AND +myProp1 < 0";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setIntProperty("myProp0", 5);
+ msg.setIntProperty("myProp1", -5);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: betweenTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:64;
+ *
+ * @test_Strategy: create receiver with selector containing BETWEEN send message
+ * matching selector check receipt of message
+ */
+ @Test
+ public void betweenTest1() throws Exception {
+ try {
+ String selector = "myProp0 BETWEEN 5 and 10 AND " + "myProp1 BETWEEN -1 and 1 AND "
+ + "myProp2 BETWEEN 0 and 2";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setIntProperty("myProp0", 7);
+ msg.setIntProperty("myProp1", -1);
+ msg.setIntProperty("myProp2", 2);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: inTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:65;
+ *
+ * @test_Strategy: create receiver with selector containing IN send message
+ * matching selector check receipt of message
+ */
+ @Test
+ public void inTest1() throws Exception {
+ try {
+ String selector = "JMSType IN ('foo','jms','test')";
+ String value = "jms"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: likeTest01
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:66;
+ *
+ * @test_Strategy: create receiver with message selector containing LIKE send
+ * message matching selector check receipt of message
+ */
+ @Test
+ public void likeTest01() throws Exception {
+ try {
+ String selector = "JMSType LIKE 'jms'";
+ String value = "jms"; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: isNullTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:67;
+ *
+ * @test_Strategy: create receiver with message selector containing IS NULL
+ * selector references unknown property send message check receipt of message
+ */
+ @Test
+ public void isNullTest1() throws Exception {
+ try {
+ String selector = "myNullProp IS NULL";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: caseTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:247;
+ *
+ * @test_Strategy: create receiver with message selector selector contains lower
+ * case versions of selector operators send message matching selector check
+ * receipt of message
+ */
+ @Test
+ public void caseTest1() throws Exception {
+ try {
+ String selector = "myProp0 is null and " + "myProp1 like 'fooG_%' escape 'G' and "
+ + "myProp2 in ('a', 'b') and " + "myProp3 not between 0 and 10 and " + "(myProp4 or false)";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setStringProperty("myProp1", "foo_test");
+ msg.setStringProperty("myProp2", "a");
+ msg.setIntProperty("myProp3", 20);
+ msg.setBooleanProperty("myProp4", true);
+ finishTestReceive();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: precedenceTest1
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:58;
+ *
+ * @test_Strategy: create receiver with message selector containing AND and OR
+ * send message not matching selector check that message is not received !F&F =
+ * (!F)&F = T&F = F incorrect order would be !F&F -> !(F&F) = !F = T
+ */
+ @Test
+ public void precedenceTest1() throws Exception {
+ try {
+ String selector = "NOT myTrueProp AND myFalseProp";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myTrueProp", true);
+ msg.setBooleanProperty("myFalseProp", false);
+ sendFirstMessage();
+ msg.setBooleanProperty("myTrueProp", false);
+ msg.setBooleanProperty("myFalseProp", true);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest01
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:49; JMS:SPEC:60;
+ *
+ * @test_Strategy: create receiver with selector referencing unknown property
+ * send message check that message is not received
+ */
+ @Test
+ public void nullTest01() throws Exception {
+ try {
+ String selector = "myProp + 2 < 10";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ sendFirstMessage();
+ msg.setIntProperty("myProp", 0);
+ finishTest();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("test failed");
+ }
+ }
+
+ /*
+ * @testName: nullTest11
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:37;
+ *
+ * @test_Strategy: create receiver with null selector. check receipt of message
+ */
+ @Test
+ public void nullTest11() throws Exception {
+ try {
+ String selector = null;
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myNullProp", false);
+ finishTest();
+ } catch (Exception e) {
+ throw new Exception("test failed", e);
+ }
+ }
+
+ /*
+ * @testName: emptyTest
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:37;
+ *
+ * @test_Strategy: create receiver with empty selector. check receipt of message
+ */
+ @Test
+ public void emptyTest() throws Exception {
+ try {
+ String selector = "";
+ String value = ""; // set for JMSType automatically
+
+ startTest(selector, value);
+ msg.setBooleanProperty("myEmptyProp", false);
+ finishTest();
+ } catch (Exception e) {
+ throw new Exception("test failed", e);
+ }
+ }
+
+ /*
+ * @testName: durableTopicEmptyStringSelTest
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:37;
+ *
+ * @test_Strategy: The javadoc documents the messageSelector parameter as
+ * follows: A value of null or an empty string indicates that there is no
+ * message selector for the message consumer.
+ *
+ * Test Case: Test with messageSelector = empty string.
+ *
+ * 1) Lookup durable connection factory (clientid set), topic, and create a
+ * durable subscription with an empty string message selector for that topic
+ * then close the connection. 2) Lookup non durable connection factory (no
+ * clientid set), topic, send a TextMessage, then close the connection. 3)
+ * Lookup durable connection factory (clientid set), topic and reactivate the
+ * durable subscription created in step 1 above but this time not specifying a
+ * message selector. Try and receive the message that was sent in step 2. The
+ * message should be received. If message received then test passes. If no
+ * message recevied then test failed.
+ *
+ */
+ @Test
+ public void durableTopicEmptyStringSelTest() throws Exception {
+ String lookupDurable = "DURABLE_SUB_CONNECTION_FACTORY";
+ String lookupNonDurable = "MyTopicConnectionFactory";
+ String msgSelectorEmptyString = "";
+ TopicSubscriber durableTS = null;
+ boolean noLocal = false;
+ boolean pass = true;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "TEST CASE [message selector=empty string] test case");
+ logger.log(Logger.Level.INFO, "BEGIN STEP1");
+ logger.log(Logger.Level.INFO, "Setup JmsTool for TOPIC using connection factory with ClientID set");
+ tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookupDurable, mode);
+
+ // create durable subscription with empty string message selector
+ logger.log(Logger.Level.INFO, "Create durable subscription subname=mySubTestEmptyString,"
+ + " msgSelector=\"\" and noLocal=false");
+ tool.getDefaultTopicSubscriber().close();
+ durableTS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ "mySubTestEmptyString", msgSelectorEmptyString, noLocal);
+ logger.log(Logger.Level.INFO, "Close connection and resources");
+ durableTS.close();
+ tool.closeAllResources();
+ tool.getDefaultTopicConnection().close();
+ logger.log(Logger.Level.INFO, "END STEP1");
+
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "BEGIN STEP2");
+ logger.log(Logger.Level.INFO, "Setup JmsTool for TOPIC using connection factory with no ClientID set");
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookupNonDurable, mode);
+ tool.getDefaultTopicConnection().start();
+
+ logger.log(Logger.Level.INFO, "Create a message and publish the message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage("Hello There!");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableTopicEmptyStringSelTest");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+
+ logger.log(Logger.Level.INFO, "Close connection and resources");
+ tool.closeAllResources();
+ tool.getDefaultTopicConnection().close();
+ logger.log(Logger.Level.INFO, "END STEP2");
+
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "BEGIN STEP3");
+ logger.log(Logger.Level.INFO, "Setup JmsTool for TOPIC using connection factory with ClientID set");
+ tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookupDurable, mode);
+
+ // Reactivate durable subscription created in step 1
+ logger.log(Logger.Level.INFO, "Reactivate durable subscription subname=mySubTestEmptyString in STEP1");
+ tool.getDefaultTopicSubscriber().close();
+ durableTS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ "mySubTestEmptyString");
+ tool.getDefaultTopicConnection().start();
+
+ logger.log(Logger.Level.INFO, "Receive the message that was sent in STEP2");
+ messageReceived = (TextMessage) durableTS.receive(jms_timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "didn't get the message");
+ logger.log(Logger.Level.ERROR, "TEST CASE [message selector=empty string] failed");
+ pass = false;
+ } else if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message: text=[" + messageReceived.getText() + "]");
+ logger.log(Logger.Level.INFO, "TEST CASE [message selector=empty string] passed");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Received incorrect message: text=[" + messageReceived.getText() + "] expected=[Hello There!]");
+ logger.log(Logger.Level.ERROR, "didn't get the right message");
+ logger.log(Logger.Level.ERROR, "TEST CASE [message selector=empty string] failed");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "END STEP3");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("durableTopicEmptyStringSelTest failed");
+ } finally {
+ try {
+ cleanupSubscription(durableTS, tool.getDefaultTopicSession(), "mySubTestEmptyString");
+ tool.closeAllResources();
+ tool.getDefaultTopicConnection().close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("durableTopicEmptyStringSelTest during cleanup");
+ }
+ }
+
+ if (!pass)
+ throw new Exception("durableTopicEmptyStringSelTest failed");
+ }
+
+ /*
+ * @testName: durableTopicNullSelTest
+ *
+ * @assertion_ids: JMS:SPEC:36; JMS:SPEC:37;
+ *
+ * @test_Strategy: The javadoc documents the messageSelector parameter as
+ * follows: A value of null or an empty string indicates that there is no
+ * message selector for the message consumer.
+ *
+ * Test Case: Test with messageSelector = null.
+ *
+ * 1) Lookup durable connection factory (clientid set), topic, and create a
+ * durable subscription with an empty string message selector for that topic
+ * then close the connection. 2) Lookup non durable connection factory (no
+ * clientid set), topic, send a TextMessage, then close the connection. 3)
+ * Lookup durable connection factory (clientid set), topic and reactivate the
+ * durable subscription created in step 1 above but this time not specifying a
+ * message selector. Try and receive the message that was sent in step 2. The
+ * message should be received. If message received then test passes. If no
+ * message recevied then test failed.
+ *
+ */
+ @Test
+ public void durableTopicNullSelTest() throws Exception {
+ String lookupDurable = "DURABLE_SUB_CONNECTION_FACTORY";
+ String lookupNonDurable = "MyTopicConnectionFactory";
+ String msgSelectorNull = null;
+ TopicSubscriber durableTS = null;
+ boolean noLocal = false;
+ boolean pass = true;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "TEST CASE [message selector=null] test case");
+ logger.log(Logger.Level.INFO, "BEGIN STEP1");
+ logger.log(Logger.Level.INFO, "Setup JmsTool for TOPIC using connection factory with ClientID set");
+ tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookupDurable, mode);
+
+ // create durable subscription with null message selector
+ logger.log(Logger.Level.INFO,
+ "Create durable subscription subname=mySubTestNull," + " msgSelector=null and noLocal=false");
+ tool.getDefaultTopicSubscriber().close();
+ durableTS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(), "mySubTestNull",
+ msgSelectorNull, noLocal);
+ logger.log(Logger.Level.INFO, "Close connection and resources");
+ durableTS.close();
+ tool.closeAllResources();
+ tool.getDefaultTopicConnection().close();
+ logger.log(Logger.Level.INFO, "END STEP1");
+
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "BEGIN STEP2");
+ logger.log(Logger.Level.INFO, "Setup JmsTool for TOPIC using connection factory with no ClientID set");
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookupNonDurable, mode);
+ tool.getDefaultTopicConnection().start();
+
+ logger.log(Logger.Level.INFO, "Create a message and publish the message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage("Hello There!");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableTopicNullSelTest");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+
+ logger.log(Logger.Level.INFO, "Close connection and resources");
+ tool.closeAllResources();
+ tool.getDefaultTopicConnection().close();
+ logger.log(Logger.Level.INFO, "END STEP2");
+
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "BEGIN STEP3");
+ logger.log(Logger.Level.INFO, "Setup JmsTool for TOPIC using connection factory with ClientID set");
+ tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookupDurable, mode);
+
+ // Reactivate durable subscription created in step 1
+ logger.log(Logger.Level.INFO, "Reactivate durable subscription subname=mySubTestNull in STEP1");
+ tool.getDefaultTopicSubscriber().close();
+ durableTS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(), "mySubTestNull");
+ tool.getDefaultTopicConnection().start();
+
+ logger.log(Logger.Level.INFO, "Receive the message that was sent in STEP2");
+ messageReceived = (TextMessage) durableTS.receive(jms_timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "didn't get the message");
+ logger.log(Logger.Level.ERROR, "TEST CASE [message selector=null] failed");
+ pass = false;
+ } else if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message: text=[" + messageReceived.getText() + "]");
+ logger.log(Logger.Level.INFO, "TEST CASE [message selector=null] passed");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Received incorrect message: text=[" + messageReceived.getText() + "] expected=[Hello There!]");
+ logger.log(Logger.Level.ERROR, "didn't get the right message");
+ logger.log(Logger.Level.ERROR, "TEST CASE [message selector=null] failed");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "END STEP3");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("durableTopicNullSelTest failed");
+ } finally {
+ try {
+ cleanupSubscription(durableTS, tool.getDefaultTopicSession(), "mySubTestNull");
+ tool.closeAllResources();
+ tool.getDefaultTopicConnection().close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("durableTopicNullSelTest during cleanup");
+ }
+ }
+
+ if (!pass)
+ throw new Exception("durableTopicNullSelTest failed");
+ }
+
+}// The End......
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/sessiontests/SessionTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/sessiontests/SessionTests.java
deleted file mode 100644
index 0606863b70..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/sessiontests/SessionTests.java
+++ /dev/null
@@ -1,1021 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.sessiontests;
-
-import java.util.Enumeration;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.Connection;
-import jakarta.jms.Destination;
-import jakarta.jms.InvalidDestinationException;
-import jakarta.jms.InvalidSelectorException;
-import jakarta.jms.MessageConsumer;
-import jakarta.jms.MessageProducer;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueBrowser;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicSubscriber;
-
-public class SessionTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.sessiontests.SessionTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- SessionTests theTests = new SessionTests();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- }
-
- /* Tests */
-
- /*
- * @testName: SimpleSendAndReceiveQ
- *
- * @assertion_ids: JMS:SPEC:195; JMS:JAVADOC:502; JMS:JAVADOC:504;
- * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
- * JMS:JAVADOC:317; JMS:JAVADOC:334;
- *
- * @test_Strategy: Create a Text Message, send use a MessageProducer and
- * receive it use a MessageConsumer via a Queue.
- */
- public void SimpleSendAndReceiveQ() throws Exception {
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultConnection().start();
-
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "SimpleSendAndReceiveQ");
-
- // send the message and then get it back
- logTrace("Sending message to a Queue");
- tool.getDefaultProducer().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultConsumer()
- .receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- logMsg("Message text: \"" + messageReceived.getText() + "\"");
- logMsg("Received correct message");
- } else {
- logErr("didn't get the right message using Queue");
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("SimpleSendAndReceiveQ Failed!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("SimpleSendAndReceiveQ");
- } finally {
- try {
- tool.closeDefaultConnections();
- tool.flushDestination();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: SimpleSendAndReceiveT
- *
- * @assertion_ids: JMS:SPEC:196; JMS:JAVADOC:502; JMS:JAVADOC:504;
- * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
- * JMS:JAVADOC:317; JMS:JAVADOC:334;
- *
- * @test_Strategy: Create a Text Message, send use a MessageProducer and
- * receive it use a MessageConsumer via a Topic.
- */
- public void SimpleSendAndReceiveT() throws Exception {
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- boolean pass = true;
-
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- tool.getDefaultConnection().start();
-
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "SimpleSendAndReceiveT");
-
- // send the message and then get it back
- logTrace("Sending message to a Topic");
- tool.getDefaultProducer().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultConsumer()
- .receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- logMsg("Message text: \"" + messageReceived.getText() + "\"");
- logMsg("Received correct message");
- } else {
- logErr("didn't get the right message");
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("SimpleSendAndReceiveT Failed!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("SimpleSendAndReceiveT");
- } finally {
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: selectorAndBrowserTests
- *
- * @assertion_ids: JMS:SPEC:195; JMS:JAVADOC:502; JMS:JAVADOC:504;
- * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:246;
- * JMS:JAVADOC:317; JMS:JAVADOC:334; JMS:JAVADOC:338; JMS:JAVADOC:258;
- * JMS:JAVADOC:260; JMS:JAVADOC:221; JMS:SPEC:148; JMS:SPEC:149;
- * JMS:JAVADOC:278; JMS:JAVADOC:280; JMS:JAVADOC:288; JMS:JAVADOC:282;
- * JMS:JAVADOC:284;
- *
- * @test_Strategy: 1. Create two TextMessages, send use a MessageProducer 2.
- * Create a QueueBrowser to browse the Queue so that all two messages can be
- * seen. 3. Create a QueueBrowser with selector to browse the Queue so that
- * only one message can be seen; 4. Create a MessageConsumer with a message
- * selector so that only last message received. 5. Then create another
- * MessageConsumer to verify all messages except the last message can be
- * received from the Queue.
- */
- public void selectorAndBrowserTests() throws Exception {
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TextMessage tempMsg = null;
- boolean pass = true;
- int numMessages = 2;
- QueueBrowser browseAll = null;
- QueueBrowser selectiveBrowser = null;
- String message = "Just a Test Message from JMS TCK";
-
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultConsumer().close();
- tool.getDefaultConnection().start();
-
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "selectorAndBrowserTests");
- messageSent.setText(message);
- messageSent.setBooleanProperty("lastMessage", false);
- tool.getDefaultProducer().send(messageSent);
-
- messageSent.setStringProperty("TEST", "test");
- messageSent.setBooleanProperty("lastMessage", true);
- tool.getDefaultProducer().send(messageSent);
-
- // check the browser w/o selector
- browseAll = tool.getDefaultSession()
- .createBrowser((Queue) tool.getDefaultDestination());
-
- // getting Emumeration that contains at least two test messages
- // without getting into dead loop.
- // Workaround for possible timing problem
- int msgCount = 0;
- Enumeration msgs = null;
- int i = 0;
- do {
- i++;
- msgCount = 0;
- msgs = browseAll.getEnumeration();
- TestUtil.logTrace("getting Enumeration " + i);
- while (msgs.hasMoreElements()) {
- tempMsg = (TextMessage) msgs.nextElement();
- if (tempMsg.getText().equals(messageSent.getText()))
- msgCount++;
- }
- TestUtil.logTrace("found " + msgCount + " messages total in browser");
- } while ((msgCount < 2) && (i < 10));
-
- if (!browseAll.getQueue().toString()
- .equals(tool.getDefaultDestination().toString())) {
- pass = false;
- logErr("Error: QueueBrowser.getQueue test failed");
- logErr(
- "QueueBrowser.getQueue=" + browseAll.getQueue().toString() + ".");
- logErr("tool.getDefaultDestination()="
- + tool.getDefaultDestination().toString() + ".");
- }
-
- browseAll.close();
-
- // Browse with selective QueueBrowser
- selectiveBrowser = tool.getDefaultSession()
- .createBrowser((Queue) tool.getDefaultDestination(), "TEST = 'test'");
-
- // getting Emumeration that contains at least two test messages
- // without getting into dead loop.
- // Workaround for possible timing problem
- i = 0;
- do {
- i++;
- msgCount = 0;
- msgs = selectiveBrowser.getEnumeration();
- TestUtil.logTrace("getting Enumeration " + i);
- while (msgs.hasMoreElements()) {
- tempMsg = (TextMessage) msgs.nextElement();
- if (tempMsg.getText().equals(messageSent.getText()))
- msgCount++;
- }
- TestUtil.logTrace("found " + msgCount + " messages total in browser");
- } while ((msgCount < 1) && (i < 10));
-
- String tmp = selectiveBrowser.getMessageSelector();
- if (tmp.indexOf("TEST") < 0 || tmp.indexOf("test") < 0) {
- pass = false;
- logErr("Error: QueueBrowser.getMessageSelector test failed");
- logErr("selectiveBrowser.getMessageSelector()="
- + selectiveBrowser.getMessageSelector());
- }
- selectiveBrowser.close();
-
- // check selective consumer
- MessageConsumer SelectorConsumer = tool.getDefaultSession()
- .createConsumer(tool.getDefaultDestination(), "TEST = 'test'");
- logTrace("Receiving message with selective consumer");
- messageReceived = (TextMessage) SelectorConsumer.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- logErr("Did not receive expected message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
- pass = false;
- logErr("Received incorrect message");
- }
- SelectorConsumer.close();
-
- // receive all remaining messages
- MessageConsumer qRec = tool.getDefaultSession()
- .createConsumer(tool.getDefaultDestination());
- logTrace("Receiving the remaining message");
- messageReceived = (TextMessage) qRec.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- logErr("message did not remain on queue");
- } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
- pass = false;
- logErr("received incorrect message");
- }
- qRec.close();
-
- if (pass != true)
- throw new Exception("selectorAndBrowserTests Failed!");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("selectorAndBrowserTests");
- } finally {
- try {
- tool.closeDefaultConnections();
- tool.flushDestination();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: SubscriberTests
- *
- * @assertion_ids: JMS:SPEC:196; JMS:SPEC:89; JMS:SPEC:162; JMS:JAVADOC:502;
- * JMS:JAVADOC:504; JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244;
- * JMS:JAVADOC:254; JMS:JAVADOC:256; JMS:JAVADOC:266;
- *
- * @test_Strategy: 1. Create a new second connection and send two
- * TextMessages. 2. Create a DurableSubscriber defaultSub to verify all
- * messages received. 3. Create another DurableSubscriber tSubNoLocal with
- * noLocal set to true, and verify that no message can be received. 4. Create
- * another DurableSubscriber tSubSelect off the new connection with selector
- * to verify only one message received. 5. Send a message from from default
- * connection. 6. Verify that tSubNoLocal can receive the message from the
- * default connection 7. Unsubscribe the 3 durable subscriptions created
- * above.
- */
- public void SubscriberTests() throws Exception {
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TextMessage tempMsg = null;
- int numMessages = 2;
- boolean pass = true;
- TopicSubscriber defaultSub = null;
- TopicSubscriber tSubSelect = null;
- TopicSubscriber tSubNoLocal = null;
- String subscriptionName1 = "DurableSubscriberNoLocal";
- String subscriptionName2 = "DurableSubscriberSelect";
- String subscriptionName3 = "DurableSubscriberDefault";
- Connection newConn = null;
- Session newSess = null;
- MessageProducer newPub = null;
- String clientID = "CTS";
-
- try {
- logTrace("Setup tool for COMMON_T setup");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
-
- logTrace("Create second connection and second session");
- newConn = tool.getNewConnection(JmsTool.COMMON_T, user, password, lookup);
- newSess = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- logTrace(
- "Create 3 durabale subscriptions (default, selector, nolocal) using second session");
- tSubNoLocal = newSess.createDurableSubscriber(
- (Topic) tool.getDefaultDestination(), subscriptionName1, "", true);
- tSubSelect = newSess.createDurableSubscriber(
- (Topic) tool.getDefaultDestination(), subscriptionName2,
- "TEST = 'test'", false);
- defaultSub = newSess.createDurableSubscriber(
- (Topic) tool.getDefaultDestination(), subscriptionName3);
- logTrace("Create producer using second session");
- newPub = newSess.createProducer(tool.getDefaultDestination());
-
- tool.getDefaultConnection().start();
- newConn.start();
-
- // Create and send two messages from new connection
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText("Just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "SubscriberTests");
- logTrace("Sending message to a Topic");
- messageSent.setBooleanProperty("lastMessage", false);
- newPub.send(messageSent);
- messageSent.setStringProperty("TEST", "test");
- messageSent.setBooleanProperty("lastMessage", true);
- newPub.send(messageSent);
-
- // Verify that tSubNoLocal cannot receive any message
- logTrace("tSubNoLocal Receiving message");
- messageReceived = (TextMessage) tSubNoLocal.receive(timeout);
- if (messageReceived != null) {
- pass = false;
- logErr("Error: No_local subscriber did receive local message");
- }
-
- // Verify that defaultSub received correct messages
- logTrace("defaultSub Receiving message");
- for (int i = 0; i < numMessages; i++) {
- messageReceived = (TextMessage) defaultSub.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- logErr("Error: Did not receive message " + i);
- } else if (messageReceived.getText().equals(messageSent.getText())) {
- logMsg("Message text: \"" + messageReceived.getText() + "\"");
- logMsg("Received correct message " + i);
- } else {
- logErr("Error: didn't get the right message " + i);
- pass = false;
- }
- }
-
- // Verify that tSubSelect only receive the last message
- logTrace("tSubSelect Receiving message");
- messageReceived = (TextMessage) tSubSelect.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- logErr("Error: Did not receive correct message");
- } else if (messageReceived.getText().equals(messageSent.getText())) {
- logMsg("Message text: \"" + messageReceived.getText() + "\"");
- logMsg("Received correct message");
- } else {
- logErr("Error: didn't get the right message");
- pass = false;
- }
-
- // send message from default connection
- logTrace("sending message from default connection");
- messageSent.setBooleanProperty("newConnection", true);
- tool.getDefaultProducer().send(messageSent);
-
- // Verify that tSubNoLocal now can receive message from second connection
- logTrace("tSubNoLocal Receiving message");
- messageReceived = (TextMessage) tSubNoLocal.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- logErr("Error: Did not receive correct message");
- } else if (messageReceived.getText().equals(messageSent.getText())) {
- logMsg("Message text: \"" + messageReceived.getText() + "\"");
- logMsg("Received correct message");
- } else {
- logErr("Error: didn't get the right message");
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("SubscriberTests Failed!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("SubscriberTests");
- } finally {
- try {
- logTrace("Close 3 durable subscriptions");
- tSubNoLocal.close();
- defaultSub.close();
- tSubSelect.close();
- logTrace("Unsubscribe from 3 durable subscriptions");
- newSess.unsubscribe(subscriptionName1);
- newSess.unsubscribe(subscriptionName2);
- newSess.unsubscribe(subscriptionName3);
- } catch (Exception ex) {
- logErr("Error closing subscribers and unsubscribing from subscriptions",
- ex);
- }
- try {
- logTrace("Closing new connection");
- newConn.close();
- } catch (Exception ex) {
- logErr("Error closing the second Connection", ex);
- }
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Default Connection", ex);
- }
- }
- }
-
- /*
- * @testName: IllegalStateTestQ
- *
- * @assertion_ids: JMS:SPEC:195; JMS:JAVADOC:502; JMS:JAVADOC:504;
- * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:635; JMS:JAVADOC:317;
- *
- * @test_Strategy: 1. Create a TextMessages, send use a MessageProducer 2.
- * Then rollback on the non-transacted session Verify that
- * IllegalStateException is thrown
- */
- public void IllegalStateTestQ() throws Exception {
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- boolean pass = true;
-
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultConnection().start();
-
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "IllegalStateTestQ");
-
- // send the message and then get it back
- logTrace("Sending message to a Queue");
- tool.getDefaultProducer().send(messageSent);
-
- try {
- logTrace(
- "Rolling back a non-transacted session must throw IllegalStateException");
- tool.getDefaultSession().rollback();
- pass = false;
- logErr(
- "Error: QueueSession.rollback() didn't throw expected IllegalStateException");
- } catch (jakarta.jms.IllegalStateException en) {
- logMsg(
- "Got expected IllegalStateException from QueueSession.rollback()");
- }
-
- if (pass != true)
- throw new Exception("IllegalStateTestQ");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("IllegalStateTestQ");
- } finally {
- try {
- tool.closeDefaultConnections();
- tool.flushDestination();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: ackTests
- *
- * @assertion_ids: JMS:SPEC:195; JMS:SPEC:196; JMS:JAVADOC:502;
- * JMS:JAVADOC:504; JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:227;
- *
- * @test_Strategy: 1. Create a Session with Queue Configuration, verify
- * getAcknowledgeMode returns correct value; 2. Create a Session with Topic
- * Configuration, verify getAcknowledgeMode returns correct value;
- */
- public void ackTests() throws Exception {
-
- try {
- boolean pass = true;
-
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- if (tool.getDefaultSession()
- .getAcknowledgeMode() != Session.AUTO_ACKNOWLEDGE) {
- pass = false;
- logErr("Error: getAcknowledgeMode failed");
- }
-
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
-
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- if (tool.getDefaultSession()
- .getAcknowledgeMode() != Session.AUTO_ACKNOWLEDGE) {
- pass = false;
- logErr("Error: getAcknowledgeMode failed");
- }
-
- if (pass != true)
- throw new Exception("ackTests");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("ackTests");
- } finally {
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: InvalidDestinationTests
- *
- * @assertion_ids: JMS:SPEC:195; JMS:SPEC:196; JMS:JAVADOC:502;
- * JMS:JAVADOC:504; JMS:JAVADOC:510; JMS:JAVADOC:638; JMS:JAVADOC:639;
- * JMS:JAVADOC:641; JMS:JAVADOC:643; JMS:JAVADOC:644; JMS:JAVADOC:646;
- * JMS:JAVADOC:647; JMS:JAVADOC:649;
- *
- * @test_Strategy: 1. Create a Session with Queue Configuration, using a null
- * Destination/Queue to verify InvalidDestinationException is thrown with
- * various methods 2. Create a Session with Topic Configuration, using a null
- * Destination/Topic to verify InvalidDestinationException is thrown with
- * various methods
- */
- public void InvalidDestinationTests() throws Exception {
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- boolean pass = true;
- Destination dummy = null;
- Topic dummyT = null;
- Queue dummyQ = null;
-
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- tool.getDefaultConsumer().close();
-
- try {
- tool.getDefaultSession().createConsumer(dummy);
- logErr(
- "Error: createConsumer(null) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createConsumer(null)");
- } catch (Exception e) {
- logErr("Error: createConsumer(null) throw incorrect Exception: ", e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'");
- logErr(
- "Error: createConsumer(null, String) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createConsumer(null, String)");
- } catch (Exception e) {
- logErr(
- "Error: createConsumer(null, String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'", true);
- logErr(
- "Error: createConsumer(null, String, boolean) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createConsumer(null, String, true)");
- } catch (Exception e) {
- logErr(
- "Error: createConsumer(null, String, true) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createBrowser(dummyQ);
- logErr(
- "Error: createBrowser(null) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createBrowser(null)");
- } catch (Exception e) {
- logErr("Error: createBrowser(null) throw incorrect Exception: ", e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createBrowser(dummyQ, "TEST = 'test'");
- logErr(
- "Error: createBrowser(null, String) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createBrowser(null, String)");
- } catch (Exception e) {
- logErr("Error: createBrowser(null, String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing the default Connection", ex);
- }
-
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- tool.getDefaultProducer().close();
- tool.getDefaultConsumer().close();
-
- try {
- tool.getDefaultSession().createConsumer(dummy);
- logErr(
- "Error: createConsumer(null) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createConsumer(null)");
- } catch (Exception e) {
- logErr("Error: createConsumer(null) throw incorrect Exception: ", e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'");
- logErr(
- "Error: createConsumer(null, String) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createConsumer(null, String)");
- } catch (Exception e) {
- logErr(
- "Error: createConsumer(null, String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'", true);
- logErr(
- "Error: createConsumer(null, String, boolean) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createConsumer(null, String, true)");
- } catch (Exception e) {
- logErr(
- "Error: createConsumer(null, String, true) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing default Connection", ex);
- }
-
- Connection newConn = tool.getNewConnection(JmsTool.COMMON_T, user,
- password, lookup);
- Session newSession = newConn.createSession(false,
- Session.AUTO_ACKNOWLEDGE);
-
- try {
- newSession.unsubscribe("foo");
- logErr(
- "Error: unsubscribe(foo) didn't throw expected InvalidDestinationException");
- pass = false;
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from unsubscribe(foo)");
- } catch (Exception e) {
- logErr("Error: unsubscribe(foo) throw incorrect Exception: ", e);
- pass = false;
- }
-
- try {
- TopicSubscriber tsub = newSession.createDurableSubscriber(dummyT,
- "cts");
- logErr(
- "Error: createDurableSubscriber(null, String) didn't throw expected InvalidDestinationException");
- pass = false;
- tsub.close();
- newSession.unsubscribe("cts");
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createDurableSubscriber(null, String)");
- } catch (Exception e) {
- logErr(
- "Error: createDurableSubscriber(null, String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- TopicSubscriber tsub = newSession.createDurableSubscriber(dummyT, "cts",
- "TEST = 'test'", true);
- logErr(
- "Error: createDurableSubscriber(null, String, String, boolean) didn't throw expected InvalidDestinationException");
- pass = false;
- tsub.close();
- newSession.unsubscribe("cts");
- } catch (InvalidDestinationException ex) {
- logMsg(
- "Got expected InvalidDestinationException from createDurableSubscriber(null, String, String, boolean)");
- } catch (Exception e) {
- logErr(
- "Error: createDurableSubscriber(null, String, String, boolean) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- newConn.close();
- } catch (Exception ex) {
- logErr("Error closing new Connection", ex);
- }
-
- if (pass != true)
- throw new Exception("InvalidDestinationTests");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("InvalidDestinationTests");
- } finally {
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-
- /*
- * @testName: InvalidSelectorTests
- *
- * @assertion_ids: JMS:SPEC:195; JMS:SPEC:196; JMS:SPEC:69; JMS:SPEC:175;
- * JMS:JAVADOC:640; JMS:JAVADOC:642; JMS:JAVADOC:645; JMS:JAVADOC:648;
- *
- * @test_Strategy: 1. Create a Session with Queue Configuration, call
- * createConsumer/createBrowser with invalid selector to verify
- * InvalidSelectorException is thrown 2. Create a Session with Topic
- * Configuration, call createConsumer/createDurableSubscriber with invalid
- * selector to verify InvalidSelectorException is thrown
- */
- public void InvalidSelectorTests() throws Exception {
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- boolean pass = true;
-
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- tool.getDefaultConsumer().close();
-
- try {
- tool.getDefaultSession().createConsumer(tool.getDefaultDestination(),
- "=TEST 'test'");
- logErr(
- "Error: createConsumer(Destination, String) didn't throw expected InvalidSelectorException");
- pass = false;
- } catch (InvalidSelectorException ex) {
- logMsg(
- "Got expected InvalidSelectorException from createConsumer(Destination, String)");
- } catch (Exception e) {
- logErr(
- "Error: createConsumer(Destination, String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.getDefaultSession().createBrowser(
- (Queue) tool.getDefaultDestination(), "=TEST 'test'");
- logErr(
- "Error: createBrowser(Queue, String) didn't throw expected InvalidSelectorException");
- pass = false;
- } catch (InvalidSelectorException ex) {
- logMsg(
- "Got expected InvalidSelectorException from createBrowser(Queue, String)");
- } catch (Exception e) {
- logErr(
- "Error: createBrowser(Queue, String) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
-
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- tool.getDefaultProducer().close();
- tool.getDefaultConsumer().close();
-
- Connection newConn = tool.getNewConnection(JmsTool.COMMON_T, user,
- password, lookup);
- Session newSess = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- try {
- TopicSubscriber tsub = newSess.createDurableSubscriber(
- (Topic) tool.getDefaultDestination(), "mysubscription",
- "=TEST 'test'", true);
- logErr("Error: createDurableSubscriber(Topic, String, String, boolean) "
- + "didn't throw expected InvalidSelectorException");
- pass = false;
- tsub.close();
- newSess.unsubscribe("mysubscription");
- } catch (InvalidSelectorException ex) {
- logMsg("Got expected InvalidSelectorException from "
- + "createDurableSubscriber(Topic, String, String, boolean)");
- } catch (Exception e) {
- logErr("Error: createDurableSubscriber(Topic, String, String, boolean) "
- + "throw incorrect Exception: ", e);
- pass = false;
- }
-
- try {
- newConn.close();
- } catch (Exception ex) {
- logErr("Error closing new Connection", ex);
- }
-
- try {
- tool.getDefaultSession().createConsumer(tool.getDefaultDestination(),
- "=TEST 'test'", true);
- logErr(
- "Error: createConsumer(Destination, String, boolean) didn't throw expected InvalidSelectorException");
- pass = false;
- } catch (InvalidSelectorException ex) {
- logMsg(
- "Got expected InvalidSelectorException from createConsumer(Destination, String, boolean)");
- } catch (Exception e) {
- logErr(
- "Error: createConsumer(Destination, String, boolean) throw incorrect Exception: ",
- e);
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("InvalidSelectorTests");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("InvalidSelectorTests");
- } finally {
- try {
- tool.closeDefaultConnections();
- } catch (Exception ex) {
- logErr("Error closing Connection", ex);
- }
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/sessiontests/SessionTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/sessiontests/SessionTestsIT.java
new file mode 100644
index 0000000000..1093a41108
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/sessiontests/SessionTestsIT.java
@@ -0,0 +1,981 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.sessiontests;
+
+import java.lang.System.Logger;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.Connection;
+import jakarta.jms.Destination;
+import jakarta.jms.InvalidDestinationException;
+import jakarta.jms.InvalidSelectorException;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueBrowser;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicSubscriber;
+
+
+public class SessionTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.sessiontests.SessionTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(SessionTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: SimpleSendAndReceiveQ
+ *
+ * @assertion_ids: JMS:SPEC:195; JMS:JAVADOC:502; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
+ * JMS:JAVADOC:317; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Create a Text Message, send use a MessageProducer and receive
+ * it use a MessageConsumer via a Queue.
+ */
+ @Test
+ public void SimpleSendAndReceiveQ() throws Exception {
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultConnection().start();
+
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "SimpleSendAndReceiveQ");
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message to a Queue");
+ tool.getDefaultProducer().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultConsumer().receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "didn't get the right message using Queue");
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("SimpleSendAndReceiveQ Failed!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("SimpleSendAndReceiveQ");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ tool.flushDestination();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: SimpleSendAndReceiveT
+ *
+ * @assertion_ids: JMS:SPEC:196; JMS:JAVADOC:502; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
+ * JMS:JAVADOC:317; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Create a Text Message, send use a MessageProducer and receive
+ * it use a MessageConsumer via a Topic.
+ */
+ @Test
+ public void SimpleSendAndReceiveT() throws Exception {
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ boolean pass = true;
+
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ tool.getDefaultConnection().start();
+
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "SimpleSendAndReceiveT");
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message to a Topic");
+ tool.getDefaultProducer().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultConsumer().receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "didn't get the right message");
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("SimpleSendAndReceiveT Failed!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("SimpleSendAndReceiveT");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: selectorAndBrowserTests
+ *
+ * @assertion_ids: JMS:SPEC:195; JMS:JAVADOC:502; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:246;
+ * JMS:JAVADOC:317; JMS:JAVADOC:334; JMS:JAVADOC:338; JMS:JAVADOC:258;
+ * JMS:JAVADOC:260; JMS:JAVADOC:221; JMS:SPEC:148; JMS:SPEC:149;
+ * JMS:JAVADOC:278; JMS:JAVADOC:280; JMS:JAVADOC:288; JMS:JAVADOC:282;
+ * JMS:JAVADOC:284;
+ *
+ * @test_Strategy: 1. Create two TextMessages, send use a MessageProducer 2.
+ * Create a QueueBrowser to browse the Queue so that all two messages can be
+ * seen. 3. Create a QueueBrowser with selector to browse the Queue so that only
+ * one message can be seen; 4. Create a MessageConsumer with a message selector
+ * so that only last message received. 5. Then create another MessageConsumer to
+ * verify all messages except the last message can be received from the Queue.
+ */
+ @Test
+ public void selectorAndBrowserTests() throws Exception {
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TextMessage tempMsg = null;
+ boolean pass = true;
+ int numMessages = 2;
+ QueueBrowser browseAll = null;
+ QueueBrowser selectiveBrowser = null;
+ String message = "Just a Test Message from JMS TCK";
+
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultConsumer().close();
+ tool.getDefaultConnection().start();
+
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "selectorAndBrowserTests");
+ messageSent.setText(message);
+ messageSent.setBooleanProperty("lastMessage", false);
+ tool.getDefaultProducer().send(messageSent);
+
+ messageSent.setStringProperty("TEST", "test");
+ messageSent.setBooleanProperty("lastMessage", true);
+ tool.getDefaultProducer().send(messageSent);
+
+ // check the browser w/o selector
+ browseAll = tool.getDefaultSession().createBrowser((Queue) tool.getDefaultDestination());
+
+ // getting Emumeration that contains at least two test messages
+ // without getting into dead loop.
+ // Workaround for possible timing problem
+ int msgCount = 0;
+ Enumeration msgs = null;
+ int i = 0;
+ do {
+ i++;
+ msgCount = 0;
+ msgs = browseAll.getEnumeration();
+ logger.log(Logger.Level.TRACE, "getting Enumeration " + i);
+ while (msgs.hasMoreElements()) {
+ tempMsg = (TextMessage) msgs.nextElement();
+ if (tempMsg.getText().equals(messageSent.getText()))
+ msgCount++;
+ }
+ logger.log(Logger.Level.TRACE, "found " + msgCount + " messages total in browser");
+ } while ((msgCount < 2) && (i < 10));
+
+ if (!browseAll.getQueue().toString().equals(tool.getDefaultDestination().toString())) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: QueueBrowser.getQueue test failed");
+ logger.log(Logger.Level.ERROR, "QueueBrowser.getQueue=" + browseAll.getQueue().toString() + ".");
+ logger.log(Logger.Level.ERROR,
+ "tool.getDefaultDestination()=" + tool.getDefaultDestination().toString() + ".");
+ }
+
+ browseAll.close();
+
+ // Browse with selective QueueBrowser
+ selectiveBrowser = tool.getDefaultSession().createBrowser((Queue) tool.getDefaultDestination(),
+ "TEST = 'test'");
+
+ // getting Emumeration that contains at least two test messages
+ // without getting into dead loop.
+ // Workaround for possible timing problem
+ i = 0;
+ do {
+ i++;
+ msgCount = 0;
+ msgs = selectiveBrowser.getEnumeration();
+ logger.log(Logger.Level.TRACE, "getting Enumeration " + i);
+ while (msgs.hasMoreElements()) {
+ tempMsg = (TextMessage) msgs.nextElement();
+ if (tempMsg.getText().equals(messageSent.getText()))
+ msgCount++;
+ }
+ logger.log(Logger.Level.TRACE, "found " + msgCount + " messages total in browser");
+ } while ((msgCount < 1) && (i < 10));
+
+ String tmp = selectiveBrowser.getMessageSelector();
+ if (tmp.indexOf("TEST") < 0 || tmp.indexOf("test") < 0) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: QueueBrowser.getMessageSelector test failed");
+ logger.log(Logger.Level.ERROR,
+ "selectiveBrowser.getMessageSelector()=" + selectiveBrowser.getMessageSelector());
+ }
+ selectiveBrowser.close();
+
+ // check selective consumer
+ MessageConsumer SelectorConsumer = tool.getDefaultSession().createConsumer(tool.getDefaultDestination(),
+ "TEST = 'test'");
+ logger.log(Logger.Level.TRACE, "Receiving message with selective consumer");
+ messageReceived = (TextMessage) SelectorConsumer.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Did not receive expected message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ }
+ SelectorConsumer.close();
+
+ // receive all remaining messages
+ MessageConsumer qRec = tool.getDefaultSession().createConsumer(tool.getDefaultDestination());
+ logger.log(Logger.Level.TRACE, "Receiving the remaining message");
+ messageReceived = (TextMessage) qRec.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "message did not remain on queue");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == true) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "received incorrect message");
+ }
+ qRec.close();
+
+ if (pass != true)
+ throw new Exception("selectorAndBrowserTests Failed!");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("selectorAndBrowserTests");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ tool.flushDestination();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: SubscriberTests
+ *
+ * @assertion_ids: JMS:SPEC:196; JMS:SPEC:89; JMS:SPEC:162; JMS:JAVADOC:502;
+ * JMS:JAVADOC:504; JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244;
+ * JMS:JAVADOC:254; JMS:JAVADOC:256; JMS:JAVADOC:266;
+ *
+ * @test_Strategy: 1. Create a new second connection and send two TextMessages.
+ * 2. Create a DurableSubscriber defaultSub to verify all messages received. 3.
+ * Create another DurableSubscriber tSubNoLocal with noLocal set to true, and
+ * verify that no message can be received. 4. Create another DurableSubscriber
+ * tSubSelect off the new connection with selector to verify only one message
+ * received. 5. Send a message from from default connection. 6. Verify that
+ * tSubNoLocal can receive the message from the default connection 7.
+ * Unsubscribe the 3 durable subscriptions created above.
+ */
+ @Test
+ public void SubscriberTests() throws Exception {
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TextMessage tempMsg = null;
+ int numMessages = 2;
+ boolean pass = true;
+ TopicSubscriber defaultSub = null;
+ TopicSubscriber tSubSelect = null;
+ TopicSubscriber tSubNoLocal = null;
+ String subscriptionName1 = "DurableSubscriberNoLocal";
+ String subscriptionName2 = "DurableSubscriberSelect";
+ String subscriptionName3 = "DurableSubscriberDefault";
+ Connection newConn = null;
+ Session newSess = null;
+ MessageProducer newPub = null;
+ String clientID = "CTS";
+
+ try {
+ logger.log(Logger.Level.TRACE, "Setup tool for COMMON_T setup");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+
+ logger.log(Logger.Level.TRACE, "Create second connection and second session");
+ newConn = tool.getNewConnection(JmsTool.COMMON_T, user, password, lookup);
+ newSess = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ logger.log(Logger.Level.TRACE,
+ "Create 3 durabale subscriptions (default, selector, nolocal) using second session");
+ tSubNoLocal = newSess.createDurableSubscriber((Topic) tool.getDefaultDestination(), subscriptionName1, "",
+ true);
+ tSubSelect = newSess.createDurableSubscriber((Topic) tool.getDefaultDestination(), subscriptionName2,
+ "TEST = 'test'", false);
+ defaultSub = newSess.createDurableSubscriber((Topic) tool.getDefaultDestination(), subscriptionName3);
+ logger.log(Logger.Level.TRACE, "Create producer using second session");
+ newPub = newSess.createProducer(tool.getDefaultDestination());
+
+ tool.getDefaultConnection().start();
+ newConn.start();
+
+ // Create and send two messages from new connection
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText("Just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "SubscriberTests");
+ logger.log(Logger.Level.TRACE, "Sending message to a Topic");
+ messageSent.setBooleanProperty("lastMessage", false);
+ newPub.send(messageSent);
+ messageSent.setStringProperty("TEST", "test");
+ messageSent.setBooleanProperty("lastMessage", true);
+ newPub.send(messageSent);
+
+ // Verify that tSubNoLocal cannot receive any message
+ logger.log(Logger.Level.TRACE, "tSubNoLocal Receiving message");
+ messageReceived = (TextMessage) tSubNoLocal.receive(timeout);
+ if (messageReceived != null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: No_local subscriber did receive local message");
+ }
+
+ // Verify that defaultSub received correct messages
+ logger.log(Logger.Level.TRACE, "defaultSub Receiving message");
+ for (int i = 0; i < numMessages; i++) {
+ messageReceived = (TextMessage) defaultSub.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: Did not receive message " + i);
+ } else if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message " + i);
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: didn't get the right message " + i);
+ pass = false;
+ }
+ }
+
+ // Verify that tSubSelect only receive the last message
+ logger.log(Logger.Level.TRACE, "tSubSelect Receiving message");
+ messageReceived = (TextMessage) tSubSelect.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: Did not receive correct message");
+ } else if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: didn't get the right message");
+ pass = false;
+ }
+
+ // send message from default connection
+ logger.log(Logger.Level.TRACE, "sending message from default connection");
+ messageSent.setBooleanProperty("newConnection", true);
+ tool.getDefaultProducer().send(messageSent);
+
+ // Verify that tSubNoLocal now can receive message from second connection
+ logger.log(Logger.Level.TRACE, "tSubNoLocal Receiving message");
+ messageReceived = (TextMessage) tSubNoLocal.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: Did not receive correct message");
+ } else if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: didn't get the right message");
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("SubscriberTests Failed!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("SubscriberTests");
+ } finally {
+ try {
+ logger.log(Logger.Level.TRACE, "Close 3 durable subscriptions");
+ tSubNoLocal.close();
+ defaultSub.close();
+ tSubSelect.close();
+ logger.log(Logger.Level.TRACE, "Unsubscribe from 3 durable subscriptions");
+ newSess.unsubscribe(subscriptionName1);
+ newSess.unsubscribe(subscriptionName2);
+ newSess.unsubscribe(subscriptionName3);
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing subscribers and unsubscribing from subscriptions", ex);
+ }
+ try {
+ logger.log(Logger.Level.TRACE, "Closing new connection");
+ newConn.close();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing the second Connection", ex);
+ }
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Default Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: IllegalStateTestQ
+ *
+ * @assertion_ids: JMS:SPEC:195; JMS:JAVADOC:502; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:635; JMS:JAVADOC:317;
+ *
+ * @test_Strategy: 1. Create a TextMessages, send use a MessageProducer 2. Then
+ * rollback on the non-transacted session Verify that IllegalStateException is
+ * thrown
+ */
+ @Test
+ public void IllegalStateTestQ() throws Exception {
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ boolean pass = true;
+
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultConnection().start();
+
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "IllegalStateTestQ");
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message to a Queue");
+ tool.getDefaultProducer().send(messageSent);
+
+ try {
+ logger.log(Logger.Level.TRACE,
+ "Rolling back a non-transacted session must throw IllegalStateException");
+ tool.getDefaultSession().rollback();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: QueueSession.rollback() didn't throw expected IllegalStateException");
+ } catch (jakarta.jms.IllegalStateException en) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateException from QueueSession.rollback()");
+ }
+
+ if (pass != true)
+ throw new Exception("IllegalStateTestQ");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("IllegalStateTestQ");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ tool.flushDestination();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: ackTests
+ *
+ * @assertion_ids: JMS:SPEC:195; JMS:SPEC:196; JMS:JAVADOC:502; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:227;
+ *
+ * @test_Strategy: 1. Create a Session with Queue Configuration, verify
+ * getAcknowledgeMode returns correct value; 2. Create a Session with Topic
+ * Configuration, verify getAcknowledgeMode returns correct value;
+ */
+ @Test
+ public void ackTests() throws Exception {
+
+ try {
+ boolean pass = true;
+
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ if (tool.getDefaultSession().getAcknowledgeMode() != Session.AUTO_ACKNOWLEDGE) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: getAcknowledgeMode failed");
+ }
+
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ if (tool.getDefaultSession().getAcknowledgeMode() != Session.AUTO_ACKNOWLEDGE) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: getAcknowledgeMode failed");
+ }
+
+ if (pass != true)
+ throw new Exception("ackTests");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("ackTests");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: InvalidDestinationTests
+ *
+ * @assertion_ids: JMS:SPEC:195; JMS:SPEC:196; JMS:JAVADOC:502; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:638; JMS:JAVADOC:639; JMS:JAVADOC:641;
+ * JMS:JAVADOC:643; JMS:JAVADOC:644; JMS:JAVADOC:646; JMS:JAVADOC:647;
+ * JMS:JAVADOC:649;
+ *
+ * @test_Strategy: 1. Create a Session with Queue Configuration, using a null
+ * Destination/Queue to verify InvalidDestinationException is thrown with
+ * various methods 2. Create a Session with Topic Configuration, using a null
+ * Destination/Topic to verify InvalidDestinationException is thrown with
+ * various methods
+ */
+ @Test
+ public void InvalidDestinationTests() throws Exception {
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ boolean pass = true;
+ Destination dummy = null;
+ Topic dummyT = null;
+ Queue dummyQ = null;
+
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ tool.getDefaultConsumer().close();
+
+ try {
+ tool.getDefaultSession().createConsumer(dummy);
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(null) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO, "Got expected InvalidDestinationException from createConsumer(null)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(null) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'");
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(null, String) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createConsumer(null, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(null, String) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'", true);
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(null, String, boolean) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createConsumer(null, String, true)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(null, String, true) throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createBrowser(dummyQ);
+ logger.log(Logger.Level.ERROR,
+ "Error: createBrowser(null) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO, "Got expected InvalidDestinationException from createBrowser(null)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createBrowser(null) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createBrowser(dummyQ, "TEST = 'test'");
+ logger.log(Logger.Level.ERROR,
+ "Error: createBrowser(null, String) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createBrowser(null, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createBrowser(null, String) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing the default Connection", ex);
+ }
+
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ tool.getDefaultProducer().close();
+ tool.getDefaultConsumer().close();
+
+ try {
+ tool.getDefaultSession().createConsumer(dummy);
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(null) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO, "Got expected InvalidDestinationException from createConsumer(null)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(null) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'");
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(null, String) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createConsumer(null, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(null, String) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createConsumer(dummy, "TEST = 'test'", true);
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(null, String, boolean) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createConsumer(null, String, true)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(null, String, true) throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing default Connection", ex);
+ }
+
+ Connection newConn = tool.getNewConnection(JmsTool.COMMON_T, user, password, lookup);
+ Session newSession = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ try {
+ newSession.unsubscribe("foo");
+ logger.log(Logger.Level.ERROR,
+ "Error: unsubscribe(foo) didn't throw expected InvalidDestinationException");
+ pass = false;
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO, "Got expected InvalidDestinationException from unsubscribe(foo)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unsubscribe(foo) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ TopicSubscriber tsub = newSession.createDurableSubscriber(dummyT, "cts");
+ logger.log(Logger.Level.ERROR,
+ "Error: createDurableSubscriber(null, String) didn't throw expected InvalidDestinationException");
+ pass = false;
+ tsub.close();
+ newSession.unsubscribe("cts");
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createDurableSubscriber(null, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error: createDurableSubscriber(null, String) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ TopicSubscriber tsub = newSession.createDurableSubscriber(dummyT, "cts", "TEST = 'test'", true);
+ logger.log(Logger.Level.ERROR,
+ "Error: createDurableSubscriber(null, String, String, boolean) didn't throw expected InvalidDestinationException");
+ pass = false;
+ tsub.close();
+ newSession.unsubscribe("cts");
+ } catch (InvalidDestinationException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidDestinationException from createDurableSubscriber(null, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error: createDurableSubscriber(null, String, String, boolean) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ newConn.close();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing new Connection", ex);
+ }
+
+ if (pass != true)
+ throw new Exception("InvalidDestinationTests");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("InvalidDestinationTests");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+
+ /*
+ * @testName: InvalidSelectorTests
+ *
+ * @assertion_ids: JMS:SPEC:195; JMS:SPEC:196; JMS:SPEC:69; JMS:SPEC:175;
+ * JMS:JAVADOC:640; JMS:JAVADOC:642; JMS:JAVADOC:645; JMS:JAVADOC:648;
+ *
+ * @test_Strategy: 1. Create a Session with Queue Configuration, call
+ * createConsumer/createBrowser with invalid selector to verify
+ * InvalidSelectorException is thrown 2. Create a Session with Topic
+ * Configuration, call createConsumer/createDurableSubscriber with invalid
+ * selector to verify InvalidSelectorException is thrown
+ */
+ @Test
+ public void InvalidSelectorTests() throws Exception {
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ boolean pass = true;
+
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ tool.getDefaultConsumer().close();
+
+ try {
+ tool.getDefaultSession().createConsumer(tool.getDefaultDestination(), "=TEST 'test'");
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(Destination, String) didn't throw expected InvalidSelectorException");
+ pass = false;
+ } catch (InvalidSelectorException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidSelectorException from createConsumer(Destination, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createConsumer(Destination, String) throw incorrect Exception: ",
+ e);
+ pass = false;
+ }
+
+ try {
+ tool.getDefaultSession().createBrowser((Queue) tool.getDefaultDestination(), "=TEST 'test'");
+ logger.log(Logger.Level.ERROR,
+ "Error: createBrowser(Queue, String) didn't throw expected InvalidSelectorException");
+ pass = false;
+ } catch (InvalidSelectorException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidSelectorException from createBrowser(Queue, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createBrowser(Queue, String) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ tool.getDefaultProducer().close();
+ tool.getDefaultConsumer().close();
+
+ Connection newConn = tool.getNewConnection(JmsTool.COMMON_T, user, password, lookup);
+ Session newSess = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ try {
+ TopicSubscriber tsub = newSess.createDurableSubscriber((Topic) tool.getDefaultDestination(),
+ "mysubscription", "=TEST 'test'", true);
+ logger.log(Logger.Level.ERROR, "Error: createDurableSubscriber(Topic, String, String, boolean) "
+ + "didn't throw expected InvalidSelectorException");
+ pass = false;
+ tsub.close();
+ newSess.unsubscribe("mysubscription");
+ } catch (InvalidSelectorException ex) {
+ logger.log(Logger.Level.INFO, "Got expected InvalidSelectorException from "
+ + "createDurableSubscriber(Topic, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: createDurableSubscriber(Topic, String, String, boolean) "
+ + "throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ newConn.close();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing new Connection", ex);
+ }
+
+ try {
+ tool.getDefaultSession().createConsumer(tool.getDefaultDestination(), "=TEST 'test'", true);
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(Destination, String, boolean) didn't throw expected InvalidSelectorException");
+ pass = false;
+ } catch (InvalidSelectorException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected InvalidSelectorException from createConsumer(Destination, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error: createConsumer(Destination, String, boolean) throw incorrect Exception: ", e);
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("InvalidSelectorTests");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("InvalidSelectorTests");
+ } finally {
+ try {
+ tool.closeDefaultConnections();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", ex);
+ }
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/streamMsgQueue/StreamMsgQueueTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/streamMsgQueue/StreamMsgQueueTests.java
deleted file mode 100644
index 7e8f7a0694..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/streamMsgQueue/StreamMsgQueueTests.java
+++ /dev/null
@@ -1,3620 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.streamMsgQueue;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.MessageNotWriteableException;
-import jakarta.jms.StreamMessage;
-
-public class StreamMsgQueueTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.streamMsgQueue.StreamMsgQueueTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- StreamMsgQueueTests theTests = new StreamMsgQueueTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(2);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.doClientQueueTestCleanup(connections, queues);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: streamMessageConversionQTestsBoolean
- *
- * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:219;
- * JMS:JAVADOC:150; JMS:JAVADOC:128; JMS:JAVADOC:144; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
- * JMS:JAVADOC:738; JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeBoolean to write a boolean to the message. Verify the proper
- * conversion support as in 3.11.3
- */
-
- public void streamMessageConversionQTestsBoolean() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsBoolean");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for boolean primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeBoolean(abool);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // now test conversions for boolean
- // -----------------------------------------------
- // boolean to boolean - valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a boolean");
- try {
- if (messageReceived.readBoolean() == abool) {
- logTrace("Pass: boolean to boolean - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a boolean");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString()
- .equals((Boolean.valueOf(abool)).toString())) {
- logTrace("Pass: boolean to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg(
- "Use readBytes[] to read a boolean - expect MessageFormatException");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logMsg("Fail: MessageFormatException was not thrown");
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // boolean to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readByte();
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // boolean to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readShort();
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // boolean to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readChar();
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // boolean to int invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readInt();
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // boolean to long invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readLong();
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // boolean to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readFloat();
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // boolean to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg(
- "Use readDouble to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readDouble();
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageConversionQTestsBoolean", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionQTestsByte
- *
- * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:152;
- * JMS:JAVADOC:130; JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138;
- * JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:729; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeByte to write a byte. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionQTestsByte() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsByte");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeByte(bValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // byte to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a byte");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Byte.toString(bValue))) {
- logTrace("Pass: byte to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a byte - expect MessageFormatException");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // byte to byte valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a byte");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readByte() == bValue) {
- logTrace("Pass: byte to byte - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to short valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a byte");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readShort() == bValue) {
- logTrace("Pass: byte to short - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- pass = false;
- logMsg("Fail: MessageFormatException was not thrown");
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte to int valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a byte");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == bValue) {
- logTrace("Pass: byte to int - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to long valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a byte");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == bValue) {
- logTrace("Pass: byte to long - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageConversionQTestsByte", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionQTestsShort
- *
- * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:154;
- * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144;
- * JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:729; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeShort to write a short. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionQTestsShort() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsShort");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeShort(sValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // short to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a short - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // short to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a short");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Short.toString(sValue))) {
- logTrace("Pass: short to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a short - expect MessageFormatException");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // short to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a short - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // short to short valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a short");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readShort() == sValue) {
- logTrace("Pass: short to short - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a short - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // short to int valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a byte");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == sValue) {
- logTrace("Pass: short to int - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to long valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a short");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == sValue) {
- logTrace("Pass: short to long - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a short - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // short to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a short - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageConversionQTestsShort", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionQTestsInt
- *
- * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:158;
- * JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720;
- * JMS:JAVADOC:723; JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeInt
- * to write an int. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void streamMessageConversionQTestsInt() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsInt");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeInt(iValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // int to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read an int - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // int to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read an int");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Integer.toString(iValue))) {
- logTrace("Pass: int to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read an int - expect MessageFormatException");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // int to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read an int - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // int to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read an int");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // int to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read an int - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // int to int valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read an int");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == iValue) {
- logTrace("Pass: int to int - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to long valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read an int");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == iValue) {
- logTrace("Pass: int to long - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read an int - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // int to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read an int - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageConversionQTestsInt", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionQTestsLong
- *
- * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:160;
- * JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeLong to write a long. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionQTestsLong() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsLong");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeLong(lValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // long to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a long - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logMsg("Fail: MessageFormatException was not thrown");
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // long to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a long");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Long.toString(lValue))) {
- logTrace("Pass: long to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a long - expect MessageFormatException");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // long to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read an long - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // long to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a long");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // long to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a long - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // long to int invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a long");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // long to long valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a long");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == lValue) {
- logTrace("Pass: int to long - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a long - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // long to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read an long - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageConversionQTestsLong", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionQTestsFloat
- *
- * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:162;
- * JMS:JAVADOC:140; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeFloat to write a float. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionQTestsFloat() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsFloat");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeFloat(fValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // float to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a float ");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // float to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a float");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Float.toString(fValue))) {
- logTrace("Pass: float to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // float to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a float ");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // float to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a float ");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // float to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a float");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // float to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a long ");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // float to int invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a float");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // float to long invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a long");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // float to float valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a float ");
- try {
- messageReceived.reset();
- if (messageReceived.readFloat() == fValue) {
- logTrace("Pass: float to float - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // float to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read an float ");
- try {
- messageReceived.reset();
- if (messageReceived.readDouble() == fValue) {
- logTrace("Pass: float to double - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageConversionQTestsFloat", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionQTestsDouble
- *
- * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:164;
- * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
- * JMS:JAVADOC:738; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeDouble to write a double. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionQTestsDouble() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsDouble");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeDouble(dValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // double to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a double ");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // double to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a double");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Double.toString(dValue))) {
- logTrace("Pass: double to string");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // double to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a double ");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // double to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a double ");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // double to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a double");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // double to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a double ");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // double to int invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a double");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // double to long invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a double");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // double to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a double ");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // double to double valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a double ");
- try {
- messageReceived.reset();
- if (messageReceived.readDouble() == dValue) {
- logTrace("Pass: double to double ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageConversionQTestsDouble", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionQTestsString
- *
- * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:SPEC:77;
- * JMS:JAVADOC:166; JMS:JAVADOC:128; JMS:JAVADOC:130; JMS:JAVADOC:132;
- * JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:140; JMS:JAVADOC:142;
- * JMS:JAVADOC:144; JMS:JAVADOC:729; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeString to write a string. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionQTestsString() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
- String myString = "10";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsString");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeString(myString);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // now test conversions for String
- // -----------------------------------------------
- // string to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a String");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(myString)) {
- logTrace("Pass: string to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a String");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // String to byte valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a String");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readByte() == Byte.parseByte(myString)) {
- logTrace("Pass: String to byte ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to short valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a string");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readShort() == Short.parseShort(myString)) {
- logTrace("Pass: String to short ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a String ");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // string to int valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a String");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == Integer.parseInt(myString)) {
- logTrace("Pass: String to int ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a String");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == Long.parseLong(myString)) {
- logTrace("Pass: String to long ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a String");
- try {
- messageReceived.reset();
- if (messageReceived.readFloat() == Float.parseFloat(myString)) {
- logTrace("Pass: String to float ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to double valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a String");
- try {
- messageReceived.reset();
- if (messageReceived.readDouble() == Double.parseDouble(myString)) {
- logTrace("Pass: String to double ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a string ");
- try {
- messageReceived.clearBody();
- messageReceived.writeString("true");
- messageReceived.reset();
- if (messageReceived.readBoolean() == abool) {
- logTrace("Pass: String to boolean ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a string that is !true ");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- if (b != true) {
- logMsg("Fail: !true should return false");
- pass = false;
- } else {
- logTrace("Pass: !true returned false");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageConversionQTestsString", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionQTestsChar
- *
- * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:156;
- * JMS:JAVADOC:134; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeChar to write a char. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionQTestsChar() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsChar");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeChar(charValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // char to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a char - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // char to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a char");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- String s = messageReceived.readString();
-
- logTrace("char returned for \"a\" is : " + s);
- if (s.equals("a")) {
- logTrace("Pass: char to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // char to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a char - expect MessageFormatException");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // char to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a char - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // char to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a char");
- try {
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // char to char valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a char ");
- try {
- messageReceived.reset();
- if (messageReceived.readChar() == 'a') {
- logTrace("Pass: char to char - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // char to int invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a char ");
- try {
- messageReceived.reset();
- int i = messageReceived.readInt();
-
- logMsg("Fail: MessageFormatException was not thrown");
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // char to long invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a char");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // char to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a char - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // char to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a char - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageConversionQTestsChar", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionQTestsBytes
- *
- * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:168;
- * JMS:JAVADOC:146; JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:725;
- * JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:744;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeBytes to write a byte[] to the message. Verify the proper conversion
- * support as in 3.11.3
- */
-
- public void streamMessageConversionQTestsBytes() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 1, 2, 3 };
- byte[] bValues2 = { 0, 0, 0 };
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsBytes");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte[] primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeBytes(bValues);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // now test conversions for boolean
- // -----------------------------------------------
- // byte[] to byte[] - valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a byte[] ");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readBytes(bValues2) == 3) { // count should be 3.
- logTrace("Pass: byte[] to byte[] - valid");
- } else {
- logMsg("Fail: count incorrect");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a byte[]");
-
- // position to beginning of stream message.
- messageReceived.reset();
- try {
- boolean b = messageReceived.readBoolean();
-
- logMsg(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte[] to string invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a byte[]");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- String s = messageReceived.readString();
-
- logMsg(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte[] to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte[] to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte[] to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte[] to int invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte[] to long invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte[] to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte[] to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- if (e instanceof jakarta.jms.MessageFormatException) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageConversionQTestsBytes", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionQTestsInvFormatString
- *
- * @assertion_ids: JMS:SPEC:76; JMS:SPEC:81; JMS:JAVADOC:166; JMS:JAVADOC:130;
- * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:140;
- * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeString to write a text string of "mytest string". Verify
- * NumberFormatException is thrown Verify that the pointer was not incremented
- * by doing a read string
- *
- */
-
- public void streamMessageConversionQTestsInvFormatString() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- boolean pass = true;
- String myString = "mytest string";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsInvFormatString");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeString(myString);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // -----------------------------------------------
- // String to byte
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a String that is not valid ");
- try {
- byte b = messageReceived.readByte();
-
- logMsg("Fail: java.lang.NumberFormatException expected");
- pass = false;
- } catch (Exception e) {
- if (e instanceof java.lang.NumberFormatException) {
- logTrace("Pass: NumberFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // pointer should not have moved
- // -----------------------------------------------
- logMsg("--");
- logMsg(
- "Verify that the data can be read as a string and pointer did not move");
- try {
- String s = messageReceived.readString();
-
- logTrace("message read: " + s);
- if (s.equals(myString)) {
- logTrace("Pass: able to read the string");
- } else {
- logMsg("Fail: string not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to short
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a string that is not valid ");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (Exception e) {
- if (e instanceof java.lang.NumberFormatException) {
- logTrace("Pass: NumberFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // string to int
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a String that is not valid ");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
-
- logMsg("Fail: NumberFormatException was expected");
- } catch (Exception e) {
- if (e instanceof java.lang.NumberFormatException) {
- logTrace("Pass: NumberFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // string to long
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a String that is not valid ");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
-
- logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (Exception e) {
- if (e instanceof java.lang.NumberFormatException) {
- logTrace("Pass: NumberFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // String to float
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a String that is not valid ");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (Exception e) {
- if (e instanceof java.lang.NumberFormatException) {
- logTrace("Pass: NumberFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // String to double
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a String that is not valid ");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (Exception e) {
- if (e instanceof java.lang.NumberFormatException) {
- logTrace("Pass: NumberFormatException thrown as expected");
- } else {
- logErr(
- "Unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageConversionQTestsInvFormatString", e);
- }
- }
-
- /*
- * @testName: streamMessageQTestsFullMsg
- *
- * @assertion_ids: JMS:SPEC:82; JMS:JAVADOC:150; JMS:JAVADOC:152;
- * JMS:JAVADOC:154; JMS:JAVADOC:156; JMS:JAVADOC:158; JMS:JAVADOC:160;
- * JMS:JAVADOC:162; JMS:JAVADOC:164; JMS:JAVADOC:166; JMS:JAVADOC:168;
- * JMS:JAVADOC:170; JMS:JAVADOC:172; JMS:JAVADOC:128; JMS:JAVADOC:130;
- * JMS:JAVADOC:132; JMS:JAVADOC:134; JMS:JAVADOC:136; JMS:JAVADOC:138;
- * JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
- * JMS:JAVADOC:148;
- *
- * @test_Strategy: Create a StreamMessage -. write one of each primitive type.
- * Send the message. Verify the data received was as sent.
- *
- */
-
- public void streamMessageQTestsFullMsg() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = false;
- byte[] bValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
- byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
- byte[] bValuesReturned = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- byte[] bValuesReturned2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- char charValue = 'Z';
- short sValue = 32767;
- long lValue = 9223372036854775807L;
- double dValue = 6.02e23;
- float fValue = 6.02e23f;
- int iValue = 6;
- boolean pass = true;
- String myString = "text";
- String sTesting = "Testing StreamMessages";
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageQTestsFullMsg");
-
- // -----------------------------------------------------------------------------
- logTrace("");
-
- // -----------------------------------------------------------------------------
- messageSent.writeBytes(bValues2, 0, bValues.length);
- messageSent.writeBoolean(abool);
- messageSent.writeByte(bValue);
- messageSent.writeBytes(bValues);
- messageSent.writeChar(charValue);
- messageSent.writeDouble(dValue);
- messageSent.writeFloat(fValue);
- messageSent.writeInt(iValue);
- messageSent.writeLong(lValue);
- messageSent.writeObject(sTesting);
- messageSent.writeShort(sValue);
- messageSent.writeString(myString);
- messageSent.writeObject(null);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
- try {
- int nCount;
- do {
- nCount = messageReceived.readBytes(bValuesReturned2);
- logTrace("nCount is " + nCount);
- if (nCount != -1) {
- for (int i = 0; i < bValuesReturned2.length; i++) {
- if (bValuesReturned2[i] != bValues2[i]) {
- logMsg("Fail: byte[] " + i + " is not valid");
- pass = false;
- } else {
- logTrace("PASS: byte[]" + i + " is valid");
- }
- }
- }
- } while (nCount >= bValuesReturned2.length);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readBoolean() == abool) {
- logTrace("Pass: boolean returned ok");
- } else {
- logMsg("Fail: boolean not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readByte() == bValue) {
- logTrace("Pass: Byte returned ok");
- } else {
- logMsg("Fail: Byte not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- try {
- int nCount;
- do {
- nCount = messageReceived.readBytes(bValuesReturned);
- logTrace("nCount is " + nCount);
- if (nCount != -1) {
- for (int i = 0; i < bValuesReturned2.length; i++) {
- if (bValuesReturned2[i] != bValues2[i]) {
- logMsg("Fail: byte[] " + i + " is not valid");
- pass = false;
- } else {
- logTrace("PASS: byte[]" + i + " is valid");
- }
- }
- }
- } while (nCount >= bValuesReturned2.length);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readChar() == charValue) {
- logTrace("Pass: correct char");
- } else {
- logMsg("Fail: char not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readDouble() == dValue) {
- logTrace("Pass: correct double");
- } else {
- logMsg("Fail: double not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readFloat() == fValue) {
- logTrace("Pass: correct float");
- } else {
- logMsg("Fail: float not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readInt() == iValue) {
- logTrace("Pass: correct int");
- } else {
- logMsg("Fail: int not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readLong() == lValue) {
- logTrace("Pass: correct long");
- } else {
- logMsg("Fail: long not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readObject().equals(sTesting)) {
- logTrace("Pass: correct object");
- } else {
- logMsg("Fail: object not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readShort() == sValue) {
- logTrace("Pass: correct short");
- } else {
- logMsg("Fail: short not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readString().equals(myString)) {
- logTrace("Pass: correct string");
- } else {
- logMsg("Fail: string not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readObject() == null) {
- logTrace("Pass: correct object");
- } else {
- logMsg("Fail: object not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("unexpected exception" + e.getClass().getName() + "was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageQTestsFullMsg", e);
- }
- }
-
- /*
- * @testName: streamMessageQTestNull
- *
- * @assertion_ids: JMS:SPEC:78; JMS:SPEC:86; JMS:JAVADOC:144; JMS:JAVADOC:172;
- *
- * @test_Strategy: Create a StreamMessage Use writeString to write a null,
- * then use readString to read it back.
- */
-
- public void streamMessageQTestNull() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- boolean pass = true;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageQTestNull");
-
- // -----------------------------------------------------------------------------
- logTrace("writeString(null) ");
-
- // -----------------------------------------------------------------------------
- try {
- messageSent.writeString(null);
- } catch (Exception e) {
- logErr(
- "unexpected exception " + e.getClass().getName() + " was thrown");
-
- // It doesn't make sense to continue, throw an exception
- throw new Exception("Error: failed to write a null object with writeString",
- e);
- }
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- // -----------------------------------------------
- //
- // -----------------------------------------------
- logMsg(" ");
- try {
- if (messageReceived.readObject() == null) {
- logTrace("Pass: Read a null");
- } else {
- logMsg("Fail: null value not returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("trying to read a null object");
- logErr(
- "unexpected exception " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageQTestNull", e);
- }
- }
-
- /*
- * @testName: streamMessageQNotWritable
- *
- * @assertion_ids: JMS:SPEC:73; JMS:JAVADOC:752; JMS:JAVADOC:753;
- * JMS:JAVADOC:754; JMS:JAVADOC:755; JMS:JAVADOC:756; JMS:JAVADOC:757;
- * JMS:JAVADOC:758; JMS:JAVADOC:759; JMS:JAVADOC:761; JMS:JAVADOC:762;
- * JMS:JAVADOC:764;
- *
- * @test_Strategy: Create a StreamMessage, send it to a Queue. Receive it and
- * try to write to the received Message's body, MessageNotWritableException
- * should be thrown.
- */
-
- public void streamMessageQNotWritable() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- boolean pass = true;
- byte bValue = 127;
- short sValue = 32767;
- char cValue = '\uFFFF';
- int iValue = 2147483647;
- long lValue = 9223372036854775807L;
- float fValue = 0.0f;
- double dValue = -0.0;
- String ssValue = "abc";
- byte[] bbValue = { 0, 88, 127 };
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
- tool.getDefaultQueueConnection().start();
- messageSent = tool.getDefaultQueueSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageQNotWritable");
-
- // -----------------------------------------------------------------------------
- try {
- messageSent.writeString("Test Message for streamMessageQNotWritable");
- } catch (Exception e) {
- logErr(
- "unexpected exception " + e.getClass().getName() + " was thrown");
- throw new Exception("Error: failed to writeString", e);
- }
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultQueueSender().send(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultQueueReceiver()
- .receive(timeout);
-
- logMsg("Writing a boolean ... ");
- try {
- messageReceived.writeBoolean(pass);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeBoolean");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeBoolean");
- }
-
- logMsg("Writing a byte ... ");
- try {
- messageReceived.writeByte(bValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeByte");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeByte");
- }
-
- logMsg("Writing a short ... ");
- try {
- messageReceived.writeShort(sValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeShort");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeShort");
- }
-
- logMsg("Writing a char ... ");
- try {
- messageReceived.writeChar(cValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeChar");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeChar");
- }
-
- logMsg("Writing a int ... ");
- try {
- messageReceived.writeInt(iValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeInt");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeInt");
- }
-
- logMsg("Writing a long ... ");
- try {
- messageReceived.writeLong(lValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeLong");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeLong");
- }
-
- logMsg("Writing a float ... ");
- try {
- messageReceived.writeFloat(fValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeFloat");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeFloat");
- }
-
- logMsg("Writing a double ... ");
- try {
- messageReceived.writeDouble(dValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeDouble");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeDouble");
- }
-
- logMsg("Writing a bytes... ");
- try {
- messageReceived.writeBytes(bbValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeBytes");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeBytes");
- }
-
- logMsg("Writing a string ... ");
- try {
- messageReceived.writeString(ssValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeString");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeString");
- }
-
- logMsg("Writing a object ... ");
- try {
- messageReceived.writeObject(new Integer(iValue));
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeObject");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeObject");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("streamMessageQNotWritable", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/streamMsgQueue/StreamMsgQueueTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/streamMsgQueue/StreamMsgQueueTestsIT.java
new file mode 100644
index 0000000000..0db667338d
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/streamMsgQueue/StreamMsgQueueTestsIT.java
@@ -0,0 +1,3485 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.streamMsgQueue;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.MessageNotWriteableException;
+import jakarta.jms.StreamMessage;
+
+
+public class StreamMsgQueueTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.streamMsgQueue.StreamMsgQueueTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(StreamMsgQueueTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(2);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.doClientQueueTestCleanup(connections, queues);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: streamMessageConversionQTestsBoolean
+ *
+ * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:219;
+ * JMS:JAVADOC:150; JMS:JAVADOC:128; JMS:JAVADOC:144; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
+ * JMS:JAVADOC:738; JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method
+ * writeBoolean to write a boolean to the message. Verify the proper conversion
+ * support as in 3.11.3
+ */
+ @Test
+ public void streamMessageConversionQTestsBoolean() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsBoolean");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for boolean primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeBoolean(abool);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // boolean to boolean - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a boolean");
+ try {
+ if (messageReceived.readBoolean() == abool) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to boolean - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a boolean");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals((Boolean.valueOf(abool)).toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a boolean - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // boolean to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readByte();
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // boolean to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readShort();
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // boolean to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readChar();
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // boolean to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readInt();
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // boolean to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readLong();
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // boolean to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readFloat();
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // boolean to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readDouble();
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageConversionQTestsBoolean", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionQTestsByte
+ *
+ * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:152;
+ * JMS:JAVADOC:130; JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138;
+ * JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:729; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeByte
+ * to write a byte. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionQTestsByte() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsByte");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeByte(bValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // byte to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a byte");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Byte.toString(bValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a byte - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // byte to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a byte");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readByte() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to byte - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a byte");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readShort() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to short - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ pass = false;
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a byte");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to int - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a byte");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageConversionQTestsByte", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionQTestsShort
+ *
+ * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:154;
+ * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144;
+ * JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:729; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeShort
+ * to write a short. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionQTestsShort() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsShort");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeShort(sValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // short to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // short to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a short");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Short.toString(sValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: short to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a short - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // short to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // short to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a short");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readShort() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to short - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // short to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a byte");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to int - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a short");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // short to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageConversionQTestsShort", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionQTestsInt
+ *
+ * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:158;
+ * JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720;
+ * JMS:JAVADOC:723; JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeInt
+ * to write an int. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionQTestsInt() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsInt");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeInt(iValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // int to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // int to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read an int");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Integer.toString(iValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: int to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read an int - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // int to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // int to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read an int");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // int to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // int to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read an int");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == iValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to int - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read an int");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == iValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // int to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageConversionQTestsInt", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionQTestsLong
+ *
+ * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:160;
+ * JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeLong
+ * to write a long. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionQTestsLong() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsLong");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeLong(lValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // long to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a long - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // long to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a long");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Long.toString(lValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: long to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a long - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // long to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read an long - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // long to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a long");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // long to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a long - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // long to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a long");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // long to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a long");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == lValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a long - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // long to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read an long - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageConversionQTestsLong", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionQTestsFloat
+ *
+ * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:162;
+ * JMS:JAVADOC:140; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeFloat
+ * to write a float. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionQTestsFloat() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsFloat");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeFloat(fValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // float to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a float ");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // float to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a float");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Float.toString(fValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: float to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a float ");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // float to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a float ");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // float to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a float");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // float to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a long ");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // float to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a float");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // float to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a long");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // float to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a float ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readFloat() == fValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to float - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read an float ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readDouble() == fValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to double - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageConversionQTestsFloat", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionQTestsDouble
+ *
+ * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:164;
+ * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
+ * JMS:JAVADOC:738; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method
+ * writeDouble to write a double. Verify the proper conversion support as in
+ * 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionQTestsDouble() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsDouble");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeDouble(dValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // double to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a double ");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // double to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a double");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Double.toString(dValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: double to string");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a double ");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // double to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a double ");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // double to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a double");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // double to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a double ");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // double to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a double");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // double to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a double");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // double to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a double ");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // double to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a double ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readDouble() == dValue) {
+ logger.log(Logger.Level.TRACE, "Pass: double to double ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageConversionQTestsDouble", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionQTestsString
+ *
+ * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:SPEC:77; JMS:JAVADOC:166;
+ * JMS:JAVADOC:128; JMS:JAVADOC:130; JMS:JAVADOC:132; JMS:JAVADOC:136;
+ * JMS:JAVADOC:138; JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144;
+ * JMS:JAVADOC:729; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method
+ * writeString to write a string. Verify the proper conversion support as in
+ * 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionQTestsString() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+ String myString = "10";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeString(myString);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // now test conversions for String
+ // -----------------------------------------------
+ // string to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a String");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: string to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a String");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // String to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a String");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readByte() == Byte.parseByte(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to byte ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a string");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readShort() == Short.parseShort(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to short ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a String ");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // string to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a String");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == Integer.parseInt(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to int ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a String");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == Long.parseLong(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to long ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a String");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readFloat() == Float.parseFloat(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to float ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a String");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readDouble() == Double.parseDouble(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to double ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a string ");
+ try {
+ messageReceived.clearBody();
+ messageReceived.writeString("true");
+ messageReceived.reset();
+ if (messageReceived.readBoolean() == abool) {
+ logger.log(Logger.Level.TRACE, "Pass: String to boolean ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a string that is !true ");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ if (b != true) {
+ logger.log(Logger.Level.INFO, "Fail: !true should return false");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: !true returned false");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageConversionQTestsString", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionQTestsChar
+ *
+ * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:156;
+ * JMS:JAVADOC:134; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeChar
+ * to write a char. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionQTestsChar() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsChar");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeChar(charValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // char to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // char to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a char");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ String s = messageReceived.readString();
+
+ logger.log(Logger.Level.TRACE, "char returned for \"a\" is : " + s);
+ if (s.equals("a")) {
+ logger.log(Logger.Level.TRACE, "Pass: char to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a char - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // char to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // char to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a char");
+ try {
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // char to char valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a char ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readChar() == 'a') {
+ logger.log(Logger.Level.TRACE, "Pass: char to char - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a char ");
+ try {
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // char to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a char");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // char to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // char to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageConversionQTestsChar", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionQTestsBytes
+ *
+ * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:168;
+ * JMS:JAVADOC:146; JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:725;
+ * JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:744;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeBytes
+ * to write a byte[] to the message. Verify the proper conversion support as in
+ * 3.11.3
+ */
+ @Test
+ public void streamMessageConversionQTestsBytes() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 1, 2, 3 };
+ byte[] bValues2 = { 0, 0, 0 };
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsBytes");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte[] primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeBytes(bValues);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // byte[] to byte[] - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a byte[] ");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readBytes(bValues2) == 3) { // count should be 3.
+ logger.log(Logger.Level.TRACE, "Pass: byte[] to byte[] - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: count incorrect");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a byte[]");
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ try {
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.INFO,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte[] to string invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a byte[]");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ String s = messageReceived.readString();
+
+ logger.log(Logger.Level.INFO,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte[] to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte[] to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte[] to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte[] to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte[] to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte[] to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte[] to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageConversionQTestsBytes", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionQTestsInvFormatString
+ *
+ * @assertion_ids: JMS:SPEC:76; JMS:SPEC:81; JMS:JAVADOC:166; JMS:JAVADOC:130;
+ * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:140;
+ * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method
+ * writeString to write a text string of "mytest string". Verify
+ * NumberFormatException is thrown Verify that the pointer was not incremented
+ * by doing a read string
+ *
+ */
+ @Test
+ public void streamMessageConversionQTestsInvFormatString() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ boolean pass = true;
+ String myString = "mytest string";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsInvFormatString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeString(myString);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // -----------------------------------------------
+ // String to byte
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a String that is not valid ");
+ try {
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.INFO, "Fail: java.lang.NumberFormatException expected");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof java.lang.NumberFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // pointer should not have moved
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Verify that the data can be read as a string and pointer did not move");
+ try {
+ String s = messageReceived.readString();
+
+ logger.log(Logger.Level.TRACE, "message read: " + s);
+ if (s.equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: able to read the string");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: string not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to short
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a string that is not valid ");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof java.lang.NumberFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // string to int
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a String that is not valid ");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ } catch (Exception e) {
+ if (e instanceof java.lang.NumberFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // string to long
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a String that is not valid ");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof java.lang.NumberFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // String to float
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a String that is not valid ");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof java.lang.NumberFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // String to double
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a String that is not valid ");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (Exception e) {
+ if (e instanceof java.lang.NumberFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageConversionQTestsInvFormatString", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageQTestsFullMsg
+ *
+ * @assertion_ids: JMS:SPEC:82; JMS:JAVADOC:150; JMS:JAVADOC:152;
+ * JMS:JAVADOC:154; JMS:JAVADOC:156; JMS:JAVADOC:158; JMS:JAVADOC:160;
+ * JMS:JAVADOC:162; JMS:JAVADOC:164; JMS:JAVADOC:166; JMS:JAVADOC:168;
+ * JMS:JAVADOC:170; JMS:JAVADOC:172; JMS:JAVADOC:128; JMS:JAVADOC:130;
+ * JMS:JAVADOC:132; JMS:JAVADOC:134; JMS:JAVADOC:136; JMS:JAVADOC:138;
+ * JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
+ * JMS:JAVADOC:148;
+ *
+ * @test_Strategy: Create a StreamMessage -. write one of each primitive type.
+ * Send the message. Verify the data received was as sent.
+ *
+ */
+ @Test
+ public void streamMessageQTestsFullMsg() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = false;
+ byte[] bValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+ byte[] bValuesReturned = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ byte[] bValuesReturned2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ char charValue = 'Z';
+ short sValue = 32767;
+ long lValue = 9223372036854775807L;
+ double dValue = 6.02e23;
+ float fValue = 6.02e23f;
+ int iValue = 6;
+ boolean pass = true;
+ String myString = "text";
+ String sTesting = "Testing StreamMessages";
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageQTestsFullMsg");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeBytes(bValues2, 0, bValues.length);
+ messageSent.writeBoolean(abool);
+ messageSent.writeByte(bValue);
+ messageSent.writeBytes(bValues);
+ messageSent.writeChar(charValue);
+ messageSent.writeDouble(dValue);
+ messageSent.writeFloat(fValue);
+ messageSent.writeInt(iValue);
+ messageSent.writeLong(lValue);
+ messageSent.writeObject(sTesting);
+ messageSent.writeShort(sValue);
+ messageSent.writeString(myString);
+ messageSent.writeObject(null);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+ try {
+ int nCount;
+ do {
+ nCount = messageReceived.readBytes(bValuesReturned2);
+ logger.log(Logger.Level.TRACE, "nCount is " + nCount);
+ if (nCount != -1) {
+ for (int i = 0; i < bValuesReturned2.length; i++) {
+ if (bValuesReturned2[i] != bValues2[i]) {
+ logger.log(Logger.Level.INFO, "Fail: byte[] " + i + " is not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "PASS: byte[]" + i + " is valid");
+ }
+ }
+ }
+ } while (nCount >= bValuesReturned2.length);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readBoolean() == abool) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean returned ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: boolean not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readByte() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: Byte returned ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Byte not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ int nCount;
+ do {
+ nCount = messageReceived.readBytes(bValuesReturned);
+ logger.log(Logger.Level.TRACE, "nCount is " + nCount);
+ if (nCount != -1) {
+ for (int i = 0; i < bValuesReturned2.length; i++) {
+ if (bValuesReturned2[i] != bValues2[i]) {
+ logger.log(Logger.Level.INFO, "Fail: byte[] " + i + " is not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "PASS: byte[]" + i + " is valid");
+ }
+ }
+ }
+ } while (nCount >= bValuesReturned2.length);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readChar() == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct char");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: char not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readDouble() == dValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct double");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: double not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readFloat() == fValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct float");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: float not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readInt() == iValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct int");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: int not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readLong() == lValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct long");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: long not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readObject().equals(sTesting)) {
+ logger.log(Logger.Level.TRACE, "Pass: correct object");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: object not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readShort() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct short");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: short not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readString().equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: correct string");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: string not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readObject() == null) {
+ logger.log(Logger.Level.TRACE, "Pass: correct object");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: object not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageQTestsFullMsg", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageQTestNull
+ *
+ * @assertion_ids: JMS:SPEC:78; JMS:SPEC:86; JMS:JAVADOC:144; JMS:JAVADOC:172;
+ *
+ * @test_Strategy: Create a StreamMessage Use writeString to write a null, then
+ * use readString to read it back.
+ */
+ @Test
+ public void streamMessageQTestNull() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageQTestNull");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "writeString(null) ");
+
+ // -----------------------------------------------------------------------------
+ try {
+ messageSent.writeString(null);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "unexpected exception " + e.getClass().getName() + " was thrown");
+
+ // It doesn't make sense to continue, throw an exception
+ throw new Exception("Error: failed to write a null object with writeString", e);
+ }
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ // -----------------------------------------------
+ //
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, " ");
+ try {
+ if (messageReceived.readObject() == null) {
+ logger.log(Logger.Level.TRACE, "Pass: Read a null");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: null value not returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "trying to read a null object");
+ logger.log(Logger.Level.ERROR, "unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageQTestNull", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageQNotWritable
+ *
+ * @assertion_ids: JMS:SPEC:73; JMS:JAVADOC:752; JMS:JAVADOC:753;
+ * JMS:JAVADOC:754; JMS:JAVADOC:755; JMS:JAVADOC:756; JMS:JAVADOC:757;
+ * JMS:JAVADOC:758; JMS:JAVADOC:759; JMS:JAVADOC:761; JMS:JAVADOC:762;
+ * JMS:JAVADOC:764;
+ *
+ * @test_Strategy: Create a StreamMessage, send it to a Queue. Receive it and
+ * try to write to the received Message's body, MessageNotWritableException
+ * should be thrown.
+ */
+ @Test
+ public void streamMessageQNotWritable() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ boolean pass = true;
+ byte bValue = 127;
+ short sValue = 32767;
+ char cValue = '\uFFFF';
+ int iValue = 2147483647;
+ long lValue = 9223372036854775807L;
+ float fValue = 0.0f;
+ double dValue = -0.0;
+ String ssValue = "abc";
+ byte[] bbValue = { 0, 88, 127 };
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+ tool.getDefaultQueueConnection().start();
+ messageSent = tool.getDefaultQueueSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageQNotWritable");
+
+ // -----------------------------------------------------------------------------
+ try {
+ messageSent.writeString("Test Message for streamMessageQNotWritable");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "unexpected exception " + e.getClass().getName() + " was thrown");
+ throw new Exception("Error: failed to writeString", e);
+ }
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultQueueSender().send(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultQueueReceiver().receive(timeout);
+
+ logger.log(Logger.Level.INFO, "Writing a boolean ... ");
+ try {
+ messageReceived.writeBoolean(pass);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeBoolean");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeBoolean");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a byte ... ");
+ try {
+ messageReceived.writeByte(bValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeByte");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeByte");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a short ... ");
+ try {
+ messageReceived.writeShort(sValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeShort");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeShort");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a char ... ");
+ try {
+ messageReceived.writeChar(cValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeChar");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeChar");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a int ... ");
+ try {
+ messageReceived.writeInt(iValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeInt");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeInt");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a long ... ");
+ try {
+ messageReceived.writeLong(lValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeLong");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeLong");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a float ... ");
+ try {
+ messageReceived.writeFloat(fValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeFloat");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeFloat");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a double ... ");
+ try {
+ messageReceived.writeDouble(dValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeDouble");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeDouble");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageReceived.writeBytes(bbValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeBytes");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a string ... ");
+ try {
+ messageReceived.writeString(ssValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeString");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeString");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a object ... ");
+ try {
+ messageReceived.writeObject(new Integer(iValue));
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeObject");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeObject");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("streamMessageQNotWritable", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/streamMsgTopic/StreamMsgTopicTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/streamMsgTopic/StreamMsgTopicTests.java
deleted file mode 100644
index 585784f846..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/streamMsgTopic/StreamMsgTopicTests.java
+++ /dev/null
@@ -1,3334 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.core.streamMsgTopic;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.MessageNotWriteableException;
-import jakarta.jms.StreamMessage;
-
-public class StreamMsgTopicTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.streamMsgTopic.StreamMsgTopicTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- StreamMsgTopicTests theTests = new StreamMsgTopicTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
-
- } catch (Exception e) {
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- logErr("An error occurred while cleaning: ");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: streamMessageConversionTopicTestsBoolean
- *
- * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:219;
- * JMS:JAVADOC:150; JMS:JAVADOC:128; JMS:JAVADOC:144; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
- * JMS:JAVADOC:738; JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeBoolean to write a boolean to the message. Verify the proper
- * conversion support as in 3.11.3
- */
-
- public void streamMessageConversionTopicTestsBoolean() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsBoolean");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for boolean primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeBoolean(abool);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for boolean
- // -----------------------------------------------
- // boolean to boolean - valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a boolean");
- try {
- if (messageReceived.readBoolean() == abool) {
- logTrace("Pass: boolean to boolean - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a boolean");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString()
- .equals((Boolean.valueOf(abool)).toString())) {
- logTrace("Pass: boolean to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg(
- "Use readBytes[] to read a boolean - expect MessageFormatException");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logErr("Fail: MessageFormatException was not thrown");
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // boolean to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readByte();
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readShort();
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readChar();
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to int invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readInt();
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to long invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readLong();
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readFloat();
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg(
- "Use readDouble to read a boolean - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readDouble();
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageConversionTopicTestsBoolean", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionTopicTestsByte
- *
- * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:152;
- * JMS:JAVADOC:130; JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138;
- * JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:729; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeByte to write a byte. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionTopicTestsByte() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsByte");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeByte(bValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // byte to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a byte");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Byte.toString(bValue))) {
- logTrace("Pass: byte to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a byte - expect MessageFormatException");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // byte to byte valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a byte");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readByte() == bValue) {
- logTrace("Pass: byte to byte - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to short valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a byte");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readShort() == bValue) {
- logTrace("Pass: byte to short - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- pass = false;
- logMsg("Fail: MessageFormatException was not thrown");
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to int valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a byte");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == bValue) {
- logTrace("Pass: byte to int - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to long valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a byte");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == bValue) {
- logTrace("Pass: byte to long - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageConversionTopicTestsByte", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionTopicTestsShort
- *
- * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:154;
- * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144;
- * JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:729; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeShort to write a short. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionTopicTestsShort() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsShort");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeShort(sValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // short to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a short - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a short");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Short.toString(sValue))) {
- logTrace("Pass: short to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a short - expect MessageFormatException");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // short to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a short - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to short valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a short");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readShort() == sValue) {
- logTrace("Pass: short to short - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a short - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to int valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a byte");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == sValue) {
- logTrace("Pass: short to int - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to long valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a short");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == sValue) {
- logTrace("Pass: short to long - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a short - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // short to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a short - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logMsg("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageConversionTopicTestsShort", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionTopicTestsInt
- *
- * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:158;
- * JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720;
- * JMS:JAVADOC:723; JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeInt
- * to write an int. Verify the proper conversion support as in 3.11.3
- *
- */
-
- public void streamMessageConversionTopicTestsInt() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsInt");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeInt(iValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // int to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read an int - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read an int");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Integer.toString(iValue))) {
- logTrace("Pass: int to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read an int - expect MessageFormatException");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // int to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read an int - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read an int");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read an int - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to int valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read an int");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == iValue) {
- logTrace("Pass: int to int - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to long valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read an int");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == iValue) {
- logTrace("Pass: int to long - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read an int - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // int to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read an int - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageConversionTopicTestsInt", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionTopicTestsLong
- *
- * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:160;
- * JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeLong to write a long. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionTopicTestsLong() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsLong");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeLong(lValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // long to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a long - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logErr("Fail: MessageFormatException was not thrown");
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a long");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Long.toString(lValue))) {
- logTrace("Pass: long to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a long - expect MessageFormatException");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // long to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read an long - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a long");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a long - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to int invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a long");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to long valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a long");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == lValue) {
- logTrace("Pass: int to long - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a long - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // long to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read an long - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageConversionTopicTestsLong", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionTopicTestsFloat
- *
- * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:162;
- * JMS:JAVADOC:140; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeFloat to write a float. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionTopicTestsFloat() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsFloat");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeFloat(fValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // float to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a float ");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a float");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Float.toString(fValue))) {
- logTrace("Pass: float to string - valid");
- } else {
- logErr("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a float ");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // float to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a float ");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a float");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a long ");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to int invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a float");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to long invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a long");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to float valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a float ");
- try {
- messageReceived.reset();
- if (messageReceived.readFloat() == fValue) {
- logTrace("Pass: float to float - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // float to double valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read an float ");
- try {
- messageReceived.reset();
- if (messageReceived.readDouble() == fValue) {
- logTrace("Pass: float to double - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageConversionTopicTestsFloat", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionTopicTestsDouble
- *
- * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:164;
- * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
- * JMS:JAVADOC:738; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeDouble to write a double. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionTopicTestsDouble() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsDouble");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeDouble(dValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // double to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a double ");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a double");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Double.toString(dValue))) {
- logTrace("Pass: double to string");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a double ");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // double to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a double ");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a double");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a double ");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to int invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a double");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to long invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a double");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a double ");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // double to double valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a double ");
- try {
- messageReceived.reset();
- if (messageReceived.readDouble() == dValue) {
- logTrace("Pass: double to double ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageConversionTopicTestsDouble", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionTopicTestsString
- *
- * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:SPEC:77;
- * JMS:JAVADOC:166; JMS:JAVADOC:128; JMS:JAVADOC:130; JMS:JAVADOC:132;
- * JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:140; JMS:JAVADOC:142;
- * JMS:JAVADOC:144; JMS:JAVADOC:729; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeString to write a string. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionTopicTestsString() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
- String myString = "10";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsString");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeString(myString);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for String
- // -----------------------------------------------
- // string to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a String");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(myString)) {
- logTrace("Pass: string to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a String");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // String to byte valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a String");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readByte() == Byte.parseByte(myString)) {
- logTrace("Pass: String to byte ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to short valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a string");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readShort() == Short.parseShort(myString)) {
- logTrace("Pass: String to short ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a String ");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // string to int valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a String");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == Integer.parseInt(myString)) {
- logTrace("Pass: String to int ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a String");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == Long.parseLong(myString)) {
- logTrace("Pass: String to long ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a String");
- try {
- messageReceived.reset();
- if (messageReceived.readFloat() == Float.parseFloat(myString)) {
- logTrace("Pass: String to float ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to double valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a String");
- try {
- messageReceived.reset();
- if (messageReceived.readDouble() == Double.parseDouble(myString)) {
- logTrace("Pass: String to double ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a string ");
- try {
- messageReceived.clearBody();
- messageReceived.writeString("true");
- messageReceived.reset();
- if (messageReceived.readBoolean() == abool) {
- logTrace("Pass: String to boolean ");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a string that is !true ");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- if (b != true) {
- logErr("Fail: !true should return false");
- pass = false;
- } else {
- logTrace("Pass: !true returned false");
- }
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageConversionTopicTestsString", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionTopicTestsChar
- *
- * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:156;
- * JMS:JAVADOC:134; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeChar to write a char. Verify the proper conversion support as in
- * 3.11.3
- *
- */
-
- public void streamMessageConversionTopicTestsChar() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsChar");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeChar(charValue);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for byte
- // -----------------------------------------------
- // char to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a char - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to string valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a char");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- String s = messageReceived.readString();
-
- logTrace("char returned for \"a\" is : " + s);
- if (s.equals("a")) {
- logTrace("Pass: char to string - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to byte[] invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a char - expect MessageFormatException");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- logMsg("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // char to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a char - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a char");
- try {
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to char valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a char ");
- try {
- messageReceived.reset();
- if (messageReceived.readChar() == 'a') {
- logTrace("Pass: char to char - valid");
- } else {
- logMsg("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to int invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a char ");
- try {
- messageReceived.reset();
- int i = messageReceived.readInt();
-
- logErr("Fail: MessageFormatException was not thrown");
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to long invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a char");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a char - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // char to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a char - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageConversionTopicTestsChar", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionTopicTestsBytes
- *
- * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:168;
- * JMS:JAVADOC:146; JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:725;
- * JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:744;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeBytes to write a byte[] to the message. Verify the proper conversion
- * support as in 3.11.3
- */
-
- public void streamMessageConversionTopicTestsBytes() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 1, 2, 3 };
- byte[] bValues2 = { 0, 0, 0 };
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsBytes");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte[] primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeBytes(bValues);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // now test conversions for boolean
- // -----------------------------------------------
- // byte[] to byte[] - valid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBytes[] to read a byte[] ");
- int nCount = 0;
-
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readBytes(bValues2) == 3) { // count should be 3.
- logTrace("Pass: byte[] to byte[] - valid");
- } else {
- logErr("Fail: count incorrect");
- pass = false;
- }
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to boolean - invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readBoolean to read a byte[]");
-
- // position to beginning of stream message.
- messageReceived.reset();
- try {
- boolean b = messageReceived.readBoolean();
-
- logErr(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to string invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readString to read a byte[]");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- String s = messageReceived.readString();
-
- logErr(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to byte invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- byte b = messageReceived.readByte();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to short invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to char invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readChar to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- char c = messageReceived.readChar();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to int invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to long invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to float invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to double invalid
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a byte[] - expect MessageFormatException");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logErr("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageConversionTopicTestsBytes", e);
- }
- }
-
- /*
- * @testName: streamMessageConversionTopicTestsInvFormatString
- *
- * @assertion_ids: JMS:SPEC:76; JMS:SPEC:81; JMS:JAVADOC:166; JMS:JAVADOC:130;
- * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:140;
- * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
- *
- * @test_Strategy: Create a StreamMessage -. use StreamMessage method
- * writeString to write a text string of "mytest string". Verify
- * NumberFormatException is thrown Verify that the pointer was not incremented
- * by doing a read string
- *
- */
-
- public void streamMessageConversionTopicTestsInvFormatString() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- boolean pass = true;
- String myString = "mytest string";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsInvFormatString");
-
- // -----------------------------------------------------------------------------
- logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
-
- // -----------------------------------------------------------------------------
- messageSent.writeString(myString);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // -----------------------------------------------
- // String to byte
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readByte to read a String that is not valid ");
- try {
- byte b = messageReceived.readByte();
-
- logErr("Fail: java.lang.NumberFormatException expected");
- pass = false;
- } catch (java.lang.NumberFormatException e) {
- logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // pointer should not have moved
- // -----------------------------------------------
- logMsg("--");
- logMsg(
- "Verify that the data can be read as a string and pointer did not move");
- try {
- String s = messageReceived.readString();
-
- logTrace("message read: " + s);
- if (s.equals(myString)) {
- logTrace("Pass: able to read the string");
- } else {
- logMsg("Fail: string not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to short
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readShort to read a string that is not valid ");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
-
- logErr("Fail: NumberFormatException was expected");
- pass = false;
- } catch (java.lang.NumberFormatException e) {
- logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to int
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readInt to read a String that is not valid ");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
-
- logErr("Fail: NumberFormatException was expected");
- } catch (java.lang.NumberFormatException e) {
- logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readLong to read a String that is not valid ");
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
-
- logErr("Fail: NumberFormatException was expected");
- pass = false;
- } catch (java.lang.NumberFormatException e) {
- logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readFloat to read a String that is not valid ");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
-
- logErr("Fail: NumberFormatException was expected");
- pass = false;
- } catch (java.lang.NumberFormatException e) {
- logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
-
- // -----------------------------------------------
- // String to double
- // -----------------------------------------------
- logMsg("--");
- logMsg("Use readDouble to read a String that is not valid ");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
-
- logMsg("Fail: NumberFormatException was expected");
- pass = false;
- } catch (java.lang.NumberFormatException e) {
- logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception ee) {
- TestUtil.logErr("Error: Unexpected exception: ", ee);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageConversionTopicTestsInvFormatString", e);
- }
- }
-
- /*
- * @testName: streamMessageTopicTestsFullMsg
- *
- * @assertion_ids: JMS:SPEC:82; JMS:JAVADOC:150; JMS:JAVADOC:152;
- * JMS:JAVADOC:154; JMS:JAVADOC:156; JMS:JAVADOC:158; JMS:JAVADOC:160;
- * JMS:JAVADOC:162; JMS:JAVADOC:164; JMS:JAVADOC:166; JMS:JAVADOC:168;
- * JMS:JAVADOC:170; JMS:JAVADOC:172; JMS:JAVADOC:128; JMS:JAVADOC:130;
- * JMS:JAVADOC:132; JMS:JAVADOC:134; JMS:JAVADOC:136; JMS:JAVADOC:138;
- * JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
- * JMS:JAVADOC:148;
- *
- * @test_Strategy: Create a StreamMessage -. write one of each primitive type.
- * Send the message. Verify the data received was as sent.
- *
- */
-
- public void streamMessageTopicTestsFullMsg() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- byte bValue = 127;
- boolean abool = false;
- byte[] bValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
- byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
- byte[] bValuesReturned = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- byte[] bValuesReturned2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- char charValue = 'Z';
- short sValue = 32767;
- long lValue = 9223372036854775807L;
- double dValue = 6.02e23;
- float fValue = 6.02e23f;
- int iValue = 6;
- boolean pass = true;
- String myString = "text";
- String sTesting = "Testing StreamMessages";
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageTopicTestsFullMsg");
-
- // -----------------------------------------------------------------------------
- logTrace("");
-
- // -----------------------------------------------------------------------------
- messageSent.writeBoolean(abool);
- messageSent.writeByte(bValue);
- messageSent.writeBytes(bValues);
- messageSent.writeChar(charValue);
- messageSent.writeDouble(dValue);
- messageSent.writeFloat(fValue);
- messageSent.writeInt(iValue);
- messageSent.writeLong(lValue);
- messageSent.writeObject(sTesting);
- messageSent.writeShort(sValue);
- messageSent.writeString(myString);
- messageSent.writeBytes(bValues2, 0, bValues.length);
- messageSent.writeObject(null);
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- try {
- if (messageReceived.readBoolean() == abool) {
- logTrace("Pass: boolean returned ok");
- } else {
- logMsg("Fail: boolean not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceived.readByte() == bValue) {
- logTrace("Pass: Byte returned ok");
- } else {
- logMsg("Fail: Byte not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- try {
- int nCount;
- do {
- nCount = messageReceived.readBytes(bValuesReturned);
- logTrace("nCount is " + nCount);
- if (nCount != -1) {
- for (int i = 0; i < bValuesReturned.length; i++) {
- if (bValuesReturned[i] != bValues[i]) {
- logMsg("Fail: byte[] " + i + " is not valid");
- pass = false;
- } else {
- logTrace("PASS: byte[]" + i + " is valid");
- }
- }
- }
- } while (nCount >= bValuesReturned.length);
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceived.readChar() == charValue) {
- logTrace("Pass: correct char");
- } else {
- logMsg("Fail: char not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceived.readDouble() == dValue) {
- logTrace("Pass: correct double");
- } else {
- logMsg("Fail: double not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceived.readFloat() == fValue) {
- logTrace("Pass: correct float");
- } else {
- logMsg("Fail: float not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceived.readInt() == iValue) {
- logTrace("Pass: correct int");
- } else {
- logMsg("Fail: int not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceived.readLong() == lValue) {
- logTrace("Pass: correct long");
- } else {
- logErr("Fail: long not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- try {
- if (messageReceived.readObject().equals(sTesting)) {
- logTrace("Pass: correct object");
- } else {
- logMsg("Fail: object not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- try {
- short tmp = messageReceived.readShort();
- if (tmp == sValue) {
- logTrace("Pass: correct short");
- } else {
- logErr("Fail: short not returned as expected");
- logErr("Expecting =" + sValue + ", got =" + tmp + ".");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
-
- try {
- String tmp = messageReceived.readString();
- if (tmp.equals(myString)) {
- logTrace("Pass: correct string");
- } else {
- logErr("Fail: string not returned as expected");
- logErr("Expecting =" + myString + ", got =" + tmp + ".");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- try {
- int nCount;
- do {
- nCount = messageReceived.readBytes(bValuesReturned2);
- logTrace("nCount is " + nCount);
- if (nCount != -1) {
- for (int i = 0; i < bValuesReturned2.length; i++) {
- if (bValuesReturned2[i] != bValues2[i]) {
- logMsg("Fail: byte[] " + i + " is not valid");
- pass = false;
- } else {
- logTrace("PASS: byte[]" + i + " is valid");
- }
- }
- }
- } while (nCount >= bValuesReturned2.length);
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- try {
- if (messageReceived.readObject() == null) {
- logTrace("Pass: correct object");
- } else {
- logErr("Fail: object not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageTopicTestsFullMsg", e);
- }
- }
-
- /*
- * @testName: streamMessageTopicTestNull
- *
- * @assertion_ids: JMS:SPEC:78; JMS:SPEC:86; JMS:JAVADOC:144; JMS:JAVADOC:172;
- *
- * @test_Strategy: Create a StreamMessage Use writeString to write a null,
- * then use readString to read it back.
- */
-
- public void streamMessageTopicTestNull() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- boolean pass = true;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageTopicTestNull");
-
- // -----------------------------------------------------------------------------
- logTrace("writeString(null) ");
-
- // -----------------------------------------------------------------------------
- try {
- messageSent.writeString(null);
- } catch (Exception e) {
- logMsg("Error: unexpected exception " + e.getClass().getName()
- + " was thrown");
-
- // It doesn't make sense to continue, throw an exception
- throw new Exception("Error: failed to write a null object with writeString",
- e);
- }
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // -----------------------------------------------
- //
- // -----------------------------------------------
- logMsg(" ");
- try {
- if (messageReceived.readObject() == null) {
- logTrace("Pass: Read a null");
- } else {
- logMsg("Fail: null value not returned");
- pass = false;
- }
- } catch (Exception e) {
- logErr("Error trying to read a null object");
- logErr("Error: unexpected exception: ", e);
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- throw new Exception("streamMessageTopicTestNull", e);
- }
- }
-
- /*
- * @testName: streamMessageQNotWritable
- *
- * @assertion_ids: JMS:SPEC:73; JMS:JAVADOC:752; JMS:JAVADOC:753;
- * JMS:JAVADOC:754; JMS:JAVADOC:755; JMS:JAVADOC:756; JMS:JAVADOC:757;
- * JMS:JAVADOC:758; JMS:JAVADOC:759; JMS:JAVADOC:761; JMS:JAVADOC:762;
- * JMS:JAVADOC:764;
- *
- * @test_Strategy: Create a StreamMessage, send it to a Topic Receive it and
- * try to write to the received Message's body, MessageNotWritableException
- * should be thrown.
- */
-
- public void streamMessageQNotWritable() throws Exception {
- try {
- StreamMessage messageSent = null;
- StreamMessage messageReceived = null;
- boolean pass = true;
- byte bValue = 127;
- short sValue = 32767;
- char cValue = '\uFFFF';
- int iValue = 2147483647;
- long lValue = 9223372036854775807L;
- float fValue = 0.0f;
- double dValue = -0.0;
- String ssValue = "abc";
- byte[] bbValue = { 0, 88, 127 };
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- messageSent = tool.getDefaultTopicSession().createStreamMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageQNotWritable");
-
- // -----------------------------------------------------------------------------
- try {
- messageSent.writeString("Test Message for streamMessageQNotWritable");
- } catch (Exception e) {
- logMsg("Error: unexpected exception " + e.getClass().getName()
- + " was thrown");
- throw new Exception("Error: failed to writeString", e);
- }
-
- // send the message and then get it back
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- logTrace("Receiving message");
- messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- logMsg("Writing a boolean ... ");
- try {
- messageReceived.writeBoolean(pass);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeBoolean");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeBoolean");
- }
-
- logMsg("Writing a byte ... ");
- try {
- messageReceived.writeByte(bValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeByte");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeByte");
- }
-
- logMsg("Writing a short ... ");
- try {
- messageReceived.writeShort(sValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeShort");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeShort");
- }
-
- logMsg("Writing a char ... ");
- try {
- messageReceived.writeChar(cValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeChar");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeChar");
- }
-
- logMsg("Writing a int ... ");
- try {
- messageReceived.writeInt(iValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeInt");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeInt");
- }
-
- logMsg("Writing a long ... ");
- try {
- messageReceived.writeLong(lValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeLong");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeLong");
- }
-
- logMsg("Writing a float ... ");
- try {
- messageReceived.writeFloat(fValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeFloat");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeFloat");
- }
- logMsg("Writing a double ... ");
- try {
- messageReceived.writeDouble(dValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeDouble");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeDouble");
- }
-
- logMsg("Writing a bytes... ");
- try {
- messageReceived.writeBytes(bbValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeBytes");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeBytes");
- }
-
- logMsg("Writing a string ... ");
- try {
- messageReceived.writeString(ssValue);
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeString");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeString");
- }
-
- logMsg("Writing a object ... ");
- try {
- messageReceived.writeObject(new Integer(iValue));
- logErr("Shouldn't get here");
- throw new Exception("Error: test failed to be able to writeObject");
- } catch (MessageNotWriteableException e) {
- logMsg("Got Expected MessageNotWriteableException with writeObject");
- }
-
- } catch (Exception e) {
- throw new Exception("streamMessageQNotWritable", e);
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/streamMsgTopic/StreamMsgTopicTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/streamMsgTopic/StreamMsgTopicTestsIT.java
new file mode 100644
index 0000000000..45b953410e
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/streamMsgTopic/StreamMsgTopicTestsIT.java
@@ -0,0 +1,3275 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.core.streamMsgTopic;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.MessageNotWriteableException;
+import jakarta.jms.StreamMessage;
+
+
+public class StreamMsgTopicTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.streamMsgTopic.StreamMsgTopicTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(StreamMsgTopicTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList connections = null;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+
+ } catch (Exception e) {
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning: ");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: streamMessageConversionTopicTestsBoolean
+ *
+ * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:219;
+ * JMS:JAVADOC:150; JMS:JAVADOC:128; JMS:JAVADOC:144; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
+ * JMS:JAVADOC:738; JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method
+ * writeBoolean to write a boolean to the message. Verify the proper conversion
+ * support as in 3.11.3
+ */
+ @Test
+ public void streamMessageConversionTopicTestsBoolean() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsBoolean");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for boolean primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeBoolean(abool);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // boolean to boolean - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a boolean");
+ try {
+ if (messageReceived.readBoolean() == abool) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to boolean - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a boolean");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals((Boolean.valueOf(abool)).toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a boolean - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // boolean to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readByte();
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readShort();
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readChar();
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readInt();
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readLong();
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readFloat();
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a boolean - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readDouble();
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageConversionTopicTestsBoolean", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionTopicTestsByte
+ *
+ * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:152;
+ * JMS:JAVADOC:130; JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138;
+ * JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:729; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeByte
+ * to write a byte. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionTopicTestsByte() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsByte");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeByte(bValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // byte to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a byte");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Byte.toString(bValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a byte - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // byte to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a byte");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readByte() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to byte - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a byte");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readShort() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to short - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ pass = false;
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a byte");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to int - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a byte");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageConversionTopicTestsByte", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionTopicTestsShort
+ *
+ * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:154;
+ * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144;
+ * JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:729; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeShort
+ * to write a short. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionTopicTestsShort() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsShort");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeShort(sValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // short to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a short");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Short.toString(sValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: short to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a short - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // short to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a short");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readShort() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to short - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a byte");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to int - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a short");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.INFO, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageConversionTopicTestsShort", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionTopicTestsInt
+ *
+ * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:158;
+ * JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720;
+ * JMS:JAVADOC:723; JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeInt
+ * to write an int. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionTopicTestsInt() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsInt");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeInt(iValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // int to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read an int");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Integer.toString(iValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: int to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read an int - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // int to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read an int");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read an int");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == iValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to int - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read an int");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == iValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageConversionTopicTestsInt", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionTopicTestsLong
+ *
+ * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:160;
+ * JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeLong
+ * to write a long. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionTopicTestsLong() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsLong");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeLong(lValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // long to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a long - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a long");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Long.toString(lValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: long to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a long - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // long to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read an long - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a long");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a long - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a long");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a long");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == lValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a long - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read an long - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageConversionTopicTestsLong", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionTopicTestsFloat
+ *
+ * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:162;
+ * JMS:JAVADOC:140; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeFloat
+ * to write a float. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionTopicTestsFloat() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsFloat");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeFloat(fValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // float to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a float ");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a float");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Float.toString(fValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: float to string - valid");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a float ");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // float to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a float ");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a float");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a long ");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a float");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a long");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a float ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readFloat() == fValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to float - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read an float ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readDouble() == fValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to double - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageConversionTopicTestsFloat", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionTopicTestsDouble
+ *
+ * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:164;
+ * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
+ * JMS:JAVADOC:738; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method
+ * writeDouble to write a double. Verify the proper conversion support as in
+ * 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionTopicTestsDouble() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsDouble");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeDouble(dValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // double to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a double ");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a double");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Double.toString(dValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: double to string");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a double ");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // double to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a double ");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a double");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a double ");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a double");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a double");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a double ");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a double ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readDouble() == dValue) {
+ logger.log(Logger.Level.TRACE, "Pass: double to double ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageConversionTopicTestsDouble", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionTopicTestsString
+ *
+ * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:SPEC:77; JMS:JAVADOC:166;
+ * JMS:JAVADOC:128; JMS:JAVADOC:130; JMS:JAVADOC:132; JMS:JAVADOC:136;
+ * JMS:JAVADOC:138; JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144;
+ * JMS:JAVADOC:729; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method
+ * writeString to write a string. Verify the proper conversion support as in
+ * 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionTopicTestsString() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+ String myString = "10";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeString(myString);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for String
+ // -----------------------------------------------
+ // string to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a String");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: string to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a String");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // String to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a String");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readByte() == Byte.parseByte(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to byte ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a string");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readShort() == Short.parseShort(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to short ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a String ");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // string to int valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a String");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == Integer.parseInt(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to int ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a String");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == Long.parseLong(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to long ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a String");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readFloat() == Float.parseFloat(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to float ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a String");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readDouble() == Double.parseDouble(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to double ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a string ");
+ try {
+ messageReceived.clearBody();
+ messageReceived.writeString("true");
+ messageReceived.reset();
+ if (messageReceived.readBoolean() == abool) {
+ logger.log(Logger.Level.TRACE, "Pass: String to boolean ");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a string that is !true ");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ if (b != true) {
+ logger.log(Logger.Level.ERROR, "Fail: !true should return false");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: !true returned false");
+ }
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageConversionTopicTestsString", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionTopicTestsChar
+ *
+ * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:156;
+ * JMS:JAVADOC:134; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeChar
+ * to write a char. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void streamMessageConversionTopicTestsChar() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsChar");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeChar(charValue);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // char to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a char");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ String s = messageReceived.readString();
+
+ logger.log(Logger.Level.TRACE, "char returned for \"a\" is : " + s);
+ if (s.equals("a")) {
+ logger.log(Logger.Level.TRACE, "Pass: char to string - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a char - expect MessageFormatException");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // char to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a char");
+ try {
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to char valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a char ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readChar() == 'a') {
+ logger.log(Logger.Level.TRACE, "Pass: char to char - valid");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a char ");
+ try {
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a char");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageConversionTopicTestsChar", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionTopicTestsBytes
+ *
+ * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:168;
+ * JMS:JAVADOC:146; JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:725;
+ * JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:744;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method writeBytes
+ * to write a byte[] to the message. Verify the proper conversion support as in
+ * 3.11.3
+ */
+ @Test
+ public void streamMessageConversionTopicTestsBytes() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 1, 2, 3 };
+ byte[] bValues2 = { 0, 0, 0 };
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsBytes");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte[] primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeBytes(bValues);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // byte[] to byte[] - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBytes[] to read a byte[] ");
+ int nCount = 0;
+
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readBytes(bValues2) == 3) { // count should be 3.
+ logger.log(Logger.Level.TRACE, "Pass: byte[] to byte[] - valid");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: count incorrect");
+ pass = false;
+ }
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readBoolean to read a byte[]");
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ try {
+ boolean b = messageReceived.readBoolean();
+
+ logger.log(Logger.Level.ERROR,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to string invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readString to read a byte[]");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ String s = messageReceived.readString();
+
+ logger.log(Logger.Level.ERROR,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readChar to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a byte[] - expect MessageFormatException");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.ERROR, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageConversionTopicTestsBytes", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageConversionTopicTestsInvFormatString
+ *
+ * @assertion_ids: JMS:SPEC:76; JMS:SPEC:81; JMS:JAVADOC:166; JMS:JAVADOC:130;
+ * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:140;
+ * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
+ *
+ * @test_Strategy: Create a StreamMessage -. use StreamMessage method
+ * writeString to write a text string of "mytest string". Verify
+ * NumberFormatException is thrown Verify that the pointer was not incremented
+ * by doing a read string
+ *
+ */
+ @Test
+ public void streamMessageConversionTopicTestsInvFormatString() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ boolean pass = true;
+ String myString = "mytest string";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsInvFormatString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeString(myString);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // -----------------------------------------------
+ // String to byte
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readByte to read a String that is not valid ");
+ try {
+ byte b = messageReceived.readByte();
+
+ logger.log(Logger.Level.ERROR, "Fail: java.lang.NumberFormatException expected");
+ pass = false;
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // pointer should not have moved
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Verify that the data can be read as a string and pointer did not move");
+ try {
+ String s = messageReceived.readString();
+
+ logger.log(Logger.Level.TRACE, "message read: " + s);
+ if (s.equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: able to read the string");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: string not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to short
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readShort to read a string that is not valid ");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+
+ logger.log(Logger.Level.ERROR, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to int
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readInt to read a String that is not valid ");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+
+ logger.log(Logger.Level.ERROR, "Fail: NumberFormatException was expected");
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readLong to read a String that is not valid ");
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+
+ logger.log(Logger.Level.ERROR, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readFloat to read a String that is not valid ");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+
+ logger.log(Logger.Level.ERROR, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to double
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, "--");
+ logger.log(Logger.Level.INFO, "Use readDouble to read a String that is not valid ");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: Unexpected exception: ", ee);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageConversionTopicTestsInvFormatString", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageTopicTestsFullMsg
+ *
+ * @assertion_ids: JMS:SPEC:82; JMS:JAVADOC:150; JMS:JAVADOC:152;
+ * JMS:JAVADOC:154; JMS:JAVADOC:156; JMS:JAVADOC:158; JMS:JAVADOC:160;
+ * JMS:JAVADOC:162; JMS:JAVADOC:164; JMS:JAVADOC:166; JMS:JAVADOC:168;
+ * JMS:JAVADOC:170; JMS:JAVADOC:172; JMS:JAVADOC:128; JMS:JAVADOC:130;
+ * JMS:JAVADOC:132; JMS:JAVADOC:134; JMS:JAVADOC:136; JMS:JAVADOC:138;
+ * JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
+ * JMS:JAVADOC:148;
+ *
+ * @test_Strategy: Create a StreamMessage -. write one of each primitive type.
+ * Send the message. Verify the data received was as sent.
+ *
+ */
+ @Test
+ public void streamMessageTopicTestsFullMsg() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ byte bValue = 127;
+ boolean abool = false;
+ byte[] bValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+ byte[] bValuesReturned = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ byte[] bValuesReturned2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ char charValue = 'Z';
+ short sValue = 32767;
+ long lValue = 9223372036854775807L;
+ double dValue = 6.02e23;
+ float fValue = 6.02e23f;
+ int iValue = 6;
+ boolean pass = true;
+ String myString = "text";
+ String sTesting = "Testing StreamMessages";
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageTopicTestsFullMsg");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "");
+
+ // -----------------------------------------------------------------------------
+ messageSent.writeBoolean(abool);
+ messageSent.writeByte(bValue);
+ messageSent.writeBytes(bValues);
+ messageSent.writeChar(charValue);
+ messageSent.writeDouble(dValue);
+ messageSent.writeFloat(fValue);
+ messageSent.writeInt(iValue);
+ messageSent.writeLong(lValue);
+ messageSent.writeObject(sTesting);
+ messageSent.writeShort(sValue);
+ messageSent.writeString(myString);
+ messageSent.writeBytes(bValues2, 0, bValues.length);
+ messageSent.writeObject(null);
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ try {
+ if (messageReceived.readBoolean() == abool) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean returned ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: boolean not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceived.readByte() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: Byte returned ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Byte not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ int nCount;
+ do {
+ nCount = messageReceived.readBytes(bValuesReturned);
+ logger.log(Logger.Level.TRACE, "nCount is " + nCount);
+ if (nCount != -1) {
+ for (int i = 0; i < bValuesReturned.length; i++) {
+ if (bValuesReturned[i] != bValues[i]) {
+ logger.log(Logger.Level.INFO, "Fail: byte[] " + i + " is not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "PASS: byte[]" + i + " is valid");
+ }
+ }
+ }
+ } while (nCount >= bValuesReturned.length);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceived.readChar() == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct char");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: char not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceived.readDouble() == dValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct double");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: double not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceived.readFloat() == fValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct float");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: float not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceived.readInt() == iValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct int");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: int not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceived.readLong() == lValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct long");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: long not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readObject().equals(sTesting)) {
+ logger.log(Logger.Level.TRACE, "Pass: correct object");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: object not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ short tmp = messageReceived.readShort();
+ if (tmp == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct short");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: short not returned as expected");
+ logger.log(Logger.Level.ERROR, "Expecting =" + sValue + ", got =" + tmp + ".");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = messageReceived.readString();
+ if (tmp.equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: correct string");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: string not returned as expected");
+ logger.log(Logger.Level.ERROR, "Expecting =" + myString + ", got =" + tmp + ".");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ int nCount;
+ do {
+ nCount = messageReceived.readBytes(bValuesReturned2);
+ logger.log(Logger.Level.TRACE, "nCount is " + nCount);
+ if (nCount != -1) {
+ for (int i = 0; i < bValuesReturned2.length; i++) {
+ if (bValuesReturned2[i] != bValues2[i]) {
+ logger.log(Logger.Level.INFO, "Fail: byte[] " + i + " is not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "PASS: byte[]" + i + " is valid");
+ }
+ }
+ }
+ } while (nCount >= bValuesReturned2.length);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ try {
+ if (messageReceived.readObject() == null) {
+ logger.log(Logger.Level.TRACE, "Pass: correct object");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: object not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageTopicTestsFullMsg", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageTopicTestNull
+ *
+ * @assertion_ids: JMS:SPEC:78; JMS:SPEC:86; JMS:JAVADOC:144; JMS:JAVADOC:172;
+ *
+ * @test_Strategy: Create a StreamMessage Use writeString to write a null, then
+ * use readString to read it back.
+ */
+ @Test
+ public void streamMessageTopicTestNull() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ boolean pass = true;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageTopicTestNull");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "writeString(null) ");
+
+ // -----------------------------------------------------------------------------
+ try {
+ messageSent.writeString(null);
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Error: unexpected exception " + e.getClass().getName() + " was thrown");
+
+ // It doesn't make sense to continue, throw an exception
+ throw new Exception("Error: failed to write a null object with writeString", e);
+ }
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // -----------------------------------------------
+ //
+ // -----------------------------------------------
+ logger.log(Logger.Level.INFO, " ");
+ try {
+ if (messageReceived.readObject() == null) {
+ logger.log(Logger.Level.TRACE, "Pass: Read a null");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: null value not returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error trying to read a null object");
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", e);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ throw new Exception("streamMessageTopicTestNull", e);
+ }
+ }
+
+ /*
+ * @testName: streamMessageQNotWritable
+ *
+ * @assertion_ids: JMS:SPEC:73; JMS:JAVADOC:752; JMS:JAVADOC:753;
+ * JMS:JAVADOC:754; JMS:JAVADOC:755; JMS:JAVADOC:756; JMS:JAVADOC:757;
+ * JMS:JAVADOC:758; JMS:JAVADOC:759; JMS:JAVADOC:761; JMS:JAVADOC:762;
+ * JMS:JAVADOC:764;
+ *
+ * @test_Strategy: Create a StreamMessage, send it to a Topic Receive it and try
+ * to write to the received Message's body, MessageNotWritableException should
+ * be thrown.
+ */
+ @Test
+ public void streamMessageQNotWritable() throws Exception {
+ try {
+ StreamMessage messageSent = null;
+ StreamMessage messageReceived = null;
+ boolean pass = true;
+ byte bValue = 127;
+ short sValue = 32767;
+ char cValue = '\uFFFF';
+ int iValue = 2147483647;
+ long lValue = 9223372036854775807L;
+ float fValue = 0.0f;
+ double dValue = -0.0;
+ String ssValue = "abc";
+ byte[] bbValue = { 0, 88, 127 };
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ messageSent = tool.getDefaultTopicSession().createStreamMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageQNotWritable");
+
+ // -----------------------------------------------------------------------------
+ try {
+ messageSent.writeString("Test Message for streamMessageQNotWritable");
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Error: unexpected exception " + e.getClass().getName() + " was thrown");
+ throw new Exception("Error: failed to writeString", e);
+ }
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ logger.log(Logger.Level.INFO, "Writing a boolean ... ");
+ try {
+ messageReceived.writeBoolean(pass);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeBoolean");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeBoolean");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a byte ... ");
+ try {
+ messageReceived.writeByte(bValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeByte");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeByte");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a short ... ");
+ try {
+ messageReceived.writeShort(sValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeShort");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeShort");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a char ... ");
+ try {
+ messageReceived.writeChar(cValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeChar");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeChar");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a int ... ");
+ try {
+ messageReceived.writeInt(iValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeInt");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeInt");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a long ... ");
+ try {
+ messageReceived.writeLong(lValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeLong");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeLong");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a float ... ");
+ try {
+ messageReceived.writeFloat(fValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeFloat");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeFloat");
+ }
+ logger.log(Logger.Level.INFO, "Writing a double ... ");
+ try {
+ messageReceived.writeDouble(dValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeDouble");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeDouble");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a bytes... ");
+ try {
+ messageReceived.writeBytes(bbValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeBytes");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeBytes");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a string ... ");
+ try {
+ messageReceived.writeString(ssValue);
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeString");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeString");
+ }
+
+ logger.log(Logger.Level.INFO, "Writing a object ... ");
+ try {
+ messageReceived.writeObject(new Integer(iValue));
+ logger.log(Logger.Level.ERROR, "Shouldn't get here");
+ throw new Exception("Error: test failed to be able to writeObject");
+ } catch (MessageNotWriteableException e) {
+ logger.log(Logger.Level.INFO, "Got Expected MessageNotWriteableException with writeObject");
+ }
+
+ } catch (Exception e) {
+ throw new Exception("streamMessageQNotWritable", e);
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/topicConnection/TopicConnectionTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/topicConnection/TopicConnectionTests.java
deleted file mode 100644
index ae09fd0f76..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/topicConnection/TopicConnectionTests.java
+++ /dev/null
@@ -1,366 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.topicConnection;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.ConnectionMetaData;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicConnection;
-import jakarta.jms.TopicSession;
-import jakarta.jms.TopicSubscriber;
-
-public class TopicConnectionTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.topicConnection.TopicConnectionTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // Harness req's
- private Properties props = null;
-
- // JMS object
- private transient JmsTool tool = null;
-
- // properties read from ts.jte file
- long timeout;
-
- private String jmsUser;
-
- private String jmsPassword;
-
- private String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- TopicConnectionTests theTests = new TopicConnectionTests();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- logMsg("Didn't get expected exception");
- throw new Exception("Didn't catch expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- logTrace("In setup");
- // get props
- jmsUser = p.getProperty("user");
- jmsPassword = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- connections = new ArrayList(5);
-
- // get ready for new test
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: connNotStartedTopicTest
- *
- * @assertion_ids: JMS:SPEC:97; JMS:JAVADOC:522;
- *
- * @test_Strategy: Make certain that one can not receive a message on a
- * non-started connection. Setup to test assertion involves a best effort
- * attempt to ensure that subscriber has a message to deliver but can not
- * because the connection has never been started. Create two subscribers to
- * the same topic on different connections. Only start one of the connections.
- * Publish messages to the topic. Receive the messages on the started
- * connection. Make sure the message is not available to be received on the
- * non-started connection. Start the previously non-started connection and
- * make sure that the message are now received.
- *
- */
- public void connNotStartedTopicTest() throws Exception {
- boolean pass = true;
- String lookup = "MyTopicConnectionFactory";
- final int NUM_MSGS = 5;
-
- try {
- Topic topic = null;
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- TopicConnection nonStartedConn = null;
- TopicSession nonStartedSess = null;
- TopicSubscriber nonStartedSub = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
- topic = tool.getDefaultTopic();
-
- nonStartedConn = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC,
- jmsUser, jmsPassword, lookup);
- connections.add(nonStartedConn);
- nonStartedSess = nonStartedConn.createTopicSession(false,
- Session.AUTO_ACKNOWLEDGE);
- nonStartedSub = nonStartedSess.createSubscriber(topic);
-
- tool.getDefaultTopicConnection().start();
-
- logMsg("Creating message");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "connNotStartedTopicTest");
-
- logMsg("Publishing messages");
- for (int i = 0; i < NUM_MSGS; i++) {
- messageSent.setText("just a test. Msg num " + i);
- tool.getDefaultTopicPublisher().publish(messageSent);
- }
-
- // receive messages on started connection.
- logMsg("Receive messages on started connection");
- for (int i = 0; i < NUM_MSGS; i++) {
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- logMsg("Fail: Did not receive expected message");
- pass = false;
- }
- }
-
- // ensure that can not receive messages on non-started connection.
- logMsg("Ensure messages not received on non-started connection");
- for (int i = 0; i < NUM_MSGS; i++) {
- messageReceived = (TextMessage) nonStartedSub.receiveNoWait();
- if (messageReceived != null) {
- logMsg("Fail: Received message on a non-started connection");
- pass = false;
- }
- }
-
- // Start connection and verify messages can be received.
- logMsg("Ensure messages received on now started connection");
- nonStartedConn.start();
- for (int i = 0; i < NUM_MSGS; i++) {
- messageReceived = (TextMessage) nonStartedSub.receive(timeout);
- if (messageReceived == null) {
- logMsg("Fail: Did not receive expected message");
- pass = false;
- }
- }
- nonStartedConn.close();
-
- if (!pass) {
- throw new Exception("Error: failures occurred during tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("connNotStartedTopicTest");
- }
- }
-
- /*
- * @testName: metaDataTests
- *
- * @assertion_ids: JMS:JAVADOC:486; JMS:JAVADOC:488; JMS:JAVADOC:490;
- * JMS:JAVADOC:492; JMS:JAVADOC:494; JMS:JAVADOC:496; JMS:JAVADOC:498;
- *
- * @test_Strategy: Create a TopicConnection to get ConnectionMetaData. Verify
- * that all Content of the ConnectionMetaData matches the type defined in API
- * and JMS API version is correct.
- */
-
- public void metaDataTests() throws Exception {
- boolean pass = true;
- ConnectionMetaData data = null;
-
- try {
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
- data = tool.getDefaultTopicConnection().getMetaData();
-
- if (!verifyMetaData(data))
- pass = false;
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- try {
- tool.getDefaultTopicConnection().close();
- } catch (Exception e) {
- logErr("Error closing TopicConnection in metaDataTests : ", e);
- }
- }
-
- try {
- tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, mode);
- data = tool.getDefaultConnection().getMetaData();
-
- if (!verifyMetaData(data))
- pass = false;
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- try {
- tool.getDefaultConnection().close();
- } catch (Exception e) {
- logErr("Error closing Connection in metaDataTests : ", e);
- }
- }
-
- if (!pass) {
- throw new Exception("Error: metaDataTests failed");
- }
- }
-
- private boolean verifyMetaData(ConnectionMetaData data) {
- boolean pass = true;
-
- try {
- String tmp = data.getJMSVersion();
- TestUtil.logTrace("JMSVersion=" + tmp);
-
- if (!tmp.equals(JmsTool.JMS_VERSION)) {
- logErr("Error: incorrect JMSVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getJMSMajorVersion();
- TestUtil.logTrace("JMSMajorVersion=" + tmp);
-
- if (tmp != JmsTool.JMS_MAJOR_VERSION) {
- logErr("Error: incorrect JMSMajorVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- logErr("Error: incorrect type returned for JMSMajorVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getJMSMinorVersion();
- TestUtil.logTrace("JMSMinorVersion=" + tmp);
- } catch (Exception e) {
- logErr("Error: incorrect type returned for JMSMinorVersion: ", e);
- pass = false;
- }
-
- try {
- String tmp = data.getJMSProviderName();
- TestUtil.logTrace("JMSProviderName=" + tmp);
- } catch (Exception e) {
- logErr("Error: incorrect type returned for JMSProviderName: ", e);
- pass = false;
- }
-
- try {
- String tmp = data.getProviderVersion();
- TestUtil.logTrace("JMSProviderVersion=" + tmp);
- } catch (Exception e) {
- logErr("Error: incorrect type returned for ProviderVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getProviderMajorVersion();
- TestUtil.logTrace("ProviderMajorVersion=" + tmp);
- } catch (Exception e) {
- logErr("Error: incorrect type returned for ProviderMajorVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getProviderMinorVersion();
- TestUtil.logTrace("ProviderMinorVersion=" + tmp);
- } catch (Exception e) {
- logErr("Error: incorrect type returned for ProviderMinorVersion: ", e);
- pass = false;
- }
- return pass;
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/topicConnection/TopicConnectionTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/topicConnection/TopicConnectionTestsIT.java
new file mode 100644
index 0000000000..8f5a0338ec
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/topicConnection/TopicConnectionTestsIT.java
@@ -0,0 +1,358 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.topicConnection;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.ConnectionMetaData;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicConnection;
+import jakarta.jms.TopicSession;
+import jakarta.jms.TopicSubscriber;
+
+
+public class TopicConnectionTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.topicConnection.TopicConnectionTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(TopicConnectionTestsIT.class.getName());
+
+ // Harness req's
+ private Properties props = null;
+
+ // JMS object
+ private transient JmsTool tool = null;
+
+ // properties read
+ long timeout;
+
+ private String jmsUser;
+
+ private String jmsPassword;
+
+ private String mode;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't catch expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, "In setup");
+ // get props
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ connections = new ArrayList(5);
+
+ // get ready for new test
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: connNotStartedTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:97; JMS:JAVADOC:522;
+ *
+ * @test_Strategy: Make certain that one can not receive a message on a
+ * non-started connection. Setup to test assertion involves a best effort
+ * attempt to ensure that subscriber has a message to deliver but can not
+ * because the connection has never been started. Create two subscribers to the
+ * same topic on different connections. Only start one of the connections.
+ * Publish messages to the topic. Receive the messages on the started
+ * connection. Make sure the message is not available to be received on the
+ * non-started connection. Start the previously non-started connection and make
+ * sure that the message are now received.
+ *
+ */
+ @Test
+ public void connNotStartedTopicTest() throws Exception {
+ boolean pass = true;
+ String lookup = "MyTopicConnectionFactory";
+ final int NUM_MSGS = 5;
+
+ try {
+ Topic topic = null;
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ TopicConnection nonStartedConn = null;
+ TopicSession nonStartedSess = null;
+ TopicSubscriber nonStartedSub = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
+ topic = tool.getDefaultTopic();
+
+ nonStartedConn = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, jmsUser, jmsPassword, lookup);
+ connections.add(nonStartedConn);
+ nonStartedSess = nonStartedConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ nonStartedSub = nonStartedSess.createSubscriber(topic);
+
+ tool.getDefaultTopicConnection().start();
+
+ logger.log(Logger.Level.INFO, "Creating message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "connNotStartedTopicTest");
+
+ logger.log(Logger.Level.INFO, "Publishing messages");
+ for (int i = 0; i < NUM_MSGS; i++) {
+ messageSent.setText("just a test. Msg num " + i);
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ }
+
+ // receive messages on started connection.
+ logger.log(Logger.Level.INFO, "Receive messages on started connection");
+ for (int i = 0; i < NUM_MSGS; i++) {
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.INFO, "Fail: Did not receive expected message");
+ pass = false;
+ }
+ }
+
+ // ensure that can not receive messages on non-started connection.
+ logger.log(Logger.Level.INFO, "Ensure messages not received on non-started connection");
+ for (int i = 0; i < NUM_MSGS; i++) {
+ messageReceived = (TextMessage) nonStartedSub.receiveNoWait();
+ if (messageReceived != null) {
+ logger.log(Logger.Level.INFO, "Fail: Received message on a non-started connection");
+ pass = false;
+ }
+ }
+
+ // Start connection and verify messages can be received.
+ logger.log(Logger.Level.INFO, "Ensure messages received on now started connection");
+ nonStartedConn.start();
+ for (int i = 0; i < NUM_MSGS; i++) {
+ messageReceived = (TextMessage) nonStartedSub.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.INFO, "Fail: Did not receive expected message");
+ pass = false;
+ }
+ }
+ nonStartedConn.close();
+
+ if (!pass) {
+ throw new Exception("Error: failures occurred during tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("connNotStartedTopicTest");
+ }
+ }
+
+ /*
+ * @testName: metaDataTests
+ *
+ * @assertion_ids: JMS:JAVADOC:486; JMS:JAVADOC:488; JMS:JAVADOC:490;
+ * JMS:JAVADOC:492; JMS:JAVADOC:494; JMS:JAVADOC:496; JMS:JAVADOC:498;
+ *
+ * @test_Strategy: Create a TopicConnection to get ConnectionMetaData. Verify
+ * that all Content of the ConnectionMetaData matches the type defined in API
+ * and JMS API version is correct.
+ */
+ @Test
+ public void metaDataTests() throws Exception {
+ boolean pass = true;
+ ConnectionMetaData data = null;
+
+ try {
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
+ data = tool.getDefaultTopicConnection().getMetaData();
+
+ if (!verifyMetaData(data))
+ pass = false;
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ try {
+ tool.getDefaultTopicConnection().close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing TopicConnection in metaDataTests : ", e);
+ }
+ }
+
+ try {
+ tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, mode);
+ data = tool.getDefaultConnection().getMetaData();
+
+ if (!verifyMetaData(data))
+ pass = false;
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ try {
+ tool.getDefaultConnection().close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection in metaDataTests : ", e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("Error: metaDataTests failed");
+ }
+ }
+
+ private boolean verifyMetaData(ConnectionMetaData data) {
+ boolean pass = true;
+
+ try {
+ String tmp = data.getJMSVersion();
+ logger.log(Logger.Level.TRACE, "JMSVersion=" + tmp);
+
+ if (!tmp.equals(JmsTool.JMS_VERSION)) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getJMSMajorVersion();
+ logger.log(Logger.Level.TRACE, "JMSMajorVersion=" + tmp);
+
+ if (tmp != JmsTool.JMS_MAJOR_VERSION) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSMajorVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSMajorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getJMSMinorVersion();
+ logger.log(Logger.Level.TRACE, "JMSMinorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSMinorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = data.getJMSProviderName();
+ logger.log(Logger.Level.TRACE, "JMSProviderName=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSProviderName: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = data.getProviderVersion();
+ logger.log(Logger.Level.TRACE, "JMSProviderVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getProviderMajorVersion();
+ logger.log(Logger.Level.TRACE, "ProviderMajorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderMajorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getProviderMinorVersion();
+ logger.log(Logger.Level.TRACE, "ProviderMinorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderMinorVersion: ", e);
+ pass = false;
+ }
+ return pass;
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/topicMsgHeaders/TopicHeaderTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/topicMsgHeaders/TopicHeaderTests.java
deleted file mode 100644
index 98437ae0c2..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/topicMsgHeaders/TopicHeaderTests.java
+++ /dev/null
@@ -1,1780 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.topicMsgHeaders;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.DeliveryMode;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-
-public class TopicHeaderTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.topicMsgHeaders.TopicHeaderTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- TopicHeaderTests theTests = new TopicHeaderTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
-
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- logMsg("Didn't get expected exception");
- throw new Exception("Didn't catch expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the TestTools object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
-
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- logMsg("Cleanup: Closing Queue and Topic Connections");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * helper method for msgHdrIDQTest and msgHdrIDTopicTest verifies that the
- * JMSMessageID starts with ID:
- *
- *
- * @param String returned from getJMSMessageID
- *
- * @return boolean true if id correctly starts with ID:
- */
-
- private boolean chkMessageID(String id) {
- String status[] = { "Pass", "Fail" };
- boolean retcode = true;
-
- // message id must start with ID: - unless it is null
- int index = 0;
-
- if (id == null) {
- ;
- } else if (id.startsWith("ID:")) {
- ;
- } else {
- index = 1;
- retcode = false;
- }
- logTrace("Results: " + status[index]);
- return retcode;
- }
-
- /*
- * @testName: msgHdrIDTopicTest
- *
- * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343;
- *
- * @test_Strategy: With a topic destination Send and receive single Text, map,
- * bytes, stream, and object message call getJMSMessageID and verify that it
- * starts with ID:
- */
-
- public void msgHdrIDTopicTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- String id = null;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentStreamMessage = null;
- StreamMessage messageReceivedStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- BytesMessage messageReceivedBytesMessage = null;
- MapMessage messageReceivedMapMessage = null;
- MapMessage messageSentMapMessage = null;
- ObjectMessage messageSentObjectMsg = null;
- ObjectMessage messageReceivedObjectMsg = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
-
- // send and receive Object message to Topic
- logTrace("Send ObjectMessage to Topic.");
- messageSentObjectMsg = tool.getDefaultTopicSession()
- .createObjectMessage();
- messageSentObjectMsg.setObject("msgHdrIDTopicTest for Object Message");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrIDToopicTest");
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("getJMSMessageID ");
- logTrace(" " + messageReceivedObjectMsg.getJMSMessageID());
- id = messageReceivedObjectMsg.getJMSMessageID();
- if (!chkMessageID(id)) {
- logMsg("ObjectMessage error: JMSMessageID does not start with ID:");
- pass = false;
- }
-
- // send and receive map message to Topic
- logTrace("Send MapMessage to Topic.");
- messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrIDTopicTest");
- messageSentMapMessage.setString("aString", "value");
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("getJMSMessageID ");
- logTrace(" " + messageReceivedMapMessage.getJMSMessageID());
- id = messageReceivedMapMessage.getJMSMessageID();
- if (!chkMessageID(id)) {
- logMsg("MapMessage error: JMSMessageID does not start with ID:");
- pass = false;
- }
-
- // send and receive bytes message to Topic
- logTrace("Send BytesMessage to Topic.");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrIDTopicTest");
- messageSentBytesMessage.writeByte(bValue);
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("getJMSMessageID ");
- logTrace(" " + messageReceivedBytesMessage.getJMSMessageID());
- id = messageReceivedBytesMessage.getJMSMessageID();
- if (!chkMessageID(id)) {
- logMsg("BytesMessage error: JMSMessageID does not start with ID:");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logTrace("sending a Stream message");
- messageSentStreamMessage = tool.getDefaultTopicSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrIDTopicTest");
- messageSentStreamMessage.writeString("Testing...");
- logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("getJMSMessageID ");
- logTrace(" " + messageReceivedStreamMessage.getJMSMessageID());
- id = messageReceivedStreamMessage.getJMSMessageID();
- if (!chkMessageID(id)) {
- logMsg("StreamMessage error: JMSMessageID does not start with ID:");
- pass = false;
- }
-
- // Text Message
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrIDTopicTest");
- logTrace("sending a Text message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("getJMSMessageID ");
- logTrace(" " + messageReceived.getJMSMessageID());
- id = messageReceived.getJMSMessageID();
- if (!chkMessageID(id)) {
- logMsg("TextMessage error: JMSMessageID does not start with ID:");
- pass = false;
- }
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSMessageID returned from JMSMessageID");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrIDTopicTest");
- }
- }
-
- /*
- * @testName: msgHdrTimeStampTopicTest
- *
- * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347;
- *
- * @test_Strategy: With a Topic destination Send a single Text, map, bytes,
- * stream, and object message check time of send against time send returns
- * JMSTimeStamp should be between these two
- */
-
- public void msgHdrTimeStampTopicTest() throws Exception {
- boolean pass = true;
- long timeBeforeSend;
- long timeAfterSend;
- byte bValue = 127;
- String id = null;
-
- try {
- TextMessage messageSent = null;
- StreamMessage messageSentStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- MapMessage messageSentMapMessage = null;
- ObjectMessage messageSentObjectMsg = null;
-
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
-
- // send an Object message to Topic
- logTrace("Send ObjectMessage to TOPIC.");
- messageSentObjectMsg = tool.getDefaultTopicSession()
- .createObjectMessage();
- messageSentObjectMsg
- .setObject("msgHdrTimeStampTopicTest for Object Message");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTopicTest");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- logTrace(" getJMSTimestamp");
- logTrace(" " + messageSentObjectMsg.getJMSTimestamp());
- logTrace("Time at send is: " + timeBeforeSend);
- logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentObjectMsg.getJMSTimestamp())
- && (timeAfterSend >= messageSentObjectMsg.getJMSTimestamp())) {
- logTrace("Object Message TimeStamp pass");
- } else {
- logMsg("Error: invalid timestamp from ObjectMessage");
- pass = false;
- }
-
- // send map message to Topic
- logTrace("Send MapMessage to Topic.");
- messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTopicTest");
- messageSentMapMessage.setString("aString", "value");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- logTrace(" getJMSTimestamp");
- logTrace(" " + messageSentMapMessage.getJMSTimestamp());
- logTrace("Time at send is: " + timeBeforeSend);
- logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentMapMessage.getJMSTimestamp())
- && (timeAfterSend >= messageSentMapMessage.getJMSTimestamp())) {
- logTrace("MapMessage TimeStamp pass");
- } else {
- logMsg("Error: invalid timestamp from MapMessage");
- pass = false;
- }
-
- // send and receive bytes message to Topic
- logTrace("Send BytesMessage to Topic.");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTopicTest");
- messageSentBytesMessage.writeByte(bValue);
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- logTrace(" getJMSTimestamp");
- logTrace(" " + messageSentBytesMessage.getJMSTimestamp());
- logTrace("Time at send is: " + timeBeforeSend);
- logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentBytesMessage.getJMSTimestamp())
- && (timeAfterSend >= messageSentBytesMessage.getJMSTimestamp())) {
- logTrace("BytesMessage TimeStamp pass");
- } else {
- logMsg("Error: invalid timestamp from BytesMessage");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logTrace("sending a Stream message");
- messageSentStreamMessage = tool.getDefaultTopicSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTopicTest");
- messageSentStreamMessage.writeString("Testing...");
- logTrace("Sending message");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- logTrace(" getJMSTimestamp");
- logTrace(" " + messageSentStreamMessage.getJMSTimestamp());
- logTrace("Time at send is: " + timeBeforeSend);
- logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentStreamMessage.getJMSTimestamp())
- && (timeAfterSend >= messageSentStreamMessage.getJMSTimestamp())) {
- logTrace("StreamMessage TimeStamp pass");
- } else {
- logMsg("Error: invalid timestamp from StreamMessage");
- pass = false;
- }
-
- // Text Message
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTopicTest");
- logTrace("sending a Text message");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- tool.getDefaultTopicPublisher().publish(messageSent);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- logTrace(" getJMSTimestamp");
- logTrace(" " + messageSent.getJMSTimestamp());
- logTrace("Time at send is: " + timeBeforeSend);
- logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSent.getJMSTimestamp())
- && (timeAfterSend >= messageSent.getJMSTimestamp())) {
- logTrace("TextMessage TimeStamp pass");
- } else {
- logMsg("Error: invalid timestamp from TextMessage");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: invalid TimeStamp returned from JMSTimeStamp");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrTimeStampTopicTest");
- }
- }
-
- /*
- * @testName: msgHdrCorlIdTopicTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- * @test_Strategy: Send a message to a Topic with CorrelationID set. Receive
- * msg and verify the correlationid is as set by client
- *
- */
-
- public void msgHdrCorlIdTopicTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- String jmsCorrelationID = "test Correlation id";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentStreamMessage = null;
- StreamMessage messageReceivedStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- BytesMessage messageReceivedBytesMessage = null;
- MapMessage messageReceivedMapMessage = null;
- MapMessage messageSentMapMessage = null;
- ObjectMessage messageSentObjectMsg = null;
- ObjectMessage messageReceivedObjectMsg = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrCorlIdTopicTest");
- logTrace("Sending Text message to Topic ");
- messageSent.setJMSCorrelationID(jmsCorrelationID);
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("jmsCorrelationID: " + messageReceived.getJMSCorrelationID());
- if (messageReceived.getJMSCorrelationID() == null) {
- pass = false;
- logMsg("Text Message Error: JMSCorrelationID returned a null");
- } else if (messageReceived.getJMSCorrelationID()
- .equals(jmsCorrelationID)) {
- logTrace("pass");
- } else {
- pass = false;
- logMsg("Text Message Error: JMSCorrelationID is incorrect");
- }
-
- // send and receive Object message to Topic
- logTrace("Send ObjectMessage to Topic.");
- messageSentObjectMsg = tool.getDefaultTopicSession()
- .createObjectMessage();
- messageSentObjectMsg
- .setObject("msgHdrCorlIdTopicTest for Object Message");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrCorlIdTopicTest");
- messageSentObjectMsg.setJMSCorrelationID(jmsCorrelationID);
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("jmsCorrelationID: "
- + messageReceivedObjectMsg.getJMSCorrelationID());
- if (messageReceivedObjectMsg.getJMSCorrelationID() == null) {
- pass = false;
- logMsg("Object Message Error: JMSCorrelationID returned a null");
- } else if (messageReceivedObjectMsg.getJMSCorrelationID()
- .equals(jmsCorrelationID)) {
- logTrace("pass");
- } else {
- pass = false;
- logMsg("Object Message Error: JMSCorrelationID is incorrect");
- }
-
- // send and receive map message to Topic
- logTrace("Send MapMessage to Topic.");
- messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrCorlIdTopicTest");
- messageSentMapMessage.setJMSCorrelationID(jmsCorrelationID);
- messageSentMapMessage.setString("aString", "value");
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("jmsCorrelationID: "
- + messageReceivedMapMessage.getJMSCorrelationID());
- if (messageReceivedMapMessage.getJMSCorrelationID() == null) {
- pass = false;
- logMsg("Map Message Error: JMSCorrelationID returned a null");
- } else if (messageReceivedMapMessage.getJMSCorrelationID()
- .equals(jmsCorrelationID)) {
- logTrace("pass");
- } else {
- pass = false;
- logMsg("Map Message Error: JMSCorrelationID is incorrect");
- }
-
- // send and receive bytes message to Topic
- logTrace("Send BytesMessage to Topic.");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrCorlIdTopicTest");
- messageSentBytesMessage.setJMSCorrelationID(jmsCorrelationID);
- messageSentBytesMessage.writeByte(bValue);
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("jmsCorrelationID: "
- + messageReceivedBytesMessage.getJMSCorrelationID());
- if (messageReceivedBytesMessage.getJMSCorrelationID() == null) {
- pass = false;
- logMsg("Bytes Message Error: JMSCorrelationID returned a null");
- } else if (messageReceivedBytesMessage.getJMSCorrelationID()
- .equals(jmsCorrelationID)) {
- logTrace("pass");
- } else {
- pass = false;
- logMsg("Byte Message Error: JMSCorrelationID is incorrect");
- }
-
- // Send and receive a StreamMessage
- logTrace("sending a Stream message");
- messageSentStreamMessage = tool.getDefaultTopicSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrCorlIdTopicTest");
- messageSentStreamMessage.setJMSCorrelationID(jmsCorrelationID);
- messageSentStreamMessage.writeString("Testing...");
- logTrace("Sending Stream message");
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("jmsCorrelationID: "
- + messageReceivedStreamMessage.getJMSCorrelationID());
- if (messageReceivedStreamMessage.getJMSCorrelationID() == null) {
- pass = false;
- logMsg("Stream Message Error: JMSCorrelationID returned a null");
- } else if (messageReceivedStreamMessage.getJMSCorrelationID()
- .equals(jmsCorrelationID)) {
- logTrace("pass");
- } else {
- pass = false;
- logMsg("Stream Message Error: JMSCorrelationID is incorrect");
- }
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSCorrelationID returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrCorlIdTopicTest");
- }
- }
-
- /*
- * @testName: msgHdrReplyToTopicTest
- *
- * @assertion_ids: JMS:SPEC:12; JMS:JAVADOC:359; JMS:JAVADOC:361;
- * JMS:JAVADOC:117; JMS:SPEC:246.8; JMS:JAVADOC:289; JMS:JAVADOC:562;
- * JMS:JAVADOC:166;
- *
- * @test_Strategy: Send a message to a Topic with ReplyTo set to null and then
- * set to a destination test with Text, map, object, byte, and stream messages
- * verify on receive.
- *
- */
-
- public void msgHdrReplyToTopicTest() throws Exception {
- boolean pass = true;
- Topic replyTopic = null;
- byte bValue = 127;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentStreamMessage = null;
- StreamMessage messageReceivedStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- BytesMessage messageReceivedBytesMessage = null;
- MapMessage messageReceivedMapMessage = null;
- MapMessage messageSentMapMessage = null;
- ObjectMessage messageSentObjectMsg = null;
- ObjectMessage messageReceivedObjectMsg = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrReplyToTopicTest");
- logTrace("Send Text message");
-
- // messageSent.setJMSReplyTo(tool.getDefaultTopic());
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived.getJMSReplyTo() == null) {
- logTrace(" as expected replyto field is null");
- } else {
- logMsg(
- "ERROR: expected replyto field should have been null for this case");
- pass = false;
- }
- logTrace("Set ReplyTo and resend msg");
- messageSent.setJMSReplyTo(tool.getDefaultTopic());
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- replyTopic = (Topic) messageReceived.getJMSReplyTo();
- logTrace("Topic name is " + replyTopic.getTopicName());
- if (replyTopic.getTopicName()
- .equals(tool.getDefaultTopic().getTopicName())) {
- logTrace("Pass ");
- } else {
- logMsg("Text Message Failed");
- pass = false;
- }
-
- // send and receive Object message to Topic
- logTrace("Send ObjectMessage to Topic.");
- messageSentObjectMsg = tool.getDefaultTopicSession()
- .createObjectMessage();
- messageSentObjectMsg
- .setObject("msgHdrReplyToTopicTest for Object Message");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrReplyToTopicTest");
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- if (messageReceivedObjectMsg.getJMSReplyTo() == null) {
- logTrace(" as expected replyto field is null");
- } else {
- logMsg("ERROR: expected replyto field to be null in this case");
- pass = false;
- }
- logTrace("Set ReplyTo and resend msg");
- messageSentObjectMsg.setJMSReplyTo(tool.getDefaultTopic());
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- replyTopic = (Topic) messageReceivedObjectMsg.getJMSReplyTo();
- logTrace("Topic name is " + replyTopic.getTopicName());
- if (replyTopic.getTopicName()
- .equals(tool.getDefaultTopic().getTopicName())) {
- logTrace("Pass ");
- } else {
- logMsg("Object Message ReplyTo Failed");
- pass = false;
- }
-
- // send and receive map message to Topic
- logTrace("Send MapMessage to Topic.");
- messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrReplyToTopicTest");
- messageSentMapMessage.setString("aString", "value");
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceivedMapMessage.getJMSReplyTo() == null) {
- logTrace(" as expected replyto field is null");
- } else {
- logMsg("ERROR: expected replyto field to be null in this case");
- pass = false;
- }
- logTrace("Set ReplyTo and resend msg");
- messageSentMapMessage.setJMSReplyTo(tool.getDefaultTopic());
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("Received Map message ");
- replyTopic = (Topic) messageReceivedMapMessage.getJMSReplyTo();
- logTrace("Topic name is " + replyTopic.getTopicName());
- if (replyTopic.getTopicName()
- .equals(tool.getDefaultTopic().getTopicName())) {
- logTrace("Pass ");
- } else {
- logMsg("Map Message ReplyTo Failed");
- pass = false;
- }
-
- // send and receive bytes message to Topic
- logTrace("Send BytesMessage to Topic.");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrReplyToTopicTest");
- messageSentBytesMessage.writeByte(bValue);
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- if (messageReceivedBytesMessage.getJMSReplyTo() == null) {
- logTrace(" as expected replyto field is null");
- } else {
- logMsg("ERROR: expected replyto field to be null in this case");
- pass = false;
- }
- logTrace("Set ReplyTo and resend msg");
- messageSentBytesMessage.setJMSReplyTo(tool.getDefaultTopic());
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("Received Bytes message ");
- replyTopic = (Topic) messageReceivedBytesMessage.getJMSReplyTo();
- logTrace("Topic name is " + replyTopic.getTopicName());
- if (replyTopic.getTopicName()
- .equals(tool.getDefaultTopic().getTopicName())) {
- logTrace("Pass ");
- } else {
- logMsg("Bytes Message ReplyTo Failed");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logTrace("sending a Stream message");
- messageSentStreamMessage = tool.getDefaultTopicSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrReplyToTopicTest");
- messageSentStreamMessage.writeString("Testing...");
- logTrace("Sending Stream message");
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- if (messageReceivedStreamMessage.getJMSReplyTo() == null) {
- logTrace(" as expected replyto field is null");
- } else {
- logMsg("ERROR: expected replyto field to be null in this case");
- pass = false;
- }
- logTrace("Set ReplyTo and resend msg");
- messageSentStreamMessage.setJMSReplyTo(tool.getDefaultTopic());
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("Received Stream message ");
- replyTopic = (Topic) messageReceivedStreamMessage.getJMSReplyTo();
- logTrace("Topic name is " + replyTopic.getTopicName());
- if (replyTopic.getTopicName()
- .equals(tool.getDefaultTopic().getTopicName())) {
- logTrace("Pass ");
- } else {
- logMsg("Stream Message ReplyTo Failed");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: invalid Replyto returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrReplyToTopicTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSTypeTopicTest
- *
- * @assertion_ids: JMS:SPEC:246.9; JMS:JAVADOC:375; JMS:JAVADOC:377;
- *
- * @test_Strategy: Send a message to a Topic with JMSType set to TESTMSG test
- * with Text, map, object, byte, and stream messages verify on receive.
- *
- */
-
- public void msgHdrJMSTypeTopicTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- String type = "TESTMSG";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentStreamMessage = null;
- StreamMessage messageReceivedStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- BytesMessage messageReceivedBytesMessage = null;
- MapMessage messageReceivedMapMessage = null;
- MapMessage messageSentMapMessage = null;
- ObjectMessage messageSentObjectMsg = null;
- ObjectMessage messageReceivedObjectMsg = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSTypeTopicTest");
- logTrace("JMSType test - Send a Text message");
- messageSent.setJMSType(type);
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("JMSType is " + (String) messageReceived.getJMSType());
- if (messageReceived.getJMSType().equals(type)) {
- logTrace("Pass ");
- } else {
- logMsg("Text Message Failed");
- pass = false;
- }
-
- // send and receive Object message to Topic
- logTrace("JMSType test - Send ObjectMessage to Topic.");
- messageSentObjectMsg = tool.getDefaultTopicSession()
- .createObjectMessage();
- messageSentObjectMsg
- .setObject("msgHdrJMSTypeTopicTest for Object Message");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSTypeTopicTest");
- messageSentObjectMsg.setJMSType(type);
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("JMSType is " + (String) messageReceivedObjectMsg.getJMSType());
- if (messageReceivedObjectMsg.getJMSType().equals(type)) {
- logTrace("Pass ");
- } else {
- logMsg("Object Message JMSType Failed");
- pass = false;
- }
-
- // send and receive map message to Topic
- logTrace("JMSType test - Send MapMessage to Topic.");
- messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSTypeTopicTest");
- messageSentMapMessage.setString("aString", "value");
- messageSentMapMessage.setJMSType(type);
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("JMSType is " + (String) messageReceivedMapMessage.getJMSType());
- if (messageReceivedMapMessage.getJMSType().equals(type)) {
- logTrace("Pass ");
- } else {
- logMsg("Map Message JMSType Failed");
- pass = false;
- }
-
- // send and receive bytes message to Topic
- logTrace("JMSType test - Send BytesMessage to Topic.");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSTypeTopicTest");
- messageSentBytesMessage.writeByte(bValue);
- messageSentBytesMessage.setJMSType(type);
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace(
- "JMSType is " + (String) messageReceivedBytesMessage.getJMSType());
- if (messageReceivedBytesMessage.getJMSType().equals(type)) {
- logTrace("Pass ");
- } else {
- logMsg("Bytes Message JMSType Failed");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logTrace("JMSType test - sending a Stream message");
- messageSentStreamMessage = tool.getDefaultTopicSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSTypeTopicTest");
- messageSentStreamMessage.writeString("Testing...");
- messageSentStreamMessage.setJMSType(type);
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace(
- "JMSType is " + (String) messageReceivedStreamMessage.getJMSType());
- if (messageReceivedStreamMessage.getJMSType().equals(type)) {
- logTrace("Pass ");
- } else {
- logMsg("Stream Message JMSType Failed");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: invalid JMSType returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrJMSTypeTopicTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSPriorityTopicTest
- *
- * @assertion_ids: JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140; JMS:JAVADOC:305;
- * JMS:JAVADOC:383;
- *
- * @test_Strategy: Send a message to a Topic with JMSPriority set to 2 test
- * with Text, map, object, byte, and stream messages verify on receive.
- *
- */
-
- public void msgHdrJMSPriorityTopicTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- int priority = 2;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentStreamMessage = null;
- StreamMessage messageReceivedStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- BytesMessage messageReceivedBytesMessage = null;
- MapMessage messageReceivedMapMessage = null;
- MapMessage messageSentMapMessage = null;
- ObjectMessage messageSentObjectMsg = null;
- ObjectMessage messageReceivedObjectMsg = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTopicTest");
- logTrace("JMSPriority test - Send a Text message");
- tool.getDefaultTopicPublisher().setPriority(priority);
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("JMSPriority is " + messageReceived.getJMSPriority());
- if (messageReceived.getJMSPriority() == priority) {
- logTrace("Pass ");
- } else {
- logMsg("Text Message Failed");
- pass = false;
- }
-
- // send and receive Object message to Topic
- logTrace("JMSPriority test - Send ObjectMessage to Topic.");
- messageSentObjectMsg = tool.getDefaultTopicSession()
- .createObjectMessage();
- messageSentObjectMsg
- .setObject("msgHdrJMSPriorityTopicTest for Object Message");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTopicTest");
- tool.getDefaultTopicPublisher().setPriority(priority);
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("JMSPriority is " + messageReceivedObjectMsg.getJMSPriority());
- if (messageReceivedObjectMsg.getJMSPriority() == priority) {
- logTrace("Pass ");
- } else {
- logMsg("Object Message JMSPriority Failed");
- pass = false;
- }
-
- // send and receive map message to Topic
- logTrace("JMSPriority test - Send MapMessage to Topic.");
- messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTopicTest");
- messageSentMapMessage.setString("aString", "value");
- tool.getDefaultTopicPublisher().setPriority(priority);
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("JMSPriority is " + messageReceivedMapMessage.getJMSPriority());
- if (messageReceivedMapMessage.getJMSPriority() == priority) {
- logTrace("Pass ");
- } else {
- logMsg("Map Message JMSPriority Failed");
- pass = false;
- }
-
- // send and receive bytes message to Topic
- logTrace("JMSPriority test - Send BytesMessage to Topic.");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTopicTest");
- messageSentBytesMessage.writeByte(bValue);
- tool.getDefaultTopicPublisher().setPriority(priority);
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace(
- "JMSPriority is " + messageReceivedBytesMessage.getJMSPriority());
- if (messageReceivedBytesMessage.getJMSPriority() == priority) {
- logTrace("Pass ");
- } else {
- logMsg("Bytes Message JMSPriority Failed");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logTrace("JMSPriority test - sending a Stream message");
- messageSentStreamMessage = tool.getDefaultTopicSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTopicTest");
- messageSentStreamMessage.writeString("Testing...");
- tool.getDefaultTopicPublisher().setPriority(priority);
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace(
- "JMSPriority is " + messageReceivedStreamMessage.getJMSPriority());
- if (messageReceivedStreamMessage.getJMSPriority() == priority) {
- logTrace("Pass ");
- } else {
- logMsg("Stream Message JMSPriority Failed");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: invalid JMSPriority returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrJMSPriorityTopicTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSExpirationTopicTest
- *
- * @assertion_ids: JMS:SPEC:15; JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140;
- * JMS:JAVADOC:309; JMS:JAVADOC:379;
- *
- * @test_Strategy: Send a message to a Topic with time to live set to 0 Verify
- * that JMSExpiration gets set to 0 test with Text, map, object, byte, and
- * stream messages verify on receive.
- *
- */
-
- public void msgHdrJMSExpirationTopicTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- long forever = 0;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentStreamMessage = null;
- StreamMessage messageReceivedStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- BytesMessage messageReceivedBytesMessage = null;
- MapMessage messageReceivedMapMessage = null;
- MapMessage messageSentMapMessage = null;
- ObjectMessage messageSentObjectMsg = null;
- ObjectMessage messageReceivedObjectMsg = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSExpirationTopicTest");
- logMsg(
- "JMSExpiration test (set timetoLive=0) - Send TextMessage to Topic");
- tool.getDefaultTopicPublisher().setTimeToLive(forever);
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logMsg("JMSExpiration is " + messageReceived.getJMSExpiration());
- if (messageReceived.getJMSExpiration() == forever) {
- logMsg("Pass ");
- } else {
- logMsg("TextMessage JMSExpiration Failed");
- logMsg("TextMessage.getJMSExpiration() returned "
- + messageReceived.getJMSExpiration() + ", expected 0");
- pass = false;
- }
- logMsg(
- "JMSExpiration test (set timetoLive=60000) - Send TextMessage to Topic");
- tool.getDefaultTopicPublisher().setTimeToLive(60000);
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- long currentTime = System.currentTimeMillis();
- logMsg("JMSExpiration is " + messageReceived.getJMSExpiration());
- long timeLeftToExpiration = messageReceived.getJMSExpiration()
- - currentTime;
- logMsg("TimeLeftToExpiration is " + timeLeftToExpiration);
- if (timeLeftToExpiration <= 60000) {
- logMsg("Pass ");
- } else {
- logMsg("TextMessage JMSExpiration Failed");
- logMsg("TextMessage JMSExpiration timeLeftToExpiration="
- + timeLeftToExpiration + ", expected <=60000");
- pass = false;
- }
-
- // send and receive Object message to Topic
- logMsg(
- "JMSExpiration test (set timeToLive=0) - Send ObjectMessage to Topic.");
- messageSentObjectMsg = tool.getDefaultTopicSession()
- .createObjectMessage();
- messageSentObjectMsg
- .setObject("msgHdrJMSExpirationTopicTest for Object Message");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSExpirationTopicTest");
- tool.getDefaultTopicPublisher().setTimeToLive(forever);
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logMsg("JMSExpiration is " + messageReceivedObjectMsg.getJMSExpiration());
- if (messageReceivedObjectMsg.getJMSExpiration() == forever) {
- logMsg("Pass ");
- } else {
- logMsg("ObjectMessage JMSExpiration Failed");
- logMsg("ObjectMessage.getJMSExpiration() returned "
- + messageReceivedObjectMsg.getJMSExpiration() + ", expected 0");
- pass = false;
- }
- logMsg(
- "JMSExpiration test (set timetoLive=60000) - Send ObjectMessage to Topic.");
- tool.getDefaultTopicPublisher().setTimeToLive(60000);
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- currentTime = System.currentTimeMillis();
- logMsg("JMSExpiration is " + messageReceivedObjectMsg.getJMSExpiration());
- timeLeftToExpiration = messageReceivedObjectMsg.getJMSExpiration()
- - currentTime;
- logMsg("TimeLeftToExpiration is " + timeLeftToExpiration);
- if (timeLeftToExpiration <= 60000) {
- logMsg("Pass ");
- } else {
- logMsg("ObjectMessage JMSExpiration Failed");
- logMsg("ObjectMessage JMSExpiration timeLeftToExpiration="
- + timeLeftToExpiration + ", expected <=60000");
- pass = false;
- }
-
- // send and receive map message to Topic
- logMsg(
- "JMSExpiration test (set timeToLive=0) - Send MapMessage to Topic.");
- messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSExpirationTopicTest");
- messageSentMapMessage.setString("aString", "value");
- tool.getDefaultTopicPublisher().setTimeToLive(forever);
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logMsg(
- "JMSExpiration is " + messageReceivedMapMessage.getJMSExpiration());
- if (messageReceivedMapMessage.getJMSExpiration() == forever) {
- logMsg("Pass ");
- } else {
- logMsg("MapMessage JMSExpiration Failed");
- logMsg("MapMessage.getJMSExpiration() returned "
- + messageReceivedMapMessage.getJMSExpiration() + ", expected 0");
- pass = false;
- }
- logMsg(
- "JMSExpiration test (set timetoLive=60000) - Send MapMessage to Topic.");
- tool.getDefaultTopicPublisher().setTimeToLive(60000);
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- currentTime = System.currentTimeMillis();
- logMsg(
- "JMSExpiration is " + messageReceivedMapMessage.getJMSExpiration());
- timeLeftToExpiration = messageReceivedMapMessage.getJMSExpiration()
- - currentTime;
- logMsg("TimeLeftToExpiration is " + timeLeftToExpiration);
- if (timeLeftToExpiration <= 60000) {
- logMsg("Pass ");
- } else {
- logMsg("MapMessage JMSExpiration Failed");
- logMsg("MapMessage JMSExpiration timeLeftToExpiration="
- + timeLeftToExpiration + ", expected <=60000");
- pass = false;
- }
-
- // send and receive bytes message to Topic
- logMsg(
- "JMSExpiration test (set timeToLive=0) - Send BytesMessage to Topic.");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSExpirationTopicTest");
- messageSentBytesMessage.writeByte(bValue);
- tool.getDefaultTopicPublisher().setTimeToLive(forever);
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logMsg(
- "JMSExpiration is " + messageReceivedBytesMessage.getJMSExpiration());
- if (messageReceivedBytesMessage.getJMSExpiration() == forever) {
- logMsg("Pass ");
- } else {
- logMsg("BytesMessage JMSExpiration Failed");
- logMsg("BytesMessage.getJMSExpiration() returned "
- + messageReceivedBytesMessage.getJMSExpiration() + ", expected 0");
- pass = false;
- }
- logMsg(
- "JMSExpiration test (set timetoLive=60000) - Send BytesMessage to Topic.");
- tool.getDefaultTopicPublisher().setTimeToLive(60000);
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- currentTime = System.currentTimeMillis();
- logMsg(
- "JMSExpiration is " + messageReceivedBytesMessage.getJMSExpiration());
- timeLeftToExpiration = messageReceivedBytesMessage.getJMSExpiration()
- - currentTime;
- logMsg("TimeLeftToExpiration is " + timeLeftToExpiration);
- if (timeLeftToExpiration <= 60000) {
- logMsg("Pass ");
- } else {
- logMsg("BytesMessage JMSExpiration Failed");
- logMsg("BytesMessage JMSExpiration timeLeftToExpiration="
- + timeLeftToExpiration + ", expected <=60000");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- logMsg(
- "JMSExpiration test (set timeToLive=0) - sending a Stream message");
- messageSentStreamMessage = tool.getDefaultTopicSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSExpirationTopicTest");
- messageSentStreamMessage.writeString("Testing...");
- tool.getDefaultTopicPublisher().setTimeToLive(forever);
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logMsg("JMSExpiration is "
- + messageReceivedStreamMessage.getJMSExpiration());
- if (messageReceivedStreamMessage.getJMSExpiration() == forever) {
- logMsg("Pass ");
- } else {
- logMsg("StreamMessage JMSExpiration Failed");
- logMsg("StreamMessage.getJMSExpiration() returned "
- + messageReceivedStreamMessage.getJMSExpiration() + ", expected 0");
- pass = false;
- }
- logMsg(
- "JMSExpiration test (set timetoLive=60000) - Send StreamMessage to Topic.");
- tool.getDefaultTopicPublisher().setTimeToLive(60000);
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- currentTime = System.currentTimeMillis();
- logMsg("JMSExpiration is "
- + messageReceivedStreamMessage.getJMSExpiration());
- timeLeftToExpiration = messageReceivedStreamMessage.getJMSExpiration()
- - currentTime;
- logMsg("TimeLeftToExpiration is " + timeLeftToExpiration);
- if (timeLeftToExpiration <= 60000) {
- logMsg("Pass ");
- } else {
- logMsg("StreamMessage JMSExpiration Failed");
- logMsg("StreamMessage JMSExpiration timeLeftToExpiration="
- + timeLeftToExpiration + ", expected <=60000");
- pass = false;
- }
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSExpiration returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrJMSExpirationTopicTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSDestinationTopicTest
- *
- * @assertion_ids: JMS:SPEC:2; JMS:JAVADOC:363; JMS:JAVADOC:117;
- *
- * @test_Strategy: Create and publish a message to the default Topic. Receive
- * the msg and verify that JMSDestination is set to the default Topic test
- * with Text, map, object, byte, and stream messages
- *
- */
-
- public void msgHdrJMSDestinationTopicTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- Topic replyDestination = null;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentStreamMessage = null;
- StreamMessage messageReceivedStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- BytesMessage messageReceivedBytesMessage = null;
- MapMessage messageReceivedMapMessage = null;
- MapMessage messageSentMapMessage = null;
- ObjectMessage messageSentObjectMsg = null;
- ObjectMessage messageReceivedObjectMsg = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("publishing a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDestinationTopicTest");
- logTrace("publish Text Message to Topic.");
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("JMSDestination: " + messageReceived.getJMSDestination());
- replyDestination = (Topic) messageReceived.getJMSDestination();
- if (replyDestination != null)
- logTrace("Topic name is " + replyDestination.getTopicName());
- if (replyDestination == null) {
- pass = false;
- logMsg("Text Message Error: JMSDestination returned a null");
- } else if (replyDestination.getTopicName()
- .equals(tool.getDefaultTopic().getTopicName())) {
- logTrace("Pass ");
- } else {
- logMsg("Text Message Failed");
- pass = false;
- }
-
- // publish and receive Object message to Topic
- logTrace("publish ObjectMessage to Topic.");
- messageSentObjectMsg = tool.getDefaultTopicSession()
- .createObjectMessage();
- messageSentObjectMsg.setObject("msgHdrIDQTest for Object Message");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDestinationTopicTest");
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace(
- "JMSDestination: " + messageReceivedObjectMsg.getJMSDestination());
- replyDestination = (Topic) messageReceived.getJMSDestination();
- if (replyDestination != null)
- logTrace("Topic name is " + replyDestination.getTopicName());
- if (replyDestination == null) {
- pass = false;
- logMsg("Object Message Error: JMSDestination returned a null");
- } else if (replyDestination.getTopicName()
- .equals(tool.getDefaultTopic().getTopicName())) {
- logTrace("Pass ");
- } else {
- logMsg("Object Message Failed");
- pass = false;
- }
-
- // publish and receive map message to Topic
- logTrace("publish MapMessage to Topic.");
- messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDestinationTopicTest");
- messageSentMapMessage.setString("aString", "value");
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace(
- "JMSDestination: " + messageReceivedMapMessage.getJMSDestination());
- replyDestination = (Topic) messageReceived.getJMSDestination();
- if (replyDestination != null)
- logTrace("Topic name is " + replyDestination.getTopicName());
- if (replyDestination == null) {
- pass = false;
- logMsg("Map Message Error: JMSDestination returned a null");
- } else if (replyDestination.getTopicName()
- .equals(tool.getDefaultTopic().getTopicName())) {
- logTrace("Pass ");
- } else {
- logMsg("Map Message Failed");
- pass = false;
- }
-
- // publish and receive bytes message to Topic
- logTrace("publish BytesMessage to Topic.");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDestinationTopicTest");
- messageSentBytesMessage.writeByte(bValue);
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("JMSDestination: "
- + messageReceivedBytesMessage.getJMSDestination());
- replyDestination = (Topic) messageReceived.getJMSDestination();
- if (replyDestination != null)
- logTrace("Topic name is " + replyDestination.getTopicName());
- if (replyDestination == null) {
- pass = false;
- logMsg("Bytes Message Error: JMSDestination returned a null");
- } else if (replyDestination.getTopicName()
- .equals(tool.getDefaultTopic().getTopicName())) {
- logTrace("Pass ");
- } else {
- logMsg("Bytes Message Failed");
- pass = false;
- }
-
- // publish and receive a StreamMessage
- logTrace("publishing a Stream message");
- messageSentStreamMessage = tool.getDefaultTopicSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDestinationTopicTest");
- messageSentStreamMessage.writeString("Testing...");
- logTrace("publishing Stream message");
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("JMSDestination: "
- + messageReceivedStreamMessage.getJMSDestination());
- replyDestination = (Topic) messageReceived.getJMSDestination();
- if (replyDestination != null)
- logTrace("Topic name is " + replyDestination.getTopicName());
- if (replyDestination == null) {
- pass = false;
- logMsg("Stream Message Error: JMSDestination returned a null");
- } else if (replyDestination.getTopicName()
- .equals(tool.getDefaultTopic().getTopicName())) {
- logTrace("Pass ");
- } else {
- logMsg("Stream Message Failed");
- pass = false;
- }
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSDestination returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrJMSDestinationTopicTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSDeliveryModeTopicTest
- *
- * @assertion_ids: JMS:SPEC:3; JMS:SPEC:140; JMS:JAVADOC:367; JMS:SPEC:246.2;
- * JMS:JAVADOC:301;
- *
- * @test_Strategy: Create and publish a message to the default Topic. Receive
- * the msg and verify that JMSDeliveryMode is set the default delivery mode of
- * persistent. Create and test another message with a nonpersistent delivery
- * mode. test with Text, map, object, byte, and stream messages
- */
-
- public void msgHdrJMSDeliveryModeTopicTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentStreamMessage = null;
- StreamMessage messageReceivedStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- BytesMessage messageReceivedBytesMessage = null;
- MapMessage messageReceivedMapMessage = null;
- MapMessage messageSentMapMessage = null;
- ObjectMessage messageSentObjectMsg = null;
- ObjectMessage messageReceivedObjectMsg = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- logMsg("default delivery mode is " + Message.DEFAULT_DELIVERY_MODE);
- logMsg("persistent is: " + DeliveryMode.PERSISTENT);
- if (Message.DEFAULT_DELIVERY_MODE != DeliveryMode.PERSISTENT) {
- pass = false;
- logMsg("Error: default delivery mode was "
- + Message.DEFAULT_DELIVERY_MODE);
- logMsg("The default delivery mode should be persistent: "
- + DeliveryMode.PERSISTENT);
- }
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("publishing a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDeliveryModeTopicTest");
- logTrace("publish Text Message to Topic.");
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logMsg(
- "Text Message Error: JMSDeliveryMode should be set to persistent as default");
- } else {
- logTrace("Text Message Pass ");
- }
-
- // publish and receive Object message to Topic
- logTrace("publish ObjectMessage to Topic.");
- messageSentObjectMsg = tool.getDefaultTopicSession()
- .createObjectMessage();
- messageSentObjectMsg.setObject("Test for Object Message");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDeliveryModeTopicTest");
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logMsg(
- "Object Message Error: JMSDeliveryMode should be set to persistent as default");
- } else {
- logTrace("Object Message Pass ");
- }
-
- // publish and receive map message to Topic
- logTrace("publish MapMessage to Topic.");
- messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDeliveryModeTopicTest");
- messageSentMapMessage.setString("aString", "value");
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logMsg(
- "Map Message Error: JMSDeliveryMode should be set to persistent as default");
- } else {
- logTrace("Map Message Pass ");
- }
-
- // publish and receive bytes message to Topic
- logTrace("publish BytesMessage to Topic.");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDeliveryModeTopicTest");
- messageSentBytesMessage.writeByte(bValue);
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logMsg(
- "Bytes Message Error: JMSDeliveryMode should be set to persistent as default");
- } else {
- logTrace("Bytes Message Pass ");
- }
-
- // publish and receive a StreamMessage
- logTrace("publishing a Stream message");
- messageSentStreamMessage = tool.getDefaultTopicSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDeliveryModeTopicTest");
- messageSentStreamMessage.writeString("Testing...");
- logTrace("publishing Stream message");
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- logTrace("JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- logMsg(
- "Stream Message Error: JMSDeliveryMode should be set to persistent as default");
- } else {
- logTrace("Stream Message Pass ");
- }
-
- // Test again - this time set delivery mode to persistent
- tool.getDefaultTopicPublisher()
- .setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("publishing a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDeliveryModeTopicTest");
- logTrace("publish Text Message to Topic.");
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- logTrace("JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logMsg(
- "Text Message Error: JMSDeliveryMode should be set to NON_PERSISTENT");
- } else {
- logTrace("Text Message Pass ");
- }
-
- // publish and receive Object message to Topic
- logTrace("publish ObjectMessage to Topic.");
- messageSentObjectMsg = tool.getDefaultTopicSession()
- .createObjectMessage();
- messageSentObjectMsg
- .setObject("msgHdrJMSDeliveryModeTopicTest for Object Message");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDeliveryModeTopicTest");
- tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
- messageReceivedObjectMsg = (ObjectMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- if (messageReceivedObjectMsg != null)
- logTrace("messageReceivedObjectMsg=" + messageReceivedObjectMsg);
- logTrace("JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logMsg(
- "Object Message Error: JMSDeliveryMode should be set to NON_PERSISTENT");
- } else {
- logTrace("Object Message Pass ");
- }
-
- // publish and receive map message to Topic
- logTrace("publish MapMessage to Topic.");
- messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDeliveryModeTopicTest");
- messageSentMapMessage.setString("aString", "value");
- tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
- messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceivedMapMessage != null)
- logTrace("messageReceivedMapMessage=" + messageReceivedMapMessage);
- logTrace("JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logMsg(
- "Map Message Error: JMSDeliveryMode should be set to NON_PERSISTENT");
- } else {
- logTrace("Map Message Pass ");
- }
-
- // publish and receive bytes message to Topic
- logTrace("publish BytesMessage to Topic.");
- messageSentBytesMessage = tool.getDefaultTopicSession()
- .createBytesMessage();
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDeliveryModeTopicTest");
- messageSentBytesMessage.writeByte(bValue);
- tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
- messageReceivedBytesMessage = (BytesMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- if (messageReceivedBytesMessage != null)
- logTrace("messageReceivedBytesMessage=" + messageReceivedBytesMessage);
- logTrace("JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logMsg(
- "Bytes Message Error: JMSDeliveryMode should be set to NON_PERSISTENT");
- } else {
- logTrace("Bytes Message Pass ");
- }
-
- // publish and receive a StreamMessage
- logTrace("publishing a Stream message");
- messageSentStreamMessage = tool.getDefaultTopicSession()
- .createStreamMessage();
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDeliveryModeTopicTest");
- messageSentStreamMessage.writeString("Testing...");
- logTrace("publishing Stream message");
- tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
- messageReceivedStreamMessage = (StreamMessage) tool
- .getDefaultTopicSubscriber().receive(timeout);
- if (messageReceivedStreamMessage != null)
- logTrace(
- "messageReceivedStreamMessage=" + messageReceivedStreamMessage);
- logTrace("JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- logMsg(
- "Stream Message Error: JMSDeliveryMode should be set to NON_PERSISTENT");
- } else {
- logTrace("Stream Message Pass ");
- }
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSDeliveryMode returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrJMSDeliveryModeTopicTest");
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/topicMsgHeaders/TopicHeaderTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/topicMsgHeaders/TopicHeaderTestsIT.java
new file mode 100644
index 0000000000..cc2ca762fb
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/topicMsgHeaders/TopicHeaderTestsIT.java
@@ -0,0 +1,1568 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.topicMsgHeaders;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.DeliveryMode;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+
+
+public class TopicHeaderTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.topicMsgHeaders.TopicHeaderTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(TopicHeaderTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't catch expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the TestTools object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Queue and Topic Connections");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * helper method for msgHdrIDQTest and msgHdrIDTopicTest verifies that the
+ * JMSMessageID starts with ID:
+ *
+ *
+ * @param String returned from getJMSMessageID
+ *
+ * @return boolean true if id correctly starts with ID:
+ */
+ @Test
+ private boolean chkMessageID(String id) {
+ String status[] = { "Pass", "Fail" };
+ boolean retcode = true;
+
+ // message id must start with ID: - unless it is null
+ int index = 0;
+
+ if (id == null) {
+ ;
+ } else if (id.startsWith("ID:")) {
+ ;
+ } else {
+ index = 1;
+ retcode = false;
+ }
+ logger.log(Logger.Level.TRACE, "Results: " + status[index]);
+ return retcode;
+ }
+
+ /*
+ * @testName: msgHdrIDTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343;
+ *
+ * @test_Strategy: With a topic destination Send and receive single Text, map,
+ * bytes, stream, and object message call getJMSMessageID and verify that it
+ * starts with ID:
+ */
+ @Test
+ public void msgHdrIDTopicTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ String id = null;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentStreamMessage = null;
+ StreamMessage messageReceivedStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ BytesMessage messageReceivedBytesMessage = null;
+ MapMessage messageReceivedMapMessage = null;
+ MapMessage messageSentMapMessage = null;
+ ObjectMessage messageSentObjectMsg = null;
+ ObjectMessage messageReceivedObjectMsg = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Topic.");
+ messageSentObjectMsg = tool.getDefaultTopicSession().createObjectMessage();
+ messageSentObjectMsg.setObject("msgHdrIDTopicTest for Object Message");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDToopicTest");
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "getJMSMessageID ");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedObjectMsg.getJMSMessageID());
+ id = messageReceivedObjectMsg.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.INFO, "ObjectMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ }
+
+ // send and receive map message to Topic
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Topic.");
+ messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDTopicTest");
+ messageSentMapMessage.setString("aString", "value");
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "getJMSMessageID ");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedMapMessage.getJMSMessageID());
+ id = messageReceivedMapMessage.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.INFO, "MapMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ }
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Topic.");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDTopicTest");
+ messageSentBytesMessage.writeByte(bValue);
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "getJMSMessageID ");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedBytesMessage.getJMSMessageID());
+ id = messageReceivedBytesMessage.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.INFO, "BytesMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a Stream message");
+ messageSentStreamMessage = tool.getDefaultTopicSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDTopicTest");
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "getJMSMessageID ");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedStreamMessage.getJMSMessageID());
+ id = messageReceivedStreamMessage.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.INFO, "StreamMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ }
+
+ // Text Message
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrIDTopicTest");
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "getJMSMessageID ");
+ logger.log(Logger.Level.TRACE, " " + messageReceived.getJMSMessageID());
+ id = messageReceived.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.INFO, "TextMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSMessageID returned from JMSMessageID");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrIDTopicTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrTimeStampTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347;
+ *
+ * @test_Strategy: With a Topic destination Send a single Text, map, bytes,
+ * stream, and object message check time of send against time send returns
+ * JMSTimeStamp should be between these two
+ */
+ @Test
+ public void msgHdrTimeStampTopicTest() throws Exception {
+ boolean pass = true;
+ long timeBeforeSend;
+ long timeAfterSend;
+ byte bValue = 127;
+ String id = null;
+
+ try {
+ TextMessage messageSent = null;
+ StreamMessage messageSentStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ MapMessage messageSentMapMessage = null;
+ ObjectMessage messageSentObjectMsg = null;
+
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+
+ // send an Object message to Topic
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to TOPIC.");
+ messageSentObjectMsg = tool.getDefaultTopicSession().createObjectMessage();
+ messageSentObjectMsg.setObject("msgHdrTimeStampTopicTest for Object Message");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTopicTest");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSentObjectMsg.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentObjectMsg.getJMSTimestamp())
+ && (timeAfterSend >= messageSentObjectMsg.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "Object Message TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from ObjectMessage");
+ pass = false;
+ }
+
+ // send map message to Topic
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Topic.");
+ messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTopicTest");
+ messageSentMapMessage.setString("aString", "value");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSentMapMessage.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentMapMessage.getJMSTimestamp())
+ && (timeAfterSend >= messageSentMapMessage.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "MapMessage TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from MapMessage");
+ pass = false;
+ }
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Topic.");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTopicTest");
+ messageSentBytesMessage.writeByte(bValue);
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSentBytesMessage.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentBytesMessage.getJMSTimestamp())
+ && (timeAfterSend >= messageSentBytesMessage.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "BytesMessage TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from BytesMessage");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a Stream message");
+ messageSentStreamMessage = tool.getDefaultTopicSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTopicTest");
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending message");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSentStreamMessage.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentStreamMessage.getJMSTimestamp())
+ && (timeAfterSend >= messageSentStreamMessage.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "StreamMessage TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from StreamMessage");
+ pass = false;
+ }
+
+ // Text Message
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTopicTest");
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ tool.getDefaultTopicPublisher().publish(messageSent);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSent.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSent.getJMSTimestamp()) && (timeAfterSend >= messageSent.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "TextMessage TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from TextMessage");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid TimeStamp returned from JMSTimeStamp");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrTimeStampTopicTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrCorlIdTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ * @test_Strategy: Send a message to a Topic with CorrelationID set. Receive msg
+ * and verify the correlationid is as set by client
+ *
+ */
+ @Test
+ public void msgHdrCorlIdTopicTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ String jmsCorrelationID = "test Correlation id";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentStreamMessage = null;
+ StreamMessage messageReceivedStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ BytesMessage messageReceivedBytesMessage = null;
+ MapMessage messageReceivedMapMessage = null;
+ MapMessage messageSentMapMessage = null;
+ ObjectMessage messageSentObjectMsg = null;
+ ObjectMessage messageReceivedObjectMsg = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrCorlIdTopicTest");
+ logger.log(Logger.Level.TRACE, "Sending Text message to Topic ");
+ messageSent.setJMSCorrelationID(jmsCorrelationID);
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "jmsCorrelationID: " + messageReceived.getJMSCorrelationID());
+ if (messageReceived.getJMSCorrelationID() == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Text Message Error: JMSCorrelationID returned a null");
+ } else if (messageReceived.getJMSCorrelationID().equals(jmsCorrelationID)) {
+ logger.log(Logger.Level.TRACE, "pass");
+ } else {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Text Message Error: JMSCorrelationID is incorrect");
+ }
+
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Topic.");
+ messageSentObjectMsg = tool.getDefaultTopicSession().createObjectMessage();
+ messageSentObjectMsg.setObject("msgHdrCorlIdTopicTest for Object Message");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrCorlIdTopicTest");
+ messageSentObjectMsg.setJMSCorrelationID(jmsCorrelationID);
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "jmsCorrelationID: " + messageReceivedObjectMsg.getJMSCorrelationID());
+ if (messageReceivedObjectMsg.getJMSCorrelationID() == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Object Message Error: JMSCorrelationID returned a null");
+ } else if (messageReceivedObjectMsg.getJMSCorrelationID().equals(jmsCorrelationID)) {
+ logger.log(Logger.Level.TRACE, "pass");
+ } else {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Object Message Error: JMSCorrelationID is incorrect");
+ }
+
+ // send and receive map message to Topic
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Topic.");
+ messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrCorlIdTopicTest");
+ messageSentMapMessage.setJMSCorrelationID(jmsCorrelationID);
+ messageSentMapMessage.setString("aString", "value");
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "jmsCorrelationID: " + messageReceivedMapMessage.getJMSCorrelationID());
+ if (messageReceivedMapMessage.getJMSCorrelationID() == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Map Message Error: JMSCorrelationID returned a null");
+ } else if (messageReceivedMapMessage.getJMSCorrelationID().equals(jmsCorrelationID)) {
+ logger.log(Logger.Level.TRACE, "pass");
+ } else {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Map Message Error: JMSCorrelationID is incorrect");
+ }
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Topic.");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrCorlIdTopicTest");
+ messageSentBytesMessage.setJMSCorrelationID(jmsCorrelationID);
+ messageSentBytesMessage.writeByte(bValue);
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "jmsCorrelationID: " + messageReceivedBytesMessage.getJMSCorrelationID());
+ if (messageReceivedBytesMessage.getJMSCorrelationID() == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Bytes Message Error: JMSCorrelationID returned a null");
+ } else if (messageReceivedBytesMessage.getJMSCorrelationID().equals(jmsCorrelationID)) {
+ logger.log(Logger.Level.TRACE, "pass");
+ } else {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Byte Message Error: JMSCorrelationID is incorrect");
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a Stream message");
+ messageSentStreamMessage = tool.getDefaultTopicSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrCorlIdTopicTest");
+ messageSentStreamMessage.setJMSCorrelationID(jmsCorrelationID);
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending Stream message");
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "jmsCorrelationID: " + messageReceivedStreamMessage.getJMSCorrelationID());
+ if (messageReceivedStreamMessage.getJMSCorrelationID() == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Stream Message Error: JMSCorrelationID returned a null");
+ } else if (messageReceivedStreamMessage.getJMSCorrelationID().equals(jmsCorrelationID)) {
+ logger.log(Logger.Level.TRACE, "pass");
+ } else {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Stream Message Error: JMSCorrelationID is incorrect");
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSCorrelationID returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrCorlIdTopicTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrReplyToTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:12; JMS:JAVADOC:359; JMS:JAVADOC:361;
+ * JMS:JAVADOC:117; JMS:SPEC:246.8; JMS:JAVADOC:289; JMS:JAVADOC:562;
+ * JMS:JAVADOC:166;
+ *
+ * @test_Strategy: Send a message to a Topic with ReplyTo set to null and then
+ * set to a destination test with Text, map, object, byte, and stream messages
+ * verify on receive.
+ *
+ */
+ @Test
+ public void msgHdrReplyToTopicTest() throws Exception {
+ boolean pass = true;
+ Topic replyTopic = null;
+ byte bValue = 127;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentStreamMessage = null;
+ StreamMessage messageReceivedStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ BytesMessage messageReceivedBytesMessage = null;
+ MapMessage messageReceivedMapMessage = null;
+ MapMessage messageSentMapMessage = null;
+ ObjectMessage messageSentObjectMsg = null;
+ ObjectMessage messageReceivedObjectMsg = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrReplyToTopicTest");
+ logger.log(Logger.Level.TRACE, "Send Text message");
+
+ // messageSent.setJMSReplyTo(tool.getDefaultTopic());
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived.getJMSReplyTo() == null) {
+ logger.log(Logger.Level.TRACE, " as expected replyto field is null");
+ } else {
+ logger.log(Logger.Level.INFO, "ERROR: expected replyto field should have been null for this case");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Set ReplyTo and resend msg");
+ messageSent.setJMSReplyTo(tool.getDefaultTopic());
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ replyTopic = (Topic) messageReceived.getJMSReplyTo();
+ logger.log(Logger.Level.TRACE, "Topic name is " + replyTopic.getTopicName());
+ if (replyTopic.getTopicName().equals(tool.getDefaultTopic().getTopicName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Text Message Failed");
+ pass = false;
+ }
+
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Topic.");
+ messageSentObjectMsg = tool.getDefaultTopicSession().createObjectMessage();
+ messageSentObjectMsg.setObject("msgHdrReplyToTopicTest for Object Message");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrReplyToTopicTest");
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceivedObjectMsg.getJMSReplyTo() == null) {
+ logger.log(Logger.Level.TRACE, " as expected replyto field is null");
+ } else {
+ logger.log(Logger.Level.INFO, "ERROR: expected replyto field to be null in this case");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Set ReplyTo and resend msg");
+ messageSentObjectMsg.setJMSReplyTo(tool.getDefaultTopic());
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ replyTopic = (Topic) messageReceivedObjectMsg.getJMSReplyTo();
+ logger.log(Logger.Level.TRACE, "Topic name is " + replyTopic.getTopicName());
+ if (replyTopic.getTopicName().equals(tool.getDefaultTopic().getTopicName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Object Message ReplyTo Failed");
+ pass = false;
+ }
+
+ // send and receive map message to Topic
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Topic.");
+ messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrReplyToTopicTest");
+ messageSentMapMessage.setString("aString", "value");
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceivedMapMessage.getJMSReplyTo() == null) {
+ logger.log(Logger.Level.TRACE, " as expected replyto field is null");
+ } else {
+ logger.log(Logger.Level.INFO, "ERROR: expected replyto field to be null in this case");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Set ReplyTo and resend msg");
+ messageSentMapMessage.setJMSReplyTo(tool.getDefaultTopic());
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received Map message ");
+ replyTopic = (Topic) messageReceivedMapMessage.getJMSReplyTo();
+ logger.log(Logger.Level.TRACE, "Topic name is " + replyTopic.getTopicName());
+ if (replyTopic.getTopicName().equals(tool.getDefaultTopic().getTopicName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Map Message ReplyTo Failed");
+ pass = false;
+ }
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Topic.");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrReplyToTopicTest");
+ messageSentBytesMessage.writeByte(bValue);
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceivedBytesMessage.getJMSReplyTo() == null) {
+ logger.log(Logger.Level.TRACE, " as expected replyto field is null");
+ } else {
+ logger.log(Logger.Level.INFO, "ERROR: expected replyto field to be null in this case");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Set ReplyTo and resend msg");
+ messageSentBytesMessage.setJMSReplyTo(tool.getDefaultTopic());
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received Bytes message ");
+ replyTopic = (Topic) messageReceivedBytesMessage.getJMSReplyTo();
+ logger.log(Logger.Level.TRACE, "Topic name is " + replyTopic.getTopicName());
+ if (replyTopic.getTopicName().equals(tool.getDefaultTopic().getTopicName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Bytes Message ReplyTo Failed");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a Stream message");
+ messageSentStreamMessage = tool.getDefaultTopicSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrReplyToTopicTest");
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending Stream message");
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceivedStreamMessage.getJMSReplyTo() == null) {
+ logger.log(Logger.Level.TRACE, " as expected replyto field is null");
+ } else {
+ logger.log(Logger.Level.INFO, "ERROR: expected replyto field to be null in this case");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Set ReplyTo and resend msg");
+ messageSentStreamMessage.setJMSReplyTo(tool.getDefaultTopic());
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "Received Stream message ");
+ replyTopic = (Topic) messageReceivedStreamMessage.getJMSReplyTo();
+ logger.log(Logger.Level.TRACE, "Topic name is " + replyTopic.getTopicName());
+ if (replyTopic.getTopicName().equals(tool.getDefaultTopic().getTopicName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Stream Message ReplyTo Failed");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid Replyto returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrReplyToTopicTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSTypeTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:246.9; JMS:JAVADOC:375; JMS:JAVADOC:377;
+ *
+ * @test_Strategy: Send a message to a Topic with JMSType set to TESTMSG test
+ * with Text, map, object, byte, and stream messages verify on receive.
+ *
+ */
+ @Test
+ public void msgHdrJMSTypeTopicTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ String type = "TESTMSG";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentStreamMessage = null;
+ StreamMessage messageReceivedStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ BytesMessage messageReceivedBytesMessage = null;
+ MapMessage messageReceivedMapMessage = null;
+ MapMessage messageSentMapMessage = null;
+ ObjectMessage messageSentObjectMsg = null;
+ ObjectMessage messageReceivedObjectMsg = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSTypeTopicTest");
+ logger.log(Logger.Level.TRACE, "JMSType test - Send a Text message");
+ messageSent.setJMSType(type);
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSType is " + (String) messageReceived.getJMSType());
+ if (messageReceived.getJMSType().equals(type)) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Text Message Failed");
+ pass = false;
+ }
+
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.TRACE, "JMSType test - Send ObjectMessage to Topic.");
+ messageSentObjectMsg = tool.getDefaultTopicSession().createObjectMessage();
+ messageSentObjectMsg.setObject("msgHdrJMSTypeTopicTest for Object Message");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSTypeTopicTest");
+ messageSentObjectMsg.setJMSType(type);
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSType is " + (String) messageReceivedObjectMsg.getJMSType());
+ if (messageReceivedObjectMsg.getJMSType().equals(type)) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Object Message JMSType Failed");
+ pass = false;
+ }
+
+ // send and receive map message to Topic
+ logger.log(Logger.Level.TRACE, "JMSType test - Send MapMessage to Topic.");
+ messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSTypeTopicTest");
+ messageSentMapMessage.setString("aString", "value");
+ messageSentMapMessage.setJMSType(type);
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSType is " + (String) messageReceivedMapMessage.getJMSType());
+ if (messageReceivedMapMessage.getJMSType().equals(type)) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Map Message JMSType Failed");
+ pass = false;
+ }
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.TRACE, "JMSType test - Send BytesMessage to Topic.");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSTypeTopicTest");
+ messageSentBytesMessage.writeByte(bValue);
+ messageSentBytesMessage.setJMSType(type);
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSType is " + (String) messageReceivedBytesMessage.getJMSType());
+ if (messageReceivedBytesMessage.getJMSType().equals(type)) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Bytes Message JMSType Failed");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "JMSType test - sending a Stream message");
+ messageSentStreamMessage = tool.getDefaultTopicSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSTypeTopicTest");
+ messageSentStreamMessage.writeString("Testing...");
+ messageSentStreamMessage.setJMSType(type);
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSType is " + (String) messageReceivedStreamMessage.getJMSType());
+ if (messageReceivedStreamMessage.getJMSType().equals(type)) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Stream Message JMSType Failed");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSType returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrJMSTypeTopicTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSPriorityTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140; JMS:JAVADOC:305;
+ * JMS:JAVADOC:383;
+ *
+ * @test_Strategy: Send a message to a Topic with JMSPriority set to 2 test with
+ * Text, map, object, byte, and stream messages verify on receive.
+ *
+ */
+ @Test
+ public void msgHdrJMSPriorityTopicTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ int priority = 2;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentStreamMessage = null;
+ StreamMessage messageReceivedStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ BytesMessage messageReceivedBytesMessage = null;
+ MapMessage messageReceivedMapMessage = null;
+ MapMessage messageSentMapMessage = null;
+ ObjectMessage messageSentObjectMsg = null;
+ ObjectMessage messageReceivedObjectMsg = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTopicTest");
+ logger.log(Logger.Level.TRACE, "JMSPriority test - Send a Text message");
+ tool.getDefaultTopicPublisher().setPriority(priority);
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSPriority is " + messageReceived.getJMSPriority());
+ if (messageReceived.getJMSPriority() == priority) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Text Message Failed");
+ pass = false;
+ }
+
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.TRACE, "JMSPriority test - Send ObjectMessage to Topic.");
+ messageSentObjectMsg = tool.getDefaultTopicSession().createObjectMessage();
+ messageSentObjectMsg.setObject("msgHdrJMSPriorityTopicTest for Object Message");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTopicTest");
+ tool.getDefaultTopicPublisher().setPriority(priority);
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSPriority is " + messageReceivedObjectMsg.getJMSPriority());
+ if (messageReceivedObjectMsg.getJMSPriority() == priority) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Object Message JMSPriority Failed");
+ pass = false;
+ }
+
+ // send and receive map message to Topic
+ logger.log(Logger.Level.TRACE, "JMSPriority test - Send MapMessage to Topic.");
+ messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTopicTest");
+ messageSentMapMessage.setString("aString", "value");
+ tool.getDefaultTopicPublisher().setPriority(priority);
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSPriority is " + messageReceivedMapMessage.getJMSPriority());
+ if (messageReceivedMapMessage.getJMSPriority() == priority) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Map Message JMSPriority Failed");
+ pass = false;
+ }
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.TRACE, "JMSPriority test - Send BytesMessage to Topic.");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTopicTest");
+ messageSentBytesMessage.writeByte(bValue);
+ tool.getDefaultTopicPublisher().setPriority(priority);
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSPriority is " + messageReceivedBytesMessage.getJMSPriority());
+ if (messageReceivedBytesMessage.getJMSPriority() == priority) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Bytes Message JMSPriority Failed");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "JMSPriority test - sending a Stream message");
+ messageSentStreamMessage = tool.getDefaultTopicSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTopicTest");
+ messageSentStreamMessage.writeString("Testing...");
+ tool.getDefaultTopicPublisher().setPriority(priority);
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSPriority is " + messageReceivedStreamMessage.getJMSPriority());
+ if (messageReceivedStreamMessage.getJMSPriority() == priority) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Stream Message JMSPriority Failed");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSPriority returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrJMSPriorityTopicTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSExpirationTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:15; JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140;
+ * JMS:JAVADOC:309; JMS:JAVADOC:379;
+ *
+ * @test_Strategy: Send a message to a Topic with time to live set to 0 Verify
+ * that JMSExpiration gets set to 0 test with Text, map, object, byte, and
+ * stream messages verify on receive.
+ *
+ */
+ @Test
+ public void msgHdrJMSExpirationTopicTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ long forever = 0;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentStreamMessage = null;
+ StreamMessage messageReceivedStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ BytesMessage messageReceivedBytesMessage = null;
+ MapMessage messageReceivedMapMessage = null;
+ MapMessage messageSentMapMessage = null;
+ ObjectMessage messageSentObjectMsg = null;
+ ObjectMessage messageReceivedObjectMsg = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSExpirationTopicTest");
+ logger.log(Logger.Level.INFO, "JMSExpiration test (set timetoLive=0) - Send TextMessage to Topic");
+ tool.getDefaultTopicPublisher().setTimeToLive(forever);
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.INFO, "JMSExpiration is " + messageReceived.getJMSExpiration());
+ if (messageReceived.getJMSExpiration() == forever) {
+ logger.log(Logger.Level.INFO, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage JMSExpiration Failed");
+ logger.log(Logger.Level.INFO, "TextMessage.getJMSExpiration() returned "
+ + messageReceived.getJMSExpiration() + ", expected 0");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "JMSExpiration test (set timetoLive=60000) - Send TextMessage to Topic");
+ tool.getDefaultTopicPublisher().setTimeToLive(60000);
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ long currentTime = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "JMSExpiration is " + messageReceived.getJMSExpiration());
+ long timeLeftToExpiration = messageReceived.getJMSExpiration() - currentTime;
+ logger.log(Logger.Level.INFO, "TimeLeftToExpiration is " + timeLeftToExpiration);
+ if (timeLeftToExpiration <= 60000) {
+ logger.log(Logger.Level.INFO, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage JMSExpiration Failed");
+ logger.log(Logger.Level.INFO, "TextMessage JMSExpiration timeLeftToExpiration=" + timeLeftToExpiration
+ + ", expected <=60000");
+ pass = false;
+ }
+
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.INFO, "JMSExpiration test (set timeToLive=0) - Send ObjectMessage to Topic.");
+ messageSentObjectMsg = tool.getDefaultTopicSession().createObjectMessage();
+ messageSentObjectMsg.setObject("msgHdrJMSExpirationTopicTest for Object Message");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSExpirationTopicTest");
+ tool.getDefaultTopicPublisher().setTimeToLive(forever);
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.INFO, "JMSExpiration is " + messageReceivedObjectMsg.getJMSExpiration());
+ if (messageReceivedObjectMsg.getJMSExpiration() == forever) {
+ logger.log(Logger.Level.INFO, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSExpiration Failed");
+ logger.log(Logger.Level.INFO, "ObjectMessage.getJMSExpiration() returned "
+ + messageReceivedObjectMsg.getJMSExpiration() + ", expected 0");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "JMSExpiration test (set timetoLive=60000) - Send ObjectMessage to Topic.");
+ tool.getDefaultTopicPublisher().setTimeToLive(60000);
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ currentTime = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "JMSExpiration is " + messageReceivedObjectMsg.getJMSExpiration());
+ timeLeftToExpiration = messageReceivedObjectMsg.getJMSExpiration() - currentTime;
+ logger.log(Logger.Level.INFO, "TimeLeftToExpiration is " + timeLeftToExpiration);
+ if (timeLeftToExpiration <= 60000) {
+ logger.log(Logger.Level.INFO, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSExpiration Failed");
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSExpiration timeLeftToExpiration=" + timeLeftToExpiration
+ + ", expected <=60000");
+ pass = false;
+ }
+
+ // send and receive map message to Topic
+ logger.log(Logger.Level.INFO, "JMSExpiration test (set timeToLive=0) - Send MapMessage to Topic.");
+ messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSExpirationTopicTest");
+ messageSentMapMessage.setString("aString", "value");
+ tool.getDefaultTopicPublisher().setTimeToLive(forever);
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.INFO, "JMSExpiration is " + messageReceivedMapMessage.getJMSExpiration());
+ if (messageReceivedMapMessage.getJMSExpiration() == forever) {
+ logger.log(Logger.Level.INFO, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSExpiration Failed");
+ logger.log(Logger.Level.INFO, "MapMessage.getJMSExpiration() returned "
+ + messageReceivedMapMessage.getJMSExpiration() + ", expected 0");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "JMSExpiration test (set timetoLive=60000) - Send MapMessage to Topic.");
+ tool.getDefaultTopicPublisher().setTimeToLive(60000);
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ currentTime = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "JMSExpiration is " + messageReceivedMapMessage.getJMSExpiration());
+ timeLeftToExpiration = messageReceivedMapMessage.getJMSExpiration() - currentTime;
+ logger.log(Logger.Level.INFO, "TimeLeftToExpiration is " + timeLeftToExpiration);
+ if (timeLeftToExpiration <= 60000) {
+ logger.log(Logger.Level.INFO, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSExpiration Failed");
+ logger.log(Logger.Level.INFO,
+ "MapMessage JMSExpiration timeLeftToExpiration=" + timeLeftToExpiration + ", expected <=60000");
+ pass = false;
+ }
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.INFO, "JMSExpiration test (set timeToLive=0) - Send BytesMessage to Topic.");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSExpirationTopicTest");
+ messageSentBytesMessage.writeByte(bValue);
+ tool.getDefaultTopicPublisher().setTimeToLive(forever);
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.INFO, "JMSExpiration is " + messageReceivedBytesMessage.getJMSExpiration());
+ if (messageReceivedBytesMessage.getJMSExpiration() == forever) {
+ logger.log(Logger.Level.INFO, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSExpiration Failed");
+ logger.log(Logger.Level.INFO, "BytesMessage.getJMSExpiration() returned "
+ + messageReceivedBytesMessage.getJMSExpiration() + ", expected 0");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "JMSExpiration test (set timetoLive=60000) - Send BytesMessage to Topic.");
+ tool.getDefaultTopicPublisher().setTimeToLive(60000);
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ currentTime = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "JMSExpiration is " + messageReceivedBytesMessage.getJMSExpiration());
+ timeLeftToExpiration = messageReceivedBytesMessage.getJMSExpiration() - currentTime;
+ logger.log(Logger.Level.INFO, "TimeLeftToExpiration is " + timeLeftToExpiration);
+ if (timeLeftToExpiration <= 60000) {
+ logger.log(Logger.Level.INFO, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSExpiration Failed");
+ logger.log(Logger.Level.INFO, "BytesMessage JMSExpiration timeLeftToExpiration=" + timeLeftToExpiration
+ + ", expected <=60000");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.INFO, "JMSExpiration test (set timeToLive=0) - sending a Stream message");
+ messageSentStreamMessage = tool.getDefaultTopicSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSExpirationTopicTest");
+ messageSentStreamMessage.writeString("Testing...");
+ tool.getDefaultTopicPublisher().setTimeToLive(forever);
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.INFO, "JMSExpiration is " + messageReceivedStreamMessage.getJMSExpiration());
+ if (messageReceivedStreamMessage.getJMSExpiration() == forever) {
+ logger.log(Logger.Level.INFO, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSExpiration Failed");
+ logger.log(Logger.Level.INFO, "StreamMessage.getJMSExpiration() returned "
+ + messageReceivedStreamMessage.getJMSExpiration() + ", expected 0");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "JMSExpiration test (set timetoLive=60000) - Send StreamMessage to Topic.");
+ tool.getDefaultTopicPublisher().setTimeToLive(60000);
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ currentTime = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "JMSExpiration is " + messageReceivedStreamMessage.getJMSExpiration());
+ timeLeftToExpiration = messageReceivedStreamMessage.getJMSExpiration() - currentTime;
+ logger.log(Logger.Level.INFO, "TimeLeftToExpiration is " + timeLeftToExpiration);
+ if (timeLeftToExpiration <= 60000) {
+ logger.log(Logger.Level.INFO, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSExpiration Failed");
+ logger.log(Logger.Level.INFO, "StreamMessage JMSExpiration timeLeftToExpiration=" + timeLeftToExpiration
+ + ", expected <=60000");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSExpiration returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrJMSExpirationTopicTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSDestinationTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:2; JMS:JAVADOC:363; JMS:JAVADOC:117;
+ *
+ * @test_Strategy: Create and publish a message to the default Topic. Receive
+ * the msg and verify that JMSDestination is set to the default Topic test with
+ * Text, map, object, byte, and stream messages
+ *
+ */
+ @Test
+ public void msgHdrJMSDestinationTopicTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ Topic replyDestination = null;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentStreamMessage = null;
+ StreamMessage messageReceivedStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ BytesMessage messageReceivedBytesMessage = null;
+ MapMessage messageReceivedMapMessage = null;
+ MapMessage messageSentMapMessage = null;
+ ObjectMessage messageSentObjectMsg = null;
+ ObjectMessage messageReceivedObjectMsg = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("publishing a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDestinationTopicTest");
+ logger.log(Logger.Level.TRACE, "publish Text Message to Topic.");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDestination: " + messageReceived.getJMSDestination());
+ replyDestination = (Topic) messageReceived.getJMSDestination();
+ if (replyDestination != null)
+ logger.log(Logger.Level.TRACE, "Topic name is " + replyDestination.getTopicName());
+ if (replyDestination == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Text Message Error: JMSDestination returned a null");
+ } else if (replyDestination.getTopicName().equals(tool.getDefaultTopic().getTopicName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Text Message Failed");
+ pass = false;
+ }
+
+ // publish and receive Object message to Topic
+ logger.log(Logger.Level.TRACE, "publish ObjectMessage to Topic.");
+ messageSentObjectMsg = tool.getDefaultTopicSession().createObjectMessage();
+ messageSentObjectMsg.setObject("msgHdrIDQTest for Object Message");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDestinationTopicTest");
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDestination: " + messageReceivedObjectMsg.getJMSDestination());
+ replyDestination = (Topic) messageReceived.getJMSDestination();
+ if (replyDestination != null)
+ logger.log(Logger.Level.TRACE, "Topic name is " + replyDestination.getTopicName());
+ if (replyDestination == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Object Message Error: JMSDestination returned a null");
+ } else if (replyDestination.getTopicName().equals(tool.getDefaultTopic().getTopicName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Object Message Failed");
+ pass = false;
+ }
+
+ // publish and receive map message to Topic
+ logger.log(Logger.Level.TRACE, "publish MapMessage to Topic.");
+ messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDestinationTopicTest");
+ messageSentMapMessage.setString("aString", "value");
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDestination: " + messageReceivedMapMessage.getJMSDestination());
+ replyDestination = (Topic) messageReceived.getJMSDestination();
+ if (replyDestination != null)
+ logger.log(Logger.Level.TRACE, "Topic name is " + replyDestination.getTopicName());
+ if (replyDestination == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Map Message Error: JMSDestination returned a null");
+ } else if (replyDestination.getTopicName().equals(tool.getDefaultTopic().getTopicName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Map Message Failed");
+ pass = false;
+ }
+
+ // publish and receive bytes message to Topic
+ logger.log(Logger.Level.TRACE, "publish BytesMessage to Topic.");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDestinationTopicTest");
+ messageSentBytesMessage.writeByte(bValue);
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDestination: " + messageReceivedBytesMessage.getJMSDestination());
+ replyDestination = (Topic) messageReceived.getJMSDestination();
+ if (replyDestination != null)
+ logger.log(Logger.Level.TRACE, "Topic name is " + replyDestination.getTopicName());
+ if (replyDestination == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Bytes Message Error: JMSDestination returned a null");
+ } else if (replyDestination.getTopicName().equals(tool.getDefaultTopic().getTopicName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Bytes Message Failed");
+ pass = false;
+ }
+
+ // publish and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "publishing a Stream message");
+ messageSentStreamMessage = tool.getDefaultTopicSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDestinationTopicTest");
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "publishing Stream message");
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDestination: " + messageReceivedStreamMessage.getJMSDestination());
+ replyDestination = (Topic) messageReceived.getJMSDestination();
+ if (replyDestination != null)
+ logger.log(Logger.Level.TRACE, "Topic name is " + replyDestination.getTopicName());
+ if (replyDestination == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Stream Message Error: JMSDestination returned a null");
+ } else if (replyDestination.getTopicName().equals(tool.getDefaultTopic().getTopicName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Stream Message Failed");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSDestination returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrJMSDestinationTopicTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSDeliveryModeTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:3; JMS:SPEC:140; JMS:JAVADOC:367; JMS:SPEC:246.2;
+ * JMS:JAVADOC:301;
+ *
+ * @test_Strategy: Create and publish a message to the default Topic. Receive
+ * the msg and verify that JMSDeliveryMode is set the default delivery mode of
+ * persistent. Create and test another message with a nonpersistent delivery
+ * mode. test with Text, map, object, byte, and stream messages
+ */
+ @Test
+ public void msgHdrJMSDeliveryModeTopicTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentStreamMessage = null;
+ StreamMessage messageReceivedStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ BytesMessage messageReceivedBytesMessage = null;
+ MapMessage messageReceivedMapMessage = null;
+ MapMessage messageSentMapMessage = null;
+ ObjectMessage messageSentObjectMsg = null;
+ ObjectMessage messageReceivedObjectMsg = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "default delivery mode is " + Message.DEFAULT_DELIVERY_MODE);
+ logger.log(Logger.Level.INFO, "persistent is: " + DeliveryMode.PERSISTENT);
+ if (Message.DEFAULT_DELIVERY_MODE != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Error: default delivery mode was " + Message.DEFAULT_DELIVERY_MODE);
+ logger.log(Logger.Level.INFO,
+ "The default delivery mode should be persistent: " + DeliveryMode.PERSISTENT);
+ }
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("publishing a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDeliveryModeTopicTest");
+ logger.log(Logger.Level.TRACE, "publish Text Message to Topic.");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO,
+ "Text Message Error: JMSDeliveryMode should be set to persistent as default");
+ } else {
+ logger.log(Logger.Level.TRACE, "Text Message Pass ");
+ }
+
+ // publish and receive Object message to Topic
+ logger.log(Logger.Level.TRACE, "publish ObjectMessage to Topic.");
+ messageSentObjectMsg = tool.getDefaultTopicSession().createObjectMessage();
+ messageSentObjectMsg.setObject("Test for Object Message");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDeliveryModeTopicTest");
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO,
+ "Object Message Error: JMSDeliveryMode should be set to persistent as default");
+ } else {
+ logger.log(Logger.Level.TRACE, "Object Message Pass ");
+ }
+
+ // publish and receive map message to Topic
+ logger.log(Logger.Level.TRACE, "publish MapMessage to Topic.");
+ messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDeliveryModeTopicTest");
+ messageSentMapMessage.setString("aString", "value");
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO,
+ "Map Message Error: JMSDeliveryMode should be set to persistent as default");
+ } else {
+ logger.log(Logger.Level.TRACE, "Map Message Pass ");
+ }
+
+ // publish and receive bytes message to Topic
+ logger.log(Logger.Level.TRACE, "publish BytesMessage to Topic.");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDeliveryModeTopicTest");
+ messageSentBytesMessage.writeByte(bValue);
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO,
+ "Bytes Message Error: JMSDeliveryMode should be set to persistent as default");
+ } else {
+ logger.log(Logger.Level.TRACE, "Bytes Message Pass ");
+ }
+
+ // publish and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "publishing a Stream message");
+ messageSentStreamMessage = tool.getDefaultTopicSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDeliveryModeTopicTest");
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "publishing Stream message");
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO,
+ "Stream Message Error: JMSDeliveryMode should be set to persistent as default");
+ } else {
+ logger.log(Logger.Level.TRACE, "Stream Message Pass ");
+ }
+
+ // Test again - this time set delivery mode to persistent
+ tool.getDefaultTopicPublisher().setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("publishing a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDeliveryModeTopicTest");
+ logger.log(Logger.Level.TRACE, "publish Text Message to Topic.");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ logger.log(Logger.Level.TRACE, "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Text Message Error: JMSDeliveryMode should be set to NON_PERSISTENT");
+ } else {
+ logger.log(Logger.Level.TRACE, "Text Message Pass ");
+ }
+
+ // publish and receive Object message to Topic
+ logger.log(Logger.Level.TRACE, "publish ObjectMessage to Topic.");
+ messageSentObjectMsg = tool.getDefaultTopicSession().createObjectMessage();
+ messageSentObjectMsg.setObject("msgHdrJMSDeliveryModeTopicTest for Object Message");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDeliveryModeTopicTest");
+ tool.getDefaultTopicPublisher().publish(messageSentObjectMsg);
+ messageReceivedObjectMsg = (ObjectMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceivedObjectMsg != null)
+ logger.log(Logger.Level.TRACE, "messageReceivedObjectMsg=" + messageReceivedObjectMsg);
+ logger.log(Logger.Level.TRACE, "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Object Message Error: JMSDeliveryMode should be set to NON_PERSISTENT");
+ } else {
+ logger.log(Logger.Level.TRACE, "Object Message Pass ");
+ }
+
+ // publish and receive map message to Topic
+ logger.log(Logger.Level.TRACE, "publish MapMessage to Topic.");
+ messageSentMapMessage = tool.getDefaultTopicSession().createMapMessage();
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDeliveryModeTopicTest");
+ messageSentMapMessage.setString("aString", "value");
+ tool.getDefaultTopicPublisher().publish(messageSentMapMessage);
+ messageReceivedMapMessage = (MapMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceivedMapMessage != null)
+ logger.log(Logger.Level.TRACE, "messageReceivedMapMessage=" + messageReceivedMapMessage);
+ logger.log(Logger.Level.TRACE, "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Map Message Error: JMSDeliveryMode should be set to NON_PERSISTENT");
+ } else {
+ logger.log(Logger.Level.TRACE, "Map Message Pass ");
+ }
+
+ // publish and receive bytes message to Topic
+ logger.log(Logger.Level.TRACE, "publish BytesMessage to Topic.");
+ messageSentBytesMessage = tool.getDefaultTopicSession().createBytesMessage();
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDeliveryModeTopicTest");
+ messageSentBytesMessage.writeByte(bValue);
+ tool.getDefaultTopicPublisher().publish(messageSentBytesMessage);
+ messageReceivedBytesMessage = (BytesMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceivedBytesMessage != null)
+ logger.log(Logger.Level.TRACE, "messageReceivedBytesMessage=" + messageReceivedBytesMessage);
+ logger.log(Logger.Level.TRACE, "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Bytes Message Error: JMSDeliveryMode should be set to NON_PERSISTENT");
+ } else {
+ logger.log(Logger.Level.TRACE, "Bytes Message Pass ");
+ }
+
+ // publish and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "publishing a Stream message");
+ messageSentStreamMessage = tool.getDefaultTopicSession().createStreamMessage();
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDeliveryModeTopicTest");
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "publishing Stream message");
+ tool.getDefaultTopicPublisher().publish(messageSentStreamMessage);
+ messageReceivedStreamMessage = (StreamMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceivedStreamMessage != null)
+ logger.log(Logger.Level.TRACE, "messageReceivedStreamMessage=" + messageReceivedStreamMessage);
+ logger.log(Logger.Level.TRACE, "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Stream Message Error: JMSDeliveryMode should be set to NON_PERSISTENT");
+ } else {
+ logger.log(Logger.Level.TRACE, "Stream Message Pass ");
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSDeliveryMode returned from JMS Header");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrJMSDeliveryModeTopicTest");
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/topicMsgProperties/TopicPropertyTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/topicMsgProperties/TopicPropertyTests.java
deleted file mode 100644
index 771eb15713..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/topicMsgProperties/TopicPropertyTests.java
+++ /dev/null
@@ -1,1684 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.topicMsgProperties;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.ConnectionMetaData;
-import jakarta.jms.MessageFormatException;
-import jakarta.jms.MessageNotWriteableException;
-import jakarta.jms.TextMessage;
-
-public class TopicPropertyTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.topicMsgProperties.TopicPropertyTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient JmsTool tool = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList connections = null;
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- TopicPropertyTests theTests = new TopicPropertyTests();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
-
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- TestUtil.logMsg("Didn't get expected exception");
- throw new Exception("Didn't catch expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default
- * TopicConnection, as well as a default Topic. Tests that require multiple
- * Destinations create the extras within the test
- *
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
-
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must be null");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must be null");
- }
- if (mode == null) {
- throw new Exception("'mode' in ts.jte must be null");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- try {
- if (tool != null) {
- TestUtil.logMsg("Cleanup: Closing TopicConnection");
- tool.closeAllConnections(connections);
- }
- } catch (Exception e) {
- TestUtil.logErr("An error occurred while cleaning: ", e);
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: msgPropertiesTopicTest
- *
- * @assertion_ids: JMS:SPEC:20.1; JMS:SPEC:20.2; JMS:SPEC:20.3; JMS:SPEC:20.4;
- * JMS:SPEC:20.5; JMS:SPEC:20.6; JMS:SPEC:20.7; JMS:SPEC:20.8; JMS:SPEC:21;
- * JMS:SPEC:23; JMS:SPEC:24; JMS:SPEC:25; JMS:SPEC:26; JMS:SPEC:10;
- * JMS:SPEC:27; JMS:SPEC:28; JMS:SPEC:29; JMS:SPEC:31; JMS:SPEC:32;
- * JMS:SPEC:19; JMS:SPEC:70; JMS:SPEC:71; JMS:JAVADOC:411; JMS:JAVADOC:413;
- * JMS:JAVADOC:415; JMS:JAVADOC:417; JMS:JAVADOC:419; JMS:JAVADOC:421;
- * JMS:JAVADOC:423; JMS:JAVADOC:425; JMS:JAVADOC:427; JMS:JAVADOC:409;
- * JMS:JAVADOC:391; JMS:JAVADOC:393; JMS:JAVADOC:395; JMS:JAVADOC:397;
- * JMS:JAVADOC:399; JMS:JAVADOC:401; JMS:JAVADOC:403; JMS:JAVADOC:405;
- * JMS:JAVADOC:407; JMS:JAVADOC:500; JMS:JAVADOC:516; JMS:JAVADOC:387;
- * JMS:JAVADOC:792; JMS:JAVADOC:776; JMS:JAVADOC:778; JMS:JAVADOC:780;
- * JMS:JAVADOC:782; JMS:JAVADOC:784; JMS:JAVADOC:786; JMS:JAVADOC:788;
- * JMS:JAVADOC:790; JMS:JAVADOC:793; JMS:SPEC:34.4; JMS:SPEC:34.5;
- *
- * @test_Strategy: set and read properties for boolean, byte, short, int,
- * long, float, double, and String. Verify expected results set and read
- * properties for Boolean, Byte, Short, Int, Long, Float, Double, and String.
- * Verify expected results.
- *
- * When a client receives a message it is in read-only mode. Send a message
- * and have the client attempt modify the properties. Verify that a
- * MessageNotWriteableException is thrown. Call setObject property with an
- * invalid object and verify that a MessageFormatException is thrown
- *
- * call property get methods( other than getStringProperty and
- * getObjectProperty) for non-existent properties and verify that a null
- * pointer exception is returned. call getStringProperty and getObjectProperty
- * for non-existent properties and verify that a null is returned.
- *
- * set object properties and verify the correct value is returned with the
- * getObjectProperty method.
- *
- * call the clearProperties method on the received message and verify that the
- * messages properties were deleted. Test that getObjectProperty returns a
- * null and the getShortProperty throws a null pointer exception.
- *
- * After clearing the message properties, call getText and verify that the
- * message body has not been cleared.
- *
- * Call ConnectionMetaData.getJMSXPropertyNames() and verify that the names of
- * the required JMSX properties for JMSXGroupID and JMSXGroupSeq are returned.
- */
-
- public void msgPropertiesTopicTest() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- Enumeration propertyNames = null;
- Enumeration jmsxDefined = null;
- int numPropertyNames = 18;
- String testMessageBody = "Testing...";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText(testMessageBody);
-
- // -------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // -------------------------------------------------------------
- messageSent.setBooleanProperty("TESTBOOLEAN", bool);
- messageSent.setByteProperty("TESTBYTE", bValue);
- messageSent.setShortProperty("TESTSHORT", nShort);
- messageSent.setIntProperty("TESTINT", nInt);
- messageSent.setFloatProperty("TESTFLOAT", nFloat);
- messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
- messageSent.setStringProperty("TESTSTRING", "test");
- messageSent.setLongProperty("TESTLONG", nLong);
-
- // --------------------------------------------------------------
- // set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
- // String.
- // --------------------------------------------------------------
- messageSent.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
- messageSent.setObjectProperty("OBJTESTBYTE", Byte.valueOf(bValue));
- messageSent.setObjectProperty("OBJTESTSHORT", Short.valueOf(nShort));
- messageSent.setObjectProperty("OBJTESTINT", Integer.valueOf(nInt));
- messageSent.setObjectProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
- messageSent.setObjectProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
- messageSent.setObjectProperty("OBJTESTSTRING", "test");
- messageSent.setObjectProperty("OBJTESTLONG", Long.valueOf(nLong));
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesTopicTest");
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // ------------------------------------------------------------------------------
- // An attempt to use any other class than Boolean, Byte, Short, Int, Long,
- // Float,
- // Double, and Stringmust throw a JMS MessageFormatException.
- // ------------------------------------------------------------------------------
- try {
- messageSent.setObjectProperty("OBJTESTLONG", new Object());
- TestUtil.logMsg("Error: expected MessageFormatException from invalid ");
- TestUtil.logMsg("call to setObjectProperty did not occur!");
- pass = false;
- } catch (MessageFormatException fe) {
- TestUtil.logTrace("Pass: ");
- TestUtil.logTrace(
- " MessageFormatException as expected from invalid setObjectProperty call");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr("from call to setObjectProperty!");
- pass = false;
- }
-
- // -------------------------------------------------------------------------
- // Received message should be read-only - verify proper exception is
- // thrown
- // when trying to modify msg properties.
- // ------------------------------------------------------------------------
- try {
- messageReceived.setBooleanProperty("TESTBOOLEAN", bool);
- TestUtil.logMsg(
- "Error: exception should have occurred for setBooleanProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil
- .logTrace("Pass: exception as expected for setBooleanProperty ");
- }
- try {
- messageReceived.setByteProperty("TESTBYTE", bValue);
- TestUtil.logMsg(
- "Error: exception should have occurred for setByteProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setByteProperty ");
- }
- try {
- messageReceived.setShortProperty("TESTSHORT", nShort);
- pass = false;
- TestUtil.logMsg(
- "Error: exception should have occurred for setShortProperty");
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setShortProperty ");
- }
- try {
- messageReceived.setIntProperty("TESTINT", nInt);
- TestUtil
- .logMsg("Error: exception should have occurred for setIntProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setIntProperty ");
- }
- try {
- messageReceived.setFloatProperty("TESTFLOAT", nFloat);
- TestUtil.logMsg(
- "Error: exception should have occurred for setFloatProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setFloatProperty ");
- }
- try {
- messageReceived.setDoubleProperty("TESTDOUBLE", nDouble);
- TestUtil.logMsg(
- "Error: exception should have occurred for setDoubleProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setDoubleProperty ");
- }
- try {
- messageReceived.setStringProperty("TESTSTRING", testString);
- TestUtil.logMsg(
- "Error: exception should have occurred for setStringProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setStringProperty ");
- }
- try {
- messageReceived.setLongProperty("TESTLONG", nLong);
- TestUtil.logMsg(
- "Error: exception should have occurred for setLongProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setLongProperty ");
- }
- try {
- messageReceived.setObjectProperty("OBJTESTBOOLEAN",
- Boolean.valueOf(bool));
- TestUtil.logMsg(
- "Error: exception should have occurred for setObjectProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setObjectProperty ");
- }
-
- // iterate thru the property names
- int i = 0;
- propertyNames = messageReceived.getPropertyNames();
- do {
- String tmp = (String) propertyNames.nextElement();
- TestUtil.logTrace("+++++++ Property Name is: " + tmp);
- if (tmp.indexOf("JMS") != 0)
- i++;
- else if (tmp.equals("JMSXDeliveryCount"))
- i++;
- } while (propertyNames.hasMoreElements());
-
- if (i == numPropertyNames) {
- TestUtil.logTrace(
- "Pass: # of properties is " + numPropertyNames + " as expected");
- } else {
- TestUtil.logMsg("Error: expected " + numPropertyNames
- + " property names, but got " + i);
- pass = false;
- }
-
- // --------------------------------------------------------------------------------
- // read and verify the property values for primitive types in the received
- // message
- // --------------------------------------------------------------------------------
- if (messageReceived.getBooleanProperty("TESTBOOLEAN") == bool) {
- TestUtil.logTrace("Pass: getBooleanProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getBooleanProperty");
- pass = false;
- }
- if (messageReceived.getByteProperty("TESTBYTE") == bValue) {
- TestUtil.logTrace("Pass: getByteProperty returned correct value");
- } else {
- TestUtil.logMsg("Error: incorrect value returned from getByteProperty");
- pass = false;
- }
- if (messageReceived.getLongProperty("TESTLONG") == nLong) {
- TestUtil.logTrace("Pass: getLongProperty returned correct value");
- } else {
- TestUtil.logMsg("Error: incorrect value returned from getLongProperty");
- pass = false;
- }
- if (messageReceived.getStringProperty("TESTSTRING").equals(testString)) {
- TestUtil.logTrace("Pass: getStringProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getStringProperty");
- pass = false;
- }
- if (messageReceived.getDoubleProperty("TESTDOUBLE") == nDouble) {
- TestUtil.logTrace("Pass: getDoubleProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getDoubleProperty");
- pass = false;
- }
- if (messageReceived.getFloatProperty("TESTFLOAT") == nFloat) {
- TestUtil.logTrace("Pass: getFloatProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getFloatProperty");
- pass = false;
- }
- if (messageReceived.getIntProperty("TESTINT") == nInt) {
- TestUtil.logTrace("Pass: getIntProperty returned correct value");
- } else {
- TestUtil.logMsg("Error: incorrect value returned from getIntProperty");
- pass = false;
- }
- if (messageReceived.getShortProperty("TESTSHORT") == nShort) {
- TestUtil.logTrace("Pass: getShortProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getShortProperty");
- pass = false;
- }
-
- // -----------------------------------------------------------
- // The other property get methods ( other than getStringProperty and
- // getObjectProperty) must behave as if the property exists with a
- // null value
- // -----------------------------------------------------------
- // Getting a property value for a name which has not been set
- // returns a null value.
- // Only the getStringProperty and getObjectProperty methods can return a
- // null
- // value. The other property get methods must throw a
- // java.lang.NullPointerException if they are used to get a non-existent
- // property.
- try {
- boolean b = messageReceived.getBooleanProperty("TESTDUMMY");
- if (b != false) {
- TestUtil.logMsg(
- "Error: should havereceived false for getBooleanProperty");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Unexpected Exception: ", e);
- pass = false;
- }
-
- try {
- byte value = messageReceived.getByteProperty("TESTDUMMY");
-
- TestUtil.logMsg(
- "Error: NumberFormatException should have occurred for getByteProperty");
- pass = false;
- } catch (java.lang.NumberFormatException e) {
- TestUtil.logTrace("Pass: NumberFormatException as expected ");
- }
- try {
- short value = messageReceived.getShortProperty("TESTDUMMY");
-
- TestUtil.logMsg(
- "Error: NumberFormatException should have occurred for getShortProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- TestUtil.logTrace("Pass: NumberFormatException as expected ");
- }
- try {
- int value = messageReceived.getIntProperty("TESTDUMMY");
-
- TestUtil.logMsg(
- "Error: NumberFormatException should have occurred for getIntProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- TestUtil.logTrace("Pass:NumberFormatException as expected ");
- }
- try {
- long value = messageReceived.getLongProperty("TESTDUMMY");
-
- TestUtil.logMsg(
- "Error: NumberFormatException should have occurred for getLongProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- TestUtil.logTrace("Pass: NumberFormatException as expected ");
- }
- try {
- float value = messageReceived.getFloatProperty("TESTDUMMY");
-
- TestUtil.logMsg(
- "Error: NullPointerException should have occurred for getFloatProperty");
- pass = false;
- } catch (java.lang.NullPointerException np) {
- TestUtil.logTrace("Pass: NullPointerException as expected ");
- }
- try {
- double value = messageReceived.getDoubleProperty("TESTDUMMY");
-
- TestUtil.logMsg(
- "Error: NullPointerException should have occurred for getDoubleProperty");
- pass = false;
- } catch (java.lang.NullPointerException np) {
- TestUtil.logTrace("Pass: NullPointerException as expected ");
- }
-
- // --------------------------------------------------------------------------------
- // Getting a property value for a name which has not been set returns a
- // null value.
- // (For getStringProperty and getObjectProperty)
- // --------------------------------------------------------------------------------
- String value = messageReceived.getStringProperty("TESTDUMMY");
-
- if (value == null) {
- TestUtil.logTrace("Pass: getStringProperty returned correct value");
- } else {
- TestUtil.logMsg(
- "Error: expected a null return from getStringProperty for invalid property");
- pass = false;
- }
- Boolean aBool = (Boolean) messageReceived.getObjectProperty("TESTDUMMY");
-
- if (aBool == null) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Boolean");
- } else {
- TestUtil.logMsg(
- "Error: expected a null return from getObjectProperty for invalid property");
- pass = false;
- }
-
- // --------------------------------------------------------------------------------
- // read and verify the property values for getObject in the received
- // message
- // --------------------------------------------------------------------------------
- Boolean boolValue = (Boolean) messageReceived
- .getObjectProperty("OBJTESTBOOLEAN");
-
- if (boolValue.booleanValue() == bool) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Boolean");
- } else {
- TestUtil.logMsg("Error: incorrect value returned for Boolean");
- pass = false;
- }
- Byte byteValue = (Byte) messageReceived.getObjectProperty("OBJTESTBYTE");
-
- if (byteValue.byteValue() == bValue) {
- TestUtil
- .logTrace("Pass: getObjectProperty returned correct Byte value");
- } else {
- TestUtil.logMsg("Error: incorrect value returned from Byte");
- pass = false;
- }
- Long lValue = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
-
- if (lValue.longValue() == nLong) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Long");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value returned for Long");
- pass = false;
- }
-
- // String value =
- // (String)messageReceived.getObjectProperty("OBJTESTSTRING");
- if (messageReceived.getObjectProperty("OBJTESTSTRING")
- .equals(testString)) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for String");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for String");
- pass = false;
- }
- Double dValue = (Double) messageReceived
- .getObjectProperty("OBJTESTDOUBLE");
-
- if (dValue.doubleValue() == nDouble) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Double");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for Double");
- pass = false;
- }
- Float fValue = (Float) messageReceived.getObjectProperty("OBJTESTFLOAT");
-
- if (fValue.floatValue() == nFloat) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Float");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for Float");
- pass = false;
- }
- Integer iValue = (Integer) messageReceived
- .getObjectProperty("OBJTESTINT");
-
- if (iValue.intValue() == nInt) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Integer");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for Integer");
- pass = false;
- }
- Short sValue = (Short) messageReceived.getObjectProperty("OBJTESTSHORT");
-
- if (sValue.shortValue() == nShort) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Short");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for Short");
- pass = false;
- }
-
- // clear message properties
- messageReceived.clearProperties();
-
- // -------------------------------------------------------------------
- // A message?s properties are deleted by the clearProperties method.
- // This leaves the message with an empty set of properties.
- // -------------------------------------------------------------------
- Long aLong = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
-
- if (aLong == null) {
- TestUtil.logTrace("Pass: property was cleared");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty should have returned null for cleared property");
- pass = false;
- }
- try {
- short aShort = messageReceived.getShortProperty("TESTSHORT");
-
- TestUtil.logMsg(
- "Error: NumberFormatException should have occurred for getShortProperty");
- TestUtil.logMsg("Properties have been cleared!");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- TestUtil.logTrace("Pass: NumberFormatException as expected ");
- }
-
- // -------------------------------------------------------------------
- // A message?s properties are deleted by the clearProperties method.
- // This leaves the message with an empty set of properties.
- // -------------------------------------------------------------------
- aLong = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
-
- if (aLong == null) {
- TestUtil.logTrace("Pass: property was cleared");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty should have returned null for cleared property");
- pass = false;
- }
- try {
- short aShort = messageReceived.getShortProperty("TESTSHORT");
-
- TestUtil.logMsg(
- "Error: NumberFormatException should have occurred for getShortProperty");
- TestUtil.logMsg("Properties have been cleared!");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- TestUtil.logTrace("Pass: NumberFormatException as expected ");
- }
-
- // -------------------------------------------------------------------
- // clearing the message property should not effect the message body.
- // -------------------------------------------------------------------
- TestUtil.logMsg("Message body is : " + messageReceived.getText());
- if (messageReceived.getText().equals(testMessageBody)) {
- TestUtil
- .logTrace("Pass: able to read message body after clearProperties");
- } else {
- TestUtil
- .logMsg("Error: unable to read message body after clearProperties");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // ConnectionMetaData.getJMSXPropertyNames() method returns the
- // names of the JMSX properties supported by a connection.
- // -------------------------------------------------------------------
- try {
- ConnectionMetaData data = tool.getDefaultTopicConnection()
- .getMetaData();
- Enumeration cmd = data.getJMSXPropertyNames();
- String propName;
-
- if (cmd == null) {
- TestUtil.logMsg("Error: no JMSX property names were returned!");
- TestUtil.logMsg(
- "expected JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount at a miniumum");
- pass = false;
- } else {
- int iCount = 0;
-
- do {
- propName = (String) cmd.nextElement();
- TestUtil.logTrace(propName);
- if (propName.equals("JMSXGroupID")
- || propName.equals("JMSXGroupSeq")
- || propName.equals("JMSXDeliveryCount")) {
- iCount++;
- }
- } while (cmd.hasMoreElements());
- if (iCount > 1) {
- TestUtil.logTrace("Pass:");
- } else {
- TestUtil.logMsg("Error: Expected property names not returned");
- pass = false;
- }
- }
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected exception: ", ee);
- TestUtil.logErr("attempting to read JMSX property names.");
- pass = false;
- }
- if (!pass) {
- throw new Exception("Error: failures occurred during property tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgPropertiesTopicTest");
- }
- }
-
- /*
- * @testName: msgPropertiesConversionTopicTest
- *
- * @assertion_ids: JMS:SPEC:22.1; JMS:SPEC:22.2; JMS:SPEC:22.3; JMS:SPEC:22.4;
- * JMS:SPEC:22.5; JMS:SPEC:22.6; JMS:SPEC:22.7; JMS:SPEC:22.8; JMS:SPEC:22.9;
- * JMS:SPEC:22.10; JMS:SPEC:22.11; JMS:SPEC:22.12; JMS:SPEC:22.13;
- * JMS:SPEC:22.14; JMS:SPEC:22.15; JMS:SPEC:22.16; JMS:JAVADOC:391;
- * JMS:JAVADOC:393; JMS:JAVADOC:395; JMS:JAVADOC:397; JMS:JAVADOC:399;
- * JMS:JAVADOC:401; JMS:JAVADOC:403; JMS:JAVADOC:405; JMS:JAVADOC:407;
- * JMS:JAVADOC:767; JMS:JAVADOC:768; JMS:JAVADOC:769; JMS:JAVADOC:770;
- * JMS:JAVADOC:771; JMS:JAVADOC:772; JMS:JAVADOC:773; JMS:JAVADOC:774;
- *
- *
- *
- * @test_Strategy: create a message, set properties for all of the primitive
- * types verify the conversion by getting the properties.
- */
-
- public void msgPropertiesConversionTopicTest() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- String testMessageBody = "Testing...";
- int ntest = 0;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText(testMessageBody);
-
- // ------------------------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- messageSent.setBooleanProperty("TESTBOOLEAN", bool);
- messageSent.setByteProperty("TESTBYTE", bValue);
- messageSent.setShortProperty("TESTSHORT", nShort);
- messageSent.setIntProperty("TESTINT", nInt);
- messageSent.setFloatProperty("TESTFLOAT", nFloat);
- messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
- messageSent.setStringProperty("TESTSTRING", "test");
- messageSent.setLongProperty("TESTLONG", nLong);
- messageSent.setStringProperty("TESTSTRINGTRUE", "true");
- messageSent.setStringProperty("TESTSTRINGFALSE", "false");
- messageSent.setStringProperty("TESTSTRING1", "1");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesConversionTopicTest");
- TestUtil.logTrace("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
-
- // -------------------------------------------------------------------
- // test conversions for property values
- // -------------------------------------------------------------------
- // property set as boolean can be read only as string or boolean
- // -------------------------------------------------------------------
- // valid - boolean to string
- String myBool = messageReceived.getStringProperty("TESTBOOLEAN");
-
- if (Boolean.valueOf(myBool).booleanValue() == bool) {
- TestUtil.logTrace("Pass: conversion from boolean to string - ok");
- } else {
- TestUtil.logErr("Error: conversion from boolean to string failed");
- pass = false;
- }
-
- // invalid - boolean to byte
- try {
- messageReceived.getByteProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- boolean to byte");
- pass = false;
- }
-
- // invalid - boolean to short
- try {
- messageReceived.getShortProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- boolean to short");
- pass = false;
- }
-
- // invalid - boolean to int
- try {
- messageReceived.getIntProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to int ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException --boolean to int ");
- pass = false;
- }
-
- // invalid - boolean to long
- try {
- messageReceived.getLongProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to long ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- boolean to long");
- pass = false;
- }
-
- // invalid - boolean to float
- try {
- messageReceived.getFloatProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- boolean to float");
- pass = false;
- }
-
- // invalid - boolean to double
- try {
- messageReceived.getDoubleProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- boolean to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as byte can be read as a byte,short,int,long or string
- // valid - byte to string
- String myByte = messageReceived.getStringProperty("TESTBYTE");
-
- if (Byte.valueOf(myByte).byteValue() == bValue) {
- TestUtil.logTrace("Pass: conversion from byte to string - ok");
- } else {
- TestUtil.logErr("Error: conversion from byte to string failed");
- pass = false;
- }
-
- // valid - byte to short
- if (messageReceived.getShortProperty("TESTBYTE") == bValue) {
- TestUtil.logTrace("Pass: conversion from byte to short - ok");
- } else {
- TestUtil.logErr("Error: conversion from byte to short failed");
- pass = false;
- }
-
- // valid - byte to int
- if (messageReceived.getIntProperty("TESTBYTE") == bValue) {
- TestUtil.logTrace("Pass: conversion from byte to int - ok");
- } else {
- TestUtil.logErr("Error: conversion from byte to int failed");
- pass = false;
- }
-
- // valid - byte to long
- if (messageReceived.getLongProperty("TESTBYTE") == bValue) {
- TestUtil.logTrace("Pass: conversion from byte to long - ok");
- } else {
- TestUtil.logErr("Error: conversion from byte to long failed");
- pass = false;
- }
-
- // invalid - byte to boolean
- try {
- messageReceived.getBooleanProperty("TESTBYTE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: byte to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- byte to boolean");
- pass = false;
- }
-
- // invalid - byte to float
- try {
- messageReceived.getFloatProperty("TESTBYTE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: byte to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException --byte to float ");
- pass = false;
- }
-
- // invalid - byte to double
- try {
- messageReceived.getDoubleProperty("TESTBYTE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: byte to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- byte to double");
- pass = false;
- }
-
- // -------------------------------------------------
- // property set as short can be read as short,int,long or string
- // valid - short to string
- String myshort = messageReceived.getStringProperty("TESTSHORT");
-
- if (Short.valueOf(myshort).shortValue() == nShort) {
- TestUtil.logTrace("Pass: conversion from short to string - ok");
- } else {
- TestUtil.logErr("Error: conversion from short to string failed");
- pass = false;
- }
-
- // valid - short to int
- if (messageReceived.getIntProperty("TESTSHORT") == nShort) {
- TestUtil.logTrace("Pass: conversion from short to int - ok");
- } else {
- TestUtil.logErr("Error: conversion from short to int failed");
- pass = false;
- }
-
- // valid - short to long
- if (messageReceived.getLongProperty("TESTSHORT") == nShort) {
- TestUtil.logTrace("Pass: conversion from short to long - ok");
- } else {
- TestUtil.logErr("Error: conversion from short to long failed");
- pass = false;
- }
-
- // invalid - short to boolean
- try {
- messageReceived.getBooleanProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: short to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- short to boolean");
- pass = false;
- }
-
- // invalid - short to byte
- try {
- messageReceived.getByteProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: short to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- short to byte");
- pass = false;
- }
-
- // invalid - short to float
- try {
- messageReceived.getFloatProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: short to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- short to float");
- pass = false;
- }
-
- // invalid - short to double
- try {
- messageReceived.getDoubleProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: short to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- short to double");
- pass = false;
- }
-
- // -------------------------------------------------
- // property set as int can be read only as int, long or string
- // valid - int to string
- if (Integer.valueOf(messageReceived.getStringProperty("TESTINT"))
- .intValue() == nInt) {
- TestUtil.logTrace("Pass: conversion from int to string - ok");
- } else {
- TestUtil.logErr("Error: conversion from int to string failed");
- pass = false;
- }
-
- // valid - int to long
- if (messageReceived.getLongProperty("TESTINT") == nInt) {
- TestUtil.logTrace("Pass: conversion from int to long - ok");
- } else {
- TestUtil.logErr("Error: conversion from int to long failed");
- pass = false;
- }
-
- // invalid - int to boolean
- try {
- messageReceived.getBooleanProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- int to boolean");
- pass = false;
- }
-
- // invalid - int to byte
- try {
- messageReceived.getByteProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- int to byte");
- pass = false;
- }
-
- // invalid - int to short
- try {
- messageReceived.getShortProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace(
- "Pass: MessageFormatException as expected -- int to short ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil
- .logErr("Error: did not catch expected MessageFormatException ");
- pass = false;
- }
-
- // invalid - int to float
- try {
- messageReceived.getFloatProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- int to float");
- pass = false;
- }
-
- // invalid - int to double
- try {
- messageReceived.getDoubleProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- int to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as long can be read only as long,or a string
- // valid - long to string
- if (Long.valueOf(messageReceived.getStringProperty("TESTLONG"))
- .longValue() == nLong) {
- TestUtil.logTrace("Pass: conversion from long to string - ok");
- } else {
- TestUtil.logErr("Error: conversion from long to string failed");
- pass = false;
- }
-
- // invalid - long to boolean
- try {
- messageReceived.getBooleanProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- long to boolean");
- pass = false;
- }
-
- // invalid - long to byte
- try {
- messageReceived.getByteProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- long to byte");
- pass = false;
- }
-
- // invalid - long to short
- try {
- messageReceived.getShortProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- long to short ");
- pass = false;
- }
-
- // invalid - long to int
- try {
- messageReceived.getIntProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to int ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- long to int");
- pass = false;
- }
-
- // invalid - long to float
- try {
- messageReceived.getFloatProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- long to float");
- pass = false;
- }
-
- // invalid - long to double
- try {
- messageReceived.getDoubleProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected Exception -- long to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as float can be read only as float,double or a string
- // valid - float to string
- if (Float.valueOf(messageReceived.getStringProperty("TESTFLOAT"))
- .floatValue() == nFloat) {
- TestUtil.logTrace("Pass: conversion from float to string - ok");
- } else {
- TestUtil.logErr("Error: conversion from float to string failed");
- pass = false;
- }
-
- // valid - float to double
- if (messageReceived.getDoubleProperty("TESTFLOAT") == nFloat) {
- TestUtil.logTrace("Pass: conversion from long to double - ok");
- } else {
- TestUtil.logErr("Error: conversion from long to double failed");
- pass = false;
- }
-
- // invalid - float to boolean
- try {
- messageReceived.getBooleanProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- float to boolean ");
- pass = false;
- }
-
- // invalid - float to byte
- try {
- messageReceived.getByteProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- float to byte");
- pass = false;
- }
-
- // invalid - float to short
- try {
- messageReceived.getShortProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException - float to short ");
- pass = false;
- }
-
- // invalid - float to int
- try {
- messageReceived.getIntProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to int ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException --- float to int");
- pass = false;
- }
-
- // invalid - float to long
- try {
- messageReceived.getLongProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to long ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- float to long");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as double can be read only as double or string
- // valid - double to string
- if (Double.valueOf(messageReceived.getStringProperty("TESTDOUBLE"))
- .doubleValue() == nDouble) {
- TestUtil.logTrace("Pass: conversion from double to string - ok");
- } else {
- TestUtil.logErr("Error: conversion from double to string failed");
- pass = false;
- }
-
- // invalid - double to boolean
- try {
- messageReceived.getBooleanProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- double to boolean ");
- pass = false;
- }
-
- // invalid - double to byte
- try {
- messageReceived.getByteProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- double to byte ");
- pass = false;
- }
-
- // invalid - double to short
- try {
- messageReceived.getShortProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- double to short");
- pass = false;
- }
-
- // invalid - double to int
- try {
- messageReceived.getIntProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to int ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException --- double to int ");
- TestUtil.logErr("Error: unexpected error ", ee);
- pass = false;
- }
-
- // invalid - double to long
- try {
- messageReceived.getLongProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to long ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- double to long");
- pass = false;
- }
-
- // invalid - double to float
- try {
- messageReceived.getFloatProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected error ", ee);
- TestUtil.logErr(
- "Error: did not catch expected MessageFormatException -- double to float");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as string can be read as boolean, byte, short,
- // int, long, float, double, and String.
- // valid - string to boolean
- if ((messageReceived.getBooleanProperty("TESTSTRINGTRUE")) == true) {
- TestUtil.logTrace(
- "Pass: conversion from string to boolean - expect true - ok");
- } else {
- TestUtil.logErr(
- "Error: conversion from string to boolean - expect true - failed");
- pass = false;
- }
- if ((messageReceived.getBooleanProperty("TESTSTRINGFALSE")) == false) {
- TestUtil.logTrace(
- "Pass: conversion from string to boolean expect false - ok");
- } else {
- TestUtil.logErr(
- "Error: conversion from string to boolean expect false - failed");
- pass = false;
- }
-
- // valid - string to byte
- if (messageReceived.getByteProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to byte - ok");
- } else {
- TestUtil.logErr("Error: conversion from string to byte failed");
- pass = false;
- }
-
- // valid - string to short
- if (messageReceived.getShortProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to short - ok");
- } else {
- TestUtil.logErr("Error: conversion from string to short failed");
- pass = false;
- }
-
- // valid - string to int
- if (messageReceived.getIntProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to int - ok");
- } else {
- TestUtil.logErr("Error: conversion from string to int failed");
- pass = false;
- }
-
- // valid - string to long
- if (messageReceived.getLongProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to long - ok");
- } else {
- TestUtil.logErr("Error: conversion from string to long failed");
- pass = false;
- }
-
- // valid - string to float
- if (messageReceived.getFloatProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to float - ok");
- } else {
- TestUtil.logErr("Error: conversion from string to float failed");
- pass = false;
- }
-
- // valid - string to double
- if (messageReceived.getDoubleProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to double - ok");
- } else {
- TestUtil.logErr("Error: conversion from string to double failed");
- pass = false;
- }
- if (!pass) {
- throw new Exception(
- "Error: failures occurred during property conversion tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgPropertiesConversionTopicTest");
- }
- }
-
- /*
- * @testName: msgJMSXPropertiesTopicTest
- *
- * @assertion_ids: JMS:SPEC:34; JMS:SPEC:34.4; JMS:SPEC:34.5;
- *
- * @test_Strategy: Set and read properties JMSXGroupID and JMSXGroupSeq.
- * Verify the value of the properties JMSXGroupID and JMSXGroupSeq are the
- * same as set by client.
- */
-
- public void msgJMSXPropertiesTopicTest() throws Exception {
- boolean pass = true;
- String testMessageBody = "Testing msgJMSXProperties";
- int seq = 123450;
- String id = "TestmsgJMSXProperties";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- tool.getDefaultConnection().start();
-
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText(testMessageBody);
-
- messageSent.setStringProperty("JMSXGroupID", id);
- messageSent.setIntProperty("JMSXGroupSeq", seq);
-
- tool.getDefaultProducer().send(messageSent);
-
- TestUtil.logTrace("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultConsumer()
- .receive(timeout);
- // -------------------------------------------------------------------
- // ConnectionMetaData.getJMSXPropertyNames() method returns the
- // names of the JMSX properties supported by a connection.
- // -------------------------------------------------------------------
- try {
- ConnectionMetaData data = tool.getDefaultConnection().getMetaData();
- Enumeration cmd = data.getJMSXPropertyNames();
- String propName;
-
- if (cmd == null) {
- logErr("Error: no JMSX property names were returned!");
- pass = false;
- } else {
- int iCount = 0;
-
- do {
- propName = (String) cmd.nextElement();
- TestUtil.logTrace(propName);
- if (propName.equals("JMSXGroupID")
- || propName.equals("JMSXGroupSeq")) {
- iCount++;
- }
- } while (cmd.hasMoreElements());
-
- if (iCount > 1) {
- TestUtil.logTrace("Pass:");
- } else {
- TestUtil.logMsg("Error: Expected property names not returned");
- pass = false;
- }
- }
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected exception: ", ee);
- TestUtil.logErr("attempting to read JMSX property names.");
- pass = false;
- }
-
- if (messageReceived.getIntProperty("JMSXGroupSeq") != seq) {
- pass = false;
- logErr("Error: incorrect JMSXGroupSeq value returned");
- }
-
- if (!messageReceived.getStringProperty("JMSXGroupID").equals(id)) {
- pass = false;
- logErr("Error: incorrect JMSXGroupID value returned");
- }
-
- if (!pass) {
- throw new Exception("Error: failures occurred during property tests");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgJMSXPropertiesTopicTest");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/topicMsgProperties/TopicPropertyTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/topicMsgProperties/TopicPropertyTestsIT.java
new file mode 100644
index 0000000000..6cccce4614
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/topicMsgProperties/TopicPropertyTestsIT.java
@@ -0,0 +1,1600 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.topicMsgProperties;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.ConnectionMetaData;
+import jakarta.jms.MessageFormatException;
+import jakarta.jms.MessageNotWriteableException;
+import jakarta.jms.TextMessage;
+
+
+public class TopicPropertyTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.topicMsgProperties.TopicPropertyTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(TopicPropertyTestsIT.class.getName());
+
+ // JMS objects
+ private transient JmsTool tool = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't catch expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default TopicConnection,
+ * as well as a default Topic. Tests that require multiple Destinations create
+ * the extras within the test
+ *
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null");
+ }
+ if (mode == null) {
+ throw new Exception("'mode' is null");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (tool != null) {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing TopicConnection");
+ tool.closeAllConnections(connections);
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning: ", e);
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: msgPropertiesTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:20.1; JMS:SPEC:20.2; JMS:SPEC:20.3; JMS:SPEC:20.4;
+ * JMS:SPEC:20.5; JMS:SPEC:20.6; JMS:SPEC:20.7; JMS:SPEC:20.8; JMS:SPEC:21;
+ * JMS:SPEC:23; JMS:SPEC:24; JMS:SPEC:25; JMS:SPEC:26; JMS:SPEC:10; JMS:SPEC:27;
+ * JMS:SPEC:28; JMS:SPEC:29; JMS:SPEC:31; JMS:SPEC:32; JMS:SPEC:19; JMS:SPEC:70;
+ * JMS:SPEC:71; JMS:JAVADOC:411; JMS:JAVADOC:413; JMS:JAVADOC:415;
+ * JMS:JAVADOC:417; JMS:JAVADOC:419; JMS:JAVADOC:421; JMS:JAVADOC:423;
+ * JMS:JAVADOC:425; JMS:JAVADOC:427; JMS:JAVADOC:409; JMS:JAVADOC:391;
+ * JMS:JAVADOC:393; JMS:JAVADOC:395; JMS:JAVADOC:397; JMS:JAVADOC:399;
+ * JMS:JAVADOC:401; JMS:JAVADOC:403; JMS:JAVADOC:405; JMS:JAVADOC:407;
+ * JMS:JAVADOC:500; JMS:JAVADOC:516; JMS:JAVADOC:387; JMS:JAVADOC:792;
+ * JMS:JAVADOC:776; JMS:JAVADOC:778; JMS:JAVADOC:780; JMS:JAVADOC:782;
+ * JMS:JAVADOC:784; JMS:JAVADOC:786; JMS:JAVADOC:788; JMS:JAVADOC:790;
+ * JMS:JAVADOC:793; JMS:SPEC:34.4; JMS:SPEC:34.5;
+ *
+ * @test_Strategy: set and read properties for boolean, byte, short, int, long,
+ * float, double, and String. Verify expected results set and read properties
+ * for Boolean, Byte, Short, Int, Long, Float, Double, and String. Verify
+ * expected results.
+ *
+ * When a client receives a message it is in read-only mode. Send a message and
+ * have the client attempt modify the properties. Verify that a
+ * MessageNotWriteableException is thrown. Call setObject property with an
+ * invalid object and verify that a MessageFormatException is thrown
+ *
+ * call property get methods( other than getStringProperty and
+ * getObjectProperty) for non-existent properties and verify that a null pointer
+ * exception is returned. call getStringProperty and getObjectProperty for
+ * non-existent properties and verify that a null is returned.
+ *
+ * set object properties and verify the correct value is returned with the
+ * getObjectProperty method.
+ *
+ * call the clearProperties method on the received message and verify that the
+ * messages properties were deleted. Test that getObjectProperty returns a null
+ * and the getShortProperty throws a null pointer exception.
+ *
+ * After clearing the message properties, call getText and verify that the
+ * message body has not been cleared.
+ *
+ * Call ConnectionMetaData.getJMSXPropertyNames() and verify that the names of
+ * the required JMSX properties for JMSXGroupID and JMSXGroupSeq are returned.
+ */
+ @Test
+ public void msgPropertiesTopicTest() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ Enumeration propertyNames = null;
+ Enumeration jmsxDefined = null;
+ int numPropertyNames = 18;
+ String testMessageBody = "Testing...";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText(testMessageBody);
+
+ // -------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // -------------------------------------------------------------
+ messageSent.setBooleanProperty("TESTBOOLEAN", bool);
+ messageSent.setByteProperty("TESTBYTE", bValue);
+ messageSent.setShortProperty("TESTSHORT", nShort);
+ messageSent.setIntProperty("TESTINT", nInt);
+ messageSent.setFloatProperty("TESTFLOAT", nFloat);
+ messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
+ messageSent.setStringProperty("TESTSTRING", "test");
+ messageSent.setLongProperty("TESTLONG", nLong);
+
+ // --------------------------------------------------------------
+ // set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
+ // String.
+ // --------------------------------------------------------------
+ messageSent.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ messageSent.setObjectProperty("OBJTESTBYTE", Byte.valueOf(bValue));
+ messageSent.setObjectProperty("OBJTESTSHORT", Short.valueOf(nShort));
+ messageSent.setObjectProperty("OBJTESTINT", Integer.valueOf(nInt));
+ messageSent.setObjectProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
+ messageSent.setObjectProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
+ messageSent.setObjectProperty("OBJTESTSTRING", "test");
+ messageSent.setObjectProperty("OBJTESTLONG", Long.valueOf(nLong));
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesTopicTest");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // ------------------------------------------------------------------------------
+ // An attempt to use any other class than Boolean, Byte, Short, Int, Long,
+ // Float,
+ // Double, and Stringmust throw a JMS MessageFormatException.
+ // ------------------------------------------------------------------------------
+ try {
+ messageSent.setObjectProperty("OBJTESTLONG", new Object());
+ logger.log(Logger.Level.INFO, "Error: expected MessageFormatException from invalid ");
+ logger.log(Logger.Level.INFO, "call to setObjectProperty did not occur!");
+ pass = false;
+ } catch (MessageFormatException fe) {
+ logger.log(Logger.Level.TRACE, "Pass: ");
+ logger.log(Logger.Level.TRACE,
+ " MessageFormatException as expected from invalid setObjectProperty call");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "from call to setObjectProperty!");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------------
+ // Received message should be read-only - verify proper exception is
+ // thrown
+ // when trying to modify msg properties.
+ // ------------------------------------------------------------------------
+ try {
+ messageReceived.setBooleanProperty("TESTBOOLEAN", bool);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setBooleanProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setBooleanProperty ");
+ }
+ try {
+ messageReceived.setByteProperty("TESTBYTE", bValue);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setByteProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setByteProperty ");
+ }
+ try {
+ messageReceived.setShortProperty("TESTSHORT", nShort);
+ pass = false;
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setShortProperty");
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setShortProperty ");
+ }
+ try {
+ messageReceived.setIntProperty("TESTINT", nInt);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setIntProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setIntProperty ");
+ }
+ try {
+ messageReceived.setFloatProperty("TESTFLOAT", nFloat);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setFloatProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setFloatProperty ");
+ }
+ try {
+ messageReceived.setDoubleProperty("TESTDOUBLE", nDouble);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setDoubleProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setDoubleProperty ");
+ }
+ try {
+ messageReceived.setStringProperty("TESTSTRING", testString);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setStringProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setStringProperty ");
+ }
+ try {
+ messageReceived.setLongProperty("TESTLONG", nLong);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setLongProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setLongProperty ");
+ }
+ try {
+ messageReceived.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setObjectProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setObjectProperty ");
+ }
+
+ // iterate thru the property names
+ int i = 0;
+ propertyNames = messageReceived.getPropertyNames();
+ do {
+ String tmp = (String) propertyNames.nextElement();
+ logger.log(Logger.Level.TRACE, "+++++++ Property Name is: " + tmp);
+ if (tmp.indexOf("JMS") != 0)
+ i++;
+ else if (tmp.equals("JMSXDeliveryCount"))
+ i++;
+ } while (propertyNames.hasMoreElements());
+
+ if (i == numPropertyNames) {
+ logger.log(Logger.Level.TRACE, "Pass: # of properties is " + numPropertyNames + " as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: expected " + numPropertyNames + " property names, but got " + i);
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------
+ // read and verify the property values for primitive types in the received
+ // message
+ // --------------------------------------------------------------------------------
+ if (messageReceived.getBooleanProperty("TESTBOOLEAN") == bool) {
+ logger.log(Logger.Level.TRACE, "Pass: getBooleanProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getBooleanProperty");
+ pass = false;
+ }
+ if (messageReceived.getByteProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: getByteProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getByteProperty");
+ pass = false;
+ }
+ if (messageReceived.getLongProperty("TESTLONG") == nLong) {
+ logger.log(Logger.Level.TRACE, "Pass: getLongProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getLongProperty");
+ pass = false;
+ }
+ if (messageReceived.getStringProperty("TESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getStringProperty");
+ pass = false;
+ }
+ if (messageReceived.getDoubleProperty("TESTDOUBLE") == nDouble) {
+ logger.log(Logger.Level.TRACE, "Pass: getDoubleProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getDoubleProperty");
+ pass = false;
+ }
+ if (messageReceived.getFloatProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: getFloatProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getFloatProperty");
+ pass = false;
+ }
+ if (messageReceived.getIntProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: getIntProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getIntProperty");
+ pass = false;
+ }
+ if (messageReceived.getShortProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: getShortProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getShortProperty");
+ pass = false;
+ }
+
+ // -----------------------------------------------------------
+ // The other property get methods ( other than getStringProperty and
+ // getObjectProperty) must behave as if the property exists with a
+ // null value
+ // -----------------------------------------------------------
+ // Getting a property value for a name which has not been set
+ // returns a null value.
+ // Only the getStringProperty and getObjectProperty methods can return a
+ // null
+ // value. The other property get methods must throw a
+ // java.lang.NullPointerException if they are used to get a non-existent
+ // property.
+ try {
+ boolean b = messageReceived.getBooleanProperty("TESTDUMMY");
+ if (b != false) {
+ logger.log(Logger.Level.INFO, "Error: should havereceived false for getBooleanProperty");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected Exception: ", e);
+ pass = false;
+ }
+
+ try {
+ byte value = messageReceived.getByteProperty("TESTDUMMY");
+
+ logger.log(Logger.Level.INFO, "Error: NumberFormatException should have occurred for getByteProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ short value = messageReceived.getShortProperty("TESTDUMMY");
+
+ logger.log(Logger.Level.INFO, "Error: NumberFormatException should have occurred for getShortProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ int value = messageReceived.getIntProperty("TESTDUMMY");
+
+ logger.log(Logger.Level.INFO, "Error: NumberFormatException should have occurred for getIntProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.TRACE, "Pass:NumberFormatException as expected ");
+ }
+ try {
+ long value = messageReceived.getLongProperty("TESTDUMMY");
+
+ logger.log(Logger.Level.INFO, "Error: NumberFormatException should have occurred for getLongProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ float value = messageReceived.getFloatProperty("TESTDUMMY");
+
+ logger.log(Logger.Level.INFO, "Error: NullPointerException should have occurred for getFloatProperty");
+ pass = false;
+ } catch (java.lang.NullPointerException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException as expected ");
+ }
+ try {
+ double value = messageReceived.getDoubleProperty("TESTDUMMY");
+
+ logger.log(Logger.Level.INFO, "Error: NullPointerException should have occurred for getDoubleProperty");
+ pass = false;
+ } catch (java.lang.NullPointerException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException as expected ");
+ }
+
+ // --------------------------------------------------------------------------------
+ // Getting a property value for a name which has not been set returns a
+ // null value.
+ // (For getStringProperty and getObjectProperty)
+ // --------------------------------------------------------------------------------
+ String value = messageReceived.getStringProperty("TESTDUMMY");
+
+ if (value == null) {
+ logger.log(Logger.Level.TRACE, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: expected a null return from getStringProperty for invalid property");
+ pass = false;
+ }
+ Boolean aBool = (Boolean) messageReceived.getObjectProperty("TESTDUMMY");
+
+ if (aBool == null) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Boolean");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: expected a null return from getObjectProperty for invalid property");
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------
+ // read and verify the property values for getObject in the received
+ // message
+ // --------------------------------------------------------------------------------
+ Boolean boolValue = (Boolean) messageReceived.getObjectProperty("OBJTESTBOOLEAN");
+
+ if (boolValue.booleanValue() == bool) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Boolean");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned for Boolean");
+ pass = false;
+ }
+ Byte byteValue = (Byte) messageReceived.getObjectProperty("OBJTESTBYTE");
+
+ if (byteValue.byteValue() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct Byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from Byte");
+ pass = false;
+ }
+ Long lValue = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
+
+ if (lValue.longValue() == nLong) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Long");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value returned for Long");
+ pass = false;
+ }
+
+ // String value =
+ // (String)messageReceived.getObjectProperty("OBJTESTSTRING");
+ if (messageReceived.getObjectProperty("OBJTESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for String");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for String");
+ pass = false;
+ }
+ Double dValue = (Double) messageReceived.getObjectProperty("OBJTESTDOUBLE");
+
+ if (dValue.doubleValue() == nDouble) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Double");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Double");
+ pass = false;
+ }
+ Float fValue = (Float) messageReceived.getObjectProperty("OBJTESTFLOAT");
+
+ if (fValue.floatValue() == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Float");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Float");
+ pass = false;
+ }
+ Integer iValue = (Integer) messageReceived.getObjectProperty("OBJTESTINT");
+
+ if (iValue.intValue() == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Integer");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Integer");
+ pass = false;
+ }
+ Short sValue = (Short) messageReceived.getObjectProperty("OBJTESTSHORT");
+
+ if (sValue.shortValue() == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Short");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Short");
+ pass = false;
+ }
+
+ // clear message properties
+ messageReceived.clearProperties();
+
+ // -------------------------------------------------------------------
+ // A message?s properties are deleted by the clearProperties method.
+ // This leaves the message with an empty set of properties.
+ // -------------------------------------------------------------------
+ Long aLong = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
+
+ if (aLong == null) {
+ logger.log(Logger.Level.TRACE, "Pass: property was cleared");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: getObjectProperty should have returned null for cleared property");
+ pass = false;
+ }
+ try {
+ short aShort = messageReceived.getShortProperty("TESTSHORT");
+
+ logger.log(Logger.Level.INFO, "Error: NumberFormatException should have occurred for getShortProperty");
+ logger.log(Logger.Level.INFO, "Properties have been cleared!");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+
+ // -------------------------------------------------------------------
+ // A message?s properties are deleted by the clearProperties method.
+ // This leaves the message with an empty set of properties.
+ // -------------------------------------------------------------------
+ aLong = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
+
+ if (aLong == null) {
+ logger.log(Logger.Level.TRACE, "Pass: property was cleared");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: getObjectProperty should have returned null for cleared property");
+ pass = false;
+ }
+ try {
+ short aShort = messageReceived.getShortProperty("TESTSHORT");
+
+ logger.log(Logger.Level.INFO, "Error: NumberFormatException should have occurred for getShortProperty");
+ logger.log(Logger.Level.INFO, "Properties have been cleared!");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+
+ // -------------------------------------------------------------------
+ // clearing the message property should not effect the message body.
+ // -------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Message body is : " + messageReceived.getText());
+ if (messageReceived.getText().equals(testMessageBody)) {
+ logger.log(Logger.Level.TRACE, "Pass: able to read message body after clearProperties");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unable to read message body after clearProperties");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // ConnectionMetaData.getJMSXPropertyNames() method returns the
+ // names of the JMSX properties supported by a connection.
+ // -------------------------------------------------------------------
+ try {
+ ConnectionMetaData data = tool.getDefaultTopicConnection().getMetaData();
+ Enumeration cmd = data.getJMSXPropertyNames();
+ String propName;
+
+ if (cmd == null) {
+ logger.log(Logger.Level.INFO, "Error: no JMSX property names were returned!");
+ logger.log(Logger.Level.INFO,
+ "expected JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount at a miniumum");
+ pass = false;
+ } else {
+ int iCount = 0;
+
+ do {
+ propName = (String) cmd.nextElement();
+ logger.log(Logger.Level.TRACE, propName);
+ if (propName.equals("JMSXGroupID") || propName.equals("JMSXGroupSeq")
+ || propName.equals("JMSXDeliveryCount")) {
+ iCount++;
+ }
+ } while (cmd.hasMoreElements());
+ if (iCount > 1) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: Expected property names not returned");
+ pass = false;
+ }
+ }
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", ee);
+ logger.log(Logger.Level.ERROR, "attempting to read JMSX property names.");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during property tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgPropertiesTopicTest");
+ }
+ }
+
+ /*
+ * @testName: msgPropertiesConversionTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:22.1; JMS:SPEC:22.2; JMS:SPEC:22.3; JMS:SPEC:22.4;
+ * JMS:SPEC:22.5; JMS:SPEC:22.6; JMS:SPEC:22.7; JMS:SPEC:22.8; JMS:SPEC:22.9;
+ * JMS:SPEC:22.10; JMS:SPEC:22.11; JMS:SPEC:22.12; JMS:SPEC:22.13;
+ * JMS:SPEC:22.14; JMS:SPEC:22.15; JMS:SPEC:22.16; JMS:JAVADOC:391;
+ * JMS:JAVADOC:393; JMS:JAVADOC:395; JMS:JAVADOC:397; JMS:JAVADOC:399;
+ * JMS:JAVADOC:401; JMS:JAVADOC:403; JMS:JAVADOC:405; JMS:JAVADOC:407;
+ * JMS:JAVADOC:767; JMS:JAVADOC:768; JMS:JAVADOC:769; JMS:JAVADOC:770;
+ * JMS:JAVADOC:771; JMS:JAVADOC:772; JMS:JAVADOC:773; JMS:JAVADOC:774;
+ *
+ *
+ *
+ * @test_Strategy: create a message, set properties for all of the primitive
+ * types verify the conversion by getting the properties.
+ */
+ @Test
+ public void msgPropertiesConversionTopicTest() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ String testMessageBody = "Testing...";
+ int ntest = 0;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, user, password, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText(testMessageBody);
+
+ // ------------------------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ messageSent.setBooleanProperty("TESTBOOLEAN", bool);
+ messageSent.setByteProperty("TESTBYTE", bValue);
+ messageSent.setShortProperty("TESTSHORT", nShort);
+ messageSent.setIntProperty("TESTINT", nInt);
+ messageSent.setFloatProperty("TESTFLOAT", nFloat);
+ messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
+ messageSent.setStringProperty("TESTSTRING", "test");
+ messageSent.setLongProperty("TESTLONG", nLong);
+ messageSent.setStringProperty("TESTSTRINGTRUE", "true");
+ messageSent.setStringProperty("TESTSTRINGFALSE", "false");
+ messageSent.setStringProperty("TESTSTRING1", "1");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesConversionTopicTest");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+
+ // -------------------------------------------------------------------
+ // test conversions for property values
+ // -------------------------------------------------------------------
+ // property set as boolean can be read only as string or boolean
+ // -------------------------------------------------------------------
+ // valid - boolean to string
+ String myBool = messageReceived.getStringProperty("TESTBOOLEAN");
+
+ if (Boolean.valueOf(myBool).booleanValue() == bool) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from boolean to string - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from boolean to string failed");
+ pass = false;
+ }
+
+ // invalid - boolean to byte
+ try {
+ messageReceived.getByteProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- boolean to byte");
+ pass = false;
+ }
+
+ // invalid - boolean to short
+ try {
+ messageReceived.getShortProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- boolean to short");
+ pass = false;
+ }
+
+ // invalid - boolean to int
+ try {
+ messageReceived.getIntProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException --boolean to int ");
+ pass = false;
+ }
+
+ // invalid - boolean to long
+ try {
+ messageReceived.getLongProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to long ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- boolean to long");
+ pass = false;
+ }
+
+ // invalid - boolean to float
+ try {
+ messageReceived.getFloatProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- boolean to float");
+ pass = false;
+ }
+
+ // invalid - boolean to double
+ try {
+ messageReceived.getDoubleProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- boolean to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as byte can be read as a byte,short,int,long or string
+ // valid - byte to string
+ String myByte = messageReceived.getStringProperty("TESTBYTE");
+
+ if (Byte.valueOf(myByte).byteValue() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to string - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from byte to string failed");
+ pass = false;
+ }
+
+ // valid - byte to short
+ if (messageReceived.getShortProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to short - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from byte to short failed");
+ pass = false;
+ }
+
+ // valid - byte to int
+ if (messageReceived.getIntProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to int - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from byte to int failed");
+ pass = false;
+ }
+
+ // valid - byte to long
+ if (messageReceived.getLongProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to long - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from byte to long failed");
+ pass = false;
+ }
+
+ // invalid - byte to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: byte to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- byte to boolean");
+ pass = false;
+ }
+
+ // invalid - byte to float
+ try {
+ messageReceived.getFloatProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: byte to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "Error: did not catch expected MessageFormatException --byte to float ");
+ pass = false;
+ }
+
+ // invalid - byte to double
+ try {
+ messageReceived.getDoubleProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: byte to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- byte to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------
+ // property set as short can be read as short,int,long or string
+ // valid - short to string
+ String myshort = messageReceived.getStringProperty("TESTSHORT");
+
+ if (Short.valueOf(myshort).shortValue() == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from short to string - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from short to string failed");
+ pass = false;
+ }
+
+ // valid - short to int
+ if (messageReceived.getIntProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from short to int - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from short to int failed");
+ pass = false;
+ }
+
+ // valid - short to long
+ if (messageReceived.getLongProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from short to long - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from short to long failed");
+ pass = false;
+ }
+
+ // invalid - short to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- short to boolean");
+ pass = false;
+ }
+
+ // invalid - short to byte
+ try {
+ messageReceived.getByteProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "Error: did not catch expected MessageFormatException -- short to byte");
+ pass = false;
+ }
+
+ // invalid - short to float
+ try {
+ messageReceived.getFloatProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- short to float");
+ pass = false;
+ }
+
+ // invalid - short to double
+ try {
+ messageReceived.getDoubleProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- short to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------
+ // property set as int can be read only as int, long or string
+ // valid - int to string
+ if (Integer.valueOf(messageReceived.getStringProperty("TESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from int to string - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from int to string failed");
+ pass = false;
+ }
+
+ // valid - int to long
+ if (messageReceived.getLongProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from int to long - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from int to long failed");
+ pass = false;
+ }
+
+ // invalid - int to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- int to boolean");
+ pass = false;
+ }
+
+ // invalid - int to byte
+ try {
+ messageReceived.getByteProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "Error: did not catch expected MessageFormatException -- int to byte");
+ pass = false;
+ }
+
+ // invalid - int to short
+ try {
+ messageReceived.getShortProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected -- int to short ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "Error: did not catch expected MessageFormatException ");
+ pass = false;
+ }
+
+ // invalid - int to float
+ try {
+ messageReceived.getFloatProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "Error: did not catch expected MessageFormatException -- int to float");
+ pass = false;
+ }
+
+ // invalid - int to double
+ try {
+ messageReceived.getDoubleProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "Error: did not catch expected MessageFormatException -- int to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as long can be read only as long,or a string
+ // valid - long to string
+ if (Long.valueOf(messageReceived.getStringProperty("TESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from long to string - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from long to string failed");
+ pass = false;
+ }
+
+ // invalid - long to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- long to boolean");
+ pass = false;
+ }
+
+ // invalid - long to byte
+ try {
+ messageReceived.getByteProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "Error: did not catch expected MessageFormatException -- long to byte");
+ pass = false;
+ }
+
+ // invalid - long to short
+ try {
+ messageReceived.getShortProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- long to short ");
+ pass = false;
+ }
+
+ // invalid - long to int
+ try {
+ messageReceived.getIntProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "Error: did not catch expected MessageFormatException -- long to int");
+ pass = false;
+ }
+
+ // invalid - long to float
+ try {
+ messageReceived.getFloatProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "Error: did not catch expected MessageFormatException -- long to float");
+ pass = false;
+ }
+
+ // invalid - long to double
+ try {
+ messageReceived.getDoubleProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "Error: did not catch expected Exception -- long to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as float can be read only as float,double or a string
+ // valid - float to string
+ if (Float.valueOf(messageReceived.getStringProperty("TESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from float to string - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from float to string failed");
+ pass = false;
+ }
+
+ // valid - float to double
+ if (messageReceived.getDoubleProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from long to double - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from long to double failed");
+ pass = false;
+ }
+
+ // invalid - float to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- float to boolean ");
+ pass = false;
+ }
+
+ // invalid - float to byte
+ try {
+ messageReceived.getByteProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "Error: did not catch expected MessageFormatException -- float to byte");
+ pass = false;
+ }
+
+ // invalid - float to short
+ try {
+ messageReceived.getShortProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException - float to short ");
+ pass = false;
+ }
+
+ // invalid - float to int
+ try {
+ messageReceived.getIntProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR, "Error: did not catch expected MessageFormatException --- float to int");
+ pass = false;
+ }
+
+ // invalid - float to long
+ try {
+ messageReceived.getLongProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to long ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- float to long");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as double can be read only as double or string
+ // valid - double to string
+ if (Double.valueOf(messageReceived.getStringProperty("TESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from double to string - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from double to string failed");
+ pass = false;
+ }
+
+ // invalid - double to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- double to boolean ");
+ pass = false;
+ }
+
+ // invalid - double to byte
+ try {
+ messageReceived.getByteProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- double to byte ");
+ pass = false;
+ }
+
+ // invalid - double to short
+ try {
+ messageReceived.getShortProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- double to short");
+ pass = false;
+ }
+
+ // invalid - double to int
+ try {
+ messageReceived.getIntProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException --- double to int ");
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ pass = false;
+ }
+
+ // invalid - double to long
+ try {
+ messageReceived.getLongProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to long ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- double to long");
+ pass = false;
+ }
+
+ // invalid - double to float
+ try {
+ messageReceived.getFloatProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected error ", ee);
+ logger.log(Logger.Level.ERROR,
+ "Error: did not catch expected MessageFormatException -- double to float");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as string can be read as boolean, byte, short,
+ // int, long, float, double, and String.
+ // valid - string to boolean
+ if ((messageReceived.getBooleanProperty("TESTSTRINGTRUE")) == true) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to boolean - expect true - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from string to boolean - expect true - failed");
+ pass = false;
+ }
+ if ((messageReceived.getBooleanProperty("TESTSTRINGFALSE")) == false) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to boolean expect false - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from string to boolean expect false - failed");
+ pass = false;
+ }
+
+ // valid - string to byte
+ if (messageReceived.getByteProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to byte - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from string to byte failed");
+ pass = false;
+ }
+
+ // valid - string to short
+ if (messageReceived.getShortProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to short - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from string to short failed");
+ pass = false;
+ }
+
+ // valid - string to int
+ if (messageReceived.getIntProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to int - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from string to int failed");
+ pass = false;
+ }
+
+ // valid - string to long
+ if (messageReceived.getLongProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to long - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from string to long failed");
+ pass = false;
+ }
+
+ // valid - string to float
+ if (messageReceived.getFloatProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to float - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from string to float failed");
+ pass = false;
+ }
+
+ // valid - string to double
+ if (messageReceived.getDoubleProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to double - ok");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: conversion from string to double failed");
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("Error: failures occurred during property conversion tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgPropertiesConversionTopicTest");
+ }
+ }
+
+ /*
+ * @testName: msgJMSXPropertiesTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:34; JMS:SPEC:34.4; JMS:SPEC:34.5;
+ *
+ * @test_Strategy: Set and read properties JMSXGroupID and JMSXGroupSeq. Verify
+ * the value of the properties JMSXGroupID and JMSXGroupSeq are the same as set
+ * by client.
+ */
+ @Test
+ public void msgJMSXPropertiesTopicTest() throws Exception {
+ boolean pass = true;
+ String testMessageBody = "Testing msgJMSXProperties";
+ int seq = 123450;
+ String id = "TestmsgJMSXProperties";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ tool.getDefaultConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText(testMessageBody);
+
+ messageSent.setStringProperty("JMSXGroupID", id);
+ messageSent.setIntProperty("JMSXGroupSeq", seq);
+
+ tool.getDefaultProducer().send(messageSent);
+
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultConsumer().receive(timeout);
+ // -------------------------------------------------------------------
+ // ConnectionMetaData.getJMSXPropertyNames() method returns the
+ // names of the JMSX properties supported by a connection.
+ // -------------------------------------------------------------------
+ try {
+ ConnectionMetaData data = tool.getDefaultConnection().getMetaData();
+ Enumeration cmd = data.getJMSXPropertyNames();
+ String propName;
+
+ if (cmd == null) {
+ logger.log(Logger.Level.ERROR, "Error: no JMSX property names were returned!");
+ pass = false;
+ } else {
+ int iCount = 0;
+
+ do {
+ propName = (String) cmd.nextElement();
+ logger.log(Logger.Level.TRACE, propName);
+ if (propName.equals("JMSXGroupID") || propName.equals("JMSXGroupSeq")) {
+ iCount++;
+ }
+ } while (cmd.hasMoreElements());
+
+ if (iCount > 1) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: Expected property names not returned");
+ pass = false;
+ }
+ }
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected exception: ", ee);
+ logger.log(Logger.Level.ERROR, "attempting to read JMSX property names.");
+ pass = false;
+ }
+
+ if (messageReceived.getIntProperty("JMSXGroupSeq") != seq) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSXGroupSeq value returned");
+ }
+
+ if (!messageReceived.getStringProperty("JMSXGroupID").equals(id)) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSXGroupID value returned");
+ }
+
+ if (!pass) {
+ throw new Exception("Error: failures occurred during property tests");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgJMSXPropertiesTopicTest");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/topictests/TopicTests.java b/jms/src/main/java/com/sun/ts/tests/jms/core/topictests/TopicTests.java
deleted file mode 100644
index e0ec132c01..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core/topictests/TopicTests.java
+++ /dev/null
@@ -1,1667 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core.topictests;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.Connection;
-import jakarta.jms.JMSException;
-import jakarta.jms.Message;
-import jakarta.jms.MessageConsumer;
-import jakarta.jms.MessageProducer;
-import jakarta.jms.Session;
-import jakarta.jms.TemporaryTopic;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicConnection;
-import jakarta.jms.TopicPublisher;
-import jakarta.jms.TopicSession;
-import jakarta.jms.TopicSubscriber;
-
-public class TopicTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core.topictests.TopicTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // Harness req's
- private Properties props = null;
-
- // JMS object
- private transient JmsTool tool = null;
-
- // properties read from ts.jte file
- long timeout;
-
- private String jmsUser;
-
- private String jmsPassword;
-
- private String mode;
-
- public static final int TOPIC = 1;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- TopicTests theTests = new TopicTests();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * Cleanup method for tests that use durable subscriptions
- */
- private void cleanupSubscription(TopicSubscriber sub, TopicSession session,
- String subName) {
- if (sub != null) {
- try {
- TestUtil.logTrace("Closing durable subscriber: " + sub);
- sub.close();
- } catch (Exception e) {
- TestUtil.logErr("exception during close: ", e);
- }
- }
-
- if (session != null) {
- try {
- TestUtil.logTrace("Unsubscribing \"" + subName + "\"");
- session.unsubscribe(subName);
- } catch (Exception e) {
- TestUtil.logErr("exception during unsubscribe: ", e);
- }
- }
- }
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- TestUtil.logMsg("Didn't get expected exception");
- throw new Exception("Didn't catch expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout;user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- TestUtil.logTrace("In setup");
- // get props
- jmsUser = p.getProperty("user");
- jmsPassword = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- if (timeout < 1) {
- throw new Exception("'timeout' (milliseconds) in ts.jte must be > 0");
- }
- connections = new ArrayList(10);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Cleanup: Closing Topic Connections");
- tool.closeAllConnections(connections);
- } catch (Exception e) {
- TestUtil.logErr("An error occurred while cleaning", e);
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /* Tests */
-
- /*
- * @testName: simpleSendReceiveTopicTest
- *
- * @assertion_ids: JMS:SPEC:158; JMS:SPEC:242; JMS:JAVADOC:122;
- *
- * @test_Strategy: Send and receive single message. Verify message receipt.
- */
- public void simpleSendReceiveTopicTest() throws Exception {
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logMsg("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "simpleSendReceiveTopicTest");
- TestUtil.logMsg("Sending message");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logMsg("Receiving message");
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- throw new Exception("didn't get any message");
- }
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logMsg("Received message");
- } else {
- throw new Exception("didn't get the right message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("simpleSendReceiveTopicTest");
- }
- }
-
- /*
- * @testName: inactiveNonDurableSubscriberTopicRecTest
- *
- * @assertion_ids: JMS:SPEC:153; JMS:SPEC:154; JMS:JAVADOC:122; JMS:SPEC:152;
- *
- * @test_Strategy: Send and receive a message to/from a topic. Inactivate the
- * subscriber, publish another message. Verify that when the subscriber is
- * activated again that there is no messages to to receive.
- */
- public void inactiveNonDurableSubscriberTopicRecTest() throws Exception {
- TopicSubscriber tSub = null;
- TopicSession tSession = null;
- TopicConnection newTConn = null;
- String lookup = "MyTopicConnectionFactory";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageSent2 = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Topic
- TestUtil.logTrace("Set up JmsTool for Topic");
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
-
- // get default Subscriber
- TestUtil.logTrace("Getting default subscriber");
- tSub = tool.getDefaultTopicSubscriber();
-
- TestUtil.logTrace("Start Connection");
- tool.getDefaultTopicConnection().start();
-
- // send message
- TestUtil.logTrace("Create and publish first message");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "inactiveNonDurableSubscriberTopicRecTest");
- tool.getDefaultTopicPublisher().publish(messageSent);
-
- TestUtil.logTrace("Receive first message");
- messageReceived = (TextMessage) tSub.receive(timeout);
-
- // Check to see if first message received
- TestUtil.logTrace("Verify that first message is received");
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logMsg("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // make the subscriber inactive
- TestUtil.logTrace("Close default subscriber");
- tSub.close();
-
- // publish another second message
- TestUtil.logTrace("Create and publish second message");
- messageSent2 = tool.getDefaultTopicSession().createTextMessage();
- messageSent2.setText("test that messages are nondurable");
- messageSent2.setStringProperty("COM_SUN_JMS_TESTNAME",
- "inactiveNonDurableSubscriberTopicRecTest");
- tool.getDefaultTopicPublisher().publish(messageSent2);
- tool.getDefaultTopicConnection().close();
-
- TestUtil.logTrace("Recreate default subscriber");
- newTConn = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, jmsUser,
- jmsPassword, lookup);
- connections.add(newTConn);
- tSession = newTConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- tSub = tSession.createSubscriber(tool.getDefaultTopic());
- newTConn.start();
- TestUtil.logTrace(
- "Try to receive second message (should not receive a message)");
- messageReceived = (TextMessage) tSub.receive(timeout);
-
- // Check to see that no message is available
- if (messageReceived != null) {
- throw new Exception("Received second message. (Expected NO messages)");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("inactiveNonDurableSubscriberTopicRecTest");
- }
- }
-
- /*
- * @testName: noLocalDeliveryTopicTest
- *
- * @assertion_ids: JMS:SPEC:161;
- *
- * @test_Strategy: Create connection with normal subscriber and no_local
- * subscriber. Send x messages to topic and receive them with regular
- * subscriber. Create second connection with subscriber. Send message from
- * first connection and receive it with second. Send message from second
- * connection and attempt receive with no_local subscriber. Should only get
- * message from second connection.
- */
- public void noLocalDeliveryTopicTest() throws Exception {
- String lookup = "MyTopicConnectionFactory";
-
- try {
- int num = 10;
- TopicSubscriber tSubNoLocal = null;
- TopicConnection newConn = null;
- TopicSession newSess = null;
- TopicPublisher newPub = null;
- TopicSubscriber newSub = null;
- Message messageSent = null;
- Message messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
- tSubNoLocal = tool.getDefaultTopicSession()
- .createSubscriber(tool.getDefaultTopic(), "", true);
- tool.getDefaultTopicConnection().start();
-
- // publish messages
- TestUtil.logTrace("Sending " + num + " messages to topic");
- messageSent = tool.getDefaultTopicSession().createMessage();
- messageSent.setBooleanProperty("lastMessage", false);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "noLocalDeliveryTopicTest");
- for (int i = 0; i < num; i++) {
- tool.getDefaultTopicPublisher().publish(messageSent);
- }
-
- // receive
- TestUtil.logMsg("Attempting to receive messages");
- for (int i = 0; i < num; i++) {
- messageReceived = tool.getDefaultTopicSubscriber().receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Should have received message");
- }
- }
-
- // create new connection
- TestUtil.logMsg("Creating new connection");
- newConn = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, jmsUser,
- jmsPassword, lookup);
- connections.add(newConn);
-
- newSess = newConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- newSub = newSess.createSubscriber(tool.getDefaultTopic());
- newPub = newSess.createPublisher(tool.getDefaultTopic());
- newConn.start();
-
- // send another message and receive with second connection
- tool.getDefaultTopicPublisher().publish(messageSent);
- messageReceived = newSub.receive(timeout);
- if (messageReceived == null) {
- throw new Exception("new connection should have received message");
- }
-
- // send message from new connection
- TestUtil.logTrace("New connection sending message");
- messageSent.setBooleanProperty("lastMessage", true);
- newPub.publish(messageSent);
- TestUtil.logTrace("Closing new connection");
- newConn.close();
-
- // receive message and check
- TestUtil.logTrace("Try to receive only message from new connection");
- messageReceived = tSubNoLocal.receive(timeout);
- if (messageReceived == null) {
- throw new Exception("No_local subscriber did not receive any message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
- throw new Exception("No_local subscriber received local message");
- }
- TestUtil.logTrace("Received correct message");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("noLocalDeliveryTopicTest");
- }
- }
-
- /*
- * @testName: simpleDurableSubscriberTopicTest
- *
- * @assertion_ids: JMS:SPEC:161; JMS:JAVADOC:87; JMS:JAVADOC:122;
- *
- * @test_Strategy: Send single message to a topic and verify receipt of it
- * with a durable subscriber.
- *
- */
- public void simpleDurableSubscriberTopicTest() throws Exception {
- TopicSubscriber durableTS = null;
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup,
- mode);
-
- // close default Subscriber and create DurableSubscriber
- TestUtil.logMsg("Create DurableSubscriber");
- tool.getDefaultTopicSubscriber().close();
- durableTS = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), "myDurableTopicSubscriber");
-
- // start Connection and send/receive message
- tool.getDefaultTopicConnection().start();
- TestUtil.logMsg("Creating and sending 1 message");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "simpleDurableSubscriberTopicTest");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logMsg("Receiving message");
- messageReceived = (TextMessage) durableTS.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logMsg("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("simpleDurableSubscriberTopicTest");
- } finally {
- cleanupSubscription(durableTS, tool.getDefaultTopicSession(),
- "myDurableTopicSubscriber");
- }
- }
-
- /*
- * @testName: temporaryTopicConnectionClosesTest
- *
- * @assertion_ids: JMS:SPEC:155; JMS:JAVADOC:93;
- *
- * @test_Strategy: Create temporary topic and then close the connection.
- * Verify that the temporary topic closes by trying to send a message to it.
- * The test also sends a blank message to the temporary topic to verify that
- * it is working.
- */
- public void temporaryTopicConnectionClosesTest() throws Exception {
- boolean passed = false;
- String lookup = "MyTopicConnectionFactory";
-
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
- tool.getDefaultTopicConnection().start();
-
- // create the TemporaryTopic
- TestUtil.logTrace("Creating TemporaryTopic");
- TemporaryTopic tempT = tool.getDefaultTopicSession()
- .createTemporaryTopic();
-
- // open a new connection, create Session and Sender
- TestUtil.logTrace("Creating new Connection");
- TopicConnection newTConn = (TopicConnection) tool
- .getNewConnection(JmsTool.TOPIC, jmsUser, jmsPassword, lookup);
- connections.add(newTConn);
-
- TestUtil.logTrace("Create new Session");
- TopicSession newTSess = newTConn.createTopicSession(false,
- Session.AUTO_ACKNOWLEDGE);
-
- TestUtil.logTrace("Create new sender for TemporaryTopic");
- TopicPublisher newTPublisher = newTSess.createPublisher(tempT);
-
- // send message to verify TemporaryTopic exists so far
- TestUtil.logTrace("Send message to TemporaryTopic");
- TextMessage tMsg = newTSess.createTextMessage();
-
- tMsg.setText("test message");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "temporaryTopicConnectionClosesTest");
- TestUtil.logTrace("TextMessage created. Now publishing");
- newTPublisher.publish(tMsg);
-
- // close the connection
- TestUtil.logTrace("Close original Connection");
- tool.getDefaultTopicConnection().close();
-
- // send message to verify TemporaryTopic no longer exists
- // TestUtil.logTrace("Send second message to TemporaryTopic. Should
- // fail.");
- // try {
- // Message tempM = newTSess.createMessage();
-
- // tempM.setStringProperty("COM_SUN_JMS_TESTNAME",
- // "temporaryTopicConnectionClosesTest");
- // newTPublisher.publish(tempM);
- // } catch (JMSException e) {
- // TestUtil.logMsg("Received expected JMSException");
- // TestUtil.logErr("Exception thrown: ", e);
- // passed = true;
- // }
-
- // close new connection
- TestUtil.logTrace("Close new TopicConnection");
- newTConn.close();
-
- // throw exception if test failed
- passed = true;
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("temporaryTopicConnectionClosesTest");
- }
- }
-
- /*
- * @testName: temporaryTopicNotConsumableTest
- *
- * @assertion_ids: JMS:SPEC:117; JMS:SPEC:243; JMS:JAVADOC:93;
- *
- * @test_Strategy: Create temporary topic and a separate TopicSession. Try to
- * create a receiver for the temporary topic from the new session, which
- * should throw a JMSException. Also sends a blank message to verify that the
- * temporary topic is working.
- */
- public void temporaryTopicNotConsumableTest() throws Exception {
- boolean passed = false;
- String lookup = "MyTopicConnectionFactory";
-
- try {
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
- tool.getDefaultTopicConnection().start();
-
- // create the TemporaryTopic
- TestUtil.logMsg("Creating TemporaryTopic");
- TemporaryTopic tempT = tool.getDefaultTopicSession()
- .createTemporaryTopic();
-
- // open a new connection, create Session and Sender
- TestUtil.logMsg("Creating new Connection");
- TopicConnection newTConn = (TopicConnection) tool
- .getNewConnection(JmsTool.TOPIC, jmsUser, jmsPassword, lookup);
- connections.add(newTConn);
- TestUtil.logMsg("Create new Session");
- TopicSession newTSess = newTConn.createTopicSession(false,
- Session.AUTO_ACKNOWLEDGE);
-
- TestUtil.logMsg("Create new publisher for TemporaryTopic");
- TopicPublisher newTPublisher = newTSess.createPublisher(tempT);
-
- // send message to verify TemporaryTopic
- TestUtil.logMsg("Send message to TemporaryTopic");
- TextMessage tMsg = newTSess.createTextMessage();
-
- tMsg.setText("test message");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "temporaryTopicNotConsumableTest");
- TestUtil.logMsg("TextMessage created. Now publishing");
- newTPublisher.publish(tMsg);
-
- // try to create receiver for the TemporaryTopic
- TestUtil.logMsg(
- "Attempt to create subscriber for TemporaryTopic from another Session");
- try {
- TopicSubscriber newTSubscriber = newTSess.createSubscriber(tempT);
- if (newTSubscriber != null)
- TestUtil.logTrace("newTSubscriber=" + newTSubscriber);
- } catch (JMSException e) {
- TestUtil.logMsg("Received expected JMSException -- GOOD");
- TestUtil.logMsg("Received Exception:", e);
- passed = true;
- }
-
- // close new connection
- TestUtil.logTrace("Close new TopicConnection");
- newTConn.close();
-
- // throw exception if test failed
- checkExceptionPass(passed);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("temporaryTopicNotConsumableTest");
- }
- }
-
- /*
- * @testName: msgSelectorMsgHeaderTopicTest
- *
- * @assertion_ids: JMS:SPEC:38; JMS:SPEC:160; JMS:SPEC:246.9;
- *
- * @test_Strategy: Create subscriber with a message selector that uses message
- * header JMSType. Send two messages, one that has the matching header value
- * and one that doesn't, and try to receive message. Should only receive one
- * matching message.
- */
- public void msgSelectorMsgHeaderTopicTest() throws Exception {
- try {
-
- // create Topic Connection
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
-
- // create subscriber with message selector
- TestUtil.logMsg("Creating subscriber with message selector");
- TopicSubscriber tSelectiveSubscriber = tool.getDefaultTopicSession()
- .createSubscriber(tool.getDefaultTopic(), "JMSType = 'test_message'",
- false);
-
- // start connection
- tool.getDefaultTopicConnection().start();
-
- // send messages
- Message m = tool.getDefaultTopicSession().createMessage();
- m.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgSelectorMsgHeaderTopicTest");
-
- TestUtil.logTrace("Sending message not matching selector");
- m.setJMSType("foo");
- m.setBooleanProperty("lastMessage", false);
- tool.getDefaultTopicPublisher().publish(m);
-
- TestUtil.logTrace("Sending message that matches selector");
- m.setJMSType("test_message");
- m.setBooleanProperty("lastMessage", true);
- tool.getDefaultTopicPublisher().publish(m);
-
- // attempt to receive correct message
- TestUtil.logMsg("Attempt to receive 'good' message");
- Message msg1 = tSelectiveSubscriber.receive(timeout);
- if (msg1 == null) {
- throw new Exception("Did not receive expected message");
- } else if (msg1.getBooleanProperty("lastMessage") == true) {
- TestUtil.logMsg("Received correct message -- GOOD");
- } else {
- TestUtil.logMsg("Received message not matching header");
- throw new Exception("Received incorrect message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("msgSelectorMsgHeaderTopicTest");
- }
- }
-
- /*
- * @testName: inactiveDurableSubscriberTopicRecTest
- *
- * @assertion_ids: JMS:SPEC:153; JMS:SPEC:154; JMS:JAVADOC:122;
- *
- * @test_Strategy: Send and receive a message from a topic. Inactivate the
- * subscriber, publish another message. Verify that when the subscriber is
- * activated the message is received.
- */
- public void inactiveDurableSubscriberTopicRecTest() throws Exception {
- TopicSubscriber durableTS = null;
- TopicSession tSession = null;
- TopicConnection newTConn = null;
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageSent1 = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup,
- mode);
-
- // close default Subscriber and create DurableSubscriber
- TestUtil.logTrace("Create DurableSubscriber");
- tool.getDefaultTopicSubscriber().close();
- durableTS = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), "inactiveDurableSubscriberTopicRecTest");
-
- TestUtil.logTrace("Start Connection");
- tool.getDefaultTopicConnection().start();
-
- // send message
- TestUtil.logTrace("Creating and sending 1 message");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "inactiveDurableSubscriberTopicRecTest");
- tool.getDefaultTopicPublisher().publish(messageSent);
-
- TestUtil.logTrace("Receiving message");
- messageReceived = (TextMessage) durableTS.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logMsg("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // make the durable subscriber inactive
- durableTS.close();
-
- // publish more messages
- messageSent1 = tool.getDefaultTopicSession().createTextMessage();
- messageSent1.setText("test that messages are durable");
- messageSent1.setStringProperty("COM_SUN_JMS_TESTNAME",
- "inactiveDurableSubscriberTopicRecTest");
- tool.getDefaultTopicPublisher().publish(messageSent1);
- tool.getDefaultTopicConnection().close();
-
- newTConn = (TopicConnection) tool.getNewConnection(JmsTool.DURABLE_TOPIC,
- jmsUser, jmsPassword, lookup);
- connections.add(newTConn);
- tSession = newTConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
-
- durableTS = tSession.createDurableSubscriber(tool.getDefaultTopic(),
- "inactiveDurableSubscriberTopicRecTest");
- newTConn.start();
- TestUtil.logTrace("Receiving message");
- messageReceived = (TextMessage) durableTS.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent1.getText())) {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logTrace("Received correct message");
- } else {
- throw new Exception("Received incorrect message.");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("inactiveDurableSubscriberTopicRecTest");
- } finally {
- cleanupSubscription(durableTS, tSession,
- "inactiveDurableSubscriberTopicRecTest");
- }
- }
-
- /*
- * @testName: durableSubscriberTopicNoLocalTest
- *
- * @assertion_ids: JMS:SPEC:161; JMS:SPEC:126;
- *
- * @test_Strategy: Create connection with normal subscriber and no_local
- * durable subscriber. Send x messages to topic and receive them with regular
- * subscriber. Create second connection with subscriber. Send message from
- * first connection and receive it with second. Send message from second
- * connection and attempt receive with no_local subscriber. Should only get
- * message from second connection.
- *
- */
- public void durableSubscriberTopicNoLocalTest() throws Exception {
- TopicSubscriber tSubNoLocal = null;
- String subscriptionName = "DurableSubscriberTopicNoLocalTestSubscription";
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
- String lookup2 = "MyTopicConnectionFactory";
-
- try {
- int num = 10;
- TopicConnection newConn = null;
- TopicSession newSess = null;
- TopicPublisher newPub = null;
- TopicSubscriber newSub = null;
- Message messageSent = null;
- Message messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup,
- mode);
-
- // create DurableSubscriber
- TestUtil.logTrace("Create DurableSubscriber");
- tSubNoLocal = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), subscriptionName, "", true);
- tool.getDefaultTopicConnection().start();
-
- // publish messages
- TestUtil.logTrace("Sending " + num + " messages to topic");
- messageSent = tool.getDefaultTopicSession().createMessage();
- messageSent.setBooleanProperty("lastMessage", false);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "noLocalDeliveryTopicTest");
- TopicPublisher defaultPub = tool.getDefaultTopicPublisher();
- for (int i = 0; i < num; i++) {
- defaultPub.publish(messageSent);
- }
-
- // receive
- TestUtil.logMsg("Attempting to receive messages");
- TopicSubscriber defaultSub = tool.getDefaultTopicSubscriber();
- for (int i = 0; i < num; i++) {
- messageReceived = defaultSub.receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Should have received message");
- }
- }
-
- // create new connection
- TestUtil.logMsg("Creating new connection");
- newConn = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, jmsUser,
- jmsPassword, lookup2);
- connections.add(newConn);
- newSess = newConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- newSub = newSess.createSubscriber(tool.getDefaultTopic());
- newPub = newSess.createPublisher(tool.getDefaultTopic());
- newConn.start();
-
- // send another message and receive with second connection
- defaultPub.publish(messageSent);
- messageReceived = newSub.receive(timeout);
- if (messageReceived == null) {
- throw new Exception("new connection should have received message");
- }
-
- // send message from new connection
- TestUtil.logTrace("New connection sending message");
- messageSent.setBooleanProperty("lastMessage", true);
- newPub.publish(messageSent);
- TestUtil.logTrace("Closing new connection");
- newConn.close();
-
- // receive message
- TestUtil.logTrace("Try to receive only message from default connection");
- messageReceived = tSubNoLocal.receive(timeout);
-
- // check message
- if (messageReceived == null) {
- throw new Exception("No_local subscriber did not receive any message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
- throw new Exception("No_local subscriber received local message");
- }
- TestUtil.logTrace("Received correct message");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("durableSubscriberTopicNoLocalTest");
- } finally {
- cleanupSubscription(tSubNoLocal, tool.getDefaultTopicSession(),
- subscriptionName);
- }
- }
-
- /*
- * @testName: durableSubscriberTopicNoLocalTest2
- *
- * @assertion_ids: JMS:SPEC:161; JMS:SPEC:164; JMS:SPEC:165; JMS:JAVADOC:256;
- * JMS:JAVADOC:99; JMS:JAVADOC:334;
- *
- *
- * @test_Strategy: 1) Create topic connection with normal subscriber and
- * (no_local=true) durable subscriber. 2) Publish x messages to topic and
- * receive them with normal subscriber. 3) Try and receive messages with
- * (no_local=true) durable subscriber and verify that you cannot receive them.
- * 4) Publish x more messages to topic. 4) Close the (no_local=true) durable
- * subscriber. 5) Create a new (no_local=false) durable subscriber with the
- * same subscription name and same topic as (no_local=true) durable
- * subscriber. 6) Try and receive messages with (no_local=false) durable
- * subscriber. Verify that you cannot receive any messages. Recreating a
- * durable subscriber with a change to (no_local setting) causes previous
- * durable subscription to become invalid so all the old messages are deleted
- * and you start anew with a clean slate.
- *
- * A client can change an existing durable subscription by creating a durable
- * TopicSubscriber with the same name and topic but different (no_local
- * setting). Changing a durable subscriber is equivalent to unsubscribing
- * (deleting) the old one and creating a new one.
- *
- * So if a client subsequently changes the no_local setting, all the existing
- * messages stored in the durable subscription become invalid since they are
- * inconsistent with the new no_local setting. The only safe thing to do is to
- * delete all the old messages and start anew.
- */
- public void durableSubscriberTopicNoLocalTest2() throws Exception {
- TopicSubscriber tSubNoLocal = null;
- String subscriptionName = "DurableSubscriberTopicNoLocalTest2Subscription";
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- int num = 10;
- Message messageSent = null;
- Message messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup,
- mode);
-
- // create DurableSubscriber with no_local=true
- TestUtil.logTrace("Create DurableSubscriber with no_local=true");
- tSubNoLocal = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), subscriptionName, "", true);
- tool.getDefaultTopicConnection().start();
-
- // publish messages from default publisher
- TestUtil.logTrace("Sending " + num + " messages to topic");
- messageSent = tool.getDefaultTopicSession().createMessage();
- messageSent.setBooleanProperty("lastMessage", false);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableSubscriberTopicNoLocalTest2");
- TopicPublisher defaultPub = tool.getDefaultTopicPublisher();
- for (int i = 0; i < num; i++) {
- defaultPub.publish(messageSent);
- }
-
- // receive with default normal subscriber
- TestUtil.logMsg("Attempting to receive messages from normal subscriber");
- TopicSubscriber defaultSub = tool.getDefaultTopicSubscriber();
- for (int i = 0; i < num; i++) {
- messageReceived = defaultSub.receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Should have received message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
- TestUtil.logTrace("Received correct message lastMessage=false");
- } else {
- throw new Exception("Received incorrect message lastMessage=true");
- }
- }
-
- // try and receive with (no_local=true) subscriber (should not receive any
- // messages)
- TestUtil.logMsg(
- "Attempting to receive messages from (no_local=true) subscriber");
- messageReceived = tSubNoLocal.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logTrace("Did not receive message (correct)");
- } else {
- throw new Exception("Received unexpected message (incorrect)");
- }
-
- // publish more messages using default topic publisher
- TestUtil.logTrace("Sending " + num + " messages to topic");
- for (int i = 0; i < num; i++) {
- defaultPub.publish(messageSent);
- }
-
- // need to inactivate durable subscriber before creating new durable
- // subscriber
- TestUtil.logTrace("Close DurableSubscriber with no_local=true");
- tSubNoLocal.close();
-
- // recreate DurableSubscriber with no_local=false
- TestUtil.logTrace("Create DurableSubscriber with no_local=false");
- tSubNoLocal = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), subscriptionName, "", false);
-
- // try and receive a message from this new durable subscriber with
- // (no_local=false)
- // should not receive any messages because creating a new
- // DurableSubscriber with a
- // different (no_local=false) setting will delete the previous
- // subscription and any
- // messages that were queued
- messageReceived = tSubNoLocal.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logMsg(
- "No_local=false subscriber did not receive any message (expected)");
- } else {
- throw new Exception(
- "No_local=false subscriber received message (unexpected)");
- }
-
- // publish more messages with default publisher
- TestUtil.logTrace("Sending " + num + " messages to topic");
- messageSent = tool.getDefaultTopicSession().createMessage();
- messageSent.setBooleanProperty("lastMessage", false);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableSubscriberTopicNoLocalTest2");
- for (int i = 0; i < num; i++) {
- defaultPub.publish(messageSent);
- }
-
- // receive messages with (no_local=false) subscriber (should receive all
- // messages)
- TestUtil.logMsg(
- "Attempting to receive messages from (no_local=false) subscriber");
- for (int i = 0; i < num; i++) {
- messageReceived = tSubNoLocal.receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Should have received message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
- TestUtil.logTrace("Received correct message lastMessage=false");
- } else {
- throw new Exception("Received incorrect message lastMessage=true");
- }
- }
-
- // try and receive one more message (there should be none at this point)
- messageReceived = tSubNoLocal.receive(timeout);
- if (messageReceived != null) {
- throw new Exception("Received unexpected final message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("durableSubscriberTopicNoLocalTest2");
- } finally {
- cleanupSubscription(tSubNoLocal, tool.getDefaultTopicSession(),
- subscriptionName);
- }
- }
-
- /*
- * @testName: durableSubscriberNewTopicTest
- *
- * @assertion_ids: JMS:SPEC:165; JMS:JAVADOC:122;
- *
- * @test_Strategy: Create 2 topics. Create a durable subscriber for the first
- * topic. send and receive a message. Create a durable topic subscriber again,
- * use the same name as the above but for the second topic.
- *
- */
- public void durableSubscriberNewTopicTest() throws Exception {
- TopicSubscriber durableTS = null;
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- Topic newTestTopic = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup,
- mode);
-
- // Create a second topic for the test
- newTestTopic = tool.createNewTopic("MY_TOPIC2");
-
- // Create a publisher for the newTestTopic Topic
- TopicPublisher newTestPublisher = tool.getDefaultTopicSession()
- .createPublisher(newTestTopic);
-
- // Create a durable subscriber for the default topic
- // close default Subscriber and create DurableSubscriber
- tool.getDefaultTopicSubscriber().close();
- durableTS = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), "durableSubscriberNewTopicTest");
-
- // start Connection and send/receive message
- tool.getDefaultTopicConnection().start();
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("For default topic");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableSubscriberNewTopicTest");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (TextMessage) durableTS.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // need to inactivate topic subscriber before switching to the new topic
- durableTS.close();
-
- // change to the new topic
- durableTS = tool.getDefaultTopicSession().createDurableSubscriber(
- newTestTopic, "durableSubscriberNewTopicTest");
-
- // Create and Publish a message to the new Topic
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText("For new topic");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableSubscriberNewTopicTest");
- newTestPublisher.publish(messageSent);
- messageReceived = (TextMessage) durableTS.receive(timeout);
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("durableSubscriberNewTopicTest");
- } finally {
- cleanupSubscription(durableTS, tool.getDefaultTopicSession(),
- "durableSubscriberNewTopicTest");
- }
- }
-
- /*
- * @testName: durableSubscriberChangeSelectorTest
- *
- * @assertion_ids: JMS:SPEC:164; JMS:SPEC:165; JMS:JAVADOC:122;
- * JMS:JAVADOC:256; JMS:JAVADOC:99; JMS:JAVADOC:334;
- *
- * @test_Strategy: Create a durable subscriber for the default topic. Create a
- * durable topic subscriber again, use the same name as the above but change
- * the selector.
- *
- */
- public void durableSubscriberChangeSelectorTest() throws Exception {
- Topic newTestTopic;
- TopicSubscriber durableTS = null;
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup,
- mode);
-
- // Create a durable subscriber for the default topic
- // close default Subscriber and create DurableSubscriber
- tool.getDefaultTopicSubscriber().close();
-
- // Create a durable subscriber with a selector specified.
- durableTS = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), "durableSubscriberChangeSelectorTest",
- "TEST = 'test'", false);
-
- // start Connection and send/receive message
- tool.getDefaultTopicConnection().start();
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setStringProperty("TEST", "test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableSubscriberChangeSelectorTest");
- messageSent.setText("For default topic ");
- tool.getDefaultTopicPublisher().publish(messageSent);
- TestUtil.logTrace("Receiving message");
- messageReceived = (TextMessage) durableTS.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // need to inactivate topic subscriber before switching to selector
- durableTS.close();
-
- // change selector
- durableTS = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), "durableSubscriberChangeSelectorTest",
- "TEST = 'new one'", false);
-
- // Publish a message with old selector
- messageSent.setBooleanProperty("lastMessage", false);
- tool.getDefaultTopicPublisher().publish(messageSent);
-
- // Create and Publish a message with the new selector
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setStringProperty("TEST", "new one");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableSubscriberChangeSelectorTest");
- messageSent.setText("For new topic");
- messageSent.setBooleanProperty("lastMessage", true);
- tool.getDefaultTopicPublisher().publish(messageSent);
-
- // receive message
- messageReceived = (TextMessage) durableTS.receive(timeout);
- if (messageReceived != null) {
- if (messageReceived.getText().equals(messageSent.getText())
- && messageReceived.getBooleanProperty("lastMessage") == true) {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logTrace("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
- } else {
- throw new Exception("didn't get any message");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("durableSubscriberChangeSelectorTest");
- } finally {
- cleanupSubscription(durableTS, tool.getDefaultTopicSession(),
- "durableSubscriberChangeSelectorTest");
- }
- }
-
- /*
- * @testName: durableSubscriberChangeSelectorTest2
- *
- * @assertion_ids: JMS:SPEC:164; JMS:SPEC:165; JMS:JAVADOC:122;
- * JMS:JAVADOC:256; JMS:JAVADOC:99; JMS:JAVADOC:334;
- *
- * @test_Strategy: 1) Create a durable subscription with a message selector
- * string property of (TEST="test") for the default topic. 2) Publish first
- * message with string property that matches the message selector
- * (TEST="test"). 3) Publish second message with string property that does not
- * match the message selector (TEST="test again"). 4) Verify that you can
- * receive the first message. 5) Verify that you cannot receive the second
- * message. 6) Close durable subscription. 7) Create a new durable
- * subscription with the same default topic and subscription name but with a
- * different message selector (TEST="test again") which matches the string
- * property of the second message that was published. 8) Try to receive this
- * second message. It should not recieve the second message. Verify that is
- * does not receive the second message. 9) Close durable subscription.
- *
- * A client can change an existing durable subscription by creating a durable
- * TopicSubscriber with the same name and a new topic and/or message selector.
- * Changing a durable subscriber is equivalent to unsubscribing (deleting) the
- * old one and creating a new one.
- *
- * So if a client subsequently changes the message selector, all the existing
- * messages stored in the durable subscription become invalid since they are
- * inconsistent with the new message selector. The only safe thing to do is to
- * delete all the old messages and start anew.
- */
- public void durableSubscriberChangeSelectorTest2() throws Exception {
- Topic newTestTopic;
- TopicSubscriber durableTS = null;
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageSent2 = null;
- TextMessage messageReceived = null;
-
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup,
- mode);
-
- // Create a durable subscriber for the default topic
- // close default Subscriber and create DurableSubscriber
- tool.getDefaultTopicSubscriber().close();
-
- TestUtil.logTrace(
- "Create durable subscription with MessageSelector=\"TEST='test'\",");
- TestUtil.logTrace("TopicName=" + tool.getDefaultTopic().getTopicName()
- + " and SubscriptionName=" + "durableSubscriberChangeSelectorTest2");
- // Create a durable subscriber with a selector specified.
- durableTS = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), "durableSubscriberChangeSelectorTest2",
- "TEST = 'test'", false);
-
- // start Connection and send/receive message
- tool.getDefaultTopicConnection().start();
-
- TestUtil.logTrace(
- "Create/Send first message with string property \"TEST = 'test'\"");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setStringProperty("TEST", "test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableSubscriberChangeSelectorTest2");
- messageSent.setText("Message #1 with string property TEST='test'");
- tool.getDefaultTopicPublisher().publish(messageSent);
-
- TestUtil.logTrace(
- "Create/Send second message with string property \"TEST = 'test again'\"");
- messageSent2 = tool.getDefaultTopicSession().createTextMessage();
- messageSent2.setStringProperty("TEST", "test again");
- messageSent2.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableSubscriberChangeSelectorTest2");
- messageSent2.setText("Message #2 with string property TEST='test again'");
- tool.getDefaultTopicPublisher().publish(messageSent2);
-
- // Check and verify that first message is received
- TestUtil.logTrace("Try receiving first message (should get message)");
- messageReceived = (TextMessage) durableTS.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logTrace("Did not receive any message (incorrect)");
- throw new Exception("didn't receive any message");
- } else if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logTrace("Received correct first message");
- } else {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- throw new Exception("didn't get the right message");
- }
-
- // Check and verify that seconde message is not received
- TestUtil
- .logTrace("Try receiving second message (should not get message)");
- messageReceived = (TextMessage) durableTS.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logTrace("Did not receive second message (correct)");
- } else if (messageReceived.getText().equals(messageSent2.getText())) {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- throw new Exception("received second message (unexpected)");
- } else {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- throw new Exception("received unexpected message");
- }
-
- // need to inactivate topic subscriber before switching new subscriber
- TestUtil.logTrace("Close durable subscription");
- durableTS.close();
-
- // change selector
- TestUtil.logTrace(
- "Create new durable subscription with MessageSelector=\"TEST='test again'\",");
- TestUtil.logTrace("TopicName=" + tool.getDefaultTopic().getTopicName()
- + " and SubscriptionName=" + "durableSubscriberChangeSelectorTest2");
- durableTS = tool.getDefaultTopicSession().createDurableSubscriber(
- tool.getDefaultTopic(), "durableSubscriberChangeSelectorTest2",
- "TEST = 'test again'", false);
-
- // receive message
- messageReceived = (TextMessage) durableTS.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logTrace("Did not receive any messages (correct)");
- } else {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- throw new Exception("received unexpected message");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("durableSubscriberChangeSelectorTest2");
- } finally {
- cleanupSubscription(durableTS, tool.getDefaultTopicSession(),
- "durableSubscriberChangeSelectorTest2");
- }
- }
-
- /*
- * @testName: msgProducerNullDestinationTopicTest
- *
- * @assertion_ids: JMS:SPEC:139; JMS:SPEC:158; JMS:SPEC:242; JMS:JAVADOC:103;
- * JMS:JAVADOC:105; JMS:JAVADOC:122;
- *
- * @test_Strategy: Create Publisher with null Destination. Send with
- * destination specified and receive single message. Verify message receipt.
- */
-
- public void msgProducerNullDestinationTopicTest() throws Exception {
- boolean pass = true;
- TopicPublisher tPublisher = null;
- Topic nullTopic = null;
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- String testName = "msgProducerNullDestinationTopicTest";
- String message = "Just a test from msgProducerNullDestinationTopicTest";
-
- try {
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
- tool.getDefaultTopicPublisher().close();
-
- try {
- tPublisher = tool.getDefaultTopicSession().createPublisher(nullTopic);
- TestUtil.logTrace("PASS: null allowed for unidentified producer");
- } catch (Exception ee) {
- TestUtil.logErr("Error: unexpected Exception: ", ee);
- pass = false;
- }
- tool.getDefaultTopicConnection().start();
-
- TestUtil.logTrace("Creating 1 message");
- messageSent = tool.getDefaultTopicSession().createTextMessage();
- messageSent.setText(message);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
-
- // publish to a topic and then get the message.
- TestUtil.logTrace("Publish a message");
- tPublisher.publish(tool.getDefaultTopic(), messageSent);
- TestUtil.logTrace("Receive a message");
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- pass = false;
- }
-
- TestUtil.logMsg("Publish message the second time ");
- tPublisher.publish(tool.getDefaultTopic(), messageSent,
- Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY,
- Message.DEFAULT_TIME_TO_LIVE);
-
- TestUtil.logMsg("Receiving message again");
- messageReceived = (TextMessage) tool.getDefaultTopicSubscriber()
- .receive(timeout);
- if (messageReceived == null) {
- TestUtil.logErr("didn't get any message");
- pass = false;
- } else if (!messageReceived.getText().equals(messageSent.getText())) {
- pass = false;
- TestUtil.logErr("didn't get the right message");
- }
-
- if (!pass) {
- throw new Exception(
- "Error: failures occurred during msgProducerNullDestinationTopicTest tests");
- }
- } catch (Exception e) {
- TestUtil.logErr("Exception occurred! ", e);
- TestUtil.printStackTrace(e);
- throw new Exception("msgProducerNullDestinationTopicTest");
- }
- }
-
- /*
- * @testName: multipleCloseTopicConnectionTest
- *
- * @assertion_ids: JMS:SPEC:108;
- *
- * @test_Strategy: Call close() twice on a connection and catch any exception.
- */
- public void multipleCloseTopicConnectionTest() throws Exception {
- try {
-
- // create Topic Connection
- tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
- tool.getDefaultTopicConnection().start();
- TestUtil.logTrace("Call close on a connection ");
- tool.getDefaultTopicConnection().close();
- TestUtil.logTrace("Call close on a connection a second time");
- tool.getDefaultTopicConnection().close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("multipleCloseTopicConnectionTest");
- }
- }
-
- /*
- * @testName: consumerTests
- *
- * @assertion_ids: JMS:SPEC:196; JMS:SPEC:158; JMS:SPEC:160; JMS:SPEC:161;
- * JMS:SPEC:126; JMS:JAVADOC:248; JMS:SPEC:266; JMS:SPEC:267;
- *
- * @test_Strategy: 1. Create a new connection and send two TextMessages; 2.
- * Create a MessageConsumer defaultConsumer to verify all messages received.
- * 3. Create another MessageConsumer noLocalConsumer with noLocal set to true,
- * and verify that no message can be received. 4. Create another
- * MessageConsumer selectConsumer off the new connection with selector to
- * verify only one message received. 5. Send a message from from default
- * connection; 6. Verify that noLocalConsumer can receive the message from the
- * default connection
- */
-
- public void consumerTests() throws Exception {
- String lookup = "MyTopicConnectionFactory";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TextMessage tempMsg = null;
- int numMessages = 2;
- boolean pass = true;
- MessageConsumer defaultConsumer = null;
- MessageConsumer selectConsumer = null;
- MessageConsumer noLocalConsumer = null;
- Connection newConn = null;
- Session newSess = null;
- MessageProducer newPub = null;
- String testName = "consumerTests";
-
- tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, mode);
-
- newConn = tool.getNewConnection(JmsTool.COMMON_T, jmsUser, jmsPassword,
- lookup);
- connections.add(newConn);
- newSess = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
- noLocalConsumer = newSess.createConsumer(tool.getDefaultDestination(),
- null, true);
- selectConsumer = newSess.createConsumer(tool.getDefaultDestination(),
- "TEST = 'test'", false);
- defaultConsumer = newSess.createConsumer(tool.getDefaultDestination());
- newPub = newSess.createProducer(tool.getDefaultDestination());
-
- tool.getDefaultConnection().start();
- newConn.start();
-
- // Create and send two messages from new connection
- messageSent = tool.getDefaultSession().createTextMessage();
- messageSent.setText("Just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- TestUtil.logTrace("Sending message to a Topic");
- messageSent.setBooleanProperty("lastMessage", false);
- newPub.send(messageSent);
-
- messageSent.setStringProperty("TEST", "test");
- messageSent.setBooleanProperty("lastMessage", true);
- newPub.send(messageSent);
-
- // Verify that noLocalConsumer cannot receive any message
- TestUtil.logTrace("noLocalConsumer Receiving message");
- messageReceived = (TextMessage) noLocalConsumer.receive(timeout);
- if (messageReceived != null) {
- pass = false;
- TestUtil.logErr(
- "Error: No_local MessageConsumer did receive local message");
- }
-
- // Verify that defaultConsumer received correct messages
- TestUtil.logTrace("defaultConsumer Receiving message");
- for (int i = 0; i < numMessages; i++) {
- messageReceived = (TextMessage) defaultConsumer.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- TestUtil.logErr("Error: Did not receive message " + i);
- } else if (!messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logErr("Error: didn't get the right message " + i);
- pass = false;
- }
- }
- // Verify that selectConsumer only receive the last message
- TestUtil.logTrace("selectConsumer Receiving message");
- messageReceived = (TextMessage) selectConsumer.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- TestUtil.logErr("Error: Did not receive correct message");
- } else if (!messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logErr("Error: didn't get the right message");
- pass = false;
- }
-
- // send message from default connection
- TestUtil.logTrace("sending message from default connection");
- messageSent.setBooleanProperty("newConnection", true);
- tool.getDefaultProducer().send(messageSent);
-
- // Verify that noLocalConsumer now can receive message from second
- // connection
- TestUtil.logTrace("noLocalConsumer Receiving message");
- messageReceived = (TextMessage) noLocalConsumer.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- TestUtil.logErr("Error: Did not receive correct message");
- } else if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logMsg("Received correct message");
- } else {
- TestUtil.logErr("Error: didn't get the right message");
- pass = false;
- }
-
- noLocalConsumer.close();
- defaultConsumer.close();
- selectConsumer.close();
-
- try {
- TestUtil.logTrace("Closing new connection");
- newConn.close();
- } catch (Exception ex) {
- TestUtil.logErr("Error closing the second Connection", ex);
- }
-
- if (pass != true)
- throw new Exception(testName + " Failed!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
- }
-
- /*
- * @testName: tempTopicTests
- *
- * @assertion_ids: JMS:SPEC:144; JMS:SPEC:161; JMS:JAVADOC:264;
- * JMS:JAVADOC:124; JMS:JAVADOC:837;
- *
- * @test_Strategy: 1. Create a TemporaryTopic from a Session. Send a
- * TextMessage and Receive it using the TemporaryTopic. Verify the Message
- * received correctly. 2. Try to delete the TemporaryTopic without closing
- * MessageConsumer, verify that JMSException is thrown. 3. Close the
- * MessageConsumer, verify that the TemporaryTopic can be deleted. 4. Try to
- * create a MessageConsumer using Session from a different Connection, verify
- * that JMSException is thrown.
- */
- public void tempTopicTests() throws Exception {
- boolean pass = true;
- TextMessage msgSent;
- TextMessage msgReceived;
- String testName = "tempTopicTests";
- String message = "Just a test from tempTopicTests";
- TemporaryTopic tempT = null;
- Connection newConn = null;
- String lookup = "MyTopicConnectionFactory";
-
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, mode);
- tool.getDefaultProducer().close();
- tool.getDefaultConsumer().close();
- tool.getDefaultConnection().start();
-
- // create the TemporaryTopic
- TestUtil.logMsg("Creating TemporaryTopic");
- tempT = tool.getDefaultSession().createTemporaryTopic();
-
- // open a new connection, create Session and Sender
- TestUtil.logMsg("Create new sender for TemporaryTopic");
- MessageProducer sender = tool.getDefaultSession().createProducer(tempT);
- MessageConsumer receiver = tool.getDefaultSession().createConsumer(tempT);
-
- // send message to verify TemporaryTopic
- TestUtil.logMsg("Send message to TemporaryTopic");
- msgSent = tool.getDefaultSession().createTextMessage();
- msgSent.setText(message);
- msgSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- sender.send(msgSent);
-
- // try to create receiver for the TemporarTopic
- msgReceived = (TextMessage) receiver.receive(timeout);
-
- if (msgReceived == null) {
- pass = false;
- TestUtil.logErr("didnot receive message");
- } else if (!msgReceived.getText().equals(message)) {
- pass = false;
- TestUtil.logErr("Received wrong message=" + msgReceived.getText());
- TestUtil.logErr("Should have: " + message);
- }
-
- try {
- tempT.delete();
- pass = false;
- TestUtil
- .logErr("TemporaryTopic.delete() didn't throw expected Exception");
- } catch (JMSException em) {
- TestUtil.logTrace("Received expected JMSException: ");
- }
- receiver.close();
-
- try {
- tempT.delete();
- } catch (Exception e) {
- pass = false;
- TestUtil.logErr("Received unexpected Exception: ", e);
- }
-
- tempT = tool.getDefaultSession().createTemporaryTopic();
- newConn = (Connection) tool.getNewConnection(JmsTool.COMMON_T, jmsUser,
- jmsPassword, lookup);
- Session newSess = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-
- // try to create receiver for the TemporaryTopic
- TestUtil.logMsg(
- "Attempt to create MessageConsumer for TemporaryTopic from another Connection");
- try {
- MessageConsumer newReceiver = newSess.createConsumer(tempT);
- if (newReceiver != null)
- TestUtil.logTrace("newReceiver=" + newReceiver);
- } catch (JMSException e) {
- TestUtil
- .logTrace("Received expected JMSException from createConsumer.");
- }
-
- if (!pass)
- throw new Exception(testName + " failed");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- } finally {
- try {
- tool.getDefaultConnection().close();
- } catch (Exception e) {
- TestUtil.logErr("Error closing Connection in " + testName, e);
- }
- try {
- newConn.close();
- } catch (Exception e) {
- TestUtil.logErr("Error closing the new Connection in " + testName, e);
- }
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core/topictests/TopicTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core/topictests/TopicTestsIT.java
new file mode 100644
index 0000000000..b2fc4be748
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core/topictests/TopicTestsIT.java
@@ -0,0 +1,1593 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core.topictests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.Connection;
+import jakarta.jms.JMSException;
+import jakarta.jms.Message;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Session;
+import jakarta.jms.TemporaryTopic;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicConnection;
+import jakarta.jms.TopicPublisher;
+import jakarta.jms.TopicSession;
+import jakarta.jms.TopicSubscriber;
+
+
+public class TopicTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.core.topictests.TopicTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(TopicTestsIT.class.getName());
+
+ // Harness req's
+ private Properties props = null;
+
+ // JMS object
+ private transient JmsTool tool = null;
+
+ // properties read
+ long timeout;
+
+ private String jmsUser;
+
+ private String jmsPassword;
+
+ private String mode;
+
+ public static final int TOPIC = 1;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * Cleanup method for tests that use durable subscriptions
+ */
+ private void cleanupSubscription(TopicSubscriber sub, TopicSession session, String subName) {
+ if (sub != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Closing durable subscriber: " + sub);
+ sub.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "exception during close: ", e);
+ }
+ }
+
+ if (session != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Unsubscribing \"" + subName + "\"");
+ session.unsubscribe(subName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "exception during unsubscribe: ", e);
+ }
+ }
+ }
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't catch expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout;user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, "In setup");
+ // get props
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ if (timeout < 1) {
+ throw new Exception("'timeout' (milliseconds) in must be > 0");
+ }
+ connections = new ArrayList(10);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Cleanup: Closing Topic Connections");
+ tool.closeAllConnections(connections);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning", e);
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: simpleSendReceiveTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:158; JMS:SPEC:242; JMS:JAVADOC:122;
+ *
+ * @test_Strategy: Send and receive single message. Verify message receipt.
+ */
+ @Test
+ public void simpleSendReceiveTopicTest() throws Exception {
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "simpleSendReceiveTopicTest");
+ logger.log(Logger.Level.INFO, "Sending message");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("didn't get any message");
+ }
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("simpleSendReceiveTopicTest");
+ }
+ }
+
+ /*
+ * @testName: inactiveNonDurableSubscriberTopicRecTest
+ *
+ * @assertion_ids: JMS:SPEC:153; JMS:SPEC:154; JMS:JAVADOC:122; JMS:SPEC:152;
+ *
+ * @test_Strategy: Send and receive a message to/from a topic. Inactivate the
+ * subscriber, publish another message. Verify that when the subscriber is
+ * activated again that there is no messages to to receive.
+ */
+ @Test
+ public void inactiveNonDurableSubscriberTopicRecTest() throws Exception {
+ TopicSubscriber tSub = null;
+ TopicSession tSession = null;
+ TopicConnection newTConn = null;
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageSent2 = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Topic
+ logger.log(Logger.Level.TRACE, "Set up JmsTool for Topic");
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, lookup, mode);
+
+ // get default Subscriber
+ logger.log(Logger.Level.TRACE, "Getting default subscriber");
+ tSub = tool.getDefaultTopicSubscriber();
+
+ logger.log(Logger.Level.TRACE, "Start Connection");
+ tool.getDefaultTopicConnection().start();
+
+ // send message
+ logger.log(Logger.Level.TRACE, "Create and publish first message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "inactiveNonDurableSubscriberTopicRecTest");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+
+ logger.log(Logger.Level.TRACE, "Receive first message");
+ messageReceived = (TextMessage) tSub.receive(timeout);
+
+ // Check to see if first message received
+ logger.log(Logger.Level.TRACE, "Verify that first message is received");
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // make the subscriber inactive
+ logger.log(Logger.Level.TRACE, "Close default subscriber");
+ tSub.close();
+
+ // publish another second message
+ logger.log(Logger.Level.TRACE, "Create and publish second message");
+ messageSent2 = tool.getDefaultTopicSession().createTextMessage();
+ messageSent2.setText("test that messages are nondurable");
+ messageSent2.setStringProperty("COM_SUN_JMS_TESTNAME", "inactiveNonDurableSubscriberTopicRecTest");
+ tool.getDefaultTopicPublisher().publish(messageSent2);
+ tool.getDefaultTopicConnection().close();
+
+ logger.log(Logger.Level.TRACE, "Recreate default subscriber");
+ newTConn = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, jmsUser, jmsPassword, lookup);
+ connections.add(newTConn);
+ tSession = newTConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ tSub = tSession.createSubscriber(tool.getDefaultTopic());
+ newTConn.start();
+ logger.log(Logger.Level.TRACE, "Try to receive second message (should not receive a message)");
+ messageReceived = (TextMessage) tSub.receive(timeout);
+
+ // Check to see that no message is available
+ if (messageReceived != null) {
+ throw new Exception("Received second message. (Expected NO messages)");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("inactiveNonDurableSubscriberTopicRecTest");
+ }
+ }
+
+ /*
+ * @testName: noLocalDeliveryTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:161;
+ *
+ * @test_Strategy: Create connection with normal subscriber and no_local
+ * subscriber. Send x messages to topic and receive them with regular
+ * subscriber. Create second connection with subscriber. Send message from first
+ * connection and receive it with second. Send message from second connection
+ * and attempt receive with no_local subscriber. Should only get message from
+ * second connection.
+ */
+ @Test
+ public void noLocalDeliveryTopicTest() throws Exception {
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+ int num = 10;
+ TopicSubscriber tSubNoLocal = null;
+ TopicConnection newConn = null;
+ TopicSession newSess = null;
+ TopicPublisher newPub = null;
+ TopicSubscriber newSub = null;
+ Message messageSent = null;
+ Message messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
+ tSubNoLocal = tool.getDefaultTopicSession().createSubscriber(tool.getDefaultTopic(), "", true);
+ tool.getDefaultTopicConnection().start();
+
+ // publish messages
+ logger.log(Logger.Level.TRACE, "Sending " + num + " messages to topic");
+ messageSent = tool.getDefaultTopicSession().createMessage();
+ messageSent.setBooleanProperty("lastMessage", false);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "noLocalDeliveryTopicTest");
+ for (int i = 0; i < num; i++) {
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ }
+
+ // receive
+ logger.log(Logger.Level.INFO, "Attempting to receive messages");
+ for (int i = 0; i < num; i++) {
+ messageReceived = tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Should have received message");
+ }
+ }
+
+ // create new connection
+ logger.log(Logger.Level.INFO, "Creating new connection");
+ newConn = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, jmsUser, jmsPassword, lookup);
+ connections.add(newConn);
+
+ newSess = newConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ newSub = newSess.createSubscriber(tool.getDefaultTopic());
+ newPub = newSess.createPublisher(tool.getDefaultTopic());
+ newConn.start();
+
+ // send another message and receive with second connection
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ messageReceived = newSub.receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("new connection should have received message");
+ }
+
+ // send message from new connection
+ logger.log(Logger.Level.TRACE, "New connection sending message");
+ messageSent.setBooleanProperty("lastMessage", true);
+ newPub.publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Closing new connection");
+ newConn.close();
+
+ // receive message and check
+ logger.log(Logger.Level.TRACE, "Try to receive only message from new connection");
+ messageReceived = tSubNoLocal.receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("No_local subscriber did not receive any message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
+ throw new Exception("No_local subscriber received local message");
+ }
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("noLocalDeliveryTopicTest");
+ }
+ }
+
+ /*
+ * @testName: simpleDurableSubscriberTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:161; JMS:JAVADOC:87; JMS:JAVADOC:122;
+ *
+ * @test_Strategy: Send single message to a topic and verify receipt of it with
+ * a durable subscriber.
+ *
+ */
+ @Test
+ public void simpleDurableSubscriberTopicTest() throws Exception {
+ TopicSubscriber durableTS = null;
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup, mode);
+
+ // close default Subscriber and create DurableSubscriber
+ logger.log(Logger.Level.INFO, "Create DurableSubscriber");
+ tool.getDefaultTopicSubscriber().close();
+ durableTS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ "myDurableTopicSubscriber");
+
+ // start Connection and send/receive message
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.INFO, "Creating and sending 1 message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "simpleDurableSubscriberTopicTest");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) durableTS.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("simpleDurableSubscriberTopicTest");
+ } finally {
+ cleanupSubscription(durableTS, tool.getDefaultTopicSession(), "myDurableTopicSubscriber");
+ }
+ }
+
+ /*
+ * @testName: temporaryTopicConnectionClosesTest
+ *
+ * @assertion_ids: JMS:SPEC:155; JMS:JAVADOC:93;
+ *
+ * @test_Strategy: Create temporary topic and then close the connection. Verify
+ * that the temporary topic closes by trying to send a message to it. The test
+ * also sends a blank message to the temporary topic to verify that it is
+ * working.
+ */
+ @Test
+ public void temporaryTopicConnectionClosesTest() throws Exception {
+ boolean passed = false;
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
+ tool.getDefaultTopicConnection().start();
+
+ // create the TemporaryTopic
+ logger.log(Logger.Level.TRACE, "Creating TemporaryTopic");
+ TemporaryTopic tempT = tool.getDefaultTopicSession().createTemporaryTopic();
+
+ // open a new connection, create Session and Sender
+ logger.log(Logger.Level.TRACE, "Creating new Connection");
+ TopicConnection newTConn = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, jmsUser, jmsPassword,
+ lookup);
+ connections.add(newTConn);
+
+ logger.log(Logger.Level.TRACE, "Create new Session");
+ TopicSession newTSess = newTConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ logger.log(Logger.Level.TRACE, "Create new sender for TemporaryTopic");
+ TopicPublisher newTPublisher = newTSess.createPublisher(tempT);
+
+ // send message to verify TemporaryTopic exists so far
+ logger.log(Logger.Level.TRACE, "Send message to TemporaryTopic");
+ TextMessage tMsg = newTSess.createTextMessage();
+
+ tMsg.setText("test message");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "temporaryTopicConnectionClosesTest");
+ logger.log(Logger.Level.TRACE, "TextMessage created. Now publishing");
+ newTPublisher.publish(tMsg);
+
+ // close the connection
+ logger.log(Logger.Level.TRACE, "Close original Connection");
+ tool.getDefaultTopicConnection().close();
+
+ // send message to verify TemporaryTopic no longer exists
+ // logger.log(Logger.Level.TRACE,"Send second message to TemporaryTopic. Should
+ // fail.");
+ // try {
+ // Message tempM = newTSess.createMessage();
+
+ // tempM.setStringProperty("COM_SUN_JMS_TESTNAME",
+ // "temporaryTopicConnectionClosesTest");
+ // newTPublisher.publish(tempM);
+ // } catch (JMSException e) {
+ // logger.log(Logger.Level.INFO,"Received expected JMSException");
+ // logger.log(Logger.Level.ERROR,"Exception thrown: ", e);
+ // passed = true;
+ // }
+
+ // close new connection
+ logger.log(Logger.Level.TRACE, "Close new TopicConnection");
+ newTConn.close();
+
+ // throw exception if test failed
+ passed = true;
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("temporaryTopicConnectionClosesTest");
+ }
+ }
+
+ /*
+ * @testName: temporaryTopicNotConsumableTest
+ *
+ * @assertion_ids: JMS:SPEC:117; JMS:SPEC:243; JMS:JAVADOC:93;
+ *
+ * @test_Strategy: Create temporary topic and a separate TopicSession. Try to
+ * create a receiver for the temporary topic from the new session, which should
+ * throw a JMSException. Also sends a blank message to verify that the temporary
+ * topic is working.
+ */
+ @Test
+ public void temporaryTopicNotConsumableTest() throws Exception {
+ boolean passed = false;
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
+ tool.getDefaultTopicConnection().start();
+
+ // create the TemporaryTopic
+ logger.log(Logger.Level.INFO, "Creating TemporaryTopic");
+ TemporaryTopic tempT = tool.getDefaultTopicSession().createTemporaryTopic();
+
+ // open a new connection, create Session and Sender
+ logger.log(Logger.Level.INFO, "Creating new Connection");
+ TopicConnection newTConn = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, jmsUser, jmsPassword,
+ lookup);
+ connections.add(newTConn);
+ logger.log(Logger.Level.INFO, "Create new Session");
+ TopicSession newTSess = newTConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ logger.log(Logger.Level.INFO, "Create new publisher for TemporaryTopic");
+ TopicPublisher newTPublisher = newTSess.createPublisher(tempT);
+
+ // send message to verify TemporaryTopic
+ logger.log(Logger.Level.INFO, "Send message to TemporaryTopic");
+ TextMessage tMsg = newTSess.createTextMessage();
+
+ tMsg.setText("test message");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "temporaryTopicNotConsumableTest");
+ logger.log(Logger.Level.INFO, "TextMessage created. Now publishing");
+ newTPublisher.publish(tMsg);
+
+ // try to create receiver for the TemporaryTopic
+ logger.log(Logger.Level.INFO, "Attempt to create subscriber for TemporaryTopic from another Session");
+ try {
+ TopicSubscriber newTSubscriber = newTSess.createSubscriber(tempT);
+ if (newTSubscriber != null)
+ logger.log(Logger.Level.TRACE, "newTSubscriber=" + newTSubscriber);
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Received expected JMSException -- GOOD");
+ logger.log(Logger.Level.INFO, "Received Exception:", e);
+ passed = true;
+ }
+
+ // close new connection
+ logger.log(Logger.Level.TRACE, "Close new TopicConnection");
+ newTConn.close();
+
+ // throw exception if test failed
+ checkExceptionPass(passed);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("temporaryTopicNotConsumableTest");
+ }
+ }
+
+ /*
+ * @testName: msgSelectorMsgHeaderTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:38; JMS:SPEC:160; JMS:SPEC:246.9;
+ *
+ * @test_Strategy: Create subscriber with a message selector that uses message
+ * header JMSType. Send two messages, one that has the matching header value and
+ * one that doesn't, and try to receive message. Should only receive one
+ * matching message.
+ */
+ @Test
+ public void msgSelectorMsgHeaderTopicTest() throws Exception {
+ try {
+
+ // create Topic Connection
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
+
+ // create subscriber with message selector
+ logger.log(Logger.Level.INFO, "Creating subscriber with message selector");
+ TopicSubscriber tSelectiveSubscriber = tool.getDefaultTopicSession()
+ .createSubscriber(tool.getDefaultTopic(), "JMSType = 'test_message'", false);
+
+ // start connection
+ tool.getDefaultTopicConnection().start();
+
+ // send messages
+ Message m = tool.getDefaultTopicSession().createMessage();
+ m.setStringProperty("COM_SUN_JMS_TESTNAME", "msgSelectorMsgHeaderTopicTest");
+
+ logger.log(Logger.Level.TRACE, "Sending message not matching selector");
+ m.setJMSType("foo");
+ m.setBooleanProperty("lastMessage", false);
+ tool.getDefaultTopicPublisher().publish(m);
+
+ logger.log(Logger.Level.TRACE, "Sending message that matches selector");
+ m.setJMSType("test_message");
+ m.setBooleanProperty("lastMessage", true);
+ tool.getDefaultTopicPublisher().publish(m);
+
+ // attempt to receive correct message
+ logger.log(Logger.Level.INFO, "Attempt to receive 'good' message");
+ Message msg1 = tSelectiveSubscriber.receive(timeout);
+ if (msg1 == null) {
+ throw new Exception("Did not receive expected message");
+ } else if (msg1.getBooleanProperty("lastMessage") == true) {
+ logger.log(Logger.Level.INFO, "Received correct message -- GOOD");
+ } else {
+ logger.log(Logger.Level.INFO, "Received message not matching header");
+ throw new Exception("Received incorrect message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgSelectorMsgHeaderTopicTest");
+ }
+ }
+
+ /*
+ * @testName: inactiveDurableSubscriberTopicRecTest
+ *
+ * @assertion_ids: JMS:SPEC:153; JMS:SPEC:154; JMS:JAVADOC:122;
+ *
+ * @test_Strategy: Send and receive a message from a topic. Inactivate the
+ * subscriber, publish another message. Verify that when the subscriber is
+ * activated the message is received.
+ */
+ @Test
+ public void inactiveDurableSubscriberTopicRecTest() throws Exception {
+ TopicSubscriber durableTS = null;
+ TopicSession tSession = null;
+ TopicConnection newTConn = null;
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageSent1 = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup, mode);
+
+ // close default Subscriber and create DurableSubscriber
+ logger.log(Logger.Level.TRACE, "Create DurableSubscriber");
+ tool.getDefaultTopicSubscriber().close();
+ durableTS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ "inactiveDurableSubscriberTopicRecTest");
+
+ logger.log(Logger.Level.TRACE, "Start Connection");
+ tool.getDefaultTopicConnection().start();
+
+ // send message
+ logger.log(Logger.Level.TRACE, "Creating and sending 1 message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "inactiveDurableSubscriberTopicRecTest");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) durableTS.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // make the durable subscriber inactive
+ durableTS.close();
+
+ // publish more messages
+ messageSent1 = tool.getDefaultTopicSession().createTextMessage();
+ messageSent1.setText("test that messages are durable");
+ messageSent1.setStringProperty("COM_SUN_JMS_TESTNAME", "inactiveDurableSubscriberTopicRecTest");
+ tool.getDefaultTopicPublisher().publish(messageSent1);
+ tool.getDefaultTopicConnection().close();
+
+ newTConn = (TopicConnection) tool.getNewConnection(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup);
+ connections.add(newTConn);
+ tSession = newTConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ durableTS = tSession.createDurableSubscriber(tool.getDefaultTopic(),
+ "inactiveDurableSubscriberTopicRecTest");
+ newTConn.start();
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) durableTS.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent1.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("Received incorrect message.");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("inactiveDurableSubscriberTopicRecTest");
+ } finally {
+ cleanupSubscription(durableTS, tSession, "inactiveDurableSubscriberTopicRecTest");
+ }
+ }
+
+ /*
+ * @testName: durableSubscriberTopicNoLocalTest
+ *
+ * @assertion_ids: JMS:SPEC:161; JMS:SPEC:126;
+ *
+ * @test_Strategy: Create connection with normal subscriber and no_local durable
+ * subscriber. Send x messages to topic and receive them with regular
+ * subscriber. Create second connection with subscriber. Send message from first
+ * connection and receive it with second. Send message from second connection
+ * and attempt receive with no_local subscriber. Should only get message from
+ * second connection.
+ *
+ */
+ @Test
+ public void durableSubscriberTopicNoLocalTest() throws Exception {
+ TopicSubscriber tSubNoLocal = null;
+ String subscriptionName = "DurableSubscriberTopicNoLocalTestSubscription";
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+ String lookup2 = "MyTopicConnectionFactory";
+
+ try {
+ int num = 10;
+ TopicConnection newConn = null;
+ TopicSession newSess = null;
+ TopicPublisher newPub = null;
+ TopicSubscriber newSub = null;
+ Message messageSent = null;
+ Message messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup, mode);
+
+ // create DurableSubscriber
+ logger.log(Logger.Level.TRACE, "Create DurableSubscriber");
+ tSubNoLocal = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ subscriptionName, "", true);
+ tool.getDefaultTopicConnection().start();
+
+ // publish messages
+ logger.log(Logger.Level.TRACE, "Sending " + num + " messages to topic");
+ messageSent = tool.getDefaultTopicSession().createMessage();
+ messageSent.setBooleanProperty("lastMessage", false);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "noLocalDeliveryTopicTest");
+ TopicPublisher defaultPub = tool.getDefaultTopicPublisher();
+ for (int i = 0; i < num; i++) {
+ defaultPub.publish(messageSent);
+ }
+
+ // receive
+ logger.log(Logger.Level.INFO, "Attempting to receive messages");
+ TopicSubscriber defaultSub = tool.getDefaultTopicSubscriber();
+ for (int i = 0; i < num; i++) {
+ messageReceived = defaultSub.receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Should have received message");
+ }
+ }
+
+ // create new connection
+ logger.log(Logger.Level.INFO, "Creating new connection");
+ newConn = (TopicConnection) tool.getNewConnection(JmsTool.TOPIC, jmsUser, jmsPassword, lookup2);
+ connections.add(newConn);
+ newSess = newConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ newSub = newSess.createSubscriber(tool.getDefaultTopic());
+ newPub = newSess.createPublisher(tool.getDefaultTopic());
+ newConn.start();
+
+ // send another message and receive with second connection
+ defaultPub.publish(messageSent);
+ messageReceived = newSub.receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("new connection should have received message");
+ }
+
+ // send message from new connection
+ logger.log(Logger.Level.TRACE, "New connection sending message");
+ messageSent.setBooleanProperty("lastMessage", true);
+ newPub.publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Closing new connection");
+ newConn.close();
+
+ // receive message
+ logger.log(Logger.Level.TRACE, "Try to receive only message from default connection");
+ messageReceived = tSubNoLocal.receive(timeout);
+
+ // check message
+ if (messageReceived == null) {
+ throw new Exception("No_local subscriber did not receive any message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
+ throw new Exception("No_local subscriber received local message");
+ }
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("durableSubscriberTopicNoLocalTest");
+ } finally {
+ cleanupSubscription(tSubNoLocal, tool.getDefaultTopicSession(), subscriptionName);
+ }
+ }
+
+ /*
+ * @testName: durableSubscriberTopicNoLocalTest2
+ *
+ * @assertion_ids: JMS:SPEC:161; JMS:SPEC:164; JMS:SPEC:165; JMS:JAVADOC:256;
+ * JMS:JAVADOC:99; JMS:JAVADOC:334;
+ *
+ *
+ * @test_Strategy: 1) Create topic connection with normal subscriber and
+ * (no_local=true) durable subscriber. 2) Publish x messages to topic and
+ * receive them with normal subscriber. 3) Try and receive messages with
+ * (no_local=true) durable subscriber and verify that you cannot receive them.
+ * 4) Publish x more messages to topic. 4) Close the (no_local=true) durable
+ * subscriber. 5) Create a new (no_local=false) durable subscriber with the same
+ * subscription name and same topic as (no_local=true) durable subscriber. 6)
+ * Try and receive messages with (no_local=false) durable subscriber. Verify
+ * that you cannot receive any messages. Recreating a durable subscriber with a
+ * change to (no_local setting) causes previous durable subscription to become
+ * invalid so all the old messages are deleted and you start anew with a clean
+ * slate.
+ *
+ * A client can change an existing durable subscription by creating a durable
+ * TopicSubscriber with the same name and topic but different (no_local
+ * setting). Changing a durable subscriber is equivalent to unsubscribing
+ * (deleting) the old one and creating a new one.
+ *
+ * So if a client subsequently changes the no_local setting, all the existing
+ * messages stored in the durable subscription become invalid since they are
+ * inconsistent with the new no_local setting. The only safe thing to do is to
+ * delete all the old messages and start anew.
+ */
+ @Test
+ public void durableSubscriberTopicNoLocalTest2() throws Exception {
+ TopicSubscriber tSubNoLocal = null;
+ String subscriptionName = "DurableSubscriberTopicNoLocalTest2Subscription";
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ int num = 10;
+ Message messageSent = null;
+ Message messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup, mode);
+
+ // create DurableSubscriber with no_local=true
+ logger.log(Logger.Level.TRACE, "Create DurableSubscriber with no_local=true");
+ tSubNoLocal = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ subscriptionName, "", true);
+ tool.getDefaultTopicConnection().start();
+
+ // publish messages from default publisher
+ logger.log(Logger.Level.TRACE, "Sending " + num + " messages to topic");
+ messageSent = tool.getDefaultTopicSession().createMessage();
+ messageSent.setBooleanProperty("lastMessage", false);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableSubscriberTopicNoLocalTest2");
+ TopicPublisher defaultPub = tool.getDefaultTopicPublisher();
+ for (int i = 0; i < num; i++) {
+ defaultPub.publish(messageSent);
+ }
+
+ // receive with default normal subscriber
+ logger.log(Logger.Level.INFO, "Attempting to receive messages from normal subscriber");
+ TopicSubscriber defaultSub = tool.getDefaultTopicSubscriber();
+ for (int i = 0; i < num; i++) {
+ messageReceived = defaultSub.receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Should have received message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
+ logger.log(Logger.Level.TRACE, "Received correct message lastMessage=false");
+ } else {
+ throw new Exception("Received incorrect message lastMessage=true");
+ }
+ }
+
+ // try and receive with (no_local=true) subscriber (should not receive any
+ // messages)
+ logger.log(Logger.Level.INFO, "Attempting to receive messages from (no_local=true) subscriber");
+ messageReceived = tSubNoLocal.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.TRACE, "Did not receive message (correct)");
+ } else {
+ throw new Exception("Received unexpected message (incorrect)");
+ }
+
+ // publish more messages using default topic publisher
+ logger.log(Logger.Level.TRACE, "Sending " + num + " messages to topic");
+ for (int i = 0; i < num; i++) {
+ defaultPub.publish(messageSent);
+ }
+
+ // need to inactivate durable subscriber before creating new durable
+ // subscriber
+ logger.log(Logger.Level.TRACE, "Close DurableSubscriber with no_local=true");
+ tSubNoLocal.close();
+
+ // recreate DurableSubscriber with no_local=false
+ logger.log(Logger.Level.TRACE, "Create DurableSubscriber with no_local=false");
+ tSubNoLocal = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ subscriptionName, "", false);
+
+ // try and receive a message from this new durable subscriber with
+ // (no_local=false)
+ // should not receive any messages because creating a new
+ // DurableSubscriber with a
+ // different (no_local=false) setting will delete the previous
+ // subscription and any
+ // messages that were queued
+ messageReceived = tSubNoLocal.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.INFO, "No_local=false subscriber did not receive any message (expected)");
+ } else {
+ throw new Exception("No_local=false subscriber received message (unexpected)");
+ }
+
+ // publish more messages with default publisher
+ logger.log(Logger.Level.TRACE, "Sending " + num + " messages to topic");
+ messageSent = tool.getDefaultTopicSession().createMessage();
+ messageSent.setBooleanProperty("lastMessage", false);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableSubscriberTopicNoLocalTest2");
+ for (int i = 0; i < num; i++) {
+ defaultPub.publish(messageSent);
+ }
+
+ // receive messages with (no_local=false) subscriber (should receive all
+ // messages)
+ logger.log(Logger.Level.INFO, "Attempting to receive messages from (no_local=false) subscriber");
+ for (int i = 0; i < num; i++) {
+ messageReceived = tSubNoLocal.receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Should have received message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
+ logger.log(Logger.Level.TRACE, "Received correct message lastMessage=false");
+ } else {
+ throw new Exception("Received incorrect message lastMessage=true");
+ }
+ }
+
+ // try and receive one more message (there should be none at this point)
+ messageReceived = tSubNoLocal.receive(timeout);
+ if (messageReceived != null) {
+ throw new Exception("Received unexpected final message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("durableSubscriberTopicNoLocalTest2");
+ } finally {
+ cleanupSubscription(tSubNoLocal, tool.getDefaultTopicSession(), subscriptionName);
+ }
+ }
+
+ /*
+ * @testName: durableSubscriberNewTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:165; JMS:JAVADOC:122;
+ *
+ * @test_Strategy: Create 2 topics. Create a durable subscriber for the first
+ * topic. send and receive a message. Create a durable topic subscriber again,
+ * use the same name as the above but for the second topic.
+ *
+ */
+ @Test
+ public void durableSubscriberNewTopicTest() throws Exception {
+ TopicSubscriber durableTS = null;
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ Topic newTestTopic = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup, mode);
+
+ // Create a second topic for the test
+ newTestTopic = tool.createNewTopic("MY_TOPIC2");
+
+ // Create a publisher for the newTestTopic Topic
+ TopicPublisher newTestPublisher = tool.getDefaultTopicSession().createPublisher(newTestTopic);
+
+ // Create a durable subscriber for the default topic
+ // close default Subscriber and create DurableSubscriber
+ tool.getDefaultTopicSubscriber().close();
+ durableTS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ "durableSubscriberNewTopicTest");
+
+ // start Connection and send/receive message
+ tool.getDefaultTopicConnection().start();
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("For default topic");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableSubscriberNewTopicTest");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) durableTS.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // need to inactivate topic subscriber before switching to the new topic
+ durableTS.close();
+
+ // change to the new topic
+ durableTS = tool.getDefaultTopicSession().createDurableSubscriber(newTestTopic,
+ "durableSubscriberNewTopicTest");
+
+ // Create and Publish a message to the new Topic
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText("For new topic");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableSubscriberNewTopicTest");
+ newTestPublisher.publish(messageSent);
+ messageReceived = (TextMessage) durableTS.receive(timeout);
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("durableSubscriberNewTopicTest");
+ } finally {
+ cleanupSubscription(durableTS, tool.getDefaultTopicSession(), "durableSubscriberNewTopicTest");
+ }
+ }
+
+ /*
+ * @testName: durableSubscriberChangeSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:164; JMS:SPEC:165; JMS:JAVADOC:122; JMS:JAVADOC:256;
+ * JMS:JAVADOC:99; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Create a durable subscriber for the default topic. Create a
+ * durable topic subscriber again, use the same name as the above but change the
+ * selector.
+ *
+ */
+ @Test
+ public void durableSubscriberChangeSelectorTest() throws Exception {
+ Topic newTestTopic;
+ TopicSubscriber durableTS = null;
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup, mode);
+
+ // Create a durable subscriber for the default topic
+ // close default Subscriber and create DurableSubscriber
+ tool.getDefaultTopicSubscriber().close();
+
+ // Create a durable subscriber with a selector specified.
+ durableTS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ "durableSubscriberChangeSelectorTest", "TEST = 'test'", false);
+
+ // start Connection and send/receive message
+ tool.getDefaultTopicConnection().start();
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setStringProperty("TEST", "test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableSubscriberChangeSelectorTest");
+ messageSent.setText("For default topic ");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) durableTS.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // need to inactivate topic subscriber before switching to selector
+ durableTS.close();
+
+ // change selector
+ durableTS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ "durableSubscriberChangeSelectorTest", "TEST = 'new one'", false);
+
+ // Publish a message with old selector
+ messageSent.setBooleanProperty("lastMessage", false);
+ tool.getDefaultTopicPublisher().publish(messageSent);
+
+ // Create and Publish a message with the new selector
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setStringProperty("TEST", "new one");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableSubscriberChangeSelectorTest");
+ messageSent.setText("For new topic");
+ messageSent.setBooleanProperty("lastMessage", true);
+ tool.getDefaultTopicPublisher().publish(messageSent);
+
+ // receive message
+ messageReceived = (TextMessage) durableTS.receive(timeout);
+ if (messageReceived != null) {
+ if (messageReceived.getText().equals(messageSent.getText())
+ && messageReceived.getBooleanProperty("lastMessage") == true) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+ } else {
+ throw new Exception("didn't get any message");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("durableSubscriberChangeSelectorTest");
+ } finally {
+ cleanupSubscription(durableTS, tool.getDefaultTopicSession(), "durableSubscriberChangeSelectorTest");
+ }
+ }
+
+ /*
+ * @testName: durableSubscriberChangeSelectorTest2
+ *
+ * @assertion_ids: JMS:SPEC:164; JMS:SPEC:165; JMS:JAVADOC:122; JMS:JAVADOC:256;
+ * JMS:JAVADOC:99; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: 1) Create a durable subscription with a message selector
+ * string property of (TEST="test") for the default topic. 2) Publish first
+ * message with string property that matches the message selector (TEST="test").
+ * 3) Publish second message with string property that does not match the
+ * message selector (TEST="test again"). 4) Verify that you can receive the
+ * first message. 5) Verify that you cannot receive the second message. 6) Close
+ * durable subscription. 7) Create a new durable subscription with the same
+ * default topic and subscription name but with a different message selector
+ * (TEST="test again") which matches the string property of the second message
+ * that was published. 8) Try to receive this second message. It should not
+ * recieve the second message. Verify that is does not receive the second
+ * message. 9) Close durable subscription.
+ *
+ * A client can change an existing durable subscription by creating a durable
+ * TopicSubscriber with the same name and a new topic and/or message selector.
+ * Changing a durable subscriber is equivalent to unsubscribing (deleting) the
+ * old one and creating a new one.
+ *
+ * So if a client subsequently changes the message selector, all the existing
+ * messages stored in the durable subscription become invalid since they are
+ * inconsistent with the new message selector. The only safe thing to do is to
+ * delete all the old messages and start anew.
+ */
+ @Test
+ public void durableSubscriberChangeSelectorTest2() throws Exception {
+ Topic newTestTopic;
+ TopicSubscriber durableTS = null;
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageSent2 = null;
+ TextMessage messageReceived = null;
+
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.DURABLE_TOPIC, jmsUser, jmsPassword, lookup, mode);
+
+ // Create a durable subscriber for the default topic
+ // close default Subscriber and create DurableSubscriber
+ tool.getDefaultTopicSubscriber().close();
+
+ logger.log(Logger.Level.TRACE, "Create durable subscription with MessageSelector=\"TEST='test'\",");
+ logger.log(Logger.Level.TRACE, "TopicName=" + tool.getDefaultTopic().getTopicName()
+ + " and SubscriptionName=" + "durableSubscriberChangeSelectorTest2");
+ // Create a durable subscriber with a selector specified.
+ durableTS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ "durableSubscriberChangeSelectorTest2", "TEST = 'test'", false);
+
+ // start Connection and send/receive message
+ tool.getDefaultTopicConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Create/Send first message with string property \"TEST = 'test'\"");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setStringProperty("TEST", "test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableSubscriberChangeSelectorTest2");
+ messageSent.setText("Message #1 with string property TEST='test'");
+ tool.getDefaultTopicPublisher().publish(messageSent);
+
+ logger.log(Logger.Level.TRACE, "Create/Send second message with string property \"TEST = 'test again'\"");
+ messageSent2 = tool.getDefaultTopicSession().createTextMessage();
+ messageSent2.setStringProperty("TEST", "test again");
+ messageSent2.setStringProperty("COM_SUN_JMS_TESTNAME", "durableSubscriberChangeSelectorTest2");
+ messageSent2.setText("Message #2 with string property TEST='test again'");
+ tool.getDefaultTopicPublisher().publish(messageSent2);
+
+ // Check and verify that first message is received
+ logger.log(Logger.Level.TRACE, "Try receiving first message (should get message)");
+ messageReceived = (TextMessage) durableTS.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.TRACE, "Did not receive any message (incorrect)");
+ throw new Exception("didn't receive any message");
+ } else if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct first message");
+ } else {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ throw new Exception("didn't get the right message");
+ }
+
+ // Check and verify that seconde message is not received
+ logger.log(Logger.Level.TRACE, "Try receiving second message (should not get message)");
+ messageReceived = (TextMessage) durableTS.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.TRACE, "Did not receive second message (correct)");
+ } else if (messageReceived.getText().equals(messageSent2.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ throw new Exception("received second message (unexpected)");
+ } else {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ throw new Exception("received unexpected message");
+ }
+
+ // need to inactivate topic subscriber before switching new subscriber
+ logger.log(Logger.Level.TRACE, "Close durable subscription");
+ durableTS.close();
+
+ // change selector
+ logger.log(Logger.Level.TRACE,
+ "Create new durable subscription with MessageSelector=\"TEST='test again'\",");
+ logger.log(Logger.Level.TRACE, "TopicName=" + tool.getDefaultTopic().getTopicName()
+ + " and SubscriptionName=" + "durableSubscriberChangeSelectorTest2");
+ durableTS = tool.getDefaultTopicSession().createDurableSubscriber(tool.getDefaultTopic(),
+ "durableSubscriberChangeSelectorTest2", "TEST = 'test again'", false);
+
+ // receive message
+ messageReceived = (TextMessage) durableTS.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.TRACE, "Did not receive any messages (correct)");
+ } else {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ throw new Exception("received unexpected message");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("durableSubscriberChangeSelectorTest2");
+ } finally {
+ cleanupSubscription(durableTS, tool.getDefaultTopicSession(), "durableSubscriberChangeSelectorTest2");
+ }
+ }
+
+ /*
+ * @testName: msgProducerNullDestinationTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:139; JMS:SPEC:158; JMS:SPEC:242; JMS:JAVADOC:103;
+ * JMS:JAVADOC:105; JMS:JAVADOC:122;
+ *
+ * @test_Strategy: Create Publisher with null Destination. Send with destination
+ * specified and receive single message. Verify message receipt.
+ */
+ @Test
+ public void msgProducerNullDestinationTopicTest() throws Exception {
+ boolean pass = true;
+ TopicPublisher tPublisher = null;
+ Topic nullTopic = null;
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ String testName = "msgProducerNullDestinationTopicTest";
+ String message = "Just a test from msgProducerNullDestinationTopicTest";
+
+ try {
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
+ tool.getDefaultTopicPublisher().close();
+
+ try {
+ tPublisher = tool.getDefaultTopicSession().createPublisher(nullTopic);
+ logger.log(Logger.Level.TRACE, "PASS: null allowed for unidentified producer");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.ERROR, "Error: unexpected Exception: ", ee);
+ pass = false;
+ }
+ tool.getDefaultTopicConnection().start();
+
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = tool.getDefaultTopicSession().createTextMessage();
+ messageSent.setText(message);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+
+ // publish to a topic and then get the message.
+ logger.log(Logger.Level.TRACE, "Publish a message");
+ tPublisher.publish(tool.getDefaultTopic(), messageSent);
+ logger.log(Logger.Level.TRACE, "Receive a message");
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO, "Publish message the second time ");
+ tPublisher.publish(tool.getDefaultTopic(), messageSent, Message.DEFAULT_DELIVERY_MODE,
+ Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
+
+ logger.log(Logger.Level.INFO, "Receiving message again");
+ messageReceived = (TextMessage) tool.getDefaultTopicSubscriber().receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "didn't get any message");
+ pass = false;
+ } else if (!messageReceived.getText().equals(messageSent.getText())) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "didn't get the right message");
+ }
+
+ if (!pass) {
+ throw new Exception("Error: failures occurred during msgProducerNullDestinationTopicTest tests");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception occurred! ", e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgProducerNullDestinationTopicTest");
+ }
+ }
+
+ /*
+ * @testName: multipleCloseTopicConnectionTest
+ *
+ * @assertion_ids: JMS:SPEC:108;
+ *
+ * @test_Strategy: Call close() twice on a connection and catch any exception.
+ */
+ @Test
+ public void multipleCloseTopicConnectionTest() throws Exception {
+ try {
+
+ // create Topic Connection
+ tool = new JmsTool(JmsTool.TOPIC, jmsUser, jmsPassword, mode);
+ tool.getDefaultTopicConnection().start();
+ logger.log(Logger.Level.TRACE, "Call close on a connection ");
+ tool.getDefaultTopicConnection().close();
+ logger.log(Logger.Level.TRACE, "Call close on a connection a second time");
+ tool.getDefaultTopicConnection().close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("multipleCloseTopicConnectionTest");
+ }
+ }
+
+ /*
+ * @testName: consumerTests
+ *
+ * @assertion_ids: JMS:SPEC:196; JMS:SPEC:158; JMS:SPEC:160; JMS:SPEC:161;
+ * JMS:SPEC:126; JMS:JAVADOC:248; JMS:SPEC:266; JMS:SPEC:267;
+ *
+ * @test_Strategy: 1. Create a new connection and send two TextMessages; 2.
+ * Create a MessageConsumer defaultConsumer to verify all messages received. 3.
+ * Create another MessageConsumer noLocalConsumer with noLocal set to true, and
+ * verify that no message can be received. 4. Create another MessageConsumer
+ * selectConsumer off the new connection with selector to verify only one
+ * message received. 5. Send a message from from default connection; 6. Verify
+ * that noLocalConsumer can receive the message from the default connection
+ */
+ @Test
+ public void consumerTests() throws Exception {
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TextMessage tempMsg = null;
+ int numMessages = 2;
+ boolean pass = true;
+ MessageConsumer defaultConsumer = null;
+ MessageConsumer selectConsumer = null;
+ MessageConsumer noLocalConsumer = null;
+ Connection newConn = null;
+ Session newSess = null;
+ MessageProducer newPub = null;
+ String testName = "consumerTests";
+
+ tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, mode);
+
+ newConn = tool.getNewConnection(JmsTool.COMMON_T, jmsUser, jmsPassword, lookup);
+ connections.add(newConn);
+ newSess = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ noLocalConsumer = newSess.createConsumer(tool.getDefaultDestination(), null, true);
+ selectConsumer = newSess.createConsumer(tool.getDefaultDestination(), "TEST = 'test'", false);
+ defaultConsumer = newSess.createConsumer(tool.getDefaultDestination());
+ newPub = newSess.createProducer(tool.getDefaultDestination());
+
+ tool.getDefaultConnection().start();
+ newConn.start();
+
+ // Create and send two messages from new connection
+ messageSent = tool.getDefaultSession().createTextMessage();
+ messageSent.setText("Just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ logger.log(Logger.Level.TRACE, "Sending message to a Topic");
+ messageSent.setBooleanProperty("lastMessage", false);
+ newPub.send(messageSent);
+
+ messageSent.setStringProperty("TEST", "test");
+ messageSent.setBooleanProperty("lastMessage", true);
+ newPub.send(messageSent);
+
+ // Verify that noLocalConsumer cannot receive any message
+ logger.log(Logger.Level.TRACE, "noLocalConsumer Receiving message");
+ messageReceived = (TextMessage) noLocalConsumer.receive(timeout);
+ if (messageReceived != null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: No_local MessageConsumer did receive local message");
+ }
+
+ // Verify that defaultConsumer received correct messages
+ logger.log(Logger.Level.TRACE, "defaultConsumer Receiving message");
+ for (int i = 0; i < numMessages; i++) {
+ messageReceived = (TextMessage) defaultConsumer.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: Did not receive message " + i);
+ } else if (!messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.ERROR, "Error: didn't get the right message " + i);
+ pass = false;
+ }
+ }
+ // Verify that selectConsumer only receive the last message
+ logger.log(Logger.Level.TRACE, "selectConsumer Receiving message");
+ messageReceived = (TextMessage) selectConsumer.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: Did not receive correct message");
+ } else if (!messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.ERROR, "Error: didn't get the right message");
+ pass = false;
+ }
+
+ // send message from default connection
+ logger.log(Logger.Level.TRACE, "sending message from default connection");
+ messageSent.setBooleanProperty("newConnection", true);
+ tool.getDefaultProducer().send(messageSent);
+
+ // Verify that noLocalConsumer now can receive message from second
+ // connection
+ logger.log(Logger.Level.TRACE, "noLocalConsumer Receiving message");
+ messageReceived = (TextMessage) noLocalConsumer.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Error: Did not receive correct message");
+ } else if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Error: didn't get the right message");
+ pass = false;
+ }
+
+ noLocalConsumer.close();
+ defaultConsumer.close();
+ selectConsumer.close();
+
+ try {
+ logger.log(Logger.Level.TRACE, "Closing new connection");
+ newConn.close();
+ } catch (Exception ex) {
+ logger.log(Logger.Level.ERROR, "Error closing the second Connection", ex);
+ }
+
+ if (pass != true)
+ throw new Exception(testName + " Failed!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+ }
+
+ /*
+ * @testName: tempTopicTests
+ *
+ * @assertion_ids: JMS:SPEC:144; JMS:SPEC:161; JMS:JAVADOC:264; JMS:JAVADOC:124;
+ * JMS:JAVADOC:837;
+ *
+ * @test_Strategy: 1. Create a TemporaryTopic from a Session. Send a TextMessage
+ * and Receive it using the TemporaryTopic. Verify the Message received
+ * correctly. 2. Try to delete the TemporaryTopic without closing
+ * MessageConsumer, verify that JMSException is thrown. 3. Close the
+ * MessageConsumer, verify that the TemporaryTopic can be deleted. 4. Try to
+ * create a MessageConsumer using Session from a different Connection, verify
+ * that JMSException is thrown.
+ */
+ @Test
+ public void tempTopicTests() throws Exception {
+ boolean pass = true;
+ TextMessage msgSent;
+ TextMessage msgReceived;
+ String testName = "tempTopicTests";
+ String message = "Just a test from tempTopicTests";
+ TemporaryTopic tempT = null;
+ Connection newConn = null;
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, jmsUser, jmsPassword, mode);
+ tool.getDefaultProducer().close();
+ tool.getDefaultConsumer().close();
+ tool.getDefaultConnection().start();
+
+ // create the TemporaryTopic
+ logger.log(Logger.Level.INFO, "Creating TemporaryTopic");
+ tempT = tool.getDefaultSession().createTemporaryTopic();
+
+ // open a new connection, create Session and Sender
+ logger.log(Logger.Level.INFO, "Create new sender for TemporaryTopic");
+ MessageProducer sender = tool.getDefaultSession().createProducer(tempT);
+ MessageConsumer receiver = tool.getDefaultSession().createConsumer(tempT);
+
+ // send message to verify TemporaryTopic
+ logger.log(Logger.Level.INFO, "Send message to TemporaryTopic");
+ msgSent = tool.getDefaultSession().createTextMessage();
+ msgSent.setText(message);
+ msgSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ sender.send(msgSent);
+
+ // try to create receiver for the TemporarTopic
+ msgReceived = (TextMessage) receiver.receive(timeout);
+
+ if (msgReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "didnot receive message");
+ } else if (!msgReceived.getText().equals(message)) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received wrong message=" + msgReceived.getText());
+ logger.log(Logger.Level.ERROR, "Should have: " + message);
+ }
+
+ try {
+ tempT.delete();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TemporaryTopic.delete() didn't throw expected Exception");
+ } catch (JMSException em) {
+ logger.log(Logger.Level.TRACE, "Received expected JMSException: ");
+ }
+ receiver.close();
+
+ try {
+ tempT.delete();
+ } catch (Exception e) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received unexpected Exception: ", e);
+ }
+
+ tempT = tool.getDefaultSession().createTemporaryTopic();
+ newConn = (Connection) tool.getNewConnection(JmsTool.COMMON_T, jmsUser, jmsPassword, lookup);
+ Session newSess = newConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ // try to create receiver for the TemporaryTopic
+ logger.log(Logger.Level.INFO,
+ "Attempt to create MessageConsumer for TemporaryTopic from another Connection");
+ try {
+ MessageConsumer newReceiver = newSess.createConsumer(tempT);
+ if (newReceiver != null)
+ logger.log(Logger.Level.TRACE, "newReceiver=" + newReceiver);
+ } catch (JMSException e) {
+ logger.log(Logger.Level.TRACE, "Received expected JMSException from createConsumer.");
+ }
+
+ if (!pass)
+ throw new Exception(testName + " failed");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ } finally {
+ try {
+ tool.getDefaultConnection().close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection in " + testName, e);
+ }
+ try {
+ newConn.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing the new Connection in " + testName, e);
+ }
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmsconsumertests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmsconsumertests/Client.java
deleted file mode 100644
index 5e0ef240dd..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmsconsumertests/Client.java
+++ /dev/null
@@ -1,396 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.appclient.jmsconsumertests;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.Destination;
-import jakarta.jms.JMSConsumer;
-import jakarta.jms.JMSContext;
-import jakarta.jms.JMSProducer;
-import jakarta.jms.MessageListener;
-import jakarta.jms.Queue;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.appclient.jmsconsumertests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null;
-
- // JMS objects
- transient ConnectionFactory cf = null;
-
- transient JMSContext context = null;
-
- transient JMSContext contextToSendMsg = null;
-
- transient JMSContext contextToCreateMsg = null;
-
- transient JMSConsumer consumer = null;
-
- transient JMSProducer producer = null;
-
- transient Destination destination = null;
-
- transient Queue queue = null;
-
- transient Topic topic = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- boolean queueTest = false;
-
- boolean topicTest = false;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- TestUtil.logMsg("Didn't get expected exception");
- throw new Exception("Didn't get expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Close JMSContext objects");
- if (context != null) {
- context.close();
- context = null;
- }
- if (contextToSendMsg != null) {
- contextToSendMsg.close();
- contextToSendMsg = null;
- }
- if (contextToCreateMsg != null) {
- contextToCreateMsg.close();
- contextToCreateMsg = null;
- }
- TestUtil.logMsg("Close JMSConsumer objects");
- if (consumer != null) {
- consumer.close();
- consumer = null;
- }
- TestUtil.logMsg("Closing default Connection");
- tool.getDefaultConnection().close();
- if (queueTest) {
- TestUtil.logMsg("Flush any messages left on Queue");
- tool.flushDestination();
- }
- tool.closeAllResources();
- producer = null;
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * @testName: queueSendRecvMessageListenerTest
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:1145; JMS:JAVADOC:1149;
- * JMS:JAVADOC:325; JMS:SPEC:264.4; JMS:SPEC:264;
- *
- * @test_Strategy: Creates a new consumer on the specified destination that
- * will deliver messages to the specified MessageListener. Tests the following
- * API method:
- *
- * JMSConsumer.setMessageListener(MessageListener)
- * JMSConsumer.getMessageListener() JMSProducer.send(Destination, Message)
- * MessageListener.onMessage(Message)
- *
- * 1 Setup MessageListener for the specified destination 2 Send a message to
- * the destination 3 Verify message received by listener
- */
- public void queueSendRecvMessageListenerTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- TestUtil.logMsg("Setup JmsTool for COMMON QUEUE");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- cf = tool.getConnectionFactory();
- tool.getDefaultConnection().close();
- destination = tool.getDefaultDestination();
- queue = (Queue) destination;
- queueTest = true;
-
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- contextToSendMsg = cf.createContext(user, password,
- JMSContext.AUTO_ACKNOWLEDGE);
- contextToCreateMsg = cf.createContext(user, password,
- JMSContext.AUTO_ACKNOWLEDGE);
-
- TestUtil.logMsg("Create JMSProducer");
- producer = contextToSendMsg.createProducer();
-
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Creates a new consumer on the specified destination that
- // will deliver messages to the specified MessageListener.
- MyMessageListener listener = new MyMessageListener();
- consumer.setMessageListener(listener);
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = contextToCreateMsg
- .createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueSendRecvMessageListenerTest");
- TestUtil.logMsg(
- "Send the TestMessage via JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
-
- TestUtil.logMsg("Poll listener waiting for TestMessage to arrive");
- TextMessage actTextMessage = null;
- for (int i = 0; i < 60; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- actTextMessage = (TextMessage) listener.getMessage();
- TestUtil.logMsg("Received TextMessage after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage (actTextMessage=NULL)");
- }
-
- TestUtil.logMsg("Check value of TextMessage returned");
- if (!actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logErr("Received [" + actTextMessage.getText() + "] expected ["
- + expTextMessage.getText() + "]");
- pass = false;
- }
-
- TestUtil.logMsg(
- "Retreive MessageListener by calling consumer.getMessageListener()");
- MessageListener messageListener = consumer.getMessageListener();
- if (messageListener == null) {
- TestUtil.logErr("getMessageListener() returned NULL");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("queueSendRecvMessageListenerTest", e);
- }
-
- if (!pass) {
- throw new Exception("queueSendRecvMessageListenerTest failed");
- }
- }
-
- /*
- * @testName: topicSendRecvMessageListenerTest
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:1145; JMS:JAVADOC:1149;
- * JMS:JAVADOC:325; JMS:SPEC:264.4; JMS:SPEC:264;
- *
- * @test_Strategy: Creates a new consumer on the specified destination that
- * will deliver messages to the specified MessageListener. Tests the following
- * API method:
- *
- * JMSConsumer.setMessageListener(MessageListener)
- * JMSConsumer.getMessageListener() JMSProducer.send(Destination, Message)
- * MessageListener.onMessage(Message)
- *
- * 1 Setup MessageListener for the specified destination 2 Send a message to
- * the destination 3 Verify message received by listener
- */
- public void topicSendRecvMessageListenerTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- TestUtil.logMsg("Setup JmsTool for COMMON TOPIC");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- cf = tool.getConnectionFactory();
- tool.getDefaultConnection().close();
- destination = tool.getDefaultDestination();
- topic = (Topic) destination;
- topicTest = true;
-
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- contextToSendMsg = cf.createContext(user, password,
- JMSContext.AUTO_ACKNOWLEDGE);
- contextToCreateMsg = cf.createContext(user, password,
- JMSContext.AUTO_ACKNOWLEDGE);
-
- TestUtil.logMsg("Create JMSProducer");
- producer = contextToSendMsg.createProducer();
-
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Creates a new consumer on the specified destination that
- // will deliver messages to the specified MessageListener.
- MyMessageListener listener = new MyMessageListener();
- consumer.setMessageListener(listener);
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = contextToCreateMsg
- .createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicSendRecvMessageListenerTest");
- TestUtil.logMsg(
- "Send the TestMessage via JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
-
- TestUtil.logMsg("Poll listener waiting for TestMessage to arrive");
- TextMessage actTextMessage = null;
- for (int i = 1; i < 60; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- actTextMessage = (TextMessage) listener.getMessage();
- TestUtil.logMsg("Received TextMessage after polling loop " + i);
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage (actTextMessage=NULL)");
- }
-
- TestUtil.logMsg("Check value of TextMessage returned");
- if (!actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logErr("Received [" + actTextMessage.getText() + "] expected ["
- + expTextMessage.getText() + "]");
- pass = false;
- }
-
- TestUtil.logMsg(
- "Retreive MessageListener by calling consumer.getMessageListener()");
- MessageListener messageListener = consumer.getMessageListener();
- if (messageListener == null) {
- TestUtil.logErr("getMessageListener() returned NULL");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("topicSendRecvMessageListenerTest", e);
- }
-
- if (!pass) {
- throw new Exception("topicSendRecvMessageListenerTest failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmsconsumertests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmsconsumertests/ClientIT.java
new file mode 100644
index 0000000000..5951cc15c2
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmsconsumertests/ClientIT.java
@@ -0,0 +1,380 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.appclient.jmsconsumertests;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.Destination;
+import jakarta.jms.JMSConsumer;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSProducer;
+import jakarta.jms.MessageListener;
+import jakarta.jms.Queue;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.appclient.jmsconsumertests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null;
+
+ // JMS objects
+ transient ConnectionFactory cf = null;
+
+ transient JMSContext context = null;
+
+ transient JMSContext contextToSendMsg = null;
+
+ transient JMSContext contextToCreateMsg = null;
+
+ transient JMSConsumer consumer = null;
+
+ transient JMSProducer producer = null;
+
+ transient Destination destination = null;
+
+ transient Queue queue = null;
+
+ transient Topic topic = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ boolean queueTest = false;
+
+ boolean topicTest = false;
+
+ /* Utility methods for tests */
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't get expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Close JMSContext objects");
+ if (context != null) {
+ context.close();
+ context = null;
+ }
+ if (contextToSendMsg != null) {
+ contextToSendMsg.close();
+ contextToSendMsg = null;
+ }
+ if (contextToCreateMsg != null) {
+ contextToCreateMsg.close();
+ contextToCreateMsg = null;
+ }
+ logger.log(Logger.Level.INFO, "Close JMSConsumer objects");
+ if (consumer != null) {
+ consumer.close();
+ consumer = null;
+ }
+ logger.log(Logger.Level.INFO, "Closing default Connection");
+ tool.getDefaultConnection().close();
+ if (queueTest) {
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ tool.flushDestination();
+ }
+ tool.closeAllResources();
+ producer = null;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: queueSendRecvMessageListenerTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:1145; JMS:JAVADOC:1149;
+ * JMS:JAVADOC:325; JMS:SPEC:264.4; JMS:SPEC:264;
+ *
+ * @test_Strategy: Creates a new consumer on the specified destination that will
+ * deliver messages to the specified MessageListener. Tests the following API
+ * method:
+ *
+ * JMSConsumer.setMessageListener(MessageListener)
+ * JMSConsumer.getMessageListener() JMSProducer.send(Destination, Message)
+ * MessageListener.onMessage(Message)
+ *
+ * 1 Setup MessageListener for the specified destination 2 Send a message to the
+ * destination 3 Verify message received by listener
+ */
+ @Test
+ public void queueSendRecvMessageListenerTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON QUEUE");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ cf = tool.getConnectionFactory();
+ tool.getDefaultConnection().close();
+ destination = tool.getDefaultDestination();
+ queue = (Queue) destination;
+ queueTest = true;
+
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ contextToSendMsg = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ contextToCreateMsg = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+
+ logger.log(Logger.Level.INFO, "Create JMSProducer");
+ producer = contextToSendMsg.createProducer();
+
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Creates a new consumer on the specified destination that
+ // will deliver messages to the specified MessageListener.
+ MyMessageListener listener = new MyMessageListener();
+ consumer.setMessageListener(listener);
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = contextToCreateMsg.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueSendRecvMessageListenerTest");
+ logger.log(Logger.Level.INFO, "Send the TestMessage via JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+
+ logger.log(Logger.Level.INFO, "Poll listener waiting for TestMessage to arrive");
+ TextMessage actTextMessage = null;
+ for (int i = 0; i < 60; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ actTextMessage = (TextMessage) listener.getMessage();
+ logger.log(Logger.Level.INFO, "Received TextMessage after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage (actTextMessage=NULL)");
+ }
+
+ logger.log(Logger.Level.INFO, "Check value of TextMessage returned");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + actTextMessage.getText() + "] expected [" + expTextMessage.getText() + "]");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO, "Retreive MessageListener by calling consumer.getMessageListener()");
+ MessageListener messageListener = consumer.getMessageListener();
+ if (messageListener == null) {
+ logger.log(Logger.Level.ERROR, "getMessageListener() returned NULL");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueSendRecvMessageListenerTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("queueSendRecvMessageListenerTest failed");
+ }
+ }
+
+ /*
+ * @testName: topicSendRecvMessageListenerTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:1145; JMS:JAVADOC:1149;
+ * JMS:JAVADOC:325; JMS:SPEC:264.4; JMS:SPEC:264;
+ *
+ * @test_Strategy: Creates a new consumer on the specified destination that will
+ * deliver messages to the specified MessageListener. Tests the following API
+ * method:
+ *
+ * JMSConsumer.setMessageListener(MessageListener)
+ * JMSConsumer.getMessageListener() JMSProducer.send(Destination, Message)
+ * MessageListener.onMessage(Message)
+ *
+ * 1 Setup MessageListener for the specified destination 2 Send a message to the
+ * destination 3 Verify message received by listener
+ */
+ @Test
+ public void topicSendRecvMessageListenerTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON TOPIC");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ cf = tool.getConnectionFactory();
+ tool.getDefaultConnection().close();
+ destination = tool.getDefaultDestination();
+ topic = (Topic) destination;
+ topicTest = true;
+
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ contextToSendMsg = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ contextToCreateMsg = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+
+ logger.log(Logger.Level.INFO, "Create JMSProducer");
+ producer = contextToSendMsg.createProducer();
+
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Creates a new consumer on the specified destination that
+ // will deliver messages to the specified MessageListener.
+ MyMessageListener listener = new MyMessageListener();
+ consumer.setMessageListener(listener);
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = contextToCreateMsg.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicSendRecvMessageListenerTest");
+ logger.log(Logger.Level.INFO, "Send the TestMessage via JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+
+ logger.log(Logger.Level.INFO, "Poll listener waiting for TestMessage to arrive");
+ TextMessage actTextMessage = null;
+ for (int i = 1; i < 60; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ actTextMessage = (TextMessage) listener.getMessage();
+ logger.log(Logger.Level.INFO, "Received TextMessage after polling loop " + i);
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage (actTextMessage=NULL)");
+ }
+
+ logger.log(Logger.Level.INFO, "Check value of TextMessage returned");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + actTextMessage.getText() + "] expected [" + expTextMessage.getText() + "]");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO, "Retreive MessageListener by calling consumer.getMessageListener()");
+ MessageListener messageListener = consumer.getMessageListener();
+ if (messageListener == null) {
+ logger.log(Logger.Level.ERROR, "getMessageListener() returned NULL");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicSendRecvMessageListenerTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("topicSendRecvMessageListenerTest failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmsconsumertests/MyMessageListener.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmsconsumertests/MyMessageListener.java
index 4cf2afc130..b9a60eb663 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmsconsumertests/MyMessageListener.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmsconsumertests/MyMessageListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,56 +19,58 @@
*/
package com.sun.ts.tests.jms.core20.appclient.jmsconsumertests;
-import com.sun.ts.lib.util.TestUtil;
+import java.lang.System.Logger;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
public class MyMessageListener implements MessageListener {
- private String name = null;
+ private static final Logger logger = (Logger) System.getLogger(MyMessageListener.class.getName());
- private Message message = null;
+ private String name = null;
- boolean complete = false;
+ private Message message = null;
- public MyMessageListener() {
- this("MyMessageListener");
- }
+ boolean complete = false;
- public MyMessageListener(String name) {
- this.name = name;
- }
+ public MyMessageListener() {
+ this("MyMessageListener");
+ }
- // getters/setters
- public String getName() {
- return name;
- }
+ public MyMessageListener(String name) {
+ this.name = name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ // getters/setters
+ public String getName() {
+ return name;
+ }
- public Message getMessage() {
- return message;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public void setMessage(Message message) {
- this.message = message;
- }
+ public Message getMessage() {
+ return message;
+ }
- public boolean isComplete() {
- return complete;
- }
+ public void setMessage(Message message) {
+ this.message = message;
+ }
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
+ public boolean isComplete() {
+ return complete;
+ }
- public void onMessage(Message message) {
- TestUtil.logMsg("Got Message: " + message);
- this.message = message;
- complete = true;
- }
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
+
+ public void onMessage(Message message) {
+ logger.log(Logger.Level.INFO, "Got Message: " + message);
+ this.message = message;
+ complete = true;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/Client.java
deleted file mode 100644
index 7c24722b02..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/Client.java
+++ /dev/null
@@ -1,2391 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2022 Contributors to Eclipse Foundation. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.appclient.jmscontextqueuetests;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.DeliveryMode;
-import jakarta.jms.Destination;
-import jakarta.jms.InvalidClientIDRuntimeException;
-import jakarta.jms.InvalidDestinationRuntimeException;
-import jakarta.jms.JMSConsumer;
-import jakarta.jms.JMSContext;
-import jakarta.jms.JMSProducer;
-import jakarta.jms.JMSRuntimeException;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.MessageFormatRuntimeException;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.Queue;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.appclient.jmscontextqueuetests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null;
-
- // JMS objects
- private transient ConnectionFactory cf = null;
-
- private transient Queue queue = null;
-
- private transient Destination destination = null;
-
- private transient JMSContext context = null;
-
- private transient JMSContext context2 = null;
-
- private transient JMSContext contextToSendMsg = null;
-
- private transient JMSContext contextToCreateMsg = null;
-
- private transient JMSConsumer consumer = null;
-
- private transient JMSProducer producer = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * Utility method to return the session mode as a String
- */
- private String printSessionMode(int sessionMode) {
- switch (sessionMode) {
- case JMSContext.SESSION_TRANSACTED:
- return "SESSION_TRANSACTED";
- case JMSContext.AUTO_ACKNOWLEDGE:
- return "AUTO_ACKNOWLEDGE";
- case JMSContext.CLIENT_ACKNOWLEDGE:
- return "CLIENT_ACKNOWLEDGE";
- case JMSContext.DUPS_OK_ACKNOWLEDGE:
- return "DUPS_OK_ACKNOWLEDGE";
- default:
- return "UNEXPECTED_SESSIONMODE";
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(3);
- connections = new ArrayList(5);
-
- // set up JmsTool for COMMON_Q setup
- TestUtil.logMsg("Setup JmsTool for COMMON_Q setup");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- queue = (Queue) destination;
- tool.getDefaultConnection().close();
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- contextToSendMsg = cf.createContext(user, password,
- JMSContext.AUTO_ACKNOWLEDGE);
- contextToCreateMsg = cf.createContext(user, password,
- JMSContext.AUTO_ACKNOWLEDGE);
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Close JMSContext objects");
- if (context != null) {
- context.close();
- context = null;
- }
- if (contextToSendMsg != null) {
- contextToSendMsg.close();
- contextToSendMsg = null;
- }
- if (contextToCreateMsg != null) {
- contextToCreateMsg.close();
- contextToCreateMsg = null;
- }
- TestUtil.logMsg("Close JMSConsumer objects");
- if (consumer != null) {
- consumer.close();
- consumer = null;
- }
- TestUtil.logMsg("Flush any messages left on Queue");
- tool.flushDestination();
- tool.closeAllResources();
- producer = null;
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * @testName: setGetClientIDTest
- *
- * @assertion_ids: JMS:JAVADOC:970; JMS:JAVADOC:1040; JMS:SPEC:264.5;
- * JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:91;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.setClientID(String clientID) JMSContext.getClientID()
- */
- public void setGetClientIDTest() throws Exception {
- boolean pass = true;
- try {
- String clientid = "myclientid";
- TestUtil.logMsg("Calling setClientID(" + clientid + ")");
- context.setClientID(clientid);
- TestUtil.logMsg(
- "Calling getClientID and expect " + clientid + " to be returned");
- String cid = context.getClientID();
- if (!cid.equals(clientid)) {
- TestUtil
- .logErr("getClientID() returned " + cid + ", expected " + clientid);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("setGetClientIDTest");
- }
-
- if (!pass) {
- throw new Exception("setGetClientIDTest failed");
- }
- }
-
- /*
- * @testName: setClientIDLateTest
- *
- * @assertion_ids: JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:94; JMS:SPEC:91;
- * JMS:JAVADOC:1040; JMS:JAVADOC:1043; JMS:SPEC:264.5;
- *
- * @test_Strategy: Create a JMSContext, send and receive a message, then try
- * to set the ClientID. Verify that IllegalStateRuntimeException is thrown.
- *
- * JMSContext.setClientID(String clientID)
- */
- public void setClientIDLateTest() throws Exception {
- boolean pass = true;
-
- try {
- TextMessage messageSent;
- TextMessage messageReceived;
- String message = "This is my message.";
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "setClientIDLateTest");
- TestUtil.logMsg("Sending TestMessage");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage != null) {
- TestUtil.logMsg("actTextMessage=" + actTextMessage.getText());
- }
-
- TestUtil.logTrace(
- "Attempt to set Client ID too late (expect IllegalStateRuntimeException)");
- try {
- context.setClientID("setClientIDLateTest");
- pass = false;
- TestUtil.logErr("IllegalStateRuntimeException was not thrown");
- } catch (jakarta.jms.IllegalStateRuntimeException is) {
- TestUtil.logMsg("IllegalStateRuntimeException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("setClientIDLateTest", e);
- }
- if (!pass) {
- throw new Exception("setClientIDLateTest failed");
- }
- }
-
- /*
- * @testName: setGetChangeClientIDTest
- *
- * @assertion_ids: JMS:SPEC:93; JMS:SPEC:95; JMS:SPEC:198; JMS:JAVADOC:1040;
- * JMS:JAVADOC:970; JMS:JAVADOC:1042; JMS:JAVADOC:1043; JMS:SPEC:264.5;
- *
- *
- * @test_Strategy: Test setClientID()/getClientID(). Make sure that the
- * clientID set is the clientID returned. Then try and reset the clientID.
- * Verify that the IllegalStateRuntimeException is thrown. 1) Use a JMSContext
- * that has no ClientID set, then call setClientID twice. 2) Try and set the
- * clientID on a second JMSContext to the clientID value of the first
- * JMSContext. Verify that InvalidClientIDRuntimeException is thrown.
- *
- * JMSContext.setClientID(String clientID) JMSContext.getClientID()
- */
- public void setGetChangeClientIDTest() throws Exception {
- boolean pass = true;
- String lookup = "MyTopicConnectionFactory";
-
- try {
- TestUtil.logMsg("Create second JMSContext with AUTO_ACKNOWLEDGE");
- context2 = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
-
- TestUtil.logMsg("Setting clientID!");
- context.setClientID("ctstest");
-
- TestUtil.logMsg("Getting clientID!");
- String clientid = context.getClientID();
-
- if (!clientid.equals("ctstest")) {
- TestUtil.logErr(
- "getClientID() returned " + clientid + ", expected ctstest");
- pass = false;
- } else {
- TestUtil.logMsg("setClientID/getClientID correct");
- }
-
- TestUtil
- .logMsg("Resetting clientID! (expect IllegalStateRuntimeException)");
- context.setClientID("changeIt");
- TestUtil.logErr("No exception was thrown on ClientID reset");
- pass = false;
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- TestUtil.logMsg("IllegalStateRuntimeException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Incorrect exception received: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Set clientID on second context to value of clientID on first "
- + "context (expect InvalidClientIDRuntimeException)");
- context2.setClientID("ctstest");
- TestUtil
- .logErr("No exception was thrown on ClientID that already exists");
- pass = false;
- } catch (InvalidClientIDRuntimeException e) {
- TestUtil.logMsg("InvalidClientIDRuntimeException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Incorrect exception received: " + e);
- pass = false;
- } finally {
- try {
- if (context2 != null) {
- context2.close();
- context2 = null;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception in finally block: " + e);
- throw new Exception("setGetChangeClientIDTest", e);
- }
- }
- if (!pass) {
- throw new Exception("setGetChangeClientIDTest");
- }
- }
-
- /*
- * @testName: setGetExceptionListenerTest
- *
- * @assertion_ids: JMS:JAVADOC:1052; JMS:JAVADOC:980;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.setExceptionListener(ExceptionListener).
- * JMSContext.getExceptionListener().
- */
- public void setGetExceptionListenerTest() throws Exception {
- boolean pass = true;
- try {
- MyExceptionListener expExceptionListener = new MyExceptionListener();
- TestUtil
- .logMsg("Calling setExceptionListener(" + expExceptionListener + ")");
- context.setExceptionListener(expExceptionListener);
- TestUtil.logMsg("Calling getExceptionListener and expect "
- + expExceptionListener + " to be returned");
- MyExceptionListener actExceptionListener = (MyExceptionListener) context
- .getExceptionListener();
- if (!actExceptionListener.equals(expExceptionListener)) {
- TestUtil.logErr("getExceptionListener() returned "
- + actExceptionListener + ", expected " + expExceptionListener);
- pass = false;
- }
- TestUtil.logMsg("Calling setExceptionListener(null)");
- context.setExceptionListener(null);
- if (context.getExceptionListener() != null) {
- TestUtil.logErr("getExceptionListener() returned "
- + context.getExceptionListener() + ", expected null");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("setGetExceptionListenerTest");
- }
-
- if (!pass) {
- throw new Exception("setGetExceptionListenerTest failed");
- }
- }
-
- /*
- * @testName: setGetAsyncTest
- *
- * @assertion_ids: JMS:JAVADOC:1182; JMS:JAVADOC:1255;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setAsync(CompletionListener). JMSProducer.getAsync().
- */
- public void setGetAsyncTest() throws Exception {
- boolean pass = true;
- try {
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- // Set and get asyncronous CompletionListener
- MyCompletionListener expCompletionListener = new MyCompletionListener();
- TestUtil.logMsg(
- "Calling JMSProducer.setAsync(" + expCompletionListener + ")");
- producer.setAsync(expCompletionListener);
- TestUtil.logMsg("Calling JMSProducer.getAsync() and expect "
- + expCompletionListener + " to be returned");
- MyCompletionListener actCompletionListener = (MyCompletionListener) producer
- .getAsync();
- if (!actCompletionListener.equals(expCompletionListener)) {
- TestUtil.logErr("getAsync() returned " + actCompletionListener
- + ", expected " + expCompletionListener);
- pass = false;
- }
-
- // Now set and get null asyncronous CompletionListener
- TestUtil.logMsg("Calling JMSProducer.setAsync(null)");
- producer.setAsync(null);
- TestUtil.logMsg(
- "Calling JMSProducer.getAsync() and expect NULL to be returned");
- if (producer.getAsync() != null) {
- TestUtil.logErr(
- "getAsync() returned " + producer.getAsync() + ", expected null");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("setGetAsyncTest");
- }
-
- if (!pass) {
- throw new Exception("setGetAsyncTest failed");
- }
- }
-
- /*
- * @testName: startStopTest
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:1076; JMS:JAVADOC:1078;
- * JMS:JAVADOC:942; JMS:JAVADOC:1102; JMS:SPEC:264; JMS:SPEC:264.5;
- *
- * @test_Strategy: Test the following APIs:
- *
- * ConnectionFactory.createContext(String, String, int) JMSContext.start()
- * JMSContext.stop() JMSContext.createConsumer(Destination)
- * JMSContext.createProducer() JMSProducer.send(Destination, Message)
- * JMSConsumer.receive(long timeout)
- *
- * 1. Create JMSContext with AUTO_ACKNOWLEDGE. This is done in the setup()
- * routine. 2. Call stop. 3. Send x messages to a Queue. 4. Create a
- * JMSConsumer to consume the messages in the Queue. 5. Try consuming messages
- * from the Queue. Should not receive any messages since the connection has
- * been stopped. 6. Call start. 7. Try consuming messages from the Queue.
- * Should receive all messages from the Queue since the connection has been
- * started.
- */
- public void startStopTest() throws Exception {
- boolean pass = true;
- try {
- TextMessage tempMsg = null;
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Stop delivery of incoming messages on JMSContext's connection
- TestUtil.logMsg("Call stop() to stop delivery of incoming messages");
- context.stop();
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- // Send "numMessages" messages to Queue
- TestUtil.logMsg("Send " + numMessages + " messages to Queue");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "startStopTest" + i);
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- // Try consuming a message from the Queue (should not receive a
- // message)
- TestUtil.logMsg("Try consuming a message on a STOPPED connection");
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("Received a message on a STOPPED connection");
- TestUtil.logErr("Message is: " + tempMsg.getText());
- pass = false;
- }
-
- // Start delivery of incoming messages on JMSContext's connection
- TestUtil.logMsg("Call start() to start delivery of incoming messages");
- context.start();
-
- TestUtil.logMsg(
- "Consume all the messages in the Queue on a STARTED connection");
- for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("JMSConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + msgCount + " missing from Queue");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + msgCount)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + msgCount + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received message: " + tempMsg.getText());
- }
- }
-
- // Try to receive one more message (should return null for no more
- // messages)
- TestUtil.logMsg("Queue should now be empty");
- TestUtil.logMsg("Try consuming one more message should return NULL");
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("JMSConsumer.receive() did not return NULL");
- TestUtil
- .logErr("JMSConsumer.receive() returned a message (unexpected)");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("startStopTest");
- }
-
- if (!pass) {
- throw new Exception("startStopTest failed");
- }
- }
-
- /*
- * @testName: createContextTest
- *
- * @assertion_ids: JMS:JAVADOC:931; JMS:SPEC:265.3;
- *
- * @test_Strategy: Creates a JMSContext with the default user identity and the
- * specified sessionMode. Tests API:
- *
- * JMSContext.createContext(int)
- */
- public void createContextTest() throws Exception {
- boolean pass = true;
- try {
-
- JMSContext newContext = null;
-
- // Test all possible session modes
- int expSessionMode[] = { JMSContext.SESSION_TRANSACTED,
- JMSContext.AUTO_ACKNOWLEDGE, JMSContext.CLIENT_ACKNOWLEDGE,
- JMSContext.DUPS_OK_ACKNOWLEDGE, };
-
- // Cycle through all session modes
- for (int i = 0; i < expSessionMode.length; i++) {
- TestUtil.logMsg("Creating context with session mode ("
- + printSessionMode(expSessionMode[i]) + ")");
- TestUtil.logMsg("Call API QueueConnectionFactory.createContext(int)");
- newContext = context.createContext(expSessionMode[i]);
- TestUtil.logMsg("Now call API JMSContext.getSessionMode()");
- TestUtil.logMsg("Calling getSessionMode and expect "
- + printSessionMode(expSessionMode[i]) + " to be returned");
- int actSessionMode = newContext.getSessionMode();
- if (actSessionMode != expSessionMode[i]) {
- TestUtil.logErr(
- "getSessionMode() returned " + printSessionMode(actSessionMode)
- + ", expected " + printSessionMode(expSessionMode[i]));
- pass = false;
- }
- newContext.close();
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("createContextTest");
- }
-
- if (!pass) {
- throw new Exception("createContextTest failed");
- }
- }
-
- /*
- * @testName: sendAndRecvCLTest1
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
- * JMS:JAVADOC:1255; JMS:SPEC:275.1; JMS:SPEC:275.5; JMS:SPEC:275.8;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data as well as onCompletion() being called. Set some
- * properties on JMSProducer and check that these properties exist on the
- * returned message after the CompletionListener's onCompletion() method has
- * been called.
- *
- * JMSContext.createProducer() JMSProducer.setAsync(CompletionListener)
- * JMSProducer.send(Destination, Message)
- */
- public void sendAndRecvCLTest1() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
-
- try {
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvCLTest1");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- // ------------------------------------------------------------------------------
- // Set JMSProducer message properties
- // Set properties for boolean, byte, short, int, long, float,
- // double, and String.
- // ------------------------------------------------------------------------------
- TestUtil.logMsg("Set primitive property types on JMSProducer");
- producer.setProperty("TESTBOOLEAN", bool);
- producer.setProperty("TESTBYTE", bValue);
- producer.setProperty("TESTDOUBLE", nDouble);
- producer.setProperty("TESTFLOAT", nFloat);
- producer.setProperty("TESTINT", nInt);
- producer.setProperty("TESTLONG", nLong);
- producer.setProperty("TESTSHORT", nShort);
- producer.setProperty("TESTSTRING", "test");
-
- // ------------------------------------------------------------------------------
- // Set JMSProducer message properties
- // Set properties for Boolean, Byte, Short, Int, Long, Float,
- // Double, and String.
- // ------------------------------------------------------------------------------
- TestUtil.logMsg("Set Object property types on JMSProducer");
- producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
- producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
- producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
- producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
- producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
- producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
- producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
- producer.setProperty("OBJTESTSTRING", "test");
-
- TestUtil.logMsg("Calling JMSProducer.setAsync(CompletionListener)");
- producer.setAsync(listener);
- TestUtil.logMsg("Calling JMSProducer.send(Destination,Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive TextMessage");
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- TextMessage actTextMessage = null;
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
-
- // --------------------------------------------------------------------------------------
- // Retrieve the properties from the received TextMessage and verify
- // that they are correct
- // Get properties for boolean, byte, short, int, long, float,
- // double, and String.
- // -------------------------------------------------------------------------------------
- TestUtil.logMsg(
- "Retrieve and verify that TextMessage message properties were set correctly");
- if (actTextMessage.getBooleanProperty("TESTBOOLEAN") == bool) {
- TestUtil.logMsg("Pass: getBooleanProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Fail: incorrect value returned from getBooleanProperty");
- pass = false;
- }
- if (actTextMessage.getByteProperty("TESTBYTE") == bValue) {
- TestUtil.logMsg("Pass: getByteProperty returned correct value");
- } else {
- TestUtil.logMsg("Fail: incorrect value returned from getByteProperty");
- pass = false;
- }
- if (actTextMessage.getLongProperty("TESTLONG") == nLong) {
- TestUtil.logMsg("Pass: getLongProperty returned correct value");
- } else {
- TestUtil.logMsg("Fail: incorrect value returned from getLongProperty");
- pass = false;
- }
- if (actTextMessage.getStringProperty("TESTSTRING").equals(testString)) {
- TestUtil.logMsg("Pass: getStringProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Fail: incorrect value returned from getStringProperty");
- pass = false;
- }
- if (actTextMessage.getDoubleProperty("TESTDOUBLE") == nDouble) {
- TestUtil.logMsg("Pass: getDoubleProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Fail: incorrect value returned from getDoubleProperty");
- pass = false;
- }
- if (actTextMessage.getFloatProperty("TESTFLOAT") == nFloat) {
- TestUtil.logMsg("Pass: getFloatProperty returned correct value");
- } else {
- TestUtil.logMsg("Fail: incorrect value returned from getFloatProperty");
- pass = false;
- }
- if (actTextMessage.getIntProperty("TESTINT") == nInt) {
- TestUtil.logMsg("Pass: getIntProperty returned correct value");
- } else {
- TestUtil.logMsg("Fail: incorrect value returned from getIntProperty");
- pass = false;
- }
- if (actTextMessage.getShortProperty("TESTSHORT") == nShort) {
- TestUtil.logMsg("Pass: getShortProperty returned correct value");
- } else {
- TestUtil.logMsg("Fail: incorrect value returned from getShortProperty");
- pass = false;
- }
-
- // --------------------------------------------------------------------------------------
- // Retrieve the properties from the received TextMessage and verify
- // that they are correct
- // Get properties for Boolean, Byte, Short, Integer, Long, Float,
- // Double, and String.
- // --------------------------------------------------------------------------------------
- if (((Boolean) actTextMessage.getObjectProperty("OBJTESTBOOLEAN"))
- .booleanValue() == bool) {
- TestUtil
- .logMsg("Pass: getObjectProperty returned correct Boolean value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Boolean value returned from getObjectProperty");
- pass = false;
- }
- if (((Byte) actTextMessage.getObjectProperty("OBJTESTBYTE"))
- .byteValue() == bValue) {
- TestUtil.logMsg("Pass: getObjectProperty returned correct Byte value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Byte value returned from getObjectProperty");
- pass = false;
- }
- if (((Long) actTextMessage.getObjectProperty("OBJTESTLONG"))
- .longValue() == nLong) {
- TestUtil.logMsg("Pass: getObjectProperty returned correct Long value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Long value returned from getObjectProperty");
- pass = false;
- }
- if (((String) actTextMessage.getObjectProperty("OBJTESTSTRING"))
- .equals(testString)) {
- TestUtil
- .logMsg("Pass: getObjectProperty returned correct String value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect String value returned from getObjectProperty");
- pass = false;
- }
- if (((Double) actTextMessage.getObjectProperty("OBJTESTDOUBLE"))
- .doubleValue() == nDouble) {
- TestUtil
- .logMsg("Pass: getObjectProperty returned correct Double value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Double value returned from getObjectProperty");
- pass = false;
- }
- if (((Float) actTextMessage.getObjectProperty("OBJTESTFLOAT"))
- .floatValue() == nFloat) {
- TestUtil.logMsg("Pass: getObjectProperty returned correct Float value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Float value returned from getObjectProperty");
- pass = false;
- }
- if (((Integer) actTextMessage.getObjectProperty("OBJTESTINT"))
- .intValue() == nInt) {
- TestUtil
- .logMsg("Pass: getObjectProperty returned correct Integer value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Integer value returned from getObjectProperty");
- pass = false;
- }
- if (((Short) actTextMessage.getObjectProperty("OBJTESTSHORT"))
- .shortValue() == nShort) {
- TestUtil.logMsg("Pass: getObjectProperty returned correct Short value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Short value returned from getObjectProperty");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvCLTest1", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvCLTest1 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvCLTest2
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
- * JMS:JAVADOC:1255; JMS:JAVADOC:1259; JMS:JAVADOC:1303;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data as well as onCompletion() being called.
- *
- * JMSContext.createProducer() JMSProducer.setDeliveryMode(int)
- * JMSProducer.setPriority(int) JMSProducer.setTimeToLive(long)
- * JMSProducer.setAsync(CompletionListener) JMSProducer.send(Destination,
- * Message)
- */
- public void sendAndRecvCLTest2() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvCLTest2");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- TestUtil.logMsg("Calling JMSProducer.setAsync(CompletionListener)");
- producer.setAsync(listener);
- TestUtil.logMsg("Set delivery mode, priority, and time to live");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- producer.setPriority(Message.DEFAULT_PRIORITY);
- producer.setTimeToLive(0L);
- TestUtil.logMsg("Calling JMSProducer.send(Destination,Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive TextMessage");
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- TextMessage actTextMessage = null;
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Check the values in TextMessage, deliverymode, priority, time to live");
- if (!actTextMessage.getText().equals(expTextMessage.getText())
- || actTextMessage.getJMSDeliveryMode() != DeliveryMode.PERSISTENT
- || actTextMessage.getJMSPriority() != Message.DEFAULT_PRIORITY
- || actTextMessage.getJMSExpiration() != 0L) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- TestUtil.logErr("DeliveryMode=" + actTextMessage.getJMSDeliveryMode()
- + ", expected " + expTextMessage.getJMSDeliveryMode());
- TestUtil.logErr("Priority=" + actTextMessage.getJMSPriority()
- + ", expected " + expTextMessage.getJMSPriority());
- TestUtil.logErr("TimeToLive=" + actTextMessage.getJMSExpiration()
- + ", expected " + expTextMessage.getJMSExpiration());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvCLTest2", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvCLTest2 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvMsgOfEachTypeCLTest
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
- * JMS:JAVADOC:1255; JMS:JAVADOC:1259; JMS:JAVADOC:1303;
- *
- * @test_Strategy: Send and receive messages of each message type: Message,
- * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Verify
- * the send and recv of data as well as onCompletion() being called in
- * CompletionListener.
- *
- * JMSContext.createProducer() JMSProducer.setAsync(CompletionListener)
- * JMSContext.createMessage() JMSContext.createBytesMessage()
- * JMSContext.createMapMessage() JMSContext.createObjectMessage()
- * JMSContext.createStreamMessage() JMSContext.createTextMessage(String)
- * JMSProducer.send(Destination, Message)
- */
- public void sendAndRecvMsgOfEachTypeCLTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
-
- // send and receive Message
- TestUtil.logMsg("Send and receive Message");
- Message msg = context.createMessage();
- TestUtil.logMsg("Set some values in Message");
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeCLTest");
- msg.setBooleanProperty("booleanProperty", true);
- MyCompletionListener2 listener = new MyCompletionListener2();
- producer = context.createProducer();
- producer.setAsync(listener);
- producer.send(destination, msg);
- TestUtil.logMsg("Poll listener until we receive Message");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- Message actMessage = null;
- if (listener.isComplete())
- actMessage = (Message) listener.getMessage();
-
- if (actMessage == null) {
- TestUtil.logErr("Did not receive Message");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in Message");
- if (actMessage.getBooleanProperty("booleanProperty") == true) {
- TestUtil.logMsg("booleanproperty is correct");
- } else {
- TestUtil.logMsg("booleanproperty is incorrect");
- pass = false;
- }
- }
-
- // send and receive BytesMessage
- TestUtil.logMsg("Send and receive BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeCLTest");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- bMsg.reset();
- listener = new MyCompletionListener2();
- producer = context.createProducer();
- producer.setAsync(listener);
- producer.send(destination, bMsg);
- TestUtil.logMsg("Poll listener until we receive BytesMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- BytesMessage bMsgRecv = null;
- if (listener.isComplete())
- bMsgRecv = (BytesMessage) listener.getMessage();
- if (bMsgRecv == null) {
- TestUtil.logErr("Did not receive BytesMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in BytesMessage");
- if (bMsgRecv.readByte() == (byte) 1) {
- TestUtil.logMsg("bytevalue is correct");
- } else {
- TestUtil.logMsg("bytevalue is incorrect");
- pass = false;
- }
- if (bMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive MapMessage
- TestUtil.logMsg("Send and receive MapMessage");
- MapMessage mMsg = context.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeCLTest");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- listener = new MyCompletionListener2();
- producer = context.createProducer();
- producer.setAsync(listener);
- producer.send(destination, mMsg);
- TestUtil.logMsg("Poll listener until we receive MapMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- MapMessage mMsgRecv = null;
- if (listener.isComplete())
- mMsgRecv = (MapMessage) listener.getMessage();
- if (mMsgRecv == null) {
- TestUtil.logErr("Did not receive MapMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in MapMessage");
- Enumeration list = mMsgRecv.getMapNames();
- String name = null;
- while (list.hasMoreElements()) {
- name = (String) list.nextElement();
- if (name.equals("booleanvalue")) {
- if (mMsgRecv.getBoolean(name) == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logErr("booleanvalue is incorrect");
- pass = false;
- }
- } else if (name.equals("intvalue")) {
- if (mMsgRecv.getInt(name) == 10) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logErr("intvalue is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Unexpected name of [" + name + "] in MapMessage");
- pass = false;
- }
- }
- }
-
- // send and receive ObjectMessage
- TestUtil.logMsg("Send and receive ObjectMessage");
- StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
- TestUtil.logMsg("Set some values in ObjectMessage");
- ObjectMessage oMsg = context.createObjectMessage();
- oMsg.setObject(sb1);
- oMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeCLTest");
- listener = new MyCompletionListener2();
- producer = context.createProducer();
- producer.setAsync(listener);
- producer.send(destination, oMsg);
- TestUtil.logMsg("Poll listener until we receive ObjectMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- ObjectMessage oMsgRecv = null;
- if (listener.isComplete())
- oMsgRecv = (ObjectMessage) listener.getMessage();
- if (oMsgRecv == null) {
- TestUtil.logErr("Did not receive ObjectMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in ObjectMessage");
- StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
- if (sb2.toString().equals(sb1.toString())) {
- TestUtil.logMsg("objectvalue is correct");
- } else {
- TestUtil.logErr("objectvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive StreamMessage
- TestUtil.logMsg("Send and receive StreamMessage");
- StreamMessage sMsg = context.createStreamMessage();
- TestUtil.logMsg("Set some values in StreamMessage");
- sMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeCLTest");
- sMsg.writeBoolean(true);
- sMsg.writeInt((int) 22);
- sMsg.reset();
- listener = new MyCompletionListener2();
- producer = context.createProducer();
- producer.setAsync(listener);
- producer.send(destination, sMsg);
- TestUtil.logMsg("Poll listener until we receive StreamMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- StreamMessage sMsgRecv = null;
- if (listener.isComplete())
- sMsgRecv = (StreamMessage) listener.getMessage();
- if (sMsgRecv == null) {
- TestUtil.logErr("Did not receive StreamMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in StreamMessage");
- if (sMsgRecv.readBoolean() == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logMsg("booleanvalue is incorrect");
- pass = false;
- }
- if (sMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive TextMessage
- TestUtil.logMsg("Send and receive TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeCLTest");
- TestUtil.logMsg("Calling JMSProducer.send(Destination,Message)");
- listener = new MyCompletionListener2();
- producer = context.createProducer();
- producer.setAsync(listener);
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive TextMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- TextMessage actTextMessage = null;
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the values in TextMessage");
- if (!actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvMsgOfEachTypeCLTest", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvMsgOfEachTypeCLTest failed");
- }
- }
-
- /*
- * @testName: sendAndRecvMsgOfEachTypeMLTest
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
- * JMS:JAVADOC:1255; JMS:JAVADOC:1259; JMS:JAVADOC:1303;
- *
- * @test_Strategy: Send and receive messages of each message type: Message,
- * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Verify
- * the send and recv of data as well as onMessage() being called in
- * MessageListener.
- *
- * JMSContext.createProducer() JMSProducer.setAsync(CompletionListener)
- * JMSContext.createMessage() JMSContext.createBytesMessage()
- * JMSContext.createMapMessage() JMSContext.createObjectMessage()
- * JMSContext.createStreamMessage() JMSContext.createTextMessage(String)
- * JMSProducer.send(Destination, Message)
- */
- public void sendAndRecvMsgOfEachTypeMLTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
-
- // send and receive Message
- TestUtil.logMsg("Send and receive Message");
- Message msg = context.createMessage();
- TestUtil.logMsg("Set some values in Message");
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeMLTest");
- msg.setBooleanProperty("booleanProperty", true);
- MyMessageListener2 listener = new MyMessageListener2();
- consumer = context.createConsumer(destination);
- consumer.setMessageListener(listener);
- producer = contextToSendMsg.createProducer();
- producer.send(destination, msg);
- TestUtil.logMsg("Poll listener until we receive Message");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- Message actMessage = null;
- if (listener.isComplete())
- actMessage = (Message) listener.getMessage();
-
- if (actMessage == null) {
- TestUtil.logErr("Did not receive Message");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in Message");
- if (actMessage.getBooleanProperty("booleanProperty") == true) {
- TestUtil.logMsg("booleanproperty is correct");
- } else {
- TestUtil.logMsg("booleanproperty is incorrect");
- pass = false;
- }
- }
-
- // send and receive BytesMessage
- TestUtil.logMsg("Send and receive BytesMessage");
- BytesMessage bMsg = contextToCreateMsg.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeMLTest");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- listener = new MyMessageListener2();
- consumer.setMessageListener(listener);
- producer = contextToSendMsg.createProducer();
- producer.send(destination, bMsg);
- TestUtil.logMsg("Poll listener until we receive BytesMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- BytesMessage bMsgRecv = null;
- if (listener.isComplete())
- bMsgRecv = (BytesMessage) listener.getMessage();
- if (bMsgRecv == null) {
- TestUtil.logErr("Did not receive BytesMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in BytesMessage");
- if (bMsgRecv.readByte() == (byte) 1) {
- TestUtil.logMsg("bytevalue is correct");
- } else {
- TestUtil.logMsg("bytevalue is incorrect");
- pass = false;
- }
- if (bMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive MapMessage
- TestUtil.logMsg("Send and receive MapMessage");
- MapMessage mMsg = contextToCreateMsg.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeMLTest");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- listener = new MyMessageListener2();
- consumer.setMessageListener(listener);
- producer = contextToSendMsg.createProducer();
- producer.send(destination, mMsg);
- TestUtil.logMsg("Poll listener until we receive MapMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- MapMessage mMsgRecv = null;
- if (listener.isComplete())
- mMsgRecv = (MapMessage) listener.getMessage();
- if (mMsgRecv == null) {
- TestUtil.logErr("Did not receive MapMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in MapMessage");
- Enumeration list = mMsgRecv.getMapNames();
- String name = null;
- while (list.hasMoreElements()) {
- name = (String) list.nextElement();
- if (name.equals("booleanvalue")) {
- if (mMsgRecv.getBoolean(name) == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logErr("booleanvalue is incorrect");
- pass = false;
- }
- } else if (name.equals("intvalue")) {
- if (mMsgRecv.getInt(name) == 10) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logErr("intvalue is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Unexpected name of [" + name + "] in MapMessage");
- pass = false;
- }
- }
- }
-
- // send and receive ObjectMessage
- TestUtil.logMsg("Send and receive ObjectMessage");
- StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
- TestUtil.logMsg("Set some values in ObjectMessage");
- ObjectMessage oMsg = contextToCreateMsg.createObjectMessage();
- oMsg.setObject(sb1);
- oMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeMLTest");
- listener = new MyMessageListener2();
- consumer.setMessageListener(listener);
- producer = contextToSendMsg.createProducer();
- producer.send(destination, oMsg);
- TestUtil.logMsg("Poll listener until we receive ObjectMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- ObjectMessage oMsgRecv = null;
- if (listener.isComplete())
- oMsgRecv = (ObjectMessage) listener.getMessage();
- if (oMsgRecv == null) {
- TestUtil.logErr("Did not receive ObjectMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in ObjectMessage");
- StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
- if (sb2.toString().equals(sb1.toString())) {
- TestUtil.logMsg("objectvalue is correct");
- } else {
- TestUtil.logErr("objectvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive StreamMessage
- TestUtil.logMsg("Send and receive StreamMessage");
- StreamMessage sMsg = contextToCreateMsg.createStreamMessage();
- TestUtil.logMsg("Set some values in StreamMessage");
- sMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeMLTest");
- sMsg.writeBoolean(true);
- sMsg.writeInt((int) 22);
- listener = new MyMessageListener2();
- consumer.setMessageListener(listener);
- producer = contextToSendMsg.createProducer();
- producer.send(destination, sMsg);
- TestUtil.logMsg("Poll listener until we receive StreamMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- StreamMessage sMsgRecv = null;
- if (listener.isComplete())
- sMsgRecv = (StreamMessage) listener.getMessage();
- if (sMsgRecv == null) {
- TestUtil.logErr("Did not receive StreamMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in StreamMessage");
- if (sMsgRecv.readBoolean() == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logMsg("booleanvalue is incorrect");
- pass = false;
- }
- if (sMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive TextMessage
- TestUtil.logMsg("Send and receive TextMessage");
- TextMessage expTextMessage = contextToCreateMsg
- .createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeMLTest");
- TestUtil.logMsg("Calling JMSProducer.send(Destination,Message)");
- listener = new MyMessageListener2();
- consumer.setMessageListener(listener);
- producer = contextToSendMsg.createProducer();
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive TextMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- TextMessage actTextMessage = null;
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the values in TextMessage");
- if (!actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvMsgOfEachTypeMLTest", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvMsgOfEachTypeMLTest failed");
- }
- }
-
- /*
- * @testName: messageOrderCLQueueTest
- *
- * @assertion_ids: JMS:SPEC:275.2; JMS:SPEC:275.7;
- *
- * @test_Strategy: Send async messages to a queue and receive them. Verify
- * that the text of each matches the order of the text in the sent messages.
- */
- public void messageOrderCLQueueTest() throws Exception {
- boolean pass = true;
- try {
- TextMessage sentTextMessage;
- String text[] = new String[numMessages];
-
- // Create CompletionListener for Message to be sent
- TestUtil.logMsg("Creating MyCompletionListener");
- MyCompletionListener listener = new MyCompletionListener(numMessages);
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- TestUtil.logMsg("Calling JMSProducer.setAsync(CompletionListener)");
- producer.setAsync(listener);
-
- // create and send async messages to queue
- TestUtil
- .logMsg("Sending " + numMessages + " asynchronous messages to queue");
- for (int i = 0; i < numMessages; i++) {
- text[i] = "message order test " + i;
- sentTextMessage = context.createTextMessage();
- sentTextMessage.setText(text[i]);
- sentTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "messageOrderCLQueueTest" + i);
- TestUtil.logMsg("Sending TextMessage: " + sentTextMessage.getText());
- producer.send(destination, sentTextMessage);
- }
-
- TestUtil.logMsg("Poll listener until we receive all " + numMessages
- + " TextMessage's from CompletionListener");
- for (int i = 0; !listener.gotAllMsgs() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
-
- for (int i = 0; i < numMessages; i++) {
- TextMessage actTextMessage = null;
- if (listener.haveMsg(i))
- actTextMessage = (TextMessage) listener.getMessage(i);
- if (actTextMessage == null) {
- TestUtil.logMsg("Did not receive TextMessage " + i + " (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("Received message: " + actTextMessage.getText());
- if (!actTextMessage.getText().equals(text[i])) {
- TestUtil.logMsg("Received message: " + actTextMessage.getText());
- TestUtil.logMsg("Should have received: " + text[i]);
- TestUtil.logErr("Received wrong message (wrong order)");
- pass = false;
- }
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("messageOrderCLQueueTest", e);
- }
-
- if (!pass)
- throw new Exception("messageOrderCLQueueTest failed");
- }
-
- /*
- * @testName: commitRollbackTest
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:914; JMS:JAVADOC:995;
- * JMS:JAVADOC:942; JMS:JAVADOC:1102; JMS:JAVADOC:847; JMS:SPEC:275.3;
- *
- * @test_Strategy: Test the following APIs:
- *
- * ConnectionFactory.createContext(String, String, int)
- * JMSProducer.send(Destination, Message) JMSContext.commit()
- * JMSContext.rollback() JMSContext.createConsumer(Destination)
- * JMSConsumer.receive(long timeout)
- *
- * 1. Create JMSContext with SESSION_TRANSACTED. This is done in the setup()
- * routine. 2. Send x messages to a Queue. 3. Call rollback() to rollback the
- * sent messages. 4. Create a JMSConsumer to consume the messages in the
- * Queue. Should not receive any messages since the sent messages were rolled
- * back. Verify that no messages are received. 5. Send x messages to a Queue.
- * 6. Call commit() to commit the sent messages. 7. Create a JMSConsumer to
- * consume the messages in the Queue. Should receive all the messages since
- * the sent messages were committed. Verify that all messages are received.
- */
- public void commitRollbackTest() throws Exception {
- boolean pass = true;
- try {
- TextMessage tempMsg = null;
-
- // Close conttext created in setup()
- context.close();
-
- // create JMSContext with SESSION_TRANSACTED then create
- // consumer/producer
- TestUtil
- .logMsg("Create transacted JMSContext, JMSConsumer and JMSProducer");
- context = cf.createContext(user, password, JMSContext.SESSION_TRANSACTED);
- producer = context.createProducer();
- consumer = context.createConsumer(destination);
-
- // Send "numMessages" messages to Queue and call rollback
- TestUtil.logMsg(
- "Send " + numMessages + " messages to Queue and call rollback()");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "commitRollbackTest" + i);
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- // Call rollback() to rollback the sent messages
- TestUtil.logMsg("Calling rollback() to rollback the sent messages");
- context.rollback();
-
- TestUtil.logMsg(
- "Should not consume any messages in Queue since rollback() was called");
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("Received message " + tempMsg.getText()
- + ", expected NULL (NO MESSAGES)");
- pass = false;
- } else {
- TestUtil.logMsg("Received no messages (CORRECT)");
- }
-
- // Send "numMessages" messages to Queue and call commit
- TestUtil.logMsg(
- "Send " + numMessages + " messages to Queue and call commit()");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "commitRollbackTest" + i);
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- // Call commit() to commit the sent messages
- TestUtil.logMsg("Calling commit() to commit the sent messages");
- context.commit();
-
- TestUtil.logMsg(
- "Should consume all messages in Queue since commit() was called");
- for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("JMSConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + msgCount + " missing from Queue");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + msgCount)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + msgCount + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received message: " + tempMsg.getText());
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("commitRollbackTest");
- }
-
- if (!pass) {
- throw new Exception("commitRollbackTest failed");
- }
- }
-
- /*
- * @testName: recoverAckTest
- *
- * @assertion_ids: JMS:JAVADOC:992; JMS:JAVADOC:909;
- *
- * @test_Strategy: Send messages to destination in a CLIENT_ACKNOWLEDGE
- * session. Receive all the messages without acknowledge and call recover on
- * context. Receive for a second time all the messages and follow with an
- * acknowledge.
- *
- * JMSContext.recover() JMSContext.acknowledge()
- */
- public void recoverAckTest() throws Exception {
- boolean pass = true;
- TextMessage textMessage = null;
- try {
- // Close JMSContext created in setup() method
- TestUtil.logMsg("Close JMSContext created in setup() method");
- context.close();
-
- // Create JMSContext with CLIENT_ACKNOWLEDGE
- TestUtil.logMsg(
- "Close JMSContext with CLIENT_ACKNOWLEDGE and create consumer/producer");
- context = cf.createContext(user, password, JMSContext.CLIENT_ACKNOWLEDGE);
-
- // Create JMSConsumer from JMSContext
- consumer = context.createConsumer(destination);
-
- // Create JMSProducer from JMSContext
- producer = context.createProducer();
-
- // send messages
- TestUtil.logMsg("Send " + numMessages + " messages");
- for (int i = 0; i < numMessages; i++) {
- String message = "text message " + i;
- textMessage = context.createTextMessage(message);
- textMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "recoverAckTest" + i);
- producer.send(destination, textMessage);
- TestUtil.logMsg("Sent message " + i);
- }
-
- // receive messages but do not acknowledge
- TestUtil.logMsg(
- "Receive " + numMessages + " messages but do not acknowledge");
- for (int i = 0; i < numMessages; i++) {
- TestUtil.logMsg("Receiving message " + i);
- textMessage = (TextMessage) consumer.receive(timeout);
- if (textMessage == null) {
- pass = false;
- TestUtil.logErr("Did not receive message " + i);
- } else {
- TestUtil.logMsg("Received message " + i);
- }
- }
-
- TestUtil.logMsg("Call JMSContext.recover()");
- context.recover();
-
- TestUtil.logMsg(
- "Receive " + numMessages + " messages again then acknowledge");
- // receive messages a second time followed by acknowledge
- for (int i = 0; i < numMessages; i++) {
- TestUtil.logMsg("Receiving message " + i);
- textMessage = (TextMessage) consumer.receive(timeout);
- if (textMessage == null) {
- pass = false;
- TestUtil.logErr("Did not receive message " + i);
- } else {
- TestUtil.logMsg("Received message " + i);
- }
- }
-
- // Acknowledge all messages
- TestUtil.logMsg(
- "Acknowledge all messages by calling JMSContext.acknowledge()");
- context.acknowledge();
-
- TestUtil.logMsg("Now try receiving a message (should get NONE)");
- textMessage = (TextMessage) consumer.receive(timeout);
- if (textMessage != null) {
- TestUtil.logErr(
- "Received message " + textMessage.getText() + " (Expected NONE)");
- pass = false;
- } else {
- TestUtil.logMsg("Received no message (Correct)");
- }
- } catch (Exception e) {
- TestUtil.logErr("recoverAckTest failed: ", e);
- throw new Exception("recoverAckTest failed", e);
- }
-
- if (!pass)
- throw new Exception("recoverAckTest failed!!!");
- }
-
- /*
- * @testName: invalidDestinationRuntimeExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1237;
- *
- * @test_Strategy: Test InvalidDestinationRuntimeException conditions from API
- * methods with CompletionListener.
- *
- * Tests the following exception conditions:
- *
- * InvalidDestinationRuntimeException
- */
- public void invalidDestinationRuntimeExceptionTests() throws Exception {
- boolean pass = true;
- Destination invalidDestination = null;
- Queue invalidQueue = null;
- String message = "Where are you!";
- Map mapMsgSend = new HashMap();
- mapMsgSend.put("StringValue", "sendAndRecvTest7");
- mapMsgSend.put("BooleanValue", true);
- mapMsgSend.put("IntValue", (int) 10);
- try {
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Creating JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- // send to an invalid destination
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "invalidDestinationRuntimeExceptionTests");
-
- // Create CompetionListener
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Message) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg("Calling JMSProducer.setAsync(CompletionListener)");
- producer.setAsync(listener);
- TestUtil.logMsg(
- "Calling JMSProducer.send(Destination, Message) -> expect InvalidDestinationRuntimeException");
- producer.send(invalidDestination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- if (listener.isComplete()) {
- exception = listener.getException();
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof InvalidDestinationRuntimeException) {
- TestUtil.logMsg(
- "Exception is expected InvalidDestinationRuntimeException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected InvalidDestinationRuntimeException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("invalidDestinationRuntimeExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("invalidDestinationRuntimeExceptionTests failed");
- }
- }
-
- /*
- * @testName: messageFormatRuntimeExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1236;
- *
- * @test_Strategy: Test MessageFormatRuntimeException conditions from API
- * methods with CompletionListener.
- *
- * Tests the following exception conditions:
- *
- * MessageFormatRuntimeException
- */
- public void messageFormatRuntimeExceptionTests() throws Exception {
- boolean pass = true;
- try {
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Creating JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- // Create CompetionListener
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Message) for MessageFormatRuntimeException");
- try {
- TestUtil.logMsg("Calling JMSProducer.setAsync(CompletionListener)");
- producer.setAsync(listener);
- TestUtil.logMsg(
- "Calling JMSProducer.send(Destination, Message) -> expect MessageFormatRuntimeException");
- producer.send(destination, (Message) null);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- if (listener.isComplete()) {
- exception = listener.getException();
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof MessageFormatRuntimeException) {
- TestUtil
- .logMsg("Exception is expected MessageFormatRuntimeException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected MessageFormatRuntimeException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Got MessageFormatRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected MessageFormatRuntimeException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("messageFormatRuntimeExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("messageFormatRuntimeExceptionTests failed");
- }
- }
-
- /*
- * @testName: jMSRuntimeExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1235;
- *
- * @test_Strategy: Test JMSRuntimeException conditions from API methods with
- * CompletionListener.
- *
- * Set delivery mode to -1 on JMSProducer and then try and send async message
- * to CompletionListener. The CompletionListener MUST throw
- * JMSRuntimeException.
- *
- * Set priority to -1 on JMSProducer and then try and send async message to
- * CompletionListener. The CompletionListener MUST throw JMSRuntimeException.
- */
- public void jMSRuntimeExceptionTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Creating JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "jMSRuntimeExceptionTests");
- try {
- TestUtil.logMsg("Set completion listener");
- producer.setAsync(listener);
- TestUtil.logMsg("Try and set an invalid delivbery mode of -1 on send");
- producer.setDeliveryMode(-1);
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- if (listener.isComplete()) {
- exception = listener.getException();
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof JMSRuntimeException) {
- TestUtil.logMsg("Exception is expected JMSRuntimeException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected JMSRuntimeException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (JMSRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSRuntimeException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Set completion listener");
- producer.setAsync(listener);
- listener.setComplete(false);
- TestUtil.logMsg("Try and set an invalid priority of -1 on send");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- producer.setPriority(-1);
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof JMSRuntimeException) {
- TestUtil.logMsg("Exception is expected JMSRuntimeException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected JMSRuntimeException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (JMSRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSRuntimeException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("jMSRuntimeExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("jMSRuntimeExceptionTests failed");
- }
- }
-
- /*
- * @testName: illegalStateRuntimeExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1353; JMS:JAVADOC:1354; JMS:JAVADOC:917;
- * JMS:JAVADOC:997;
- *
- * @test_Strategy: Test IllegalStateRuntimeException conditions.
- *
- * 1) Calling JMSContext.stop() in a MessageListener MUST throw
- * IllegalStateRuntimeException. 2) Calling JMSContext.close() from a
- * CompletionListener MUST throw IllegalStateRuntimeException. 3) Calling
- * JMSContext.commit() or JMSContext.rollback() in a CompletionListener MUST
- * throw IllegalStateRuntimeException.
- */
- public void illegalStateRuntimeExceptionTests() throws Exception {
- boolean pass = true;
- try {
- // Create JMSProducer/JMSConsumer from JMSContext
- TestUtil.logMsg("Creating JMSProducer/JMSConsumer");
- producer = contextToSendMsg.createProducer();
- consumer = context.createConsumer(destination);
-
- TestUtil.logMsg("-----------------------------------------------------");
- TestUtil.logMsg("CompletionListener IllegalStateRuntimeException Tests");
- TestUtil.logMsg("-----------------------------------------------------");
- TestUtil.logMsg(
- "Testing JMSContext.commit() from CompletionListener (expect IllegalStateRuntimeException)");
- try {
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context
- .createTextMessage("Call commit method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateRuntimeExceptionTests");
-
- TestUtil.logMsg(
- "Send async message specifying CompletionListener to recieve async message");
- TestUtil.logMsg(
- "CompletionListener will call JMSContext.commit() (expect IllegalStateRuntimeException)");
- MyCompletionListener listener = new MyCompletionListener(context);
- producer.setAsync(listener);
- producer.send(destination, expTextMessage);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until we receive exception");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil.logMsg(
- "Check if we got correct exception from JMSContext.commit()");
- if (listener.gotException()) {
- if (listener.gotCorrectException()) {
- TestUtil.logMsg("Got correct IllegalStateRuntimeException");
- } else {
- TestUtil.logErr("Expected IllegalStateRuntimeException, received: "
- + listener.getException());
- pass = false;
- }
- } else {
- TestUtil.logErr(
- "Expected IllegalStateRuntimeException, got no exception");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalStateRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.rollback() from CompletionListener (expect IllegalStateRuntimeException)");
- try {
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context
- .createTextMessage("Call rollback method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateRuntimeExceptionTests");
-
- TestUtil.logMsg(
- "Send async message specifying CompletionListener to recieve async message");
- TestUtil.logMsg(
- "CompletionListener will call JMSContext.rollback() (expect IllegalStateRuntimeException)");
- MyCompletionListener listener = new MyCompletionListener(
- contextToSendMsg);
- producer.setAsync(listener);
- listener.setComplete(false);
- producer.send(destination, expTextMessage);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until we receive exception");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil.logMsg(
- "Check if we got correct exception from JMSContext.rollback()");
- if (listener.gotException()) {
- if (listener.gotCorrectException()) {
- TestUtil.logMsg("Got correct IllegalStateRuntimeException");
- } else {
- TestUtil.logErr("Expected IllegalStateRuntimeException, received: "
- + listener.getException());
- pass = false;
- }
- } else {
- TestUtil.logErr(
- "Expected IllegalStateRuntimeException, got no exception");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalStateRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.stop() from CompletionListener is allowed (expect no exception)");
- try {
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context
- .createTextMessage("Call stop method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateRuntimeExceptionTests");
-
- TestUtil.logMsg(
- "Send async message specifying CompletionListener to recieve async message");
- TestUtil.logMsg(
- "CompletionListener will call JMSContext.stop() (expect no exception)");
- MyCompletionListener listener = new MyCompletionListener(
- contextToSendMsg);
- producer.setAsync(listener);
- listener.setComplete(false);
- producer.send(destination, expTextMessage);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until we receive exception");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil.logMsg(
- "Check if we got correct exception from JMSContext.stop() (expect no exception)");
- if (listener.gotException()) {
- TestUtil.logErr(
- "Got exception calling JMSContext.stop() (expected no exception)");
- TestUtil.logErr("Exception was: " + listener.getException());
- pass = false;
- } else {
- TestUtil.logErr("Got no exception (Correct)");
- }
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalStateRuntimeException, received " + e);
- pass = false;
- }
-
- try {
- cleanup();
- } catch (Exception e) {
- TestUtil.logMsg("Caught exception calling cleanup: " + e);
- }
- try {
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- contextToSendMsg = cf.createContext(user, password,
- JMSContext.AUTO_ACKNOWLEDGE);
- producer = contextToSendMsg.createProducer();
- consumer = context.createConsumer(destination);
- } catch (Exception e) {
- TestUtil.logMsg("Caught exception creating JMSContext: " + e);
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.close() from CompletionListener (expect IllegalStateRuntimeException)");
- try {
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context
- .createTextMessage("Call close method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateRuntimeExceptionTests");
-
- TestUtil.logMsg(
- "Send async message specifying CompletionListener to recieve async message");
- TestUtil.logMsg(
- "CompletionListener will call JMSContext.close() (expect IllegalStateRuntimeException)");
- MyCompletionListener listener = new MyCompletionListener(
- contextToSendMsg);
- producer.setAsync(listener);
- listener.setComplete(false);
- producer.send(destination, expTextMessage);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until we receive exception");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil.logMsg(
- "Check if we got correct exception from JMSContext.close()");
- if (listener.gotException()) {
- if (listener.gotCorrectException()) {
- TestUtil.logMsg("Got correct IllegalStateRuntimeException");
- } else {
- TestUtil.logErr("Expected IllegalStateRuntimeException, received: "
- + listener.getException());
- pass = false;
- }
- } else {
- TestUtil.logErr(
- "Expected IllegalStateRuntimeException, got no exception");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalStateRuntimeException, received " + e);
- pass = false;
- }
-
- try {
- cleanup();
- } catch (Exception e) {
- TestUtil.logMsg("Caught exception calling cleanup: " + e);
- }
- try {
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- contextToSendMsg = cf.createContext(user, password,
- JMSContext.AUTO_ACKNOWLEDGE);
- producer = contextToSendMsg.createProducer();
- consumer = context.createConsumer(destination);
- } catch (Exception e) {
- TestUtil.logMsg("Caught exception creating JMSContext: " + e);
- }
-
- TestUtil.logMsg("--------------------------------------------------");
- TestUtil.logMsg("MessageListener IllegalStateRuntimeException Tests");
- TestUtil.logMsg("--------------------------------------------------");
- TestUtil.logMsg(
- "Testing JMSContext.stop() from MessageListener (expect IllegalStateRuntimeException)");
- try {
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context
- .createTextMessage("Call stop method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateRuntimeExceptionTests");
-
- TestUtil.logMsg("Set MessageListener to receive async message");
- TestUtil.logMsg(
- "MessageListener will call JMSContext.stop() (expect IllegalStateRuntimeException)");
- MyMessageListener listener = new MyMessageListener(context);
- consumer.setMessageListener(listener);
- listener.setComplete(false);
- producer.send(destination, expTextMessage);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until we receive exception");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil
- .logMsg("Check if we got correct exception from JMSContext.stop()");
- if (listener.gotException()) {
- if (listener.gotCorrectException()) {
- TestUtil.logMsg("Got correct IllegalStateRuntimeException");
- } else {
- TestUtil.logErr("Expected IllegalStateRuntimeException, received: "
- + listener.getException());
- pass = false;
- }
- } else {
- TestUtil.logErr(
- "Expected IllegalStateRuntimeException, got no exception");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalStateRuntimeException, received " + e);
- pass = false;
- }
-
- try {
- cleanup();
- } catch (Exception e) {
- TestUtil.logMsg("Caught exception calling cleanup: " + e);
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("illegalStateRuntimeExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("illegalStateRuntimeExceptionTests failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/ClientIT.java
new file mode 100644
index 0000000000..6e9267be85
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/ClientIT.java
@@ -0,0 +1,2291 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022 Contributors to Eclipse Foundation. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.appclient.jmscontextqueuetests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.DeliveryMode;
+import jakarta.jms.Destination;
+import jakarta.jms.InvalidClientIDRuntimeException;
+import jakarta.jms.InvalidDestinationRuntimeException;
+import jakarta.jms.JMSConsumer;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSProducer;
+import jakarta.jms.JMSRuntimeException;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.MessageFormatRuntimeException;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.Queue;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.appclient.jmscontextqueuetests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null;
+
+ // JMS objects
+ private transient ConnectionFactory cf = null;
+
+ private transient Queue queue = null;
+
+ private transient Destination destination = null;
+
+ private transient JMSContext context = null;
+
+ private transient JMSContext context2 = null;
+
+ private transient JMSContext contextToSendMsg = null;
+
+ private transient JMSContext contextToCreateMsg = null;
+
+ private transient JMSConsumer consumer = null;
+
+ private transient JMSProducer producer = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /*
+ * Utility method to return the session mode as a String
+ */
+ private String printSessionMode(int sessionMode) {
+ switch (sessionMode) {
+ case JMSContext.SESSION_TRANSACTED:
+ return "SESSION_TRANSACTED";
+ case JMSContext.AUTO_ACKNOWLEDGE:
+ return "AUTO_ACKNOWLEDGE";
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ return "CLIENT_ACKNOWLEDGE";
+ case JMSContext.DUPS_OK_ACKNOWLEDGE:
+ return "DUPS_OK_ACKNOWLEDGE";
+ default:
+ return "UNEXPECTED_SESSIONMODE";
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(3);
+ connections = new ArrayList(5);
+
+ // set up JmsTool for COMMON_Q setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_Q setup");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ queue = (Queue) destination;
+ tool.getDefaultConnection().close();
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ contextToSendMsg = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ contextToCreateMsg = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Close JMSContext objects");
+ if (context != null) {
+ context.close();
+ context = null;
+ }
+ if (contextToSendMsg != null) {
+ contextToSendMsg.close();
+ contextToSendMsg = null;
+ }
+ if (contextToCreateMsg != null) {
+ contextToCreateMsg.close();
+ contextToCreateMsg = null;
+ }
+ logger.log(Logger.Level.INFO, "Close JMSConsumer objects");
+ if (consumer != null) {
+ consumer.close();
+ consumer = null;
+ }
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ tool.flushDestination();
+ tool.closeAllResources();
+ producer = null;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: setGetClientIDTest
+ *
+ * @assertion_ids: JMS:JAVADOC:970; JMS:JAVADOC:1040; JMS:SPEC:264.5;
+ * JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:91;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.setClientID(String clientID) JMSContext.getClientID()
+ */
+ @Test
+ public void setGetClientIDTest() throws Exception {
+ boolean pass = true;
+ try {
+ String clientid = "myclientid";
+ logger.log(Logger.Level.INFO, "Calling setClientID(" + clientid + ")");
+ context.setClientID(clientid);
+ logger.log(Logger.Level.INFO, "Calling getClientID and expect " + clientid + " to be returned");
+ String cid = context.getClientID();
+ if (!cid.equals(clientid)) {
+ logger.log(Logger.Level.ERROR, "getClientID() returned " + cid + ", expected " + clientid);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("setGetClientIDTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetClientIDTest failed");
+ }
+ }
+
+ /*
+ * @testName: setClientIDLateTest
+ *
+ * @assertion_ids: JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:94; JMS:SPEC:91;
+ * JMS:JAVADOC:1040; JMS:JAVADOC:1043; JMS:SPEC:264.5;
+ *
+ * @test_Strategy: Create a JMSContext, send and receive a message, then try to
+ * set the ClientID. Verify that IllegalStateRuntimeException is thrown.
+ *
+ * JMSContext.setClientID(String clientID)
+ */
+ @Test
+ public void setClientIDLateTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ TextMessage messageSent;
+ TextMessage messageReceived;
+ String message = "This is my message.";
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "setClientIDLateTest");
+ logger.log(Logger.Level.INFO, "Sending TestMessage");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.INFO, "actTextMessage=" + actTextMessage.getText());
+ }
+
+ logger.log(Logger.Level.TRACE, "Attempt to set Client ID too late (expect IllegalStateRuntimeException)");
+ try {
+ context.setClientID("setClientIDLateTest");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "IllegalStateRuntimeException was not thrown");
+ } catch (jakarta.jms.IllegalStateRuntimeException is) {
+ logger.log(Logger.Level.INFO, "IllegalStateRuntimeException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("setClientIDLateTest", e);
+ }
+ if (!pass) {
+ throw new Exception("setClientIDLateTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetChangeClientIDTest
+ *
+ * @assertion_ids: JMS:SPEC:93; JMS:SPEC:95; JMS:SPEC:198; JMS:JAVADOC:1040;
+ * JMS:JAVADOC:970; JMS:JAVADOC:1042; JMS:JAVADOC:1043; JMS:SPEC:264.5;
+ *
+ *
+ * @test_Strategy: Test setClientID()/getClientID(). Make sure that the clientID
+ * set is the clientID returned. Then try and reset the clientID. Verify that
+ * the IllegalStateRuntimeException is thrown. 1) Use a JMSContext that has no
+ * ClientID set, then call setClientID twice. 2) Try and set the clientID on a
+ * second JMSContext to the clientID value of the first JMSContext. Verify that
+ * InvalidClientIDRuntimeException is thrown.
+ *
+ * JMSContext.setClientID(String clientID) JMSContext.getClientID()
+ */
+ @Test
+ public void setGetChangeClientIDTest() throws Exception {
+ boolean pass = true;
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+ logger.log(Logger.Level.INFO, "Create second JMSContext with AUTO_ACKNOWLEDGE");
+ context2 = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+
+ logger.log(Logger.Level.INFO, "Setting clientID!");
+ context.setClientID("ctstest");
+
+ logger.log(Logger.Level.INFO, "Getting clientID!");
+ String clientid = context.getClientID();
+
+ if (!clientid.equals("ctstest")) {
+ logger.log(Logger.Level.ERROR, "getClientID() returned " + clientid + ", expected ctstest");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "setClientID/getClientID correct");
+ }
+
+ logger.log(Logger.Level.INFO, "Resetting clientID! (expect IllegalStateRuntimeException)");
+ context.setClientID("changeIt");
+ logger.log(Logger.Level.ERROR, "No exception was thrown on ClientID reset");
+ pass = false;
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "IllegalStateRuntimeException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Incorrect exception received: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO, "Set clientID on second context to value of clientID on first "
+ + "context (expect InvalidClientIDRuntimeException)");
+ context2.setClientID("ctstest");
+ logger.log(Logger.Level.ERROR, "No exception was thrown on ClientID that already exists");
+ pass = false;
+ } catch (InvalidClientIDRuntimeException e) {
+ logger.log(Logger.Level.INFO, "InvalidClientIDRuntimeException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Incorrect exception received: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (context2 != null) {
+ context2.close();
+ context2 = null;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception in finally block: " + e);
+ throw new Exception("setGetChangeClientIDTest", e);
+ }
+ }
+ if (!pass) {
+ throw new Exception("setGetChangeClientIDTest");
+ }
+ }
+
+ /*
+ * @testName: setGetExceptionListenerTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1052; JMS:JAVADOC:980;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.setExceptionListener(ExceptionListener).
+ * JMSContext.getExceptionListener().
+ */
+ @Test
+ public void setGetExceptionListenerTest() throws Exception {
+ boolean pass = true;
+ try {
+ MyExceptionListener expExceptionListener = new MyExceptionListener();
+ logger.log(Logger.Level.INFO, "Calling setExceptionListener(" + expExceptionListener + ")");
+ context.setExceptionListener(expExceptionListener);
+ logger.log(Logger.Level.INFO,
+ "Calling getExceptionListener and expect " + expExceptionListener + " to be returned");
+ MyExceptionListener actExceptionListener = (MyExceptionListener) context.getExceptionListener();
+ if (!actExceptionListener.equals(expExceptionListener)) {
+ logger.log(Logger.Level.ERROR, "getExceptionListener() returned " + actExceptionListener + ", expected "
+ + expExceptionListener);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling setExceptionListener(null)");
+ context.setExceptionListener(null);
+ if (context.getExceptionListener() != null) {
+ logger.log(Logger.Level.ERROR,
+ "getExceptionListener() returned " + context.getExceptionListener() + ", expected null");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("setGetExceptionListenerTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetExceptionListenerTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetAsyncTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1182; JMS:JAVADOC:1255;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setAsync(CompletionListener). JMSProducer.getAsync().
+ */
+ @Test
+ public void setGetAsyncTest() throws Exception {
+ boolean pass = true;
+ try {
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ // Set and get asyncronous CompletionListener
+ MyCompletionListener expCompletionListener = new MyCompletionListener();
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(" + expCompletionListener + ")");
+ producer.setAsync(expCompletionListener);
+ logger.log(Logger.Level.INFO,
+ "Calling JMSProducer.getAsync() and expect " + expCompletionListener + " to be returned");
+ MyCompletionListener actCompletionListener = (MyCompletionListener) producer.getAsync();
+ if (!actCompletionListener.equals(expCompletionListener)) {
+ logger.log(Logger.Level.ERROR,
+ "getAsync() returned " + actCompletionListener + ", expected " + expCompletionListener);
+ pass = false;
+ }
+
+ // Now set and get null asyncronous CompletionListener
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(null)");
+ producer.setAsync(null);
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.getAsync() and expect NULL to be returned");
+ if (producer.getAsync() != null) {
+ logger.log(Logger.Level.ERROR, "getAsync() returned " + producer.getAsync() + ", expected null");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("setGetAsyncTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetAsyncTest failed");
+ }
+ }
+
+ /*
+ * @testName: startStopTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:1076; JMS:JAVADOC:1078;
+ * JMS:JAVADOC:942; JMS:JAVADOC:1102; JMS:SPEC:264; JMS:SPEC:264.5;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * ConnectionFactory.createContext(String, String, int) JMSContext.start()
+ * JMSContext.stop() JMSContext.createConsumer(Destination)
+ * JMSContext.createProducer() JMSProducer.send(Destination, Message)
+ * JMSConsumer.receive(long timeout)
+ *
+ * 1. Create JMSContext with AUTO_ACKNOWLEDGE. This is done in the setup()
+ * routine. 2. Call stop. 3. Send x messages to a Queue. 4. Create a JMSConsumer
+ * to consume the messages in the Queue. 5. Try consuming messages from the
+ * Queue. Should not receive any messages since the connection has been stopped.
+ * 6. Call start. 7. Try consuming messages from the Queue. Should receive all
+ * messages from the Queue since the connection has been started.
+ */
+ @Test
+ public void startStopTest() throws Exception {
+ boolean pass = true;
+ try {
+ TextMessage tempMsg = null;
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Stop delivery of incoming messages on JMSContext's connection
+ logger.log(Logger.Level.INFO, "Call stop() to stop delivery of incoming messages");
+ context.stop();
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ // Send "numMessages" messages to Queue
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Queue");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "startStopTest" + i);
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ // Try consuming a message from the Queue (should not receive a
+ // message)
+ logger.log(Logger.Level.INFO, "Try consuming a message on a STOPPED connection");
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR, "Received a message on a STOPPED connection");
+ logger.log(Logger.Level.ERROR, "Message is: " + tempMsg.getText());
+ pass = false;
+ }
+
+ // Start delivery of incoming messages on JMSContext's connection
+ logger.log(Logger.Level.INFO, "Call start() to start delivery of incoming messages");
+ context.start();
+
+ logger.log(Logger.Level.INFO, "Consume all the messages in the Queue on a STARTED connection");
+ for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + msgCount + " missing from Queue");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + msgCount)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + msgCount + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message: " + tempMsg.getText());
+ }
+ }
+
+ // Try to receive one more message (should return null for no more
+ // messages)
+ logger.log(Logger.Level.INFO, "Queue should now be empty");
+ logger.log(Logger.Level.INFO, "Try consuming one more message should return NULL");
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() did not return NULL");
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() returned a message (unexpected)");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("startStopTest");
+ }
+
+ if (!pass) {
+ throw new Exception("startStopTest failed");
+ }
+ }
+
+ /*
+ * @testName: createContextTest
+ *
+ * @assertion_ids: JMS:JAVADOC:931; JMS:SPEC:265.3;
+ *
+ * @test_Strategy: Creates a JMSContext with the default user identity and the
+ * specified sessionMode. Tests API:
+ *
+ * JMSContext.createContext(int)
+ */
+ @Test
+ public void createContextTest() throws Exception {
+ boolean pass = true;
+ try {
+
+ JMSContext newContext = null;
+
+ // Test all possible session modes
+ int expSessionMode[] = { JMSContext.SESSION_TRANSACTED, JMSContext.AUTO_ACKNOWLEDGE,
+ JMSContext.CLIENT_ACKNOWLEDGE, JMSContext.DUPS_OK_ACKNOWLEDGE, };
+
+ // Cycle through all session modes
+ for (int i = 0; i < expSessionMode.length; i++) {
+ logger.log(Logger.Level.INFO,
+ "Creating context with session mode (" + printSessionMode(expSessionMode[i]) + ")");
+ logger.log(Logger.Level.INFO, "Call API QueueConnectionFactory.createContext(int)");
+ newContext = context.createContext(expSessionMode[i]);
+ logger.log(Logger.Level.INFO, "Now call API JMSContext.getSessionMode()");
+ logger.log(Logger.Level.INFO,
+ "Calling getSessionMode and expect " + printSessionMode(expSessionMode[i]) + " to be returned");
+ int actSessionMode = newContext.getSessionMode();
+ if (actSessionMode != expSessionMode[i]) {
+ logger.log(Logger.Level.ERROR, "getSessionMode() returned " + printSessionMode(actSessionMode)
+ + ", expected " + printSessionMode(expSessionMode[i]));
+ pass = false;
+ }
+ newContext.close();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("createContextTest");
+ }
+
+ if (!pass) {
+ throw new Exception("createContextTest failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvCLTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
+ * JMS:JAVADOC:1255; JMS:SPEC:275.1; JMS:SPEC:275.5; JMS:SPEC:275.8;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data as well as onCompletion() being called. Set some
+ * properties on JMSProducer and check that these properties exist on the
+ * returned message after the CompletionListener's onCompletion() method has
+ * been called.
+ *
+ * JMSContext.createProducer() JMSProducer.setAsync(CompletionListener)
+ * JMSProducer.send(Destination, Message)
+ */
+ @Test
+ public void sendAndRecvCLTest1() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+
+ try {
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvCLTest1");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ // ------------------------------------------------------------------------------
+ // Set JMSProducer message properties
+ // Set properties for boolean, byte, short, int, long, float,
+ // double, and String.
+ // ------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Set primitive property types on JMSProducer");
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTSTRING", "test");
+
+ // ------------------------------------------------------------------------------
+ // Set JMSProducer message properties
+ // Set properties for Boolean, Byte, Short, Int, Long, Float,
+ // Double, and String.
+ // ------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Set Object property types on JMSProducer");
+ producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
+ producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
+ producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
+ producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
+ producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
+ producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
+ producer.setProperty("OBJTESTSTRING", "test");
+
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(CompletionListener)");
+ producer.setAsync(listener);
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.send(Destination,Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive TextMessage");
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ TextMessage actTextMessage = null;
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------------
+ // Retrieve the properties from the received TextMessage and verify
+ // that they are correct
+ // Get properties for boolean, byte, short, int, long, float,
+ // double, and String.
+ // -------------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Retrieve and verify that TextMessage message properties were set correctly");
+ if (actTextMessage.getBooleanProperty("TESTBOOLEAN") == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getBooleanProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getBooleanProperty");
+ pass = false;
+ }
+ if (actTextMessage.getByteProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getByteProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getByteProperty");
+ pass = false;
+ }
+ if (actTextMessage.getLongProperty("TESTLONG") == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getLongProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getLongProperty");
+ pass = false;
+ }
+ if (actTextMessage.getStringProperty("TESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getStringProperty");
+ pass = false;
+ }
+ if (actTextMessage.getDoubleProperty("TESTDOUBLE") == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getDoubleProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getDoubleProperty");
+ pass = false;
+ }
+ if (actTextMessage.getFloatProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getFloatProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getFloatProperty");
+ pass = false;
+ }
+ if (actTextMessage.getIntProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getIntProperty");
+ pass = false;
+ }
+ if (actTextMessage.getShortProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getShortProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getShortProperty");
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------------
+ // Retrieve the properties from the received TextMessage and verify
+ // that they are correct
+ // Get properties for Boolean, Byte, Short, Integer, Long, Float,
+ // Double, and String.
+ // --------------------------------------------------------------------------------------
+ if (((Boolean) actTextMessage.getObjectProperty("OBJTESTBOOLEAN")).booleanValue() == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Boolean value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Byte) actTextMessage.getObjectProperty("OBJTESTBYTE")).byteValue() == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Byte value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Long) actTextMessage.getObjectProperty("OBJTESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Long value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Long value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((String) actTextMessage.getObjectProperty("OBJTESTSTRING")).equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct String value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect String value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Double) actTextMessage.getObjectProperty("OBJTESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Double value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Double value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Float) actTextMessage.getObjectProperty("OBJTESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Float value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Float value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Integer) actTextMessage.getObjectProperty("OBJTESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Integer value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Integer value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Short) actTextMessage.getObjectProperty("OBJTESTSHORT")).shortValue() == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Short value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Short value returned from getObjectProperty");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvCLTest1", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvCLTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvCLTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
+ * JMS:JAVADOC:1255; JMS:JAVADOC:1259; JMS:JAVADOC:1303;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data as well as onCompletion() being called.
+ *
+ * JMSContext.createProducer() JMSProducer.setDeliveryMode(int)
+ * JMSProducer.setPriority(int) JMSProducer.setTimeToLive(long)
+ * JMSProducer.setAsync(CompletionListener) JMSProducer.send(Destination,
+ * Message)
+ */
+ @Test
+ public void sendAndRecvCLTest2() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvCLTest2");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(CompletionListener)");
+ producer.setAsync(listener);
+ logger.log(Logger.Level.INFO, "Set delivery mode, priority, and time to live");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ producer.setPriority(Message.DEFAULT_PRIORITY);
+ producer.setTimeToLive(0L);
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.send(Destination,Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive TextMessage");
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ TextMessage actTextMessage = null;
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage, deliverymode, priority, time to live");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())
+ || actTextMessage.getJMSDeliveryMode() != DeliveryMode.PERSISTENT
+ || actTextMessage.getJMSPriority() != Message.DEFAULT_PRIORITY
+ || actTextMessage.getJMSExpiration() != 0L) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode=" + actTextMessage.getJMSDeliveryMode() + ", expected "
+ + expTextMessage.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority=" + actTextMessage.getJMSPriority() + ", expected "
+ + expTextMessage.getJMSPriority());
+ logger.log(Logger.Level.ERROR, "TimeToLive=" + actTextMessage.getJMSExpiration() + ", expected "
+ + expTextMessage.getJMSExpiration());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvCLTest2", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvCLTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvMsgOfEachTypeCLTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
+ * JMS:JAVADOC:1255; JMS:JAVADOC:1259; JMS:JAVADOC:1303;
+ *
+ * @test_Strategy: Send and receive messages of each message type: Message,
+ * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Verify
+ * the send and recv of data as well as onCompletion() being called in
+ * CompletionListener.
+ *
+ * JMSContext.createProducer() JMSProducer.setAsync(CompletionListener)
+ * JMSContext.createMessage() JMSContext.createBytesMessage()
+ * JMSContext.createMapMessage() JMSContext.createObjectMessage()
+ * JMSContext.createStreamMessage() JMSContext.createTextMessage(String)
+ * JMSProducer.send(Destination, Message)
+ */
+ @Test
+ public void sendAndRecvMsgOfEachTypeCLTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+
+ // send and receive Message
+ logger.log(Logger.Level.INFO, "Send and receive Message");
+ Message msg = context.createMessage();
+ logger.log(Logger.Level.INFO, "Set some values in Message");
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
+ msg.setBooleanProperty("booleanProperty", true);
+ MyCompletionListener2 listener = new MyCompletionListener2();
+ producer = context.createProducer();
+ producer.setAsync(listener);
+ producer.send(destination, msg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive Message");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ Message actMessage = null;
+ if (listener.isComplete())
+ actMessage = (Message) listener.getMessage();
+
+ if (actMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive Message");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in Message");
+ if (actMessage.getBooleanProperty("booleanProperty") == true) {
+ logger.log(Logger.Level.INFO, "booleanproperty is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanproperty is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Send and receive BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ bMsg.reset();
+ listener = new MyCompletionListener2();
+ producer = context.createProducer();
+ producer.setAsync(listener);
+ producer.send(destination, bMsg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive BytesMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ BytesMessage bMsgRecv = null;
+ if (listener.isComplete())
+ bMsgRecv = (BytesMessage) listener.getMessage();
+ if (bMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive BytesMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in BytesMessage");
+ if (bMsgRecv.readByte() == (byte) 1) {
+ logger.log(Logger.Level.INFO, "bytevalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "bytevalue is incorrect");
+ pass = false;
+ }
+ if (bMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send and receive MapMessage");
+ MapMessage mMsg = context.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ listener = new MyCompletionListener2();
+ producer = context.createProducer();
+ producer.setAsync(listener);
+ producer.send(destination, mMsg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive MapMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ MapMessage mMsgRecv = null;
+ if (listener.isComplete())
+ mMsgRecv = (MapMessage) listener.getMessage();
+ if (mMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive MapMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in MapMessage");
+ Enumeration list = mMsgRecv.getMapNames();
+ String name = null;
+ while (list.hasMoreElements()) {
+ name = (String) list.nextElement();
+ if (name.equals("booleanvalue")) {
+ if (mMsgRecv.getBoolean(name) == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "booleanvalue is incorrect");
+ pass = false;
+ }
+ } else if (name.equals("intvalue")) {
+ if (mMsgRecv.getInt(name) == 10) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "intvalue is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected name of [" + name + "] in MapMessage");
+ pass = false;
+ }
+ }
+ }
+
+ // send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Send and receive ObjectMessage");
+ StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ ObjectMessage oMsg = context.createObjectMessage();
+ oMsg.setObject(sb1);
+ oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
+ listener = new MyCompletionListener2();
+ producer = context.createProducer();
+ producer.setAsync(listener);
+ producer.send(destination, oMsg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive ObjectMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ ObjectMessage oMsgRecv = null;
+ if (listener.isComplete())
+ oMsgRecv = (ObjectMessage) listener.getMessage();
+ if (oMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive ObjectMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in ObjectMessage");
+ StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
+ if (sb2.toString().equals(sb1.toString())) {
+ logger.log(Logger.Level.INFO, "objectvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "objectvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive StreamMessage
+ logger.log(Logger.Level.INFO, "Send and receive StreamMessage");
+ StreamMessage sMsg = context.createStreamMessage();
+ logger.log(Logger.Level.INFO, "Set some values in StreamMessage");
+ sMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
+ sMsg.writeBoolean(true);
+ sMsg.writeInt((int) 22);
+ sMsg.reset();
+ listener = new MyCompletionListener2();
+ producer = context.createProducer();
+ producer.setAsync(listener);
+ producer.send(destination, sMsg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive StreamMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ StreamMessage sMsgRecv = null;
+ if (listener.isComplete())
+ sMsgRecv = (StreamMessage) listener.getMessage();
+ if (sMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive StreamMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in StreamMessage");
+ if (sMsgRecv.readBoolean() == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanvalue is incorrect");
+ pass = false;
+ }
+ if (sMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Send and receive TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.send(Destination,Message)");
+ listener = new MyCompletionListener2();
+ producer = context.createProducer();
+ producer.setAsync(listener);
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive TextMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ TextMessage actTextMessage = null;
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvMsgOfEachTypeCLTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvMsgOfEachTypeCLTest failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvMsgOfEachTypeMLTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
+ * JMS:JAVADOC:1255; JMS:JAVADOC:1259; JMS:JAVADOC:1303;
+ *
+ * @test_Strategy: Send and receive messages of each message type: Message,
+ * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Verify
+ * the send and recv of data as well as onMessage() being called in
+ * MessageListener.
+ *
+ * JMSContext.createProducer() JMSProducer.setAsync(CompletionListener)
+ * JMSContext.createMessage() JMSContext.createBytesMessage()
+ * JMSContext.createMapMessage() JMSContext.createObjectMessage()
+ * JMSContext.createStreamMessage() JMSContext.createTextMessage(String)
+ * JMSProducer.send(Destination, Message)
+ */
+ @Test
+ public void sendAndRecvMsgOfEachTypeMLTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+
+ // send and receive Message
+ logger.log(Logger.Level.INFO, "Send and receive Message");
+ Message msg = context.createMessage();
+ logger.log(Logger.Level.INFO, "Set some values in Message");
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeMLTest");
+ msg.setBooleanProperty("booleanProperty", true);
+ MyMessageListener2 listener = new MyMessageListener2();
+ consumer = context.createConsumer(destination);
+ consumer.setMessageListener(listener);
+ producer = contextToSendMsg.createProducer();
+ producer.send(destination, msg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive Message");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ Message actMessage = null;
+ if (listener.isComplete())
+ actMessage = (Message) listener.getMessage();
+
+ if (actMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive Message");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in Message");
+ if (actMessage.getBooleanProperty("booleanProperty") == true) {
+ logger.log(Logger.Level.INFO, "booleanproperty is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanproperty is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Send and receive BytesMessage");
+ BytesMessage bMsg = contextToCreateMsg.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeMLTest");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ listener = new MyMessageListener2();
+ consumer.setMessageListener(listener);
+ producer = contextToSendMsg.createProducer();
+ producer.send(destination, bMsg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive BytesMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ BytesMessage bMsgRecv = null;
+ if (listener.isComplete())
+ bMsgRecv = (BytesMessage) listener.getMessage();
+ if (bMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive BytesMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in BytesMessage");
+ if (bMsgRecv.readByte() == (byte) 1) {
+ logger.log(Logger.Level.INFO, "bytevalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "bytevalue is incorrect");
+ pass = false;
+ }
+ if (bMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send and receive MapMessage");
+ MapMessage mMsg = contextToCreateMsg.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeMLTest");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ listener = new MyMessageListener2();
+ consumer.setMessageListener(listener);
+ producer = contextToSendMsg.createProducer();
+ producer.send(destination, mMsg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive MapMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ MapMessage mMsgRecv = null;
+ if (listener.isComplete())
+ mMsgRecv = (MapMessage) listener.getMessage();
+ if (mMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive MapMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in MapMessage");
+ Enumeration list = mMsgRecv.getMapNames();
+ String name = null;
+ while (list.hasMoreElements()) {
+ name = (String) list.nextElement();
+ if (name.equals("booleanvalue")) {
+ if (mMsgRecv.getBoolean(name) == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "booleanvalue is incorrect");
+ pass = false;
+ }
+ } else if (name.equals("intvalue")) {
+ if (mMsgRecv.getInt(name) == 10) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "intvalue is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected name of [" + name + "] in MapMessage");
+ pass = false;
+ }
+ }
+ }
+
+ // send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Send and receive ObjectMessage");
+ StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ ObjectMessage oMsg = contextToCreateMsg.createObjectMessage();
+ oMsg.setObject(sb1);
+ oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeMLTest");
+ listener = new MyMessageListener2();
+ consumer.setMessageListener(listener);
+ producer = contextToSendMsg.createProducer();
+ producer.send(destination, oMsg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive ObjectMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ ObjectMessage oMsgRecv = null;
+ if (listener.isComplete())
+ oMsgRecv = (ObjectMessage) listener.getMessage();
+ if (oMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive ObjectMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in ObjectMessage");
+ StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
+ if (sb2.toString().equals(sb1.toString())) {
+ logger.log(Logger.Level.INFO, "objectvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "objectvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive StreamMessage
+ logger.log(Logger.Level.INFO, "Send and receive StreamMessage");
+ StreamMessage sMsg = contextToCreateMsg.createStreamMessage();
+ logger.log(Logger.Level.INFO, "Set some values in StreamMessage");
+ sMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeMLTest");
+ sMsg.writeBoolean(true);
+ sMsg.writeInt((int) 22);
+ listener = new MyMessageListener2();
+ consumer.setMessageListener(listener);
+ producer = contextToSendMsg.createProducer();
+ producer.send(destination, sMsg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive StreamMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ StreamMessage sMsgRecv = null;
+ if (listener.isComplete())
+ sMsgRecv = (StreamMessage) listener.getMessage();
+ if (sMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive StreamMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in StreamMessage");
+ if (sMsgRecv.readBoolean() == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanvalue is incorrect");
+ pass = false;
+ }
+ if (sMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Send and receive TextMessage");
+ TextMessage expTextMessage = contextToCreateMsg.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeMLTest");
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.send(Destination,Message)");
+ listener = new MyMessageListener2();
+ consumer.setMessageListener(listener);
+ producer = contextToSendMsg.createProducer();
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive TextMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ TextMessage actTextMessage = null;
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvMsgOfEachTypeMLTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvMsgOfEachTypeMLTest failed");
+ }
+ }
+
+ /*
+ * @testName: messageOrderCLQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:275.2; JMS:SPEC:275.7;
+ *
+ * @test_Strategy: Send async messages to a queue and receive them. Verify that
+ * the text of each matches the order of the text in the sent messages.
+ */
+ @Test
+ public void messageOrderCLQueueTest() throws Exception {
+ boolean pass = true;
+ try {
+ TextMessage sentTextMessage;
+ String text[] = new String[numMessages];
+
+ // Create CompletionListener for Message to be sent
+ logger.log(Logger.Level.INFO, "Creating MyCompletionListener");
+ MyCompletionListener listener = new MyCompletionListener(numMessages);
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(CompletionListener)");
+ producer.setAsync(listener);
+
+ // create and send async messages to queue
+ logger.log(Logger.Level.INFO, "Sending " + numMessages + " asynchronous messages to queue");
+ for (int i = 0; i < numMessages; i++) {
+ text[i] = "message order test " + i;
+ sentTextMessage = context.createTextMessage();
+ sentTextMessage.setText(text[i]);
+ sentTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "messageOrderCLQueueTest" + i);
+ logger.log(Logger.Level.INFO, "Sending TextMessage: " + sentTextMessage.getText());
+ producer.send(destination, sentTextMessage);
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Poll listener until we receive all " + numMessages + " TextMessage's from CompletionListener");
+ for (int i = 0; !listener.gotAllMsgs() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+
+ for (int i = 0; i < numMessages; i++) {
+ TextMessage actTextMessage = null;
+ if (listener.haveMsg(i))
+ actTextMessage = (TextMessage) listener.getMessage(i);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.INFO, "Did not receive TextMessage " + i + " (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message: " + actTextMessage.getText());
+ if (!actTextMessage.getText().equals(text[i])) {
+ logger.log(Logger.Level.INFO, "Received message: " + actTextMessage.getText());
+ logger.log(Logger.Level.INFO, "Should have received: " + text[i]);
+ logger.log(Logger.Level.ERROR, "Received wrong message (wrong order)");
+ pass = false;
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("messageOrderCLQueueTest", e);
+ }
+
+ if (!pass)
+ throw new Exception("messageOrderCLQueueTest failed");
+ }
+
+ /*
+ * @testName: commitRollbackTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:914; JMS:JAVADOC:995;
+ * JMS:JAVADOC:942; JMS:JAVADOC:1102; JMS:JAVADOC:847; JMS:SPEC:275.3;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * ConnectionFactory.createContext(String, String, int)
+ * JMSProducer.send(Destination, Message) JMSContext.commit()
+ * JMSContext.rollback() JMSContext.createConsumer(Destination)
+ * JMSConsumer.receive(long timeout)
+ *
+ * 1. Create JMSContext with SESSION_TRANSACTED. This is done in the setup()
+ * routine. 2. Send x messages to a Queue. 3. Call rollback() to rollback the
+ * sent messages. 4. Create a JMSConsumer to consume the messages in the Queue.
+ * Should not receive any messages since the sent messages were rolled back.
+ * Verify that no messages are received. 5. Send x messages to a Queue. 6. Call
+ * commit() to commit the sent messages. 7. Create a JMSConsumer to consume the
+ * messages in the Queue. Should receive all the messages since the sent
+ * messages were committed. Verify that all messages are received.
+ */
+ @Test
+ public void commitRollbackTest() throws Exception {
+ boolean pass = true;
+ try {
+ TextMessage tempMsg = null;
+
+ // Close conttext created in setup()
+ context.close();
+
+ // create JMSContext with SESSION_TRANSACTED then create
+ // consumer/producer
+ logger.log(Logger.Level.INFO, "Create transacted JMSContext, JMSConsumer and JMSProducer");
+ context = cf.createContext(user, password, JMSContext.SESSION_TRANSACTED);
+ producer = context.createProducer();
+ consumer = context.createConsumer(destination);
+
+ // Send "numMessages" messages to Queue and call rollback
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Queue and call rollback()");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "commitRollbackTest" + i);
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ // Call rollback() to rollback the sent messages
+ logger.log(Logger.Level.INFO, "Calling rollback() to rollback the sent messages");
+ context.rollback();
+
+ logger.log(Logger.Level.INFO, "Should not consume any messages in Queue since rollback() was called");
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR,
+ "Received message " + tempMsg.getText() + ", expected NULL (NO MESSAGES)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received no messages (CORRECT)");
+ }
+
+ // Send "numMessages" messages to Queue and call commit
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Queue and call commit()");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "commitRollbackTest" + i);
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ // Call commit() to commit the sent messages
+ logger.log(Logger.Level.INFO, "Calling commit() to commit the sent messages");
+ context.commit();
+
+ logger.log(Logger.Level.INFO, "Should consume all messages in Queue since commit() was called");
+ for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + msgCount + " missing from Queue");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + msgCount)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + msgCount + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message: " + tempMsg.getText());
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("commitRollbackTest");
+ }
+
+ if (!pass) {
+ throw new Exception("commitRollbackTest failed");
+ }
+ }
+
+ /*
+ * @testName: recoverAckTest
+ *
+ * @assertion_ids: JMS:JAVADOC:992; JMS:JAVADOC:909;
+ *
+ * @test_Strategy: Send messages to destination in a CLIENT_ACKNOWLEDGE session.
+ * Receive all the messages without acknowledge and call recover on context.
+ * Receive for a second time all the messages and follow with an acknowledge.
+ *
+ * JMSContext.recover() JMSContext.acknowledge()
+ */
+ @Test
+ public void recoverAckTest() throws Exception {
+ boolean pass = true;
+ TextMessage textMessage = null;
+ try {
+ // Close JMSContext created in setup() method
+ logger.log(Logger.Level.INFO, "Close JMSContext created in setup() method");
+ context.close();
+
+ // Create JMSContext with CLIENT_ACKNOWLEDGE
+ logger.log(Logger.Level.INFO, "Close JMSContext with CLIENT_ACKNOWLEDGE and create consumer/producer");
+ context = cf.createContext(user, password, JMSContext.CLIENT_ACKNOWLEDGE);
+
+ // Create JMSConsumer from JMSContext
+ consumer = context.createConsumer(destination);
+
+ // Create JMSProducer from JMSContext
+ producer = context.createProducer();
+
+ // send messages
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages");
+ for (int i = 0; i < numMessages; i++) {
+ String message = "text message " + i;
+ textMessage = context.createTextMessage(message);
+ textMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "recoverAckTest" + i);
+ producer.send(destination, textMessage);
+ logger.log(Logger.Level.INFO, "Sent message " + i);
+ }
+
+ // receive messages but do not acknowledge
+ logger.log(Logger.Level.INFO, "Receive " + numMessages + " messages but do not acknowledge");
+ for (int i = 0; i < numMessages; i++) {
+ logger.log(Logger.Level.INFO, "Receiving message " + i);
+ textMessage = (TextMessage) consumer.receive(timeout);
+ if (textMessage == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Did not receive message " + i);
+ } else {
+ logger.log(Logger.Level.INFO, "Received message " + i);
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Call JMSContext.recover()");
+ context.recover();
+
+ logger.log(Logger.Level.INFO, "Receive " + numMessages + " messages again then acknowledge");
+ // receive messages a second time followed by acknowledge
+ for (int i = 0; i < numMessages; i++) {
+ logger.log(Logger.Level.INFO, "Receiving message " + i);
+ textMessage = (TextMessage) consumer.receive(timeout);
+ if (textMessage == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Did not receive message " + i);
+ } else {
+ logger.log(Logger.Level.INFO, "Received message " + i);
+ }
+ }
+
+ // Acknowledge all messages
+ logger.log(Logger.Level.INFO, "Acknowledge all messages by calling JMSContext.acknowledge()");
+ context.acknowledge();
+
+ logger.log(Logger.Level.INFO, "Now try receiving a message (should get NONE)");
+ textMessage = (TextMessage) consumer.receive(timeout);
+ if (textMessage != null) {
+ logger.log(Logger.Level.ERROR, "Received message " + textMessage.getText() + " (Expected NONE)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received no message (Correct)");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "recoverAckTest failed: ", e);
+ throw new Exception("recoverAckTest failed", e);
+ }
+
+ if (!pass)
+ throw new Exception("recoverAckTest failed!!!");
+ }
+
+ /*
+ * @testName: invalidDestinationRuntimeExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1237;
+ *
+ * @test_Strategy: Test InvalidDestinationRuntimeException conditions from API
+ * methods with CompletionListener.
+ *
+ * Tests the following exception conditions:
+ *
+ * InvalidDestinationRuntimeException
+ */
+ @Test
+ public void invalidDestinationRuntimeExceptionTests() throws Exception {
+ boolean pass = true;
+ Destination invalidDestination = null;
+ Queue invalidQueue = null;
+ String message = "Where are you!";
+ Map mapMsgSend = new HashMap();
+ mapMsgSend.put("StringValue", "sendAndRecvTest7");
+ mapMsgSend.put("BooleanValue", true);
+ mapMsgSend.put("IntValue", (int) 10);
+ try {
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ // send to an invalid destination
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "invalidDestinationRuntimeExceptionTests");
+
+ // Create CompetionListener
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Message) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(CompletionListener)");
+ producer.setAsync(listener);
+ logger.log(Logger.Level.INFO,
+ "Calling JMSProducer.send(Destination, Message) -> expect InvalidDestinationRuntimeException");
+ producer.send(invalidDestination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ if (listener.isComplete()) {
+ exception = listener.getException();
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof InvalidDestinationRuntimeException) {
+ logger.log(Logger.Level.INFO, "Exception is expected InvalidDestinationRuntimeException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected InvalidDestinationRuntimeException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("invalidDestinationRuntimeExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("invalidDestinationRuntimeExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: messageFormatRuntimeExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1236;
+ *
+ * @test_Strategy: Test MessageFormatRuntimeException conditions from API
+ * methods with CompletionListener.
+ *
+ * Tests the following exception conditions:
+ *
+ * MessageFormatRuntimeException
+ */
+ @Test
+ public void messageFormatRuntimeExceptionTests() throws Exception {
+ boolean pass = true;
+ try {
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ // Create CompetionListener
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Message) for MessageFormatRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(CompletionListener)");
+ producer.setAsync(listener);
+ logger.log(Logger.Level.INFO,
+ "Calling JMSProducer.send(Destination, Message) -> expect MessageFormatRuntimeException");
+ producer.send(destination, (Message) null);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ if (listener.isComplete()) {
+ exception = listener.getException();
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof MessageFormatRuntimeException) {
+ logger.log(Logger.Level.INFO, "Exception is expected MessageFormatRuntimeException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected MessageFormatRuntimeException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got MessageFormatRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatRuntimeException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("messageFormatRuntimeExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("messageFormatRuntimeExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: jMSRuntimeExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1235;
+ *
+ * @test_Strategy: Test JMSRuntimeException conditions from API methods with
+ * CompletionListener.
+ *
+ * Set delivery mode to -1 on JMSProducer and then try and send async message to
+ * CompletionListener. The CompletionListener MUST throw JMSRuntimeException.
+ *
+ * Set priority to -1 on JMSProducer and then try and send async message to
+ * CompletionListener. The CompletionListener MUST throw JMSRuntimeException.
+ */
+ @Test
+ public void jMSRuntimeExceptionTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "jMSRuntimeExceptionTests");
+ try {
+ logger.log(Logger.Level.INFO, "Set completion listener");
+ producer.setAsync(listener);
+ logger.log(Logger.Level.INFO, "Try and set an invalid delivbery mode of -1 on send");
+ producer.setDeliveryMode(-1);
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ if (listener.isComplete()) {
+ exception = listener.getException();
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof JMSRuntimeException) {
+ logger.log(Logger.Level.INFO, "Exception is expected JMSRuntimeException");
+ } else {
+ logger.log(Logger.Level.ERROR, "Exception is incorrect expected JMSRuntimeException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (JMSRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSRuntimeException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Set completion listener");
+ producer.setAsync(listener);
+ listener.setComplete(false);
+ logger.log(Logger.Level.INFO, "Try and set an invalid priority of -1 on send");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ producer.setPriority(-1);
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof JMSRuntimeException) {
+ logger.log(Logger.Level.INFO, "Exception is expected JMSRuntimeException");
+ } else {
+ logger.log(Logger.Level.ERROR, "Exception is incorrect expected JMSRuntimeException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (JMSRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSRuntimeException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("jMSRuntimeExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("jMSRuntimeExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: illegalStateRuntimeExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1353; JMS:JAVADOC:1354; JMS:JAVADOC:917;
+ * JMS:JAVADOC:997;
+ *
+ * @test_Strategy: Test IllegalStateRuntimeException conditions.
+ *
+ * 1) Calling JMSContext.stop() in a MessageListener MUST throw
+ * IllegalStateRuntimeException. 2) Calling JMSContext.close() from a
+ * CompletionListener MUST throw IllegalStateRuntimeException. 3) Calling
+ * JMSContext.commit() or JMSContext.rollback() in a CompletionListener MUST
+ * throw IllegalStateRuntimeException.
+ */
+ @Test
+ public void illegalStateRuntimeExceptionTests() throws Exception {
+ boolean pass = true;
+ try {
+ // Create JMSProducer/JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer/JMSConsumer");
+ producer = contextToSendMsg.createProducer();
+ consumer = context.createConsumer(destination);
+
+ logger.log(Logger.Level.INFO, "-----------------------------------------------------");
+ logger.log(Logger.Level.INFO, "CompletionListener IllegalStateRuntimeException Tests");
+ logger.log(Logger.Level.INFO, "-----------------------------------------------------");
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.commit() from CompletionListener (expect IllegalStateRuntimeException)");
+ try {
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage("Call commit method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateRuntimeExceptionTests");
+
+ logger.log(Logger.Level.INFO,
+ "Send async message specifying CompletionListener to recieve async message");
+ logger.log(Logger.Level.INFO,
+ "CompletionListener will call JMSContext.commit() (expect IllegalStateRuntimeException)");
+ MyCompletionListener listener = new MyCompletionListener(context);
+ producer.setAsync(listener);
+ producer.send(destination, expTextMessage);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Check if we got correct exception from JMSContext.commit()");
+ if (listener.gotException()) {
+ if (listener.gotCorrectException()) {
+ logger.log(Logger.Level.INFO, "Got correct IllegalStateRuntimeException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Expected IllegalStateRuntimeException, received: " + listener.getException());
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateRuntimeException, got no exception");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.rollback() from CompletionListener (expect IllegalStateRuntimeException)");
+ try {
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage("Call rollback method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateRuntimeExceptionTests");
+
+ logger.log(Logger.Level.INFO,
+ "Send async message specifying CompletionListener to recieve async message");
+ logger.log(Logger.Level.INFO,
+ "CompletionListener will call JMSContext.rollback() (expect IllegalStateRuntimeException)");
+ MyCompletionListener listener = new MyCompletionListener(contextToSendMsg);
+ producer.setAsync(listener);
+ listener.setComplete(false);
+ producer.send(destination, expTextMessage);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Check if we got correct exception from JMSContext.rollback()");
+ if (listener.gotException()) {
+ if (listener.gotCorrectException()) {
+ logger.log(Logger.Level.INFO, "Got correct IllegalStateRuntimeException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Expected IllegalStateRuntimeException, received: " + listener.getException());
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateRuntimeException, got no exception");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.stop() from CompletionListener is allowed (expect no exception)");
+ try {
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage("Call stop method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateRuntimeExceptionTests");
+
+ logger.log(Logger.Level.INFO,
+ "Send async message specifying CompletionListener to recieve async message");
+ logger.log(Logger.Level.INFO, "CompletionListener will call JMSContext.stop() (expect no exception)");
+ MyCompletionListener listener = new MyCompletionListener(contextToSendMsg);
+ producer.setAsync(listener);
+ listener.setComplete(false);
+ producer.send(destination, expTextMessage);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO,
+ "Check if we got correct exception from JMSContext.stop() (expect no exception)");
+ if (listener.gotException()) {
+ logger.log(Logger.Level.ERROR, "Got exception calling JMSContext.stop() (expected no exception)");
+ logger.log(Logger.Level.ERROR, "Exception was: " + listener.getException());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.ERROR, "Got no exception (Correct)");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateRuntimeException, received " + e);
+ pass = false;
+ }
+
+ try {
+ cleanup();
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught exception calling cleanup: " + e);
+ }
+ try {
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ contextToSendMsg = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ producer = contextToSendMsg.createProducer();
+ consumer = context.createConsumer(destination);
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught exception creating JMSContext: " + e);
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.close() from CompletionListener (expect IllegalStateRuntimeException)");
+ try {
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage("Call close method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateRuntimeExceptionTests");
+
+ logger.log(Logger.Level.INFO,
+ "Send async message specifying CompletionListener to recieve async message");
+ logger.log(Logger.Level.INFO,
+ "CompletionListener will call JMSContext.close() (expect IllegalStateRuntimeException)");
+ MyCompletionListener listener = new MyCompletionListener(contextToSendMsg);
+ producer.setAsync(listener);
+ listener.setComplete(false);
+ producer.send(destination, expTextMessage);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Check if we got correct exception from JMSContext.close()");
+ if (listener.gotException()) {
+ if (listener.gotCorrectException()) {
+ logger.log(Logger.Level.INFO, "Got correct IllegalStateRuntimeException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Expected IllegalStateRuntimeException, received: " + listener.getException());
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateRuntimeException, got no exception");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateRuntimeException, received " + e);
+ pass = false;
+ }
+
+ try {
+ cleanup();
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught exception calling cleanup: " + e);
+ }
+ try {
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ contextToSendMsg = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ producer = contextToSendMsg.createProducer();
+ consumer = context.createConsumer(destination);
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught exception creating JMSContext: " + e);
+ }
+
+ logger.log(Logger.Level.INFO, "--------------------------------------------------");
+ logger.log(Logger.Level.INFO, "MessageListener IllegalStateRuntimeException Tests");
+ logger.log(Logger.Level.INFO, "--------------------------------------------------");
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.stop() from MessageListener (expect IllegalStateRuntimeException)");
+ try {
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage("Call stop method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateRuntimeExceptionTests");
+
+ logger.log(Logger.Level.INFO, "Set MessageListener to receive async message");
+ logger.log(Logger.Level.INFO,
+ "MessageListener will call JMSContext.stop() (expect IllegalStateRuntimeException)");
+ MyMessageListener listener = new MyMessageListener(context);
+ consumer.setMessageListener(listener);
+ listener.setComplete(false);
+ producer.send(destination, expTextMessage);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Check if we got correct exception from JMSContext.stop()");
+ if (listener.gotException()) {
+ if (listener.gotCorrectException()) {
+ logger.log(Logger.Level.INFO, "Got correct IllegalStateRuntimeException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Expected IllegalStateRuntimeException, received: " + listener.getException());
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateRuntimeException, got no exception");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateRuntimeException, received " + e);
+ pass = false;
+ }
+
+ try {
+ cleanup();
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught exception calling cleanup: " + e);
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("illegalStateRuntimeExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("illegalStateRuntimeExceptionTests failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyCompletionListener.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyCompletionListener.java
index 1ae96b93f2..fd358085b1 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyCompletionListener.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyCompletionListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,10 +19,9 @@
*/
package com.sun.ts.tests.jms.core20.appclient.jmscontextqueuetests;
+import java.lang.System.Logger;
import java.util.ArrayList;
-import com.sun.ts.lib.util.TestUtil;
-
import jakarta.jms.CompletionListener;
import jakarta.jms.IllegalStateRuntimeException;
import jakarta.jms.JMSContext;
@@ -31,146 +30,146 @@
public class MyCompletionListener implements CompletionListener {
- private String name = null;
+ private String name = null;
+
+ private Message message = null;
+
+ private JMSContext context = null;
- private Message message = null;
+ private ArrayList messages = new ArrayList();
- private JMSContext context = null;
+ private Exception exception = null;
- private ArrayList messages = new ArrayList();
+ private int numMessages = 1;
- private Exception exception = null;
+ boolean complete = false;
- private int numMessages = 1;
-
- boolean complete = false;
-
- boolean gotCorrectException = false;
-
- boolean gotException = false;
-
- public MyCompletionListener() {
- this("MyCompletionListener");
- }
-
- public MyCompletionListener(String name) {
- this.name = name;
- }
-
- public MyCompletionListener(int numMessages) {
- this.numMessages = numMessages;
- messages.clear();
- }
-
- public MyCompletionListener(JMSContext context) {
- this.context = context;
- }
-
- // getters/setters
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Message getMessage() {
- return message;
- }
-
- public Message getMessage(int index) {
- return messages.get(index);
- }
-
- public void setMessage(Message message) {
- this.message = message;
- }
-
- public Exception getException() {
- return exception;
- }
-
- public void setException(Exception exception) {
- this.exception = exception;
- }
-
- public boolean gotAllMsgs() {
- return (messages.size() == numMessages) ? true : false;
- }
-
- public boolean haveMsg(int i) {
- return (messages.size() > i) ? true : false;
- }
-
- public boolean isComplete() {
- return complete;
- }
-
- public boolean gotCorrectException() {
- return gotCorrectException;
- }
-
- public boolean gotException() {
- return gotException;
- }
-
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
-
- public void onCompletion(Message message) {
- try {
- TestUtil.logMsg(
- "onCompletion(): Got Message: " + ((TextMessage) message).getText());
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- this.message = message;
- messages.add(message);
- if (message instanceof TextMessage) {
- TextMessage tMsg = (TextMessage) message;
- try {
- if (tMsg.getText().equals("Call close method")) {
- TestUtil.logMsg(
- "Calling JMSContext.close() MUST throw IllegalStateRuntimeException");
- if (context != null)
- context.close();
- } else if (tMsg.getText().equals("Call stop method")) {
- TestUtil.logMsg("Calling JMSContext.stop() MUST be allowed");
- if (context != null)
- context.stop();
- } else if (tMsg.getText().equals("Call commit method")) {
- TestUtil.logMsg(
- "Calling JMSContext.commit() MUST throw IllegalStateRuntimeException");
- if (context != null)
- context.commit();
- } else if (tMsg.getText().equals("Call rollback method")) {
- TestUtil.logMsg(
- "Calling JMSContext.rollback() MUST throw IllegalStateRuntimeException");
- if (context != null)
- context.rollback();
- }
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- gotCorrectException = true;
- gotException = true;
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- gotCorrectException = false;
- gotException = true;
- exception = e;
- }
- }
- complete = true;
- }
-
- public void onException(Message message, Exception exception) {
- TestUtil.logMsg("Got Exception: " + exception);
- TestUtil.logMsg("With Message: " + message);
- this.exception = exception;
- this.message = message;
- complete = true;
- }
+ boolean gotCorrectException = false;
+
+ boolean gotException = false;
+
+ private static final Logger logger = (Logger) System.getLogger(MyCompletionListener.class.getName());
+
+ public MyCompletionListener() {
+ this("MyCompletionListener");
+ }
+
+ public MyCompletionListener(String name) {
+ this.name = name;
+ }
+
+ public MyCompletionListener(int numMessages) {
+ this.numMessages = numMessages;
+ messages.clear();
+ }
+
+ public MyCompletionListener(JMSContext context) {
+ this.context = context;
+ }
+
+ // getters/setters
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+
+ public Message getMessage(int index) {
+ return messages.get(index);
+ }
+
+ public void setMessage(Message message) {
+ this.message = message;
+ }
+
+ public Exception getException() {
+ return exception;
+ }
+
+ public void setException(Exception exception) {
+ this.exception = exception;
+ }
+
+ public boolean gotAllMsgs() {
+ return (messages.size() == numMessages) ? true : false;
+ }
+
+ public boolean haveMsg(int i) {
+ return (messages.size() > i) ? true : false;
+ }
+
+ public boolean isComplete() {
+ return complete;
+ }
+
+ public boolean gotCorrectException() {
+ return gotCorrectException;
+ }
+
+ public boolean gotException() {
+ return gotException;
+ }
+
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
+
+ public void onCompletion(Message message) {
+ try {
+ logger.log(Logger.Level.INFO, "onCompletion(): Got Message: " + ((TextMessage) message).getText());
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ this.message = message;
+ messages.add(message);
+ if (message instanceof TextMessage) {
+ TextMessage tMsg = (TextMessage) message;
+ try {
+ if (tMsg.getText().equals("Call close method")) {
+ logger.log(Logger.Level.INFO, "Calling JMSContext.close() MUST throw IllegalStateRuntimeException");
+ if (context != null)
+ context.close();
+ } else if (tMsg.getText().equals("Call stop method")) {
+ logger.log(Logger.Level.INFO, "Calling JMSContext.stop() MUST be allowed");
+ if (context != null)
+ context.stop();
+ } else if (tMsg.getText().equals("Call commit method")) {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.commit() MUST throw IllegalStateRuntimeException");
+ if (context != null)
+ context.commit();
+ } else if (tMsg.getText().equals("Call rollback method")) {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.rollback() MUST throw IllegalStateRuntimeException");
+ if (context != null)
+ context.rollback();
+ }
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ gotCorrectException = true;
+ gotException = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ gotCorrectException = false;
+ gotException = true;
+ exception = e;
+ }
+ }
+ complete = true;
+ }
+
+ public void onException(Message message, Exception exception) {
+ logger.log(Logger.Level.INFO, "Got Exception: " + exception);
+ logger.log(Logger.Level.INFO, "With Message: " + message);
+ this.exception = exception;
+ this.message = message;
+ complete = true;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyCompletionListener2.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyCompletionListener2.java
index 14fcbc0a55..57a66f185e 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyCompletionListener2.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyCompletionListener2.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,76 +19,78 @@
*/
package com.sun.ts.tests.jms.core20.appclient.jmscontextqueuetests;
-import com.sun.ts.lib.util.TestUtil;
+import java.lang.System.Logger;
import jakarta.jms.CompletionListener;
import jakarta.jms.Message;
public class MyCompletionListener2 implements CompletionListener {
- private String name = null;
+ private String name = null;
- private Message message = null;
+ private Message message = null;
- private Exception exception = null;
+ private Exception exception = null;
- private int numMessages = 1;
+ private int numMessages = 1;
- boolean complete = false;
+ boolean complete = false;
- public MyCompletionListener2() {
- this("MyCompletionListener2");
- }
+ private static final Logger logger = (Logger) System.getLogger(MyCompletionListener2.class.getName());
- public MyCompletionListener2(String name) {
- this.name = name;
- }
+ public MyCompletionListener2() {
+ this("MyCompletionListener2");
+ }
- // getters/setters
- public String getName() {
- return name;
- }
+ public MyCompletionListener2(String name) {
+ this.name = name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ // getters/setters
+ public String getName() {
+ return name;
+ }
- public Message getMessage() {
- return message;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public void setMessage(Message message) {
- this.message = message;
- }
+ public Message getMessage() {
+ return message;
+ }
- public Exception getException() {
- return exception;
- }
+ public void setMessage(Message message) {
+ this.message = message;
+ }
- public void setException(Exception exception) {
- this.exception = exception;
- }
+ public Exception getException() {
+ return exception;
+ }
- public boolean isComplete() {
- return complete;
- }
+ public void setException(Exception exception) {
+ this.exception = exception;
+ }
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
+ public boolean isComplete() {
+ return complete;
+ }
- public void onCompletion(Message message) {
- TestUtil.logMsg("onCompletion(): Got Message: " + message);
- this.message = message;
- complete = true;
- }
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
- public void onException(Message message, Exception exception) {
- TestUtil.logMsg("OnException(): Got Exception: " + exception);
- TestUtil.logMsg("With Message: " + message);
- this.exception = exception;
- this.message = message;
- complete = true;
- }
+ public void onCompletion(Message message) {
+ logger.log(Logger.Level.INFO, "onCompletion(): Got Message: " + message);
+ this.message = message;
+ complete = true;
+ }
+
+ public void onException(Message message, Exception exception) {
+ logger.log(Logger.Level.INFO, "OnException(): Got Exception: " + exception);
+ logger.log(Logger.Level.INFO, "With Message: " + message);
+ this.exception = exception;
+ this.message = message;
+ complete = true;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyExceptionListener.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyExceptionListener.java
index b354dcb417..dc56e11f98 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyExceptionListener.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyExceptionListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,56 +19,58 @@
*/
package com.sun.ts.tests.jms.core20.appclient.jmscontextqueuetests;
-import com.sun.ts.lib.util.TestUtil;
+import java.lang.System.Logger;
import jakarta.jms.ExceptionListener;
import jakarta.jms.JMSException;
public class MyExceptionListener implements ExceptionListener {
- private String name = null;
+ private String name = null;
- private JMSException exception = null;
+ private JMSException exception = null;
- boolean complete = false;
+ boolean complete = false;
- public MyExceptionListener() {
- this("MyExceptionListener");
- }
+ private static final Logger logger = (Logger) System.getLogger(MyExceptionListener.class.getName());
- public MyExceptionListener(String name) {
- this.name = name;
- }
+ public MyExceptionListener() {
+ this("MyExceptionListener");
+ }
- // getters/setters
- public String getName() {
- return name;
- }
+ public MyExceptionListener(String name) {
+ this.name = name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ // getters/setters
+ public String getName() {
+ return name;
+ }
- public JMSException getException() {
- return exception;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public void setException(JMSException exception) {
- this.exception = exception;
- }
+ public JMSException getException() {
+ return exception;
+ }
- public boolean isComplete() {
- return complete;
- }
+ public void setException(JMSException exception) {
+ this.exception = exception;
+ }
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
+ public boolean isComplete() {
+ return complete;
+ }
- public void onException(JMSException exception) {
- TestUtil.logMsg("Got JMSException: " + exception);
- this.exception = exception;
- complete = true;
- }
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
+
+ public void onException(JMSException exception) {
+ logger.log(Logger.Level.INFO, "Got JMSException: " + exception);
+ this.exception = exception;
+ complete = true;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyMessageListener.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyMessageListener.java
index c90b6aec76..663a4f3df5 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyMessageListener.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyMessageListener.java
@@ -19,10 +19,9 @@
*/
package com.sun.ts.tests.jms.core20.appclient.jmscontextqueuetests;
+import java.lang.System.Logger;
import java.util.ArrayList;
-import com.sun.ts.lib.util.TestUtil;
-
import jakarta.jms.IllegalStateRuntimeException;
import jakarta.jms.JMSContext;
import jakarta.jms.Message;
@@ -31,138 +30,137 @@
public class MyMessageListener implements MessageListener {
- private String name = null;
+ private String name = null;
+
+ private Message message = null;
+
+ private JMSContext context = null;
- private Message message = null;
+ private ArrayList messages = new ArrayList();
- private JMSContext context = null;
+ private Exception exception = null;
- private ArrayList messages = new ArrayList();
+ private int numMessages = 1;
- private Exception exception = null;
+ boolean complete = false;
- private int numMessages = 1;
-
- boolean complete = false;
-
- boolean gotCorrectException = false;
-
- boolean gotException = false;
-
- public MyMessageListener() {
- this("MyMessageListener");
- }
-
- public MyMessageListener(String name) {
- this.name = name;
- }
-
- public MyMessageListener(int numMessages) {
- this.numMessages = numMessages;
- messages.clear();
- }
-
- public MyMessageListener(JMSContext context) {
- this.context = context;
- }
-
- // getters/setters
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Message getMessage() {
- return message;
- }
-
- public Message getMessage(int index) {
- return messages.get(index);
- }
-
- public void setMessage(Message message) {
- this.message = message;
- }
-
- public Exception getException() {
- return exception;
- }
-
- public void setException(Exception exception) {
- this.exception = exception;
- }
-
- public boolean isComplete() {
- return complete;
- }
-
- public boolean gotCorrectException() {
- return gotCorrectException;
- }
-
- public boolean gotException() {
- return gotException;
- }
-
- public boolean gotAllMsgs() {
- return (messages.size() == numMessages) ? true : false;
- }
-
- public boolean haveMsg(int i) {
- return (messages.size() > i) ? true : false;
- }
-
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
-
- public void onMessage(Message message) {
- try {
- TestUtil.logMsg(
- "onMessage(): Got Message: " + ((TextMessage) message).getText());
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- this.message = message;
- messages.add(message);
- if (message instanceof TextMessage) {
- TextMessage tMsg = (TextMessage) message;
- try {
- if (tMsg.getText().equals("Call close method")) {
- TestUtil.logMsg(
- "Calling JMSContext.close() MUST throw IllegalStateRuntimeException");
- if (context != null)
- context.close();
- } else if (tMsg.getText().equals("Call stop method")) {
- TestUtil.logMsg(
- "Calling JMSContext.stop() MUST throw IllegalStateRuntimeException");
- if (context != null)
- context.stop();
- } else if (tMsg.getText().equals("Call commit method")) {
- TestUtil.logMsg(
- "Calling JMSContext.commit() MUST throw IllegalStateRuntimeException");
- if (context != null)
- context.commit();
- } else if (tMsg.getText().equals("Call rollback method")) {
- TestUtil.logMsg(
- "Calling JMSContext.rollback() MUST throw IllegalStateRuntimeException");
- if (context != null)
- context.rollback();
- }
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- gotCorrectException = true;
- gotException = true;
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- gotCorrectException = false;
- gotException = true;
- exception = e;
- }
- }
- complete = true;
- }
+ boolean gotCorrectException = false;
+
+ boolean gotException = false;
+
+ private static final Logger logger = (Logger) System.getLogger(MyMessageListener.class.getName());
+
+ public MyMessageListener() {
+ this("MyMessageListener");
+ }
+
+ public MyMessageListener(String name) {
+ this.name = name;
+ }
+
+ public MyMessageListener(int numMessages) {
+ this.numMessages = numMessages;
+ messages.clear();
+ }
+
+ public MyMessageListener(JMSContext context) {
+ this.context = context;
+ }
+
+ // getters/setters
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+
+ public Message getMessage(int index) {
+ return messages.get(index);
+ }
+
+ public void setMessage(Message message) {
+ this.message = message;
+ }
+
+ public Exception getException() {
+ return exception;
+ }
+
+ public void setException(Exception exception) {
+ this.exception = exception;
+ }
+
+ public boolean isComplete() {
+ return complete;
+ }
+
+ public boolean gotCorrectException() {
+ return gotCorrectException;
+ }
+
+ public boolean gotException() {
+ return gotException;
+ }
+
+ public boolean gotAllMsgs() {
+ return (messages.size() == numMessages) ? true : false;
+ }
+
+ public boolean haveMsg(int i) {
+ return (messages.size() > i) ? true : false;
+ }
+
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
+
+ public void onMessage(Message message) {
+ try {
+ logger.log(Logger.Level.INFO, "onMessage(): Got Message: " + ((TextMessage) message).getText());
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ this.message = message;
+ messages.add(message);
+ if (message instanceof TextMessage) {
+ TextMessage tMsg = (TextMessage) message;
+ try {
+ if (tMsg.getText().equals("Call close method")) {
+ logger.log(Logger.Level.INFO, "Calling JMSContext.close() MUST throw IllegalStateRuntimeException");
+ if (context != null)
+ context.close();
+ } else if (tMsg.getText().equals("Call stop method")) {
+ logger.log(Logger.Level.INFO, "Calling JMSContext.stop() MUST throw IllegalStateRuntimeException");
+ if (context != null)
+ context.stop();
+ } else if (tMsg.getText().equals("Call commit method")) {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.commit() MUST throw IllegalStateRuntimeException");
+ if (context != null)
+ context.commit();
+ } else if (tMsg.getText().equals("Call rollback method")) {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.rollback() MUST throw IllegalStateRuntimeException");
+ if (context != null)
+ context.rollback();
+ }
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ gotCorrectException = true;
+ gotException = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ gotCorrectException = false;
+ gotException = true;
+ exception = e;
+ }
+ }
+ complete = true;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyMessageListener2.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyMessageListener2.java
index a24ca60858..00f72d48a7 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyMessageListener2.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontextqueuetests/MyMessageListener2.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,59 +19,61 @@
*/
package com.sun.ts.tests.jms.core20.appclient.jmscontextqueuetests;
-import com.sun.ts.lib.util.TestUtil;
+import java.lang.System.Logger;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
public class MyMessageListener2 implements MessageListener {
- private String name = null;
+ private String name = null;
- private Message message = null;
+ private Message message = null;
- private Exception exception = null;
+ private Exception exception = null;
- private int numMessages = 1;
+ private int numMessages = 1;
- boolean complete = false;
+ boolean complete = false;
- public MyMessageListener2() {
- this("MyMessageListener2");
- }
+ private static final Logger logger = (Logger) System.getLogger(MyMessageListener2.class.getName());
- public MyMessageListener2(String name) {
- this.name = name;
- }
+ public MyMessageListener2() {
+ this("MyMessageListener2");
+ }
- // getters/setters
- public String getName() {
- return name;
- }
+ public MyMessageListener2(String name) {
+ this.name = name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ // getters/setters
+ public String getName() {
+ return name;
+ }
- public Message getMessage() {
- return message;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public void setMessage(Message message) {
- this.message = message;
- }
+ public Message getMessage() {
+ return message;
+ }
- public boolean isComplete() {
- return complete;
- }
+ public void setMessage(Message message) {
+ this.message = message;
+ }
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
+ public boolean isComplete() {
+ return complete;
+ }
- public void onMessage(Message message) {
- TestUtil.logMsg("onCompletion(): Got Message: " + message);
- this.message = message;
- complete = true;
- }
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
+
+ public void onMessage(Message message) {
+ logger.log(Logger.Level.INFO, "onCompletion(): Got Message: " + message);
+ this.message = message;
+ complete = true;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/Client.java
deleted file mode 100644
index f73e846999..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/Client.java
+++ /dev/null
@@ -1,1811 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.appclient.jmscontexttopictests;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.DeliveryMode;
-import jakarta.jms.Destination;
-import jakarta.jms.InvalidClientIDRuntimeException;
-import jakarta.jms.InvalidDestinationRuntimeException;
-import jakarta.jms.JMSConsumer;
-import jakarta.jms.JMSContext;
-import jakarta.jms.JMSProducer;
-import jakarta.jms.JMSRuntimeException;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.MessageFormatRuntimeException;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.appclient.jmscontexttopictests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null;
-
- private transient JmsTool tool2 = null;
-
- // JMS objects
- private transient ConnectionFactory cf = null;
-
- private transient ConnectionFactory cf2 = null;
-
- private transient Topic topic = null;
-
- private transient Destination destination = null;
-
- private transient JMSContext context = null;
-
- private transient JMSContext context2 = null;
-
- private transient JMSContext contextD = null;
-
- private transient JMSConsumer consumer = null;
-
- private transient JMSProducer producer = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * Utility method to return the session mode as a String
- */
- private String printSessionMode(int sessionMode) {
- switch (sessionMode) {
- case JMSContext.SESSION_TRANSACTED:
- return "SESSION_TRANSACTED";
- case JMSContext.AUTO_ACKNOWLEDGE:
- return "AUTO_ACKNOWLEDGE";
- case JMSContext.CLIENT_ACKNOWLEDGE:
- return "CLIENT_ACKNOWLEDGE";
- case JMSContext.DUPS_OK_ACKNOWLEDGE:
- return "DUPS_OK_ACKNOWLEDGE";
- default:
- return "UNEXPECTED_SESSIONMODE";
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- String lookupDurableTopicFactory = "DURABLE_SUB_CONNECTION_FACTORY";
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- connections = new ArrayList(5);
-
- // set up JmsTool for COMMON_T setup
- TestUtil.logMsg("Setup JmsTool for COMMON_T setup");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- topic = (Topic) destination;
- tool.getDefaultConnection().close();
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
-
- // set up JmsTool for COMMON_T setup
- TestUtil.logMsg(
- "Setup JmsTool for COMMON_T and durable topic connection factory");
- tool2 = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupDurableTopicFactory, mode);
- tool2.getDefaultConnection().close();
- cf2 = tool2.getConnectionFactory();
- contextD = cf2.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /* leanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Close JMSContext objects");
- if (context != null) {
- context.close();
- context = null;
- }
- if (contextD != null) {
- contextD.close();
- contextD = null;
- }
- TestUtil.logMsg("Close JMSConsumer objects");
- if (consumer != null) {
- consumer.close();
- consumer = null;
- }
- tool.closeAllResources();
- tool2.closeAllResources();
- producer = null;
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * @testName: setGetClientIDTest
- *
- * @assertion_ids: JMS:JAVADOC:970; JMS:JAVADOC:1040; JMS:SPEC:264.5;
- * JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:91;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.setClientID(String clientID) JMSContext.getClientID()
- */
- public void setGetClientIDTest() throws Exception {
- boolean pass = true;
- try {
- String clientid = "myclientid";
- TestUtil.logMsg("Calling setClientID(" + clientid + ")");
- context.setClientID(clientid);
- TestUtil.logMsg(
- "Calling getClientID and expect " + clientid + " to be returned");
- String cid = context.getClientID();
- if (!cid.equals(clientid)) {
- TestUtil
- .logErr("getClientID() returned " + cid + ", expected " + clientid);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("setGetClientIDTest");
- }
-
- if (!pass) {
- throw new Exception("setGetClientIDTest failed");
- }
- }
-
- /*
- * @testName: setClientIDLateTest
- *
- * @assertion_ids: JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:94; JMS:SPEC:91;
- * JMS:JAVADOC:1040; JMS:JAVADOC:1043; JMS:SPEC:264.5;
- *
- * @test_Strategy: Create a JMSContext, send and receive a message, then try
- * to set the ClientID. Verify that IllegalStateRuntimeException is thrown.
- *
- * JMSContext.setClientID(String clientID)
- */
- public void setClientIDLateTest() throws Exception {
- boolean pass = true;
-
- try {
- TextMessage messageSent;
- TextMessage messageReceived;
- String message = "This is my message.";
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "setClientIDLateTest");
- TestUtil.logMsg("Calling JMSProduce.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage != null) {
- TestUtil.logMsg("actTextMessage=" + actTextMessage.getText());
- }
-
- TestUtil.logTrace(
- "Attempt to set Client ID too late (expect IllegalStateRuntimeException)");
- try {
- context.setClientID("setClientIDLateTest");
- pass = false;
- TestUtil.logErr("IllegalStateRuntimeException was not thrown");
- } catch (jakarta.jms.IllegalStateRuntimeException is) {
- TestUtil.logMsg("IllegalStateRuntimeException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Incorrect exception received: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("setClientIDLateTest", e);
- }
- if (!pass) {
- throw new Exception("setClientIDLateTest failed");
- }
- }
-
- /*
- * @testName: setClientIDOnAdminConfiguredIDTest
- *
- * @assertion_ids: JMS:JAVADOC:970; JMS:JAVADOC:1040; JMS:SPEC:264.5;
- * JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:91;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.setClientID(String clientID)
- *
- * Expect IllegalStateRuntimeException
- */
- public void setClientIDOnAdminConfiguredIDTest() throws Exception {
- boolean pass = true;
- try {
- String clientid = "myclientid";
- TestUtil.logMsg("Try setting ClientID on JMSContext administratively "
- + "configured with ClientID (expect IllegalStateRuntimeException)");
- contextD.setClientID(clientid);
- TestUtil.logErr("Did not throw expected IllegalStateRuntimeException");
- pass = false;
- String cid = contextD.getClientID();
- if (cid == null) {
- TestUtil.logErr("getClientID returned null (expected cts)");
- pass = false;
- } else if (!cid.equals("cts")) {
- TestUtil.logErr("getClientID() returned " + cid + ", expected cts");
- pass = false;
- } else {
- TestUtil.logMsg("getClientID returned cts (Correct)");
- }
- } catch (jakarta.jms.IllegalStateRuntimeException is) {
- TestUtil.logMsg("IllegalStateRuntimeException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Incorrect exception received: " + e);
- throw new Exception("setClientIDOnAdminConfiguredIDTest");
- }
-
- if (!pass) {
- throw new Exception("setClientIDOnAdminConfiguredIDTest failed");
- }
- }
-
- /*
- * @testName: setGetChangeClientIDTest
- *
- * @assertion_ids: JMS:SPEC:93; JMS:SPEC:95; JMS:SPEC:198; JMS:JAVADOC:1040;
- * JMS:JAVADOC:970; JMS:JAVADOC:1042; JMS:JAVADOC:1043; JMS:SPEC:264.5;
- *
- *
- * @test_Strategy: Test setClientID()/getClientID(). Make sure that the
- * clientID set is the clientID returned. Then try and reset the clientID.
- * Verify that the IllegalStateRuntimeException is thrown. 1) Use a JMSContext
- * that has no ClientID set, then call setClientID twice. 2) Try and set the
- * clientID on a second JMSContext to the clientID value of the first
- * JMSContext. Verify that InvalidClientIDRuntimeException is thrown.
- *
- * JMSContext.setClientID(String clientID) JMSContext.getClientID()
- */
- public void setGetChangeClientIDTest() throws Exception {
- boolean pass = true;
- String lookup = "MyTopicConnectionFactory";
-
- try {
- TestUtil.logMsg("Create second JMSContext with AUTO_ACKNOWLEDGE");
- context2 = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
-
- TestUtil.logMsg("Setting clientID!");
- context.setClientID("ctstest");
-
- TestUtil.logMsg("Getting clientID!");
- String clientid = context.getClientID();
-
- if (!clientid.equals("ctstest")) {
- TestUtil.logErr(
- "getClientID() returned " + clientid + ", expected ctstest");
- pass = false;
- } else {
- TestUtil.logMsg("setClientID/getClientID correct");
- }
-
- TestUtil
- .logMsg("Resetting clientID! (expect IllegalStateRuntimeException)");
- context.setClientID("changeIt");
- TestUtil.logErr("No exception was thrown on ClientID reset");
- pass = false;
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- TestUtil.logMsg("IllegalStateRuntimeException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Incorrect exception received: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Set clientID on second context to value of clientID on first "
- + "context (expect InvalidClientIDRuntimeException)");
- context2.setClientID("ctstest");
- TestUtil
- .logErr("No exception was thrown on ClientID that already exists");
- pass = false;
- } catch (InvalidClientIDRuntimeException e) {
- TestUtil.logMsg("InvalidClientIDRuntimeException thrown as expected");
- } catch (Exception e) {
- TestUtil.logErr("Incorrect exception received: " + e);
- pass = false;
- } finally {
- try {
- if (context2 != null) {
- context2.close();
- context2 = null;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception in finally block: " + e);
- throw new Exception("setGetChangeClientIDTest", e);
- }
- }
-
- if (!pass) {
- throw new Exception("setGetChangeClientIDTest");
- }
- }
-
- /*
- * @testName: setGetExceptionListenerTest
- *
- * @assertion_ids: JMS:JAVADOC:1052; JMS:JAVADOC:980;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.setExceptionListener(ExceptionListener).
- * JMSContext.getExceptionListener().
- */
- public void setGetExceptionListenerTest() throws Exception {
- boolean pass = true;
- try {
- MyExceptionListener expExceptionListener = new MyExceptionListener();
- TestUtil
- .logMsg("Calling setExceptionListener(" + expExceptionListener + ")");
- context.setExceptionListener(expExceptionListener);
- TestUtil.logMsg("Calling getExceptionListener and expect "
- + expExceptionListener + " to be returned");
- MyExceptionListener actExceptionListener = (MyExceptionListener) context
- .getExceptionListener();
- if (!actExceptionListener.equals(expExceptionListener)) {
- TestUtil.logErr("getExceptionListener() returned "
- + actExceptionListener + ", expected " + expExceptionListener);
- pass = false;
- }
- TestUtil.logMsg("Calling setExceptionListener(null)");
- context.setExceptionListener(null);
- if (context.getExceptionListener() != null) {
- TestUtil.logErr("getExceptionListener() returned "
- + context.getExceptionListener() + ", expected null");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("setGetExceptionListenerTest");
- }
-
- if (!pass) {
- throw new Exception("setGetExceptionListenerTest failed");
- }
- }
-
- /*
- * @testName: setGetAsyncTest
- *
- * @assertion_ids: JMS:JAVADOC:1182; JMS:JAVADOC:1255;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.setAsync(CompletionListener). JMSContext.getAsync().
- */
- public void setGetAsyncTest() throws Exception {
- boolean pass = true;
- try {
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- // Set and get asyncronous CompletionListener
- MyCompletionListener expCompletionListener = new MyCompletionListener();
- TestUtil.logMsg(
- "Calling JMSProducer.setAsync(" + expCompletionListener + ")");
- producer.setAsync(expCompletionListener);
- TestUtil.logMsg("Calling JMSProducer.getAsync() and expect "
- + expCompletionListener + " to be returned");
- MyCompletionListener actCompletionListener = (MyCompletionListener) producer
- .getAsync();
- if (!actCompletionListener.equals(expCompletionListener)) {
- TestUtil.logErr("getAsync() returned " + actCompletionListener
- + ", expected " + expCompletionListener);
- pass = false;
- }
-
- // Now set and get null asyncronous CompletionListener
- TestUtil.logMsg("Calling setAsync(null)");
- producer.setAsync(null);
- TestUtil.logMsg(
- "Calling JMSProducer.getAsync() and expect NULL to be returned");
- if (producer.getAsync() != null) {
- TestUtil.logErr(
- "getAsync() returned " + producer.getAsync() + ", expected null");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("setGetAsyncTest");
- }
-
- if (!pass) {
- throw new Exception("setGetAsyncTest failed");
- }
- }
-
- /*
- * @testName: startStopTest
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:1076; JMS:JAVADOC:1078;
- * JMS:JAVADOC:942; JMS:JAVADOC:1102; JMS:SPEC:264; JMS:SPEC:264.5;
- *
- * @test_Strategy: Test the following APIs:
- *
- * ConnectionFactory.createContext(String, String, int) JMSContext.start()
- * JMSContext.stop() JMSContext.createConsumer(Destination)
- * JMSContext.createProducer() JMSProducer.send(Destination, Message)
- * JMSConsumer.receive(long timeout)
- *
- * 1. Create JMSContext with AUTO_ACKNOWLEDGE. This is done in the setup()
- * routine. 2. Call stop. 3. Send x messages to a Topic. 4. Create a
- * JMSConsumer to consume the messages in the Topic. 5. Try consuming messages
- * from the Topic. Should not receive any messages since the connection has
- * been stopped. 6. Call start. 7. Try consuming messages from the Topic.
- * Should receive all messages from the Topic since the connection has been
- * started.
- *
- */
- public void startStopTest() throws Exception {
- boolean pass = true;
- try {
- TextMessage tempMsg = null;
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Stop delivery of incoming messages on JMSContext's connection
- TestUtil.logMsg("Call stop() to stop delivery of incoming messages");
- context.stop();
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- // Send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " messages to Topic");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "startStopTest" + i);
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- // Try consuming a message from the Topic (should not receive a message)
- TestUtil.logMsg("Try consuming a message on a STOPPED connection");
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("Received a message on a STOPPED connection");
- TestUtil.logErr("Message is: " + tempMsg.getText());
- pass = false;
- }
-
- // Start delivery of incoming messages on JMSContext's connection
- TestUtil.logMsg("Call start() to start delivery of incoming messages");
- context.start();
-
- TestUtil.logMsg(
- "Consume all the messages in the Topic on a STARTED connection");
- for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("JMSConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + msgCount + " missing from Topic");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + msgCount)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + msgCount + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received message: " + tempMsg.getText());
- }
- }
-
- // Try to receive one more message (should return null for no more
- // messages)
- TestUtil.logMsg("Topic should now be empty");
- TestUtil.logMsg("Try consuming one more message should return NULL");
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("JMSConsumer.receive() did not return NULL");
- TestUtil
- .logErr("JMSConsumer.receive() returned a message (unexpected)");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("startStopTest");
- }
-
- if (!pass) {
- throw new Exception("startStopTest failed");
- }
- }
-
- /*
- * @testName: createContextTest
- *
- * @assertion_ids: JMS:JAVADOC:931; JMS:SPEC:265.3;
- *
- * @test_Strategy: Creates a JMSContext with the default user identity and the
- * specified sessionMode. Tests API:
- *
- * JMSContext.createContext(int)
- */
- public void createContextTest() throws Exception {
- boolean pass = true;
- try {
-
- JMSContext newContext = null;
-
- // Test all possible session modes
- int expSessionMode[] = { JMSContext.SESSION_TRANSACTED,
- JMSContext.AUTO_ACKNOWLEDGE, JMSContext.CLIENT_ACKNOWLEDGE,
- JMSContext.DUPS_OK_ACKNOWLEDGE, };
-
- // Cycle through all session modes
- for (int i = 0; i < expSessionMode.length; i++) {
- TestUtil.logMsg("Creating context with session mode ("
- + printSessionMode(expSessionMode[i]) + ")");
- TestUtil.logMsg("Call API TopicConnectionFactory.createContext(int)");
- newContext = context.createContext(expSessionMode[i]);
- TestUtil.logMsg("Now call API JMSContext.getSessionMode()");
- TestUtil.logMsg("Calling getSessionMode and expect "
- + printSessionMode(expSessionMode[i]) + " to be returned");
- int actSessionMode = newContext.getSessionMode();
- if (actSessionMode != expSessionMode[i]) {
- TestUtil.logErr(
- "getSessionMode() returned " + printSessionMode(actSessionMode)
- + ", expected " + printSessionMode(expSessionMode[i]));
- pass = false;
- }
- newContext.close();
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("createContextTest");
- }
-
- if (!pass) {
- throw new Exception("createContextTest failed");
- }
- }
-
- /*
- * @testName: sendAndRecvCLTest1
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
- * JMS:JAVADOC:1255; JMS:SPEC:275.1; JMS:SPEC:275.5; JMS:SPEC:275.8;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data as well as onCompletion() being called. Set some
- * properties on JMSProducer and check that these properties exist on the
- * returned message after the CompletionListener's onCompletion() method has
- * been called.
- *
- * JMSContext.createProducer() JMSProducer.setAsync(CompletionListener)
- * JMSProducer.send(Destination, Message)
- */
- public void sendAndRecvCLTest1() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
-
- try {
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvCLTest1");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- // ------------------------------------------------------------------------------
- // Set JMSProducer message properties
- // Set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- TestUtil.logMsg("Set primitive property types on JMSProducer");
- producer.setProperty("TESTBOOLEAN", bool);
- producer.setProperty("TESTBYTE", bValue);
- producer.setProperty("TESTDOUBLE", nDouble);
- producer.setProperty("TESTFLOAT", nFloat);
- producer.setProperty("TESTINT", nInt);
- producer.setProperty("TESTLONG", nLong);
- producer.setProperty("TESTSHORT", nShort);
- producer.setProperty("TESTSTRING", "test");
-
- // ------------------------------------------------------------------------------
- // Set JMSProducer message properties
- // Set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
- // String.
- // ------------------------------------------------------------------------------
- TestUtil.logMsg("Set Object property types on JMSProducer");
- producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
- producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
- producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
- producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
- producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
- producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
- producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
- producer.setProperty("OBJTESTSTRING", "test");
-
- TestUtil.logMsg("Calling JMSProducer.setAsync(CompletionListener)");
- producer.setAsync(listener);
- TestUtil.logMsg("Calling JMSProducer.send(Destination,Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive TextMessage");
- TextMessage actTextMessage = null;
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
-
- // --------------------------------------------------------------------------------------
- // Retrieve the properties from the received TextMessage and verify that
- // they are correct
- // Get properties for boolean, byte, short, int, long, float, double, and
- // String.
- // -------------------------------------------------------------------------------------
- TestUtil.logMsg(
- "Retrieve and verify that TextMessage message properties were set correctly");
- if (actTextMessage.getBooleanProperty("TESTBOOLEAN") == bool) {
- TestUtil.logMsg("Pass: getBooleanProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Fail: incorrect value returned from getBooleanProperty");
- pass = false;
- }
- if (actTextMessage.getByteProperty("TESTBYTE") == bValue) {
- TestUtil.logMsg("Pass: getByteProperty returned correct value");
- } else {
- TestUtil.logMsg("Fail: incorrect value returned from getByteProperty");
- pass = false;
- }
- if (actTextMessage.getLongProperty("TESTLONG") == nLong) {
- TestUtil.logMsg("Pass: getLongProperty returned correct value");
- } else {
- TestUtil.logMsg("Fail: incorrect value returned from getLongProperty");
- pass = false;
- }
- if (actTextMessage.getStringProperty("TESTSTRING").equals(testString)) {
- TestUtil.logMsg("Pass: getStringProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Fail: incorrect value returned from getStringProperty");
- pass = false;
- }
- if (actTextMessage.getDoubleProperty("TESTDOUBLE") == nDouble) {
- TestUtil.logMsg("Pass: getDoubleProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Fail: incorrect value returned from getDoubleProperty");
- pass = false;
- }
- if (actTextMessage.getFloatProperty("TESTFLOAT") == nFloat) {
- TestUtil.logMsg("Pass: getFloatProperty returned correct value");
- } else {
- TestUtil.logMsg("Fail: incorrect value returned from getFloatProperty");
- pass = false;
- }
- if (actTextMessage.getIntProperty("TESTINT") == nInt) {
- TestUtil.logMsg("Pass: getIntProperty returned correct value");
- } else {
- TestUtil.logMsg("Fail: incorrect value returned from getIntProperty");
- pass = false;
- }
- if (actTextMessage.getShortProperty("TESTSHORT") == nShort) {
- TestUtil.logMsg("Pass: getShortProperty returned correct value");
- } else {
- TestUtil.logMsg("Fail: incorrect value returned from getShortProperty");
- pass = false;
- }
-
- // --------------------------------------------------------------------------------------
- // Retrieve the properties from the received TextMessage and verify that
- // they are correct
- // Get properties for Boolean, Byte, Short, Integer, Long, Float, Double,
- // and String.
- // --------------------------------------------------------------------------------------
- if (((Boolean) actTextMessage.getObjectProperty("OBJTESTBOOLEAN"))
- .booleanValue() == bool) {
- TestUtil
- .logMsg("Pass: getObjectProperty returned correct Boolean value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Boolean value returned from getObjectProperty");
- pass = false;
- }
- if (((Byte) actTextMessage.getObjectProperty("OBJTESTBYTE"))
- .byteValue() == bValue) {
- TestUtil.logMsg("Pass: getObjectProperty returned correct Byte value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Byte value returned from getObjectProperty");
- pass = false;
- }
- if (((Long) actTextMessage.getObjectProperty("OBJTESTLONG"))
- .longValue() == nLong) {
- TestUtil.logMsg("Pass: getObjectProperty returned correct Long value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Long value returned from getObjectProperty");
- pass = false;
- }
- if (((String) actTextMessage.getObjectProperty("OBJTESTSTRING"))
- .equals(testString)) {
- TestUtil
- .logMsg("Pass: getObjectProperty returned correct String value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect String value returned from getObjectProperty");
- pass = false;
- }
- if (((Double) actTextMessage.getObjectProperty("OBJTESTDOUBLE"))
- .doubleValue() == nDouble) {
- TestUtil
- .logMsg("Pass: getObjectProperty returned correct Double value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Double value returned from getObjectProperty");
- pass = false;
- }
- if (((Float) actTextMessage.getObjectProperty("OBJTESTFLOAT"))
- .floatValue() == nFloat) {
- TestUtil.logMsg("Pass: getObjectProperty returned correct Float value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Float value returned from getObjectProperty");
- pass = false;
- }
- if (((Integer) actTextMessage.getObjectProperty("OBJTESTINT"))
- .intValue() == nInt) {
- TestUtil
- .logMsg("Pass: getObjectProperty returned correct Integer value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Integer value returned from getObjectProperty");
- pass = false;
- }
- if (((Short) actTextMessage.getObjectProperty("OBJTESTSHORT"))
- .shortValue() == nShort) {
- TestUtil.logMsg("Pass: getObjectProperty returned correct Short value");
- } else {
- TestUtil.logMsg(
- "Fail: incorrect Short value returned from getObjectProperty");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvCLTest1", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvCLTest1 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvCLTest2
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
- * JMS:JAVADOC:1255; JMS:JAVADOC:1259; JMS:JAVADOC:1303;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data as well as onCompletion() being called.
- *
- * JMSContext.createProducer() JMSProducer.setDeliveryMode(int)
- * JMSProducer.setPriority(int) JMSProducer.setTimeToLive(long)
- * JMSProducer.setAsync(CompletionListener) JMSProducer.send(Destination,
- * Message)
- */
- public void sendAndRecvCLTest2() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvCLTest2");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- TestUtil.logMsg("Calling JMSProducer.setAsync(CompletionListener)");
- producer.setAsync(listener);
- TestUtil.logMsg("Set delivery mode, priority, and time to live");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- producer.setPriority(Message.DEFAULT_PRIORITY);
- producer.setTimeToLive(0L);
- TestUtil.logMsg("Calling JMSProducer.send(Destination,Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive TextMessage");
- TextMessage actTextMessage = null;
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Check the values in TextMessage, deliverymode, priority, time to live");
- if (!actTextMessage.getText().equals(expTextMessage.getText())
- || actTextMessage.getJMSDeliveryMode() != DeliveryMode.PERSISTENT
- || actTextMessage.getJMSPriority() != Message.DEFAULT_PRIORITY
- || actTextMessage.getJMSExpiration() != 0L) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- TestUtil.logErr("DeliveryMode=" + actTextMessage.getJMSDeliveryMode()
- + ", expected " + expTextMessage.getJMSDeliveryMode());
- TestUtil.logErr("Priority=" + actTextMessage.getJMSPriority()
- + ", expected " + expTextMessage.getJMSPriority());
- TestUtil.logErr("TimeToLive=" + actTextMessage.getJMSExpiration()
- + ", expected " + expTextMessage.getJMSExpiration());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvCLTest2", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvCLTest2 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvMsgOfEachTypeCLTest
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
- * JMS:JAVADOC:1255; JMS:JAVADOC:1259; JMS:JAVADOC:1303;
- *
- * @test_Strategy: Send and receive messages of each message type: Message,
- * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Verify
- * the send and recv of data as well as onCompletion() being called in
- * CompletionListener.
- *
- * JMSContext.createProducer() JMSProducer.setAsync(CompletionListener)
- * JMSContext.createMessage() JMSContext.createBytesMessage()
- * JMSContext.createMapMessage() JMSContext.createObjectMessage()
- * JMSContext.createStreamMessage() JMSContext.createTextMessage(String)
- * JMSProducer.send(Destination, Message)
- */
- public void sendAndRecvMsgOfEachTypeCLTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
-
- // send and receive Message
- TestUtil.logMsg("Send and receive Message");
- Message msg = context.createMessage();
- TestUtil.logMsg("Set some values in Message");
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeCLTest");
- msg.setBooleanProperty("booleanProperty", true);
- MyCompletionListener2 listener = new MyCompletionListener2();
- producer = context.createProducer();
- producer.setAsync(listener);
- producer.send(destination, msg);
- TestUtil.logMsg("Poll listener until we receive Message");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- Message actMessage = null;
- if (listener.isComplete())
- actMessage = (Message) listener.getMessage();
-
- if (actMessage == null) {
- TestUtil.logErr("Did not receive Message");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in Message");
- if (actMessage.getBooleanProperty("booleanProperty") == true) {
- TestUtil.logMsg("booleanproperty is correct");
- } else {
- TestUtil.logMsg("booleanproperty is incorrect");
- pass = false;
- }
- }
-
- // send and receive BytesMessage
- TestUtil.logMsg("Send and receive BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeCLTest");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- bMsg.reset();
- listener = new MyCompletionListener2();
- producer = context.createProducer();
- producer.setAsync(listener);
- producer.send(destination, bMsg);
- TestUtil.logMsg("Poll listener until we receive BytesMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- BytesMessage bMsgRecv = null;
- if (listener.isComplete())
- bMsgRecv = (BytesMessage) listener.getMessage();
- if (bMsgRecv == null) {
- TestUtil.logErr("Did not receive BytesMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in BytesMessage");
- if (bMsgRecv.readByte() == (byte) 1) {
- TestUtil.logMsg("bytevalue is correct");
- } else {
- TestUtil.logMsg("bytevalue is incorrect");
- pass = false;
- }
- if (bMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive MapMessage
- TestUtil.logMsg("Send and receive MapMessage");
- MapMessage mMsg = context.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeCLTest");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- listener = new MyCompletionListener2();
- producer = context.createProducer();
- producer.setAsync(listener);
- producer.send(destination, mMsg);
- TestUtil.logMsg("Poll listener until we receive MapMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- MapMessage mMsgRecv = null;
- if (listener.isComplete())
- mMsgRecv = (MapMessage) listener.getMessage();
- if (mMsgRecv == null) {
- TestUtil.logErr("Did not receive MapMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in MapMessage");
- Enumeration list = mMsgRecv.getMapNames();
- String name = null;
- while (list.hasMoreElements()) {
- name = (String) list.nextElement();
- if (name.equals("booleanvalue")) {
- if (mMsgRecv.getBoolean(name) == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logErr("booleanvalue is incorrect");
- pass = false;
- }
- } else if (name.equals("intvalue")) {
- if (mMsgRecv.getInt(name) == 10) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logErr("intvalue is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Unexpected name of [" + name + "] in MapMessage");
- pass = false;
- }
- }
- }
-
- // send and receive ObjectMessage
- TestUtil.logMsg("Send and receive ObjectMessage");
- StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
- TestUtil.logMsg("Set some values in ObjectMessage");
- ObjectMessage oMsg = context.createObjectMessage();
- oMsg.setObject(sb1);
- oMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeCLTest");
- listener = new MyCompletionListener2();
- producer = context.createProducer();
- producer.setAsync(listener);
- producer.send(destination, oMsg);
- TestUtil.logMsg("Poll listener until we receive ObjectMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- ObjectMessage oMsgRecv = null;
- if (listener.isComplete())
- oMsgRecv = (ObjectMessage) listener.getMessage();
- if (oMsgRecv == null) {
- TestUtil.logErr("Did not receive ObjectMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in ObjectMessage");
- StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
- if (sb2.toString().equals(sb1.toString())) {
- TestUtil.logMsg("objectvalue is correct");
- } else {
- TestUtil.logErr("objectvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive StreamMessage
- TestUtil.logMsg("Send and receive StreamMessage");
- StreamMessage sMsg = context.createStreamMessage();
- TestUtil.logMsg("Set some values in StreamMessage");
- sMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeCLTest");
- sMsg.writeBoolean(true);
- sMsg.writeInt((int) 22);
- sMsg.reset();
- listener = new MyCompletionListener2();
- producer = context.createProducer();
- producer.setAsync(listener);
- producer.send(destination, sMsg);
- TestUtil.logMsg("Poll listener until we receive StreamMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- StreamMessage sMsgRecv = null;
- if (listener.isComplete())
- sMsgRecv = (StreamMessage) listener.getMessage();
- if (sMsgRecv == null) {
- TestUtil.logErr("Did not receive StreamMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in StreamMessage");
- if (sMsgRecv.readBoolean() == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logMsg("booleanvalue is incorrect");
- pass = false;
- }
- if (sMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive TextMessage
- TestUtil.logMsg("Send and receive TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgOfEachTypeCLTest");
- TestUtil.logMsg("Calling JMSProducer.send(Destination,Message)");
- listener = new MyCompletionListener2();
- producer = context.createProducer();
- producer.setAsync(listener);
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive TextMessage");
- for (int i = 0; !listener.isComplete() && i < 15; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for message to arrive at listener");
- TestUtil.sleepSec(2);
- }
- TextMessage actTextMessage = null;
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the values in TextMessage");
- if (!actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvMsgOfEachTypeCLTest", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvMsgOfEachTypeCLTest failed");
- }
- }
-
- /*
- * @testName: messageOrderCLTopicTest
- *
- * @assertion_ids: JMS:SPEC:275.2; JMS:SPEC:275.7;
- *
- * @test_Strategy: Send async messages to a topic and receive them. Verify
- * that the text of each matches the order of the text in the sent messages.
- */
- public void messageOrderCLTopicTest() throws Exception {
- boolean pass = true;
- try {
- TextMessage sentTextMessage;
- String text[] = new String[numMessages];
-
- // Create CompletionListener for Message to be sent
- TestUtil.logMsg("Creating MyCompletionListener");
- MyCompletionListener listener = new MyCompletionListener(numMessages);
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- TestUtil.logMsg("Calling JMSProducer.setAsync(CompletionListener)");
- producer.setAsync(listener);
-
- // create and send async messages to topic
- TestUtil
- .logMsg("Sending " + numMessages + " asynchronous messages to topic");
- for (int i = 0; i < numMessages; i++) {
- text[i] = "message order test " + i;
- sentTextMessage = context.createTextMessage();
- sentTextMessage.setText(text[i]);
- sentTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "messageOrderCLTopicTest" + i);
- TestUtil.logMsg("Sending TextMessage: " + sentTextMessage.getText());
- producer.send(destination, sentTextMessage);
- }
-
- TestUtil.logMsg("Poll listener until we receive all " + numMessages
- + " TextMessage's from topic");
- for (int i = 0; !listener.gotAllMsgs() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
-
- for (int i = 0; i < numMessages; i++) {
- TextMessage actTextMessage = null;
- if (listener.haveMsg(i))
- actTextMessage = (TextMessage) listener.getMessage(i);
- if (actTextMessage == null) {
- TestUtil.logMsg("Did not receive TextMessage " + i + " (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("Received message: " + actTextMessage.getText());
- if (!actTextMessage.getText().equals(text[i])) {
- TestUtil.logMsg("Received message: " + actTextMessage.getText());
- TestUtil.logMsg("Should have received: " + text[i]);
- TestUtil.logErr("Received wrong message (wrong order)");
- pass = false;
- }
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("messageOrderCLTopicTest", e);
- }
-
- if (!pass)
- throw new Exception("messageOrderCLTopicTest failed");
- }
-
- /*
- * @testName: acknowledgeTest
- *
- * @assertion_ids: JMS:JAVADOC:909;
- *
- * @test_Strategy: Send and receive a message from JMSContext with
- * CLIENT_ACKNOWLEDGE and call the acknowlege method to acknowledge the
- * message consumed.
- *
- */
- public void acknowledgeTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- JMSContext msgcontext = null;
- JMSProducer msgproducer = null;
- JMSConsumer msgconsumer = null;
- try {
- msgcontext = cf.createContext(user, password,
- JMSContext.CLIENT_ACKNOWLEDGE);
- msgproducer = msgcontext.createProducer();
- msgconsumer = msgcontext.createConsumer(topic);
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = msgcontext.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "acknowledgeTest");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- msgproducer.send(destination, expTextMessage);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) msgconsumer.receive(timeout);
- TestUtil.logMsg("Received message: " + actTextMessage.getText());
- TestUtil.logMsg("Calling acknowlege to acknowledge message.");
- msgcontext.acknowledge();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("acknowledgeTest", e);
- } finally {
- try {
- if (msgconsumer != null)
- msgconsumer.close();
- if (msgcontext != null)
- msgcontext.close();
- msgproducer = null;
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("acknowledgeTest failed");
- }
- }
-
- /*
- * @testName: commitRollbackTest
- *
- * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:914; JMS:JAVADOC:995;
- * JMS:JAVADOC:942; JMS:JAVADOC:1102; JMS:JAVADOC:847; JMS:SPEC:275.3;
- *
- * @test_Strategy: Test the following APIs:
- *
- * ConnectionFactory.createContext(String, String, int)
- * JMSProducer.send(Destination, Message) JMSContext.commit()
- * JMSContext.rollback() JMSContext.createConsumer(Destination)
- * JMSContext.receive(long timeout)
- *
- * 1. Create JMSContext with SESSION_TRANSACTED. This is done in the setup()
- * routine. 2. Send x messages to a Topic. 3. Call rollback() to rollback the
- * sent messages. 4. Create a JMSConsumer to consume the messages in the
- * Topic. Should not receive any messages since the sent messages were rolled
- * back. Verify that no messages are received. 5. Send x messages to a Topic.
- * 6. Call commit() to commit the sent messages. 7. Create a JMSConsumer to
- * consume the messages in the Topic. Should receive all the messages since
- * the sent messages were committed. Verify that all messages are received.
- */
- public void commitRollbackTest() throws Exception {
- boolean pass = true;
- try {
- TextMessage tempMsg = null;
-
- // Close conttext created in setup()
- context.close();
-
- // create JMSContext with SESSION_TRANSACTED then create consumer/producer
- TestUtil
- .logMsg("Create transacted JMSContext, JMSConsumer and JMSProducer");
- context = cf.createContext(user, password, JMSContext.SESSION_TRANSACTED);
- producer = context.createProducer();
- consumer = context.createConsumer(destination);
-
- // Send "numMessages" messages to Topic and call rollback
- TestUtil.logMsg(
- "Send " + numMessages + " messages to Topic and call rollback()");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "commitRollbackTest" + i);
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- // Call rollback() to rollback the sent messages
- TestUtil.logMsg("Calling rollback() to rollback the sent messages");
- context.rollback();
-
- TestUtil.logMsg(
- "Should not consume any messages in Topic since rollback() was called");
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("Received message " + tempMsg.getText()
- + ", expected NULL (NO MESSAGES)");
- pass = false;
- }
-
- // Send "numMessages" messages to Topic and call commit
- TestUtil.logMsg(
- "Send " + numMessages + " messages to Topic and call commit()");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "commitRollbackTest" + i);
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- // Call commit() to commit the sent messages
- TestUtil.logMsg("Calling commit() to commit the sent messages");
- context.commit();
-
- TestUtil.logMsg(
- "Should consume all messages in Topic since commit() was called");
- for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("JMSConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + msgCount + " missing from Topic");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + msgCount)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + msgCount + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received message: " + tempMsg.getText());
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("commitRollbackTest");
- }
-
- if (!pass) {
- throw new Exception("commitRollbackTest failed");
- }
- }
-
- /*
- * @testName: invalidDestinationRuntimeExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1237;
- *
- * @test_Strategy: Test InvalidDestinationRuntimeException conditions from API
- * methods with CompletionListener.
- *
- * Tests the following exception conditions:
- *
- * InvalidDestinationRuntimeException
- *
- */
- public void invalidDestinationRuntimeExceptionTests() throws Exception {
- boolean pass = true;
- Destination invalidDestination = null;
- Topic invalidTopic = null;
- String message = "Where are you!";
- Map mapMsgSend = new HashMap();
- mapMsgSend.put("StringValue", "sendAndRecvTest7");
- mapMsgSend.put("BooleanValue", true);
- mapMsgSend.put("IntValue", (int) 10);
- try {
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Creating JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- // send to an invalid destination
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "invalidDestinationRuntimeExceptionTests");
-
- // Create CompetionListener
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Message) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg("Calling JMSProducer.setAsync(CompletionListener)");
- producer.setAsync(listener);
- TestUtil.logMsg(
- "Calling JMSProducer.send(Destination, Message) -> expect InvalidDestinationRuntimeException");
- producer.send(invalidDestination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- exception = listener.getException();
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof InvalidDestinationRuntimeException) {
- TestUtil.logMsg(
- "Exception is expected InvalidDestinationRuntimeException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected InvalidDestinationRuntimeException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("invalidDestinationRuntimeExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("invalidDestinationRuntimeExceptionTests failed");
- }
- }
-
- /*
- * @testName: messageFormatRuntimeExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1236;
- *
- * @test_Strategy: Test MessageFormatRuntimeException conditions from API
- * methods with CompletionListener.
- *
- * Tests the following exception conditions:
- *
- * MessageFormatRuntimeException
- *
- */
- public void messageFormatRuntimeExceptionTests() throws Exception {
- boolean pass = true;
- try {
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Creating JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- // Create CompetionListener
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Message) for MessageFormatRuntimeException");
- try {
- TestUtil.logMsg("Calling JMSProducer.setAsync(CompletionListener)");
- producer.setAsync(listener);
- TestUtil.logMsg(
- "Calling JMSProducer.send(Destination, Message) -> expect MessageFormatRuntimeException");
- producer.send(destination, (Message) null);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof MessageFormatRuntimeException) {
- TestUtil
- .logMsg("Exception is expected MessageFormatRuntimeException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected MessageFormatRuntimeException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Got MessageFormatRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected MessageFormatRuntimeException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("messageFormatRuntimeExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("messageFormatRuntimeExceptionTests failed");
- }
- }
-
- /*
- * @testName: jMSRuntimeExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1235;
- *
- * @test_Strategy: Test JMSRuntimeException conditions from API methods with
- * CompletionListener.
- *
- * Tests the following exception conditions:
- *
- * Set delivery mode to -1 on JMSProducer and then try and send async message
- * to CompletionListener. The CompletionListener MUST throw
- * JMSRuntimeException.
- *
- * Set priority to -1 on JMSProducer and then try and send async message to
- * CompletionListener. The CompletionListener MUST throw JMSRuntimeException.
- */
- public void jMSRuntimeExceptionTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Creating JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Creating JMSProducer");
- producer = context.createProducer();
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "jMSRuntimeExceptionTests");
- try {
- TestUtil.logMsg("Set completion listener");
- TestUtil.logMsg("Calling JMSProducer.setAsync(CompletionListener)");
- producer.setAsync(listener);
- TestUtil.logMsg("Try and set an invalid delivery mode of -1 on send");
- producer.setDeliveryMode(-1);
- TestUtil.logMsg(
- "Calling JMSProducer.send(Destination, Message) -> expect JMSRuntimeException");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof JMSRuntimeException) {
- TestUtil.logMsg("Exception is expected JMSRuntimeException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected JMSRuntimeException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (JMSRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSRuntimeException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Set completion listener");
- TestUtil.logMsg("Calling JMSProducer.setAsync(CompletionListener)");
- producer.setAsync(listener);
- TestUtil.logMsg("Try and set an invalid priority of -1 on send");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- producer.setPriority(-1);
- TestUtil.logMsg(
- "Calling JMSProducer.send(Destination, Message) -> expect JMSRuntimeException");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof JMSRuntimeException) {
- TestUtil.logMsg("Exception is expected JMSRuntimeException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected JMSRuntimeException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (JMSRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSRuntimeException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("jMSRuntimeExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("jMSRuntimeExceptionTests failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/ClientIT.java
new file mode 100644
index 0000000000..68ce6878af
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/ClientIT.java
@@ -0,0 +1,1746 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.appclient.jmscontexttopictests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.DeliveryMode;
+import jakarta.jms.Destination;
+import jakarta.jms.InvalidClientIDRuntimeException;
+import jakarta.jms.InvalidDestinationRuntimeException;
+import jakarta.jms.JMSConsumer;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSProducer;
+import jakarta.jms.JMSRuntimeException;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.MessageFormatRuntimeException;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.appclient.jmscontexttopictests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null;
+
+ private transient JmsTool tool2 = null;
+
+ // JMS objects
+ private transient ConnectionFactory cf = null;
+
+ private transient ConnectionFactory cf2 = null;
+
+ private transient Topic topic = null;
+
+ private transient Destination destination = null;
+
+ private transient JMSContext context = null;
+
+ private transient JMSContext context2 = null;
+
+ private transient JMSContext contextD = null;
+
+ private transient JMSConsumer consumer = null;
+
+ private transient JMSProducer producer = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ ArrayList connections = null;
+
+ /*
+ * Utility method to return the session mode as a String
+ */
+ private String printSessionMode(int sessionMode) {
+ switch (sessionMode) {
+ case JMSContext.SESSION_TRANSACTED:
+ return "SESSION_TRANSACTED";
+ case JMSContext.AUTO_ACKNOWLEDGE:
+ return "AUTO_ACKNOWLEDGE";
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ return "CLIENT_ACKNOWLEDGE";
+ case JMSContext.DUPS_OK_ACKNOWLEDGE:
+ return "DUPS_OK_ACKNOWLEDGE";
+ default:
+ return "UNEXPECTED_SESSIONMODE";
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ String lookupDurableTopicFactory = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ connections = new ArrayList(5);
+
+ // set up JmsTool for COMMON_T setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_T setup");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ topic = (Topic) destination;
+ tool.getDefaultConnection().close();
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+
+ // set up JmsTool for COMMON_T setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_T and durable topic connection factory");
+ tool2 = new JmsTool(JmsTool.COMMON_T, user, password, lookupDurableTopicFactory, mode);
+ tool2.getDefaultConnection().close();
+ cf2 = tool2.getConnectionFactory();
+ contextD = cf2.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* leanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Close JMSContext objects");
+ if (context != null) {
+ context.close();
+ context = null;
+ }
+ if (contextD != null) {
+ contextD.close();
+ contextD = null;
+ }
+ logger.log(Logger.Level.INFO, "Close JMSConsumer objects");
+ if (consumer != null) {
+ consumer.close();
+ consumer = null;
+ }
+ tool.closeAllResources();
+ tool2.closeAllResources();
+ producer = null;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: setGetClientIDTest
+ *
+ * @assertion_ids: JMS:JAVADOC:970; JMS:JAVADOC:1040; JMS:SPEC:264.5;
+ * JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:91;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.setClientID(String clientID) JMSContext.getClientID()
+ */
+ @Test
+ public void setGetClientIDTest() throws Exception {
+ boolean pass = true;
+ try {
+ String clientid = "myclientid";
+ logger.log(Logger.Level.INFO, "Calling setClientID(" + clientid + ")");
+ context.setClientID(clientid);
+ logger.log(Logger.Level.INFO, "Calling getClientID and expect " + clientid + " to be returned");
+ String cid = context.getClientID();
+ if (!cid.equals(clientid)) {
+ logger.log(Logger.Level.ERROR, "getClientID() returned " + cid + ", expected " + clientid);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("setGetClientIDTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetClientIDTest failed");
+ }
+ }
+
+ /*
+ * @testName: setClientIDLateTest
+ *
+ * @assertion_ids: JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:94; JMS:SPEC:91;
+ * JMS:JAVADOC:1040; JMS:JAVADOC:1043; JMS:SPEC:264.5;
+ *
+ * @test_Strategy: Create a JMSContext, send and receive a message, then try to
+ * set the ClientID. Verify that IllegalStateRuntimeException is thrown.
+ *
+ * JMSContext.setClientID(String clientID)
+ */
+ @Test
+ public void setClientIDLateTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ TextMessage messageSent;
+ TextMessage messageReceived;
+ String message = "This is my message.";
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "setClientIDLateTest");
+ logger.log(Logger.Level.INFO, "Calling JMSProduce.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.INFO, "actTextMessage=" + actTextMessage.getText());
+ }
+
+ logger.log(Logger.Level.TRACE, "Attempt to set Client ID too late (expect IllegalStateRuntimeException)");
+ try {
+ context.setClientID("setClientIDLateTest");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "IllegalStateRuntimeException was not thrown");
+ } catch (jakarta.jms.IllegalStateRuntimeException is) {
+ logger.log(Logger.Level.INFO, "IllegalStateRuntimeException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Incorrect exception received: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("setClientIDLateTest", e);
+ }
+ if (!pass) {
+ throw new Exception("setClientIDLateTest failed");
+ }
+ }
+
+ /*
+ * @testName: setClientIDOnAdminConfiguredIDTest
+ *
+ * @assertion_ids: JMS:JAVADOC:970; JMS:JAVADOC:1040; JMS:SPEC:264.5;
+ * JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:91;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.setClientID(String clientID)
+ *
+ * Expect IllegalStateRuntimeException
+ */
+ @Test
+ public void setClientIDOnAdminConfiguredIDTest() throws Exception {
+ boolean pass = true;
+ try {
+ String clientid = "myclientid";
+ logger.log(Logger.Level.INFO, "Try setting ClientID on JMSContext administratively "
+ + "configured with ClientID (expect IllegalStateRuntimeException)");
+ contextD.setClientID(clientid);
+ logger.log(Logger.Level.ERROR, "Did not throw expected IllegalStateRuntimeException");
+ pass = false;
+ String cid = contextD.getClientID();
+ if (cid == null) {
+ logger.log(Logger.Level.ERROR, "getClientID returned null (expected cts)");
+ pass = false;
+ } else if (!cid.equals("cts")) {
+ logger.log(Logger.Level.ERROR, "getClientID() returned " + cid + ", expected cts");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "getClientID returned cts (Correct)");
+ }
+ } catch (jakarta.jms.IllegalStateRuntimeException is) {
+ logger.log(Logger.Level.INFO, "IllegalStateRuntimeException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Incorrect exception received: " + e);
+ throw new Exception("setClientIDOnAdminConfiguredIDTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setClientIDOnAdminConfiguredIDTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetChangeClientIDTest
+ *
+ * @assertion_ids: JMS:SPEC:93; JMS:SPEC:95; JMS:SPEC:198; JMS:JAVADOC:1040;
+ * JMS:JAVADOC:970; JMS:JAVADOC:1042; JMS:JAVADOC:1043; JMS:SPEC:264.5;
+ *
+ *
+ * @test_Strategy: Test setClientID()/getClientID(). Make sure that the clientID
+ * set is the clientID returned. Then try and reset the clientID. Verify that
+ * the IllegalStateRuntimeException is thrown. 1) Use a JMSContext that has no
+ * ClientID set, then call setClientID twice. 2) Try and set the clientID on a
+ * second JMSContext to the clientID value of the first JMSContext. Verify that
+ * InvalidClientIDRuntimeException is thrown.
+ *
+ * JMSContext.setClientID(String clientID) JMSContext.getClientID()
+ */
+ @Test
+ public void setGetChangeClientIDTest() throws Exception {
+ boolean pass = true;
+ String lookup = "MyTopicConnectionFactory";
+
+ try {
+ logger.log(Logger.Level.INFO, "Create second JMSContext with AUTO_ACKNOWLEDGE");
+ context2 = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+
+ logger.log(Logger.Level.INFO, "Setting clientID!");
+ context.setClientID("ctstest");
+
+ logger.log(Logger.Level.INFO, "Getting clientID!");
+ String clientid = context.getClientID();
+
+ if (!clientid.equals("ctstest")) {
+ logger.log(Logger.Level.ERROR, "getClientID() returned " + clientid + ", expected ctstest");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "setClientID/getClientID correct");
+ }
+
+ logger.log(Logger.Level.INFO, "Resetting clientID! (expect IllegalStateRuntimeException)");
+ context.setClientID("changeIt");
+ logger.log(Logger.Level.ERROR, "No exception was thrown on ClientID reset");
+ pass = false;
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "IllegalStateRuntimeException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Incorrect exception received: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO, "Set clientID on second context to value of clientID on first "
+ + "context (expect InvalidClientIDRuntimeException)");
+ context2.setClientID("ctstest");
+ logger.log(Logger.Level.ERROR, "No exception was thrown on ClientID that already exists");
+ pass = false;
+ } catch (InvalidClientIDRuntimeException e) {
+ logger.log(Logger.Level.INFO, "InvalidClientIDRuntimeException thrown as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Incorrect exception received: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (context2 != null) {
+ context2.close();
+ context2 = null;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception in finally block: " + e);
+ throw new Exception("setGetChangeClientIDTest", e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("setGetChangeClientIDTest");
+ }
+ }
+
+ /*
+ * @testName: setGetExceptionListenerTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1052; JMS:JAVADOC:980;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.setExceptionListener(ExceptionListener).
+ * JMSContext.getExceptionListener().
+ */
+ @Test
+ public void setGetExceptionListenerTest() throws Exception {
+ boolean pass = true;
+ try {
+ MyExceptionListener expExceptionListener = new MyExceptionListener();
+ logger.log(Logger.Level.INFO, "Calling setExceptionListener(" + expExceptionListener + ")");
+ context.setExceptionListener(expExceptionListener);
+ logger.log(Logger.Level.INFO,
+ "Calling getExceptionListener and expect " + expExceptionListener + " to be returned");
+ MyExceptionListener actExceptionListener = (MyExceptionListener) context.getExceptionListener();
+ if (!actExceptionListener.equals(expExceptionListener)) {
+ logger.log(Logger.Level.ERROR, "getExceptionListener() returned " + actExceptionListener + ", expected "
+ + expExceptionListener);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling setExceptionListener(null)");
+ context.setExceptionListener(null);
+ if (context.getExceptionListener() != null) {
+ logger.log(Logger.Level.ERROR,
+ "getExceptionListener() returned " + context.getExceptionListener() + ", expected null");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("setGetExceptionListenerTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetExceptionListenerTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetAsyncTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1182; JMS:JAVADOC:1255;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.setAsync(CompletionListener). JMSContext.getAsync().
+ */
+ @Test
+ public void setGetAsyncTest() throws Exception {
+ boolean pass = true;
+ try {
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ // Set and get asyncronous CompletionListener
+ MyCompletionListener expCompletionListener = new MyCompletionListener();
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(" + expCompletionListener + ")");
+ producer.setAsync(expCompletionListener);
+ logger.log(Logger.Level.INFO,
+ "Calling JMSProducer.getAsync() and expect " + expCompletionListener + " to be returned");
+ MyCompletionListener actCompletionListener = (MyCompletionListener) producer.getAsync();
+ if (!actCompletionListener.equals(expCompletionListener)) {
+ logger.log(Logger.Level.ERROR,
+ "getAsync() returned " + actCompletionListener + ", expected " + expCompletionListener);
+ pass = false;
+ }
+
+ // Now set and get null asyncronous CompletionListener
+ logger.log(Logger.Level.INFO, "Calling setAsync(null)");
+ producer.setAsync(null);
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.getAsync() and expect NULL to be returned");
+ if (producer.getAsync() != null) {
+ logger.log(Logger.Level.ERROR, "getAsync() returned " + producer.getAsync() + ", expected null");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("setGetAsyncTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetAsyncTest failed");
+ }
+ }
+
+ /*
+ * @testName: startStopTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:1076; JMS:JAVADOC:1078;
+ * JMS:JAVADOC:942; JMS:JAVADOC:1102; JMS:SPEC:264; JMS:SPEC:264.5;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * ConnectionFactory.createContext(String, String, int) JMSContext.start()
+ * JMSContext.stop() JMSContext.createConsumer(Destination)
+ * JMSContext.createProducer() JMSProducer.send(Destination, Message)
+ * JMSConsumer.receive(long timeout)
+ *
+ * 1. Create JMSContext with AUTO_ACKNOWLEDGE. This is done in the setup()
+ * routine. 2. Call stop. 3. Send x messages to a Topic. 4. Create a JMSConsumer
+ * to consume the messages in the Topic. 5. Try consuming messages from the
+ * Topic. Should not receive any messages since the connection has been stopped.
+ * 6. Call start. 7. Try consuming messages from the Topic. Should receive all
+ * messages from the Topic since the connection has been started.
+ *
+ */
+ @Test
+ public void startStopTest() throws Exception {
+ boolean pass = true;
+ try {
+ TextMessage tempMsg = null;
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Stop delivery of incoming messages on JMSContext's connection
+ logger.log(Logger.Level.INFO, "Call stop() to stop delivery of incoming messages");
+ context.stop();
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ // Send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "startStopTest" + i);
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ // Try consuming a message from the Topic (should not receive a message)
+ logger.log(Logger.Level.INFO, "Try consuming a message on a STOPPED connection");
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR, "Received a message on a STOPPED connection");
+ logger.log(Logger.Level.ERROR, "Message is: " + tempMsg.getText());
+ pass = false;
+ }
+
+ // Start delivery of incoming messages on JMSContext's connection
+ logger.log(Logger.Level.INFO, "Call start() to start delivery of incoming messages");
+ context.start();
+
+ logger.log(Logger.Level.INFO, "Consume all the messages in the Topic on a STARTED connection");
+ for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + msgCount + " missing from Topic");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + msgCount)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + msgCount + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message: " + tempMsg.getText());
+ }
+ }
+
+ // Try to receive one more message (should return null for no more
+ // messages)
+ logger.log(Logger.Level.INFO, "Topic should now be empty");
+ logger.log(Logger.Level.INFO, "Try consuming one more message should return NULL");
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() did not return NULL");
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() returned a message (unexpected)");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("startStopTest");
+ }
+
+ if (!pass) {
+ throw new Exception("startStopTest failed");
+ }
+ }
+
+ /*
+ * @testName: createContextTest
+ *
+ * @assertion_ids: JMS:JAVADOC:931; JMS:SPEC:265.3;
+ *
+ * @test_Strategy: Creates a JMSContext with the default user identity and the
+ * specified sessionMode. Tests API:
+ *
+ * JMSContext.createContext(int)
+ */
+ @Test
+ public void createContextTest() throws Exception {
+ boolean pass = true;
+ try {
+
+ JMSContext newContext = null;
+
+ // Test all possible session modes
+ int expSessionMode[] = { JMSContext.SESSION_TRANSACTED, JMSContext.AUTO_ACKNOWLEDGE,
+ JMSContext.CLIENT_ACKNOWLEDGE, JMSContext.DUPS_OK_ACKNOWLEDGE, };
+
+ // Cycle through all session modes
+ for (int i = 0; i < expSessionMode.length; i++) {
+ logger.log(Logger.Level.INFO,
+ "Creating context with session mode (" + printSessionMode(expSessionMode[i]) + ")");
+ logger.log(Logger.Level.INFO, "Call API TopicConnectionFactory.createContext(int)");
+ newContext = context.createContext(expSessionMode[i]);
+ logger.log(Logger.Level.INFO, "Now call API JMSContext.getSessionMode()");
+ logger.log(Logger.Level.INFO,
+ "Calling getSessionMode and expect " + printSessionMode(expSessionMode[i]) + " to be returned");
+ int actSessionMode = newContext.getSessionMode();
+ if (actSessionMode != expSessionMode[i]) {
+ logger.log(Logger.Level.ERROR, "getSessionMode() returned " + printSessionMode(actSessionMode)
+ + ", expected " + printSessionMode(expSessionMode[i]));
+ pass = false;
+ }
+ newContext.close();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("createContextTest");
+ }
+
+ if (!pass) {
+ throw new Exception("createContextTest failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvCLTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
+ * JMS:JAVADOC:1255; JMS:SPEC:275.1; JMS:SPEC:275.5; JMS:SPEC:275.8;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data as well as onCompletion() being called. Set some
+ * properties on JMSProducer and check that these properties exist on the
+ * returned message after the CompletionListener's onCompletion() method has
+ * been called.
+ *
+ * JMSContext.createProducer() JMSProducer.setAsync(CompletionListener)
+ * JMSProducer.send(Destination, Message)
+ */
+ @Test
+ public void sendAndRecvCLTest1() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+
+ try {
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvCLTest1");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ // ------------------------------------------------------------------------------
+ // Set JMSProducer message properties
+ // Set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Set primitive property types on JMSProducer");
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTSTRING", "test");
+
+ // ------------------------------------------------------------------------------
+ // Set JMSProducer message properties
+ // Set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Set Object property types on JMSProducer");
+ producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
+ producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
+ producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
+ producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
+ producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
+ producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
+ producer.setProperty("OBJTESTSTRING", "test");
+
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(CompletionListener)");
+ producer.setAsync(listener);
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.send(Destination,Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive TextMessage");
+ TextMessage actTextMessage = null;
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------------
+ // Retrieve the properties from the received TextMessage and verify that
+ // they are correct
+ // Get properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // -------------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Retrieve and verify that TextMessage message properties were set correctly");
+ if (actTextMessage.getBooleanProperty("TESTBOOLEAN") == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getBooleanProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getBooleanProperty");
+ pass = false;
+ }
+ if (actTextMessage.getByteProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getByteProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getByteProperty");
+ pass = false;
+ }
+ if (actTextMessage.getLongProperty("TESTLONG") == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getLongProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getLongProperty");
+ pass = false;
+ }
+ if (actTextMessage.getStringProperty("TESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getStringProperty");
+ pass = false;
+ }
+ if (actTextMessage.getDoubleProperty("TESTDOUBLE") == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getDoubleProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getDoubleProperty");
+ pass = false;
+ }
+ if (actTextMessage.getFloatProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getFloatProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getFloatProperty");
+ pass = false;
+ }
+ if (actTextMessage.getIntProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getIntProperty");
+ pass = false;
+ }
+ if (actTextMessage.getShortProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getShortProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getShortProperty");
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------------
+ // Retrieve the properties from the received TextMessage and verify that
+ // they are correct
+ // Get properties for Boolean, Byte, Short, Integer, Long, Float, Double,
+ // and String.
+ // --------------------------------------------------------------------------------------
+ if (((Boolean) actTextMessage.getObjectProperty("OBJTESTBOOLEAN")).booleanValue() == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Boolean value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Byte) actTextMessage.getObjectProperty("OBJTESTBYTE")).byteValue() == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Byte value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Long) actTextMessage.getObjectProperty("OBJTESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Long value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Long value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((String) actTextMessage.getObjectProperty("OBJTESTSTRING")).equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct String value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect String value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Double) actTextMessage.getObjectProperty("OBJTESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Double value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Double value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Float) actTextMessage.getObjectProperty("OBJTESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Float value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Float value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Integer) actTextMessage.getObjectProperty("OBJTESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Integer value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Integer value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Short) actTextMessage.getObjectProperty("OBJTESTSHORT")).shortValue() == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Short value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Short value returned from getObjectProperty");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvCLTest1", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvCLTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvCLTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
+ * JMS:JAVADOC:1255; JMS:JAVADOC:1259; JMS:JAVADOC:1303;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data as well as onCompletion() being called.
+ *
+ * JMSContext.createProducer() JMSProducer.setDeliveryMode(int)
+ * JMSProducer.setPriority(int) JMSProducer.setTimeToLive(long)
+ * JMSProducer.setAsync(CompletionListener) JMSProducer.send(Destination,
+ * Message)
+ */
+ @Test
+ public void sendAndRecvCLTest2() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvCLTest2");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(CompletionListener)");
+ producer.setAsync(listener);
+ logger.log(Logger.Level.INFO, "Set delivery mode, priority, and time to live");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ producer.setPriority(Message.DEFAULT_PRIORITY);
+ producer.setTimeToLive(0L);
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.send(Destination,Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive TextMessage");
+ TextMessage actTextMessage = null;
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage, deliverymode, priority, time to live");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())
+ || actTextMessage.getJMSDeliveryMode() != DeliveryMode.PERSISTENT
+ || actTextMessage.getJMSPriority() != Message.DEFAULT_PRIORITY
+ || actTextMessage.getJMSExpiration() != 0L) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode=" + actTextMessage.getJMSDeliveryMode() + ", expected "
+ + expTextMessage.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority=" + actTextMessage.getJMSPriority() + ", expected "
+ + expTextMessage.getJMSPriority());
+ logger.log(Logger.Level.ERROR, "TimeToLive=" + actTextMessage.getJMSExpiration() + ", expected "
+ + expTextMessage.getJMSExpiration());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvCLTest2", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvCLTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvMsgOfEachTypeCLTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:835; JMS:JAVADOC:1177;
+ * JMS:JAVADOC:1255; JMS:JAVADOC:1259; JMS:JAVADOC:1303;
+ *
+ * @test_Strategy: Send and receive messages of each message type: Message,
+ * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Verify
+ * the send and recv of data as well as onCompletion() being called in
+ * CompletionListener.
+ *
+ * JMSContext.createProducer() JMSProducer.setAsync(CompletionListener)
+ * JMSContext.createMessage() JMSContext.createBytesMessage()
+ * JMSContext.createMapMessage() JMSContext.createObjectMessage()
+ * JMSContext.createStreamMessage() JMSContext.createTextMessage(String)
+ * JMSProducer.send(Destination, Message)
+ */
+ @Test
+ public void sendAndRecvMsgOfEachTypeCLTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+
+ // send and receive Message
+ logger.log(Logger.Level.INFO, "Send and receive Message");
+ Message msg = context.createMessage();
+ logger.log(Logger.Level.INFO, "Set some values in Message");
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
+ msg.setBooleanProperty("booleanProperty", true);
+ MyCompletionListener2 listener = new MyCompletionListener2();
+ producer = context.createProducer();
+ producer.setAsync(listener);
+ producer.send(destination, msg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive Message");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ Message actMessage = null;
+ if (listener.isComplete())
+ actMessage = (Message) listener.getMessage();
+
+ if (actMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive Message");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in Message");
+ if (actMessage.getBooleanProperty("booleanProperty") == true) {
+ logger.log(Logger.Level.INFO, "booleanproperty is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanproperty is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Send and receive BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ bMsg.reset();
+ listener = new MyCompletionListener2();
+ producer = context.createProducer();
+ producer.setAsync(listener);
+ producer.send(destination, bMsg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive BytesMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ BytesMessage bMsgRecv = null;
+ if (listener.isComplete())
+ bMsgRecv = (BytesMessage) listener.getMessage();
+ if (bMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive BytesMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in BytesMessage");
+ if (bMsgRecv.readByte() == (byte) 1) {
+ logger.log(Logger.Level.INFO, "bytevalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "bytevalue is incorrect");
+ pass = false;
+ }
+ if (bMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send and receive MapMessage");
+ MapMessage mMsg = context.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ listener = new MyCompletionListener2();
+ producer = context.createProducer();
+ producer.setAsync(listener);
+ producer.send(destination, mMsg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive MapMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ MapMessage mMsgRecv = null;
+ if (listener.isComplete())
+ mMsgRecv = (MapMessage) listener.getMessage();
+ if (mMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive MapMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in MapMessage");
+ Enumeration list = mMsgRecv.getMapNames();
+ String name = null;
+ while (list.hasMoreElements()) {
+ name = (String) list.nextElement();
+ if (name.equals("booleanvalue")) {
+ if (mMsgRecv.getBoolean(name) == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "booleanvalue is incorrect");
+ pass = false;
+ }
+ } else if (name.equals("intvalue")) {
+ if (mMsgRecv.getInt(name) == 10) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "intvalue is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected name of [" + name + "] in MapMessage");
+ pass = false;
+ }
+ }
+ }
+
+ // send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Send and receive ObjectMessage");
+ StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ ObjectMessage oMsg = context.createObjectMessage();
+ oMsg.setObject(sb1);
+ oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
+ listener = new MyCompletionListener2();
+ producer = context.createProducer();
+ producer.setAsync(listener);
+ producer.send(destination, oMsg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive ObjectMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ ObjectMessage oMsgRecv = null;
+ if (listener.isComplete())
+ oMsgRecv = (ObjectMessage) listener.getMessage();
+ if (oMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive ObjectMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in ObjectMessage");
+ StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
+ if (sb2.toString().equals(sb1.toString())) {
+ logger.log(Logger.Level.INFO, "objectvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "objectvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive StreamMessage
+ logger.log(Logger.Level.INFO, "Send and receive StreamMessage");
+ StreamMessage sMsg = context.createStreamMessage();
+ logger.log(Logger.Level.INFO, "Set some values in StreamMessage");
+ sMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
+ sMsg.writeBoolean(true);
+ sMsg.writeInt((int) 22);
+ sMsg.reset();
+ listener = new MyCompletionListener2();
+ producer = context.createProducer();
+ producer.setAsync(listener);
+ producer.send(destination, sMsg);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive StreamMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ StreamMessage sMsgRecv = null;
+ if (listener.isComplete())
+ sMsgRecv = (StreamMessage) listener.getMessage();
+ if (sMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive StreamMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in StreamMessage");
+ if (sMsgRecv.readBoolean() == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanvalue is incorrect");
+ pass = false;
+ }
+ if (sMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Send and receive TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgOfEachTypeCLTest");
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.send(Destination,Message)");
+ listener = new MyCompletionListener2();
+ producer = context.createProducer();
+ producer.setAsync(listener);
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive TextMessage");
+ for (int i = 0; !listener.isComplete() && i < 15; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for message to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ TextMessage actTextMessage = null;
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvMsgOfEachTypeCLTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvMsgOfEachTypeCLTest failed");
+ }
+ }
+
+ /*
+ * @testName: messageOrderCLTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:275.2; JMS:SPEC:275.7;
+ *
+ * @test_Strategy: Send async messages to a topic and receive them. Verify that
+ * the text of each matches the order of the text in the sent messages.
+ */
+ @Test
+ public void messageOrderCLTopicTest() throws Exception {
+ boolean pass = true;
+ try {
+ TextMessage sentTextMessage;
+ String text[] = new String[numMessages];
+
+ // Create CompletionListener for Message to be sent
+ logger.log(Logger.Level.INFO, "Creating MyCompletionListener");
+ MyCompletionListener listener = new MyCompletionListener(numMessages);
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(CompletionListener)");
+ producer.setAsync(listener);
+
+ // create and send async messages to topic
+ logger.log(Logger.Level.INFO, "Sending " + numMessages + " asynchronous messages to topic");
+ for (int i = 0; i < numMessages; i++) {
+ text[i] = "message order test " + i;
+ sentTextMessage = context.createTextMessage();
+ sentTextMessage.setText(text[i]);
+ sentTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "messageOrderCLTopicTest" + i);
+ logger.log(Logger.Level.INFO, "Sending TextMessage: " + sentTextMessage.getText());
+ producer.send(destination, sentTextMessage);
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Poll listener until we receive all " + numMessages + " TextMessage's from topic");
+ for (int i = 0; !listener.gotAllMsgs() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+
+ for (int i = 0; i < numMessages; i++) {
+ TextMessage actTextMessage = null;
+ if (listener.haveMsg(i))
+ actTextMessage = (TextMessage) listener.getMessage(i);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.INFO, "Did not receive TextMessage " + i + " (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message: " + actTextMessage.getText());
+ if (!actTextMessage.getText().equals(text[i])) {
+ logger.log(Logger.Level.INFO, "Received message: " + actTextMessage.getText());
+ logger.log(Logger.Level.INFO, "Should have received: " + text[i]);
+ logger.log(Logger.Level.ERROR, "Received wrong message (wrong order)");
+ pass = false;
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("messageOrderCLTopicTest", e);
+ }
+
+ if (!pass)
+ throw new Exception("messageOrderCLTopicTest failed");
+ }
+
+ /*
+ * @testName: acknowledgeTest
+ *
+ * @assertion_ids: JMS:JAVADOC:909;
+ *
+ * @test_Strategy: Send and receive a message from JMSContext with
+ * CLIENT_ACKNOWLEDGE and call the acknowlege method to acknowledge the message
+ * consumed.
+ *
+ */
+ @Test
+ public void acknowledgeTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ JMSContext msgcontext = null;
+ JMSProducer msgproducer = null;
+ JMSConsumer msgconsumer = null;
+ try {
+ msgcontext = cf.createContext(user, password, JMSContext.CLIENT_ACKNOWLEDGE);
+ msgproducer = msgcontext.createProducer();
+ msgconsumer = msgcontext.createConsumer(topic);
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = msgcontext.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "acknowledgeTest");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ msgproducer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) msgconsumer.receive(timeout);
+ logger.log(Logger.Level.INFO, "Received message: " + actTextMessage.getText());
+ logger.log(Logger.Level.INFO, "Calling acknowlege to acknowledge message.");
+ msgcontext.acknowledge();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("acknowledgeTest", e);
+ } finally {
+ try {
+ if (msgconsumer != null)
+ msgconsumer.close();
+ if (msgcontext != null)
+ msgcontext.close();
+ msgproducer = null;
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("acknowledgeTest failed");
+ }
+ }
+
+ /*
+ * @testName: commitRollbackTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1234; JMS:JAVADOC:914; JMS:JAVADOC:995;
+ * JMS:JAVADOC:942; JMS:JAVADOC:1102; JMS:JAVADOC:847; JMS:SPEC:275.3;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * ConnectionFactory.createContext(String, String, int)
+ * JMSProducer.send(Destination, Message) JMSContext.commit()
+ * JMSContext.rollback() JMSContext.createConsumer(Destination)
+ * JMSContext.receive(long timeout)
+ *
+ * 1. Create JMSContext with SESSION_TRANSACTED. This is done in the setup()
+ * routine. 2. Send x messages to a Topic. 3. Call rollback() to rollback the
+ * sent messages. 4. Create a JMSConsumer to consume the messages in the Topic.
+ * Should not receive any messages since the sent messages were rolled back.
+ * Verify that no messages are received. 5. Send x messages to a Topic. 6. Call
+ * commit() to commit the sent messages. 7. Create a JMSConsumer to consume the
+ * messages in the Topic. Should receive all the messages since the sent
+ * messages were committed. Verify that all messages are received.
+ */
+ @Test
+ public void commitRollbackTest() throws Exception {
+ boolean pass = true;
+ try {
+ TextMessage tempMsg = null;
+
+ // Close conttext created in setup()
+ context.close();
+
+ // create JMSContext with SESSION_TRANSACTED then create consumer/producer
+ logger.log(Logger.Level.INFO, "Create transacted JMSContext, JMSConsumer and JMSProducer");
+ context = cf.createContext(user, password, JMSContext.SESSION_TRANSACTED);
+ producer = context.createProducer();
+ consumer = context.createConsumer(destination);
+
+ // Send "numMessages" messages to Topic and call rollback
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Topic and call rollback()");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "commitRollbackTest" + i);
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ // Call rollback() to rollback the sent messages
+ logger.log(Logger.Level.INFO, "Calling rollback() to rollback the sent messages");
+ context.rollback();
+
+ logger.log(Logger.Level.INFO, "Should not consume any messages in Topic since rollback() was called");
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR,
+ "Received message " + tempMsg.getText() + ", expected NULL (NO MESSAGES)");
+ pass = false;
+ }
+
+ // Send "numMessages" messages to Topic and call commit
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Topic and call commit()");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "commitRollbackTest" + i);
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ // Call commit() to commit the sent messages
+ logger.log(Logger.Level.INFO, "Calling commit() to commit the sent messages");
+ context.commit();
+
+ logger.log(Logger.Level.INFO, "Should consume all messages in Topic since commit() was called");
+ for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + msgCount + " missing from Topic");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + msgCount)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + msgCount + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message: " + tempMsg.getText());
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("commitRollbackTest");
+ }
+
+ if (!pass) {
+ throw new Exception("commitRollbackTest failed");
+ }
+ }
+
+ /*
+ * @testName: invalidDestinationRuntimeExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1237;
+ *
+ * @test_Strategy: Test InvalidDestinationRuntimeException conditions from API
+ * methods with CompletionListener.
+ *
+ * Tests the following exception conditions:
+ *
+ * InvalidDestinationRuntimeException
+ *
+ */
+ @Test
+ public void invalidDestinationRuntimeExceptionTests() throws Exception {
+ boolean pass = true;
+ Destination invalidDestination = null;
+ Topic invalidTopic = null;
+ String message = "Where are you!";
+ Map mapMsgSend = new HashMap();
+ mapMsgSend.put("StringValue", "sendAndRecvTest7");
+ mapMsgSend.put("BooleanValue", true);
+ mapMsgSend.put("IntValue", (int) 10);
+ try {
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ // send to an invalid destination
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "invalidDestinationRuntimeExceptionTests");
+
+ // Create CompetionListener
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Message) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(CompletionListener)");
+ producer.setAsync(listener);
+ logger.log(Logger.Level.INFO,
+ "Calling JMSProducer.send(Destination, Message) -> expect InvalidDestinationRuntimeException");
+ producer.send(invalidDestination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ exception = listener.getException();
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof InvalidDestinationRuntimeException) {
+ logger.log(Logger.Level.INFO, "Exception is expected InvalidDestinationRuntimeException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected InvalidDestinationRuntimeException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("invalidDestinationRuntimeExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("invalidDestinationRuntimeExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: messageFormatRuntimeExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1236;
+ *
+ * @test_Strategy: Test MessageFormatRuntimeException conditions from API
+ * methods with CompletionListener.
+ *
+ * Tests the following exception conditions:
+ *
+ * MessageFormatRuntimeException
+ *
+ */
+ @Test
+ public void messageFormatRuntimeExceptionTests() throws Exception {
+ boolean pass = true;
+ try {
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ // Create CompetionListener
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Message) for MessageFormatRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(CompletionListener)");
+ producer.setAsync(listener);
+ logger.log(Logger.Level.INFO,
+ "Calling JMSProducer.send(Destination, Message) -> expect MessageFormatRuntimeException");
+ producer.send(destination, (Message) null);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof MessageFormatRuntimeException) {
+ logger.log(Logger.Level.INFO, "Exception is expected MessageFormatRuntimeException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected MessageFormatRuntimeException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got MessageFormatRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatRuntimeException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("messageFormatRuntimeExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("messageFormatRuntimeExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: jMSRuntimeExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1235;
+ *
+ * @test_Strategy: Test JMSRuntimeException conditions from API methods with
+ * CompletionListener.
+ *
+ * Tests the following exception conditions:
+ *
+ * Set delivery mode to -1 on JMSProducer and then try and send async message to
+ * CompletionListener. The CompletionListener MUST throw JMSRuntimeException.
+ *
+ * Set priority to -1 on JMSProducer and then try and send async message to
+ * CompletionListener. The CompletionListener MUST throw JMSRuntimeException.
+ */
+ @Test
+ public void jMSRuntimeExceptionTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Creating JMSProducer");
+ producer = context.createProducer();
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "jMSRuntimeExceptionTests");
+ try {
+ logger.log(Logger.Level.INFO, "Set completion listener");
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(CompletionListener)");
+ producer.setAsync(listener);
+ logger.log(Logger.Level.INFO, "Try and set an invalid delivery mode of -1 on send");
+ producer.setDeliveryMode(-1);
+ logger.log(Logger.Level.INFO,
+ "Calling JMSProducer.send(Destination, Message) -> expect JMSRuntimeException");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof JMSRuntimeException) {
+ logger.log(Logger.Level.INFO, "Exception is expected JMSRuntimeException");
+ } else {
+ logger.log(Logger.Level.ERROR, "Exception is incorrect expected JMSRuntimeException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (JMSRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSRuntimeException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Set completion listener");
+ logger.log(Logger.Level.INFO, "Calling JMSProducer.setAsync(CompletionListener)");
+ producer.setAsync(listener);
+ logger.log(Logger.Level.INFO, "Try and set an invalid priority of -1 on send");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ producer.setPriority(-1);
+ logger.log(Logger.Level.INFO,
+ "Calling JMSProducer.send(Destination, Message) -> expect JMSRuntimeException");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof JMSRuntimeException) {
+ logger.log(Logger.Level.INFO, "Exception is expected JMSRuntimeException");
+ } else {
+ logger.log(Logger.Level.ERROR, "Exception is incorrect expected JMSRuntimeException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (JMSRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSRuntimeException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("jMSRuntimeExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("jMSRuntimeExceptionTests failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/MyCompletionListener.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/MyCompletionListener.java
index b86777eef2..1f5ddb021c 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/MyCompletionListener.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/MyCompletionListener.java
@@ -19,98 +19,99 @@
*/
package com.sun.ts.tests.jms.core20.appclient.jmscontexttopictests;
+import java.lang.System.Logger;
import java.util.ArrayList;
-import com.sun.ts.lib.util.TestUtil;
-
import jakarta.jms.CompletionListener;
import jakarta.jms.Message;
public class MyCompletionListener implements CompletionListener {
- private String name = null;
+ private String name = null;
+
+ private Message message = null;
- private Message message = null;
+ private ArrayList messages = new ArrayList();
- private ArrayList messages = new ArrayList();
+ private Exception exception = null;
- private Exception exception = null;
+ private int numMessages = 1;
- private int numMessages = 1;
+ boolean complete = false;
- boolean complete = false;
+ private static final Logger logger = (Logger) System.getLogger(MyCompletionListener.class.getName());
- public MyCompletionListener() {
- this("MyCompletionListener");
- }
+ public MyCompletionListener() {
+ this("MyCompletionListener");
+ }
- public MyCompletionListener(String name) {
- this.name = name;
- }
+ public MyCompletionListener(String name) {
+ this.name = name;
+ }
- public MyCompletionListener(int numMessages) {
- this.numMessages = numMessages;
- messages.clear();
- }
+ public MyCompletionListener(int numMessages) {
+ this.numMessages = numMessages;
+ messages.clear();
+ }
- // getters/setters
- public String getName() {
- return name;
- }
+ // getters/setters
+ public String getName() {
+ return name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public Message getMessage() {
- return message;
- }
+ public Message getMessage() {
+ return message;
+ }
- public Message getMessage(int index) {
- return messages.get(index);
- }
+ public Message getMessage(int index) {
+ return messages.get(index);
+ }
- public void setMessage(Message message) {
- this.message = message;
- }
+ public void setMessage(Message message) {
+ this.message = message;
+ }
- public Exception getException() {
- return exception;
- }
+ public Exception getException() {
+ return exception;
+ }
- public void setException(Exception exception) {
- this.exception = exception;
- }
+ public void setException(Exception exception) {
+ this.exception = exception;
+ }
- public boolean gotAllMsgs() {
- return (messages.size() == numMessages) ? true : false;
- }
+ public boolean gotAllMsgs() {
+ return (messages.size() == numMessages) ? true : false;
+ }
- public boolean haveMsg(int i) {
- return (messages.size() > i) ? true : false;
- }
+ public boolean haveMsg(int i) {
+ return (messages.size() > i) ? true : false;
+ }
- public boolean isComplete() {
- return complete;
- }
+ public boolean isComplete() {
+ return complete;
+ }
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
- public void onCompletion(Message message) {
- TestUtil.logMsg("Got Message: " + message);
- this.message = message;
- messages.add(message);
- complete = true;
- }
+ public void onCompletion(Message message) {
+ logger.log(Logger.Level.INFO, "Got Message: " + message);
+ this.message = message;
+ messages.add(message);
+ complete = true;
+ }
- public void onException(Message message, Exception exception) {
- TestUtil.logMsg("Got Exception: " + exception);
- TestUtil.logMsg("With Message: " + message);
- this.exception = exception;
- this.message = message;
- complete = true;
- }
+ public void onException(Message message, Exception exception) {
+ logger.log(Logger.Level.INFO, "Got Exception: " + exception);
+ logger.log(Logger.Level.INFO, "With Message: " + message);
+ this.exception = exception;
+ this.message = message;
+ complete = true;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/MyCompletionListener2.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/MyCompletionListener2.java
index 989b39298c..8da1694c7b 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/MyCompletionListener2.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/MyCompletionListener2.java
@@ -19,76 +19,78 @@
*/
package com.sun.ts.tests.jms.core20.appclient.jmscontexttopictests;
-import com.sun.ts.lib.util.TestUtil;
+import java.lang.System.Logger;
import jakarta.jms.CompletionListener;
import jakarta.jms.Message;
public class MyCompletionListener2 implements CompletionListener {
- private String name = null;
+ private String name = null;
- private Message message = null;
+ private Message message = null;
- private Exception exception = null;
+ private Exception exception = null;
- private int numMessages = 1;
+ private int numMessages = 1;
- boolean complete = false;
+ boolean complete = false;
- public MyCompletionListener2() {
- this("MyCompletionListener2");
- }
+ private static final Logger logger = (Logger) System.getLogger(MyCompletionListener2.class.getName());
- public MyCompletionListener2(String name) {
- this.name = name;
- }
+ public MyCompletionListener2() {
+ this("MyCompletionListener2");
+ }
- // getters/setters
- public String getName() {
- return name;
- }
+ public MyCompletionListener2(String name) {
+ this.name = name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ // getters/setters
+ public String getName() {
+ return name;
+ }
- public Message getMessage() {
- return message;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public void setMessage(Message message) {
- this.message = message;
- }
+ public Message getMessage() {
+ return message;
+ }
- public Exception getException() {
- return exception;
- }
+ public void setMessage(Message message) {
+ this.message = message;
+ }
- public void setException(Exception exception) {
- this.exception = exception;
- }
+ public Exception getException() {
+ return exception;
+ }
- public boolean isComplete() {
- return complete;
- }
+ public void setException(Exception exception) {
+ this.exception = exception;
+ }
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
+ public boolean isComplete() {
+ return complete;
+ }
- public void onCompletion(Message message) {
- TestUtil.logMsg("onCompletion(): Got Message: " + message);
- this.message = message;
- complete = true;
- }
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
- public void onException(Message message, Exception exception) {
- TestUtil.logMsg("onException(): Got Exception: " + exception);
- TestUtil.logMsg("With Message: " + message);
- this.exception = exception;
- this.message = message;
- complete = true;
- }
+ public void onCompletion(Message message) {
+ logger.log(Logger.Level.INFO, "onCompletion(): Got Message: " + message);
+ this.message = message;
+ complete = true;
+ }
+
+ public void onException(Message message, Exception exception) {
+ logger.log(Logger.Level.INFO, "onException(): Got Exception: " + exception);
+ logger.log(Logger.Level.INFO, "With Message: " + message);
+ this.exception = exception;
+ this.message = message;
+ complete = true;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/MyExceptionListener.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/MyExceptionListener.java
index efd4c52828..4950c77746 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/MyExceptionListener.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/jmscontexttopictests/MyExceptionListener.java
@@ -19,56 +19,58 @@
*/
package com.sun.ts.tests.jms.core20.appclient.jmscontexttopictests;
-import com.sun.ts.lib.util.TestUtil;
+import java.lang.System.Logger;
import jakarta.jms.ExceptionListener;
import jakarta.jms.JMSException;
public class MyExceptionListener implements ExceptionListener {
- private String name = null;
+ private String name = null;
- private JMSException exception = null;
+ private JMSException exception = null;
- boolean complete = false;
+ boolean complete = false;
- public MyExceptionListener() {
- this("MyExceptionListener");
- }
+ private static final Logger logger = (Logger) System.getLogger(MyExceptionListener.class.getName());
- public MyExceptionListener(String name) {
- this.name = name;
- }
+ public MyExceptionListener() {
+ this("MyExceptionListener");
+ }
- // getters/setters
- public String getName() {
- return name;
- }
+ public MyExceptionListener(String name) {
+ this.name = name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ // getters/setters
+ public String getName() {
+ return name;
+ }
- public JMSException getException() {
- return exception;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public void setException(JMSException exception) {
- this.exception = exception;
- }
+ public JMSException getException() {
+ return exception;
+ }
- public boolean isComplete() {
- return complete;
- }
+ public void setException(JMSException exception) {
+ this.exception = exception;
+ }
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
+ public boolean isComplete() {
+ return complete;
+ }
- public void onException(JMSException exception) {
- TestUtil.logMsg("Got JMSException: " + exception);
- this.exception = exception;
- complete = true;
- }
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
+
+ public void onException(JMSException exception) {
+ logger.log(Logger.Level.INFO, "Got JMSException: " + exception);
+ this.exception = exception;
+ complete = true;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/Client.java
deleted file mode 100644
index f9be68bf42..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/Client.java
+++ /dev/null
@@ -1,757 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.appclient.listenerexceptiontests;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.common.TextMessageTestImpl;
-
-import jakarta.jms.Connection;
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.Destination;
-import jakarta.jms.JMSConsumer;
-import jakarta.jms.JMSContext;
-import jakarta.jms.JMSProducer;
-import jakarta.jms.MessageConsumer;
-import jakarta.jms.MessageProducer;
-import jakarta.jms.Queue;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.appclient.listenerexceptiontests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null;
-
- // JMS objects
- private transient ConnectionFactory cf = null;
-
- private transient Queue queue = null;
-
- private transient Session session = null;
-
- private transient Destination destination = null;
-
- private transient Connection connection = null;
-
- private transient MessageConsumer consumer = null;
-
- private transient MessageProducer producer = null;
-
- private transient JMSContext context = null;
-
- private transient JMSContext contextToSendMsg = null;
-
- private transient JMSContext contextToCreateMsg = null;
-
- private transient JMSConsumer jmsconsumer = null;
-
- private transient JMSProducer jmsproducer = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- // used for tests
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- boolean jmscontextTest = false;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * Utility methods
- */
- private void setupForQueue2() throws Exception {
- try {
- // set up JmsTool for COMMON_Q setup
- TestUtil.logMsg("Setup JmsTool for COMMON_Q setup");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- queue = (Queue) destination;
- tool.getDefaultConnection().close();
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- contextToSendMsg = cf.createContext(user, password,
- JMSContext.AUTO_ACKNOWLEDGE);
- contextToCreateMsg = cf.createContext(user, password,
- JMSContext.AUTO_ACKNOWLEDGE);
- jmsconsumer = context.createConsumer(destination);
- jmsproducer = contextToSendMsg.createProducer();
- jmscontextTest = true;
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("setupForQueue2 failed!", e);
- }
- }
-
- private void setupForQueue() throws Exception {
- try {
- // set up JmsTool for COMMON_Q setup
- TestUtil.logMsg("Setup JmsTool for COMMON_Q setup");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- cf = tool.getConnectionFactory();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- consumer = tool.getDefaultConsumer();
- producer = tool.getDefaultProducer();
- destination = tool.getDefaultDestination();
- queue = (Queue) destination;
- connection.start();
- jmscontextTest = false;
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("setupForQueue failed!", e);
- }
- }
-
- private void setupForQueueWithMultipleSessions() throws Exception {
- Connection newConnection = null;
- Session newSession = null;
- boolean transacted = false;
- try {
- // set up JmsTool for COMMON_Q setup
- TestUtil.logMsg("Setup JmsTool for COMMON_Q setup");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- cf = tool.getConnectionFactory();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- producer = tool.getDefaultProducer();
- destination = tool.getDefaultDestination();
- queue = (Queue) destination;
-
- // Create a consumer that uses new connection and new session
- newConnection = tool.getNewConnection(JmsTool.QUEUE, user, password);
- newSession = newConnection.createSession(transacted,
- Session.AUTO_ACKNOWLEDGE);
- consumer = newSession.createConsumer(destination);
- connection.start();
- jmscontextTest = false;
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("setupForQueue failed!", e);
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(3);
- connections = new ArrayList(5);
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Close Consumer objects");
- if (jmscontextTest) {
- if (jmsconsumer != null) {
- jmsconsumer.close();
- jmsconsumer = null;
- }
- TestUtil.logMsg("Close JMSContext objects");
- if (context != null) {
- context.close();
- context = null;
- }
- if (contextToSendMsg != null) {
- contextToSendMsg.close();
- contextToSendMsg = null;
- }
- if (contextToCreateMsg != null) {
- contextToCreateMsg.close();
- contextToCreateMsg = null;
- }
- } else {
- if (consumer != null) {
- consumer.close();
- consumer = null;
- }
- }
- TestUtil.logMsg("Flush any messages left on Queue");
- tool.flushDestination();
- tool.closeAllResources();
- tool.getDefaultConnection().close();
- producer = null;
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * @testName: illegalStateExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:1351;
- *
- * @test_Strategy: Calling Connection.close() from a CompletionListener MUST
- * throw IllegalStateException.
- */
- public void illegalStateExceptionTest1() throws Exception {
- boolean pass = true;
- try {
-
- TestUtil.logMsg(
- "Testing Connection.close() from CompletionListener (expect IllegalStateException)");
- try {
- // Setup for QUEUE
- setupForQueue();
-
- // Create CompetionListener
- MyCompletionListener listener = new MyCompletionListener(connection);
-
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session
- .createTextMessage("Call connection close method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateExceptionTest1");
-
- TestUtil.logMsg(
- "Send async message specifying CompletionListener to recieve async message");
- TestUtil.logMsg(
- "CompletionListener will call Connection.close() (expect IllegalStateException)");
- producer.send(expTextMessage, listener);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until we receive exception");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- listener.setComplete(false);
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil.logMsg(
- "Check if we got correct exception from Connection.close()");
- if (listener.gotException()) {
- if (listener.gotCorrectException()) {
- TestUtil.logMsg("Got correct IllegalStateException");
- } else {
- TestUtil.logErr("Expected IllegalStateException, received: "
- + listener.getException());
- pass = false;
- }
- } else {
- TestUtil.logErr("Expected IllegalStateException, got no exception");
- pass = false;
- }
- } catch (jakarta.jms.IllegalStateException e) {
- TestUtil.logMsg("Caught IllegalStateException as expected");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalStateException, received " + e);
- TestUtil.printStackTrace(e);
- pass = false;
- }
-
- try {
- cleanup();
- } catch (Exception e) {
- TestUtil.logMsg("Exception during cleanup: " + e);
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("illegalStateExceptionTest1", e);
- }
-
- if (!pass) {
- throw new Exception("illegalStateExceptionTest1 failed");
- }
- }
-
- /*
- * @testName: illegalStateExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:1351; JMS:JAVADOC:1352;
- *
- * @test_Strategy: Calling Connection.close() or Connection.stop() from a
- * MessageListener MUST throw IllegalStateException.
- */
- public void illegalStateExceptionTest2() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg(
- "Testing Connection.close() from MessageListener (expect IllegalStateException)");
- try {
- // Setup for QUEUE
- setupForQueue();
-
- // Create MessageListener
- MyMessageListener listener = new MyMessageListener(connection);
-
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session
- .createTextMessage("Call connection close method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateExceptionTest2");
-
- TestUtil.logMsg("Set MessageListener to receive async message");
- consumer.setMessageListener(listener);
-
- TestUtil.logMsg("Send async message to MessageListener");
- TestUtil.logMsg(
- "MessageListener will call Connection.close() (expect IllegalStateException)");
- producer.send(expTextMessage);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until we receive exception");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- listener.setComplete(false);
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil.logMsg(
- "Check if we got correct exception from Connection.close()");
- if (listener.gotException()) {
- if (listener.gotCorrectException()) {
- TestUtil.logMsg("Got correct IllegalStateException");
- } else {
- TestUtil.logErr("Expected IllegalStateException, received: "
- + listener.getException());
- pass = false;
- }
- } else {
- TestUtil.logErr("Expected IllegalStateException, got no exception");
- pass = false;
- }
- } catch (jakarta.jms.IllegalStateException e) {
- TestUtil.logMsg("Caught IllegalStateException as expected");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalStateException, received " + e);
- TestUtil.printStackTrace(e);
- pass = false;
- }
-
- try {
- cleanup();
- } catch (Exception e) {
- TestUtil.logMsg("Exception during cleanup: " + e);
- }
-
- TestUtil.logMsg(
- "Testing Connection.stop() from MessageListener (expect IllegalStateException)");
- try {
- // Setup for QUEUE
- setupForQueue();
-
- // Create MessageListener
- MyMessageListener listener = new MyMessageListener(connection);
-
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session
- .createTextMessage("Call connection stop method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateExceptionTest2");
-
- TestUtil.logMsg("Set MessageListener to receive async message");
- consumer.setMessageListener(listener);
-
- TestUtil.logMsg("Send async message to MessageListener");
- TestUtil.logMsg(
- "MessageListener will call Connection.stop() (expect IllegalStateException)");
- producer.send(expTextMessage);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until we receive exception");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- listener.setComplete(false);
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil
- .logMsg("Check if we got correct exception from Connection.stop()");
- if (listener.gotException()) {
- if (listener.gotCorrectException()) {
- TestUtil.logMsg("Got correct IllegalStateException");
- } else {
- TestUtil.logErr("Expected IllegalStateException, received: "
- + listener.getException());
- pass = false;
- }
- } else {
- TestUtil.logErr("Expected IllegalStateException, got no exception");
- pass = false;
- }
- } catch (jakarta.jms.IllegalStateException e) {
- TestUtil.logMsg("Caught IllegalStateException as expected");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalStateException, received " + e);
- TestUtil.printStackTrace(e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("illegalStateExceptionTest2", e);
- }
-
- if (!pass) {
- throw new Exception("illegalStateExceptionTest2 failed");
- }
- }
-
- /*
- * @testName: illegalStateExceptionTest3
- *
- * @assertion_ids: JMS:JAVADOC:1356;
- *
- * @test_Strategy: Calling Session.close() from a CompletionListener or
- * MessageListener MUST throw IllegalStateException.
- */
- public void illegalStateExceptionTest3() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg(
- "Testing Session.close() from CompletionListener (expect IllegalStateException)");
- try {
- // Setup for QUEUE
- setupForQueue();
-
- // Create CompetionListener
- MyCompletionListener listener = new MyCompletionListener(session);
-
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session
- .createTextMessage("Call session close method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateExceptionTest3");
-
- TestUtil.logMsg("Send message specifying CompletionListener");
- TestUtil.logMsg(
- "CompletionListener will call Session.close() (expect IllegalStateException)");
- producer.send(expTextMessage, listener);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until we receive exception");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- listener.setComplete(false);
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil
- .logMsg("Check if we got correct exception from Session.close()");
- if (listener.gotException()) {
- if (listener.gotCorrectException()) {
- TestUtil.logMsg("Got correct IllegalStateException");
- } else {
- TestUtil.logErr("Expected IllegalStateException, received: "
- + listener.getException());
- pass = false;
- }
- } else {
- TestUtil.logErr("Expected IllegalStateException, got no exception");
- pass = false;
- }
- } catch (jakarta.jms.IllegalStateException e) {
- TestUtil.logMsg("Caught IllegalStateException as expected");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalStateException, received " + e);
- TestUtil.printStackTrace(e);
- pass = false;
- }
-
- try {
- cleanup();
- } catch (Exception e) {
- TestUtil.logMsg("Exception during cleanup: " + e);
- }
-
- TestUtil.logMsg(
- "Testing Session.close() from MessageListener (expect IllegalStateException)");
- try {
- // Setup for QUEUE
- setupForQueue();
-
- // Create MessageListener
- MyMessageListener listener = new MyMessageListener(session);
-
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session
- .createTextMessage("Call session close method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateExceptionTest6");
-
- TestUtil.logMsg("Set MessageListener to receive async message");
- consumer.setMessageListener(listener);
-
- TestUtil.logMsg("Send async message to MessageListener");
- TestUtil.logMsg(
- "MessageListener will call Session.close() (expect IllegalStateException)");
- producer.send(expTextMessage);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until we receive exception");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- listener.setComplete(false);
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil
- .logMsg("Check if we got correct exception from Session.close()");
- if (listener.gotException()) {
- if (listener.gotCorrectException()) {
- TestUtil.logMsg("Got correct IllegalStateException");
- } else {
- TestUtil.logErr("Expected IllegalStateException, received: "
- + listener.getException());
- pass = false;
- }
- } else {
- TestUtil.logErr("Expected IllegalStateException, got no exception");
- pass = false;
- }
- } catch (jakarta.jms.IllegalStateException e) {
- TestUtil.logMsg("Caught IllegalStateException as expected");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalStateException, received " + e);
- TestUtil.printStackTrace(e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("illegalStateExceptionTest3", e);
- }
-
- if (!pass) {
- throw new Exception("illegalStateExceptionTest3 failed");
- }
- }
-
- /*
- * @testName: callingMessageConsumerCloseIsAllowed
- *
- * @assertion_ids: JMS:JAVADOC:338;
- *
- * @test_Strategy: Calling MessageConsumer.close() from a MessageListener is
- * allowed.
- */
- public void callingMessageConsumerCloseIsAllowed() throws Exception {
- boolean pass = true;
- try {
-
- try {
- // Setup for QUEUE
- setupForQueueWithMultipleSessions();
-
- // Create MessageListener
- MyMessageListener listener = new MyMessageListener(consumer);
-
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- // TextMessage expTextMessage = session
- // .createTextMessage("Call MessageConsumer close method");
- TextMessage expTextMessage = new TextMessageTestImpl();
- expTextMessage.setText("Call MessageConsumer close method");
-
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "callingMessageConsumerCloseIsAllowed");
-
- TestUtil.logMsg("Set MessageListener to receive async message");
- consumer.setMessageListener(listener);
-
- TestUtil.logMsg("Send async message to MessageListener");
- TestUtil.logMsg(
- "MessageListener will call MessageConsumer.close() which is allowed");
- producer.send(expTextMessage);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until complete");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- listener.setComplete(false);
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil.logMsg("Make sure MessageConsumer.close() was allowed");
- if (!listener.gotException()) {
- TestUtil.logMsg("MessageConsumer.close() was allowed");
- } else {
- TestUtil.logErr("MessageConsumer.close() through an exception");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("callingMessageConsumerCloseIsAllowed", e);
- }
-
- if (!pass) {
- throw new Exception("callingMessageConsumerCloseIsAllowed failed");
- }
- }
-
- /*
- * @testName: callingJMSConsumerCloseIsAllowed
- *
- * @assertion_ids: JMS:JAVADOC:1098;
- *
- * @test_Strategy: Calling JMSConsumer.close() from a MessageListsner is
- * allowed.
- */
- public void callingJMSConsumerCloseIsAllowed() throws Exception {
- boolean pass = true;
- try {
-
- try {
- // Setup for QUEUE
- setupForQueue2();
-
- // Create MessageListener
- MyMessageListener listener = new MyMessageListener(jmsconsumer);
-
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = contextToCreateMsg
- .createTextMessage("Call JMSConsumer close method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "callingJMSConsumerCloseIsAllowed");
-
- TestUtil.logMsg("Set MessageListener to receive async message");
- jmsconsumer.setMessageListener(listener);
-
- TestUtil.logMsg("Send async message to MessageListener");
- TestUtil.logMsg(
- "MessageListener will call JMSConsumer.close() which is allowed");
- jmsproducer.send(destination, expTextMessage);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until complete");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- listener.setComplete(false);
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil.logMsg("Make sure JMSConsumer.close() was allowed");
- if (!listener.gotException()) {
- TestUtil.logMsg("JMSConsumer.close() was allowed");
- } else {
- TestUtil.logErr("JMSConsumer.close() through an exception");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("callingJMSConsumerCloseIsAllowed", e);
- }
-
- if (!pass) {
- throw new Exception("callingJMSConsumerCloseIsAllowed failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/ClientIT.java
new file mode 100644
index 0000000000..c15be6da9a
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/ClientIT.java
@@ -0,0 +1,733 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.appclient.listenerexceptiontests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.common.TextMessageTestImpl;
+
+import jakarta.jms.Connection;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.Destination;
+import jakarta.jms.JMSConsumer;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSProducer;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Queue;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.appclient.listenerexceptiontests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null;
+
+ // JMS objects
+ private transient ConnectionFactory cf = null;
+
+ private transient Queue queue = null;
+
+ private transient Session session = null;
+
+ private transient Destination destination = null;
+
+ private transient Connection connection = null;
+
+ private transient MessageConsumer consumer = null;
+
+ private transient MessageProducer producer = null;
+
+ private transient JMSContext context = null;
+
+ private transient JMSContext contextToSendMsg = null;
+
+ private transient JMSContext contextToCreateMsg = null;
+
+ private transient JMSConsumer jmsconsumer = null;
+
+ private transient JMSProducer jmsproducer = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ // used for tests
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ boolean jmscontextTest = false;
+
+ /*
+ * Utility methods
+ */
+ private void setupForQueue2() throws Exception {
+ try {
+ // set up JmsTool for COMMON_Q setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_Q setup");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ queue = (Queue) destination;
+ tool.getDefaultConnection().close();
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ contextToSendMsg = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ contextToCreateMsg = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ jmsconsumer = context.createConsumer(destination);
+ jmsproducer = contextToSendMsg.createProducer();
+ jmscontextTest = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("setupForQueue2 failed!", e);
+ }
+ }
+
+ private void setupForQueue() throws Exception {
+ try {
+ // set up JmsTool for COMMON_Q setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_Q setup");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ cf = tool.getConnectionFactory();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ consumer = tool.getDefaultConsumer();
+ producer = tool.getDefaultProducer();
+ destination = tool.getDefaultDestination();
+ queue = (Queue) destination;
+ connection.start();
+ jmscontextTest = false;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("setupForQueue failed!", e);
+ }
+ }
+
+ private void setupForQueueWithMultipleSessions() throws Exception {
+ Connection newConnection = null;
+ Session newSession = null;
+ boolean transacted = false;
+ try {
+ // set up JmsTool for COMMON_Q setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_Q setup");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ cf = tool.getConnectionFactory();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ producer = tool.getDefaultProducer();
+ destination = tool.getDefaultDestination();
+ queue = (Queue) destination;
+
+ // Create a consumer that uses new connection and new session
+ newConnection = tool.getNewConnection(JmsTool.QUEUE, user, password);
+ newSession = newConnection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
+ consumer = newSession.createConsumer(destination);
+ connection.start();
+ jmscontextTest = false;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("setupForQueue failed!", e);
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(3);
+ connections = new ArrayList(5);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Close Consumer objects");
+ if (jmscontextTest) {
+ if (jmsconsumer != null) {
+ jmsconsumer.close();
+ jmsconsumer = null;
+ }
+ logger.log(Logger.Level.INFO, "Close JMSContext objects");
+ if (context != null) {
+ context.close();
+ context = null;
+ }
+ if (contextToSendMsg != null) {
+ contextToSendMsg.close();
+ contextToSendMsg = null;
+ }
+ if (contextToCreateMsg != null) {
+ contextToCreateMsg.close();
+ contextToCreateMsg = null;
+ }
+ } else {
+ if (consumer != null) {
+ consumer.close();
+ consumer = null;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ tool.flushDestination();
+ tool.closeAllResources();
+ tool.getDefaultConnection().close();
+ producer = null;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: illegalStateExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1351;
+ *
+ * @test_Strategy: Calling Connection.close() from a CompletionListener MUST
+ * throw IllegalStateException.
+ */
+ @Test
+ public void illegalStateExceptionTest1() throws Exception {
+ boolean pass = true;
+ try {
+
+ logger.log(Logger.Level.INFO,
+ "Testing Connection.close() from CompletionListener (expect IllegalStateException)");
+ try {
+ // Setup for QUEUE
+ setupForQueue();
+
+ // Create CompetionListener
+ MyCompletionListener listener = new MyCompletionListener(connection);
+
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage("Call connection close method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateExceptionTest1");
+
+ logger.log(Logger.Level.INFO,
+ "Send async message specifying CompletionListener to recieve async message");
+ logger.log(Logger.Level.INFO,
+ "CompletionListener will call Connection.close() (expect IllegalStateException)");
+ producer.send(expTextMessage, listener);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Check if we got correct exception from Connection.close()");
+ if (listener.gotException()) {
+ if (listener.gotCorrectException()) {
+ logger.log(Logger.Level.INFO, "Got correct IllegalStateException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Expected IllegalStateException, received: " + listener.getException());
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, got no exception");
+ pass = false;
+ }
+ } catch (jakarta.jms.IllegalStateException e) {
+ logger.log(Logger.Level.INFO, "Caught IllegalStateException as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, received " + e);
+ TestUtil.printStackTrace(e);
+ pass = false;
+ }
+
+ try {
+ cleanup();
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Exception during cleanup: " + e);
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("illegalStateExceptionTest1", e);
+ }
+
+ if (!pass) {
+ throw new Exception("illegalStateExceptionTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: illegalStateExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1351; JMS:JAVADOC:1352;
+ *
+ * @test_Strategy: Calling Connection.close() or Connection.stop() from a
+ * MessageListener MUST throw IllegalStateException.
+ */
+ @Test
+ public void illegalStateExceptionTest2() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO,
+ "Testing Connection.close() from MessageListener (expect IllegalStateException)");
+ try {
+ // Setup for QUEUE
+ setupForQueue();
+
+ // Create MessageListener
+ MyMessageListener listener = new MyMessageListener(connection);
+
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage("Call connection close method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateExceptionTest2");
+
+ logger.log(Logger.Level.INFO, "Set MessageListener to receive async message");
+ consumer.setMessageListener(listener);
+
+ logger.log(Logger.Level.INFO, "Send async message to MessageListener");
+ logger.log(Logger.Level.INFO,
+ "MessageListener will call Connection.close() (expect IllegalStateException)");
+ producer.send(expTextMessage);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Check if we got correct exception from Connection.close()");
+ if (listener.gotException()) {
+ if (listener.gotCorrectException()) {
+ logger.log(Logger.Level.INFO, "Got correct IllegalStateException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Expected IllegalStateException, received: " + listener.getException());
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, got no exception");
+ pass = false;
+ }
+ } catch (jakarta.jms.IllegalStateException e) {
+ logger.log(Logger.Level.INFO, "Caught IllegalStateException as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, received " + e);
+ TestUtil.printStackTrace(e);
+ pass = false;
+ }
+
+ try {
+ cleanup();
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Exception during cleanup: " + e);
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing Connection.stop() from MessageListener (expect IllegalStateException)");
+ try {
+ // Setup for QUEUE
+ setupForQueue();
+
+ // Create MessageListener
+ MyMessageListener listener = new MyMessageListener(connection);
+
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage("Call connection stop method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateExceptionTest2");
+
+ logger.log(Logger.Level.INFO, "Set MessageListener to receive async message");
+ consumer.setMessageListener(listener);
+
+ logger.log(Logger.Level.INFO, "Send async message to MessageListener");
+ logger.log(Logger.Level.INFO,
+ "MessageListener will call Connection.stop() (expect IllegalStateException)");
+ producer.send(expTextMessage);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Check if we got correct exception from Connection.stop()");
+ if (listener.gotException()) {
+ if (listener.gotCorrectException()) {
+ logger.log(Logger.Level.INFO, "Got correct IllegalStateException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Expected IllegalStateException, received: " + listener.getException());
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, got no exception");
+ pass = false;
+ }
+ } catch (jakarta.jms.IllegalStateException e) {
+ logger.log(Logger.Level.INFO, "Caught IllegalStateException as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, received " + e);
+ TestUtil.printStackTrace(e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("illegalStateExceptionTest2", e);
+ }
+
+ if (!pass) {
+ throw new Exception("illegalStateExceptionTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: illegalStateExceptionTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:1356;
+ *
+ * @test_Strategy: Calling Session.close() from a CompletionListener or
+ * MessageListener MUST throw IllegalStateException.
+ */
+ @Test
+ public void illegalStateExceptionTest3() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO,
+ "Testing Session.close() from CompletionListener (expect IllegalStateException)");
+ try {
+ // Setup for QUEUE
+ setupForQueue();
+
+ // Create CompetionListener
+ MyCompletionListener listener = new MyCompletionListener(session);
+
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage("Call session close method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateExceptionTest3");
+
+ logger.log(Logger.Level.INFO, "Send message specifying CompletionListener");
+ logger.log(Logger.Level.INFO,
+ "CompletionListener will call Session.close() (expect IllegalStateException)");
+ producer.send(expTextMessage, listener);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Check if we got correct exception from Session.close()");
+ if (listener.gotException()) {
+ if (listener.gotCorrectException()) {
+ logger.log(Logger.Level.INFO, "Got correct IllegalStateException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Expected IllegalStateException, received: " + listener.getException());
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, got no exception");
+ pass = false;
+ }
+ } catch (jakarta.jms.IllegalStateException e) {
+ logger.log(Logger.Level.INFO, "Caught IllegalStateException as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, received " + e);
+ TestUtil.printStackTrace(e);
+ pass = false;
+ }
+
+ try {
+ cleanup();
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Exception during cleanup: " + e);
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing Session.close() from MessageListener (expect IllegalStateException)");
+ try {
+ // Setup for QUEUE
+ setupForQueue();
+
+ // Create MessageListener
+ MyMessageListener listener = new MyMessageListener(session);
+
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage("Call session close method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateExceptionTest6");
+
+ logger.log(Logger.Level.INFO, "Set MessageListener to receive async message");
+ consumer.setMessageListener(listener);
+
+ logger.log(Logger.Level.INFO, "Send async message to MessageListener");
+ logger.log(Logger.Level.INFO,
+ "MessageListener will call Session.close() (expect IllegalStateException)");
+ producer.send(expTextMessage);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Check if we got correct exception from Session.close()");
+ if (listener.gotException()) {
+ if (listener.gotCorrectException()) {
+ logger.log(Logger.Level.INFO, "Got correct IllegalStateException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Expected IllegalStateException, received: " + listener.getException());
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, got no exception");
+ pass = false;
+ }
+ } catch (jakarta.jms.IllegalStateException e) {
+ logger.log(Logger.Level.INFO, "Caught IllegalStateException as expected");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, received " + e);
+ TestUtil.printStackTrace(e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("illegalStateExceptionTest3", e);
+ }
+
+ if (!pass) {
+ throw new Exception("illegalStateExceptionTest3 failed");
+ }
+ }
+
+ /*
+ * @testName: callingMessageConsumerCloseIsAllowed
+ *
+ * @assertion_ids: JMS:JAVADOC:338;
+ *
+ * @test_Strategy: Calling MessageConsumer.close() from a MessageListener is
+ * allowed.
+ */
+ @Test
+ public void callingMessageConsumerCloseIsAllowed() throws Exception {
+ boolean pass = true;
+ try {
+
+ try {
+ // Setup for QUEUE
+ setupForQueueWithMultipleSessions();
+
+ // Create MessageListener
+ MyMessageListener listener = new MyMessageListener(consumer);
+
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ // TextMessage expTextMessage = session
+ // .createTextMessage("Call MessageConsumer close method");
+ TextMessage expTextMessage = new TextMessageTestImpl();
+ expTextMessage.setText("Call MessageConsumer close method");
+
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "callingMessageConsumerCloseIsAllowed");
+
+ logger.log(Logger.Level.INFO, "Set MessageListener to receive async message");
+ consumer.setMessageListener(listener);
+
+ logger.log(Logger.Level.INFO, "Send async message to MessageListener");
+ logger.log(Logger.Level.INFO, "MessageListener will call MessageConsumer.close() which is allowed");
+ producer.send(expTextMessage);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until complete");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Make sure MessageConsumer.close() was allowed");
+ if (!listener.gotException()) {
+ logger.log(Logger.Level.INFO, "MessageConsumer.close() was allowed");
+ } else {
+ logger.log(Logger.Level.ERROR, "MessageConsumer.close() through an exception");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("callingMessageConsumerCloseIsAllowed", e);
+ }
+
+ if (!pass) {
+ throw new Exception("callingMessageConsumerCloseIsAllowed failed");
+ }
+ }
+
+ /*
+ * @testName: callingJMSConsumerCloseIsAllowed
+ *
+ * @assertion_ids: JMS:JAVADOC:1098;
+ *
+ * @test_Strategy: Calling JMSConsumer.close() from a MessageListsner is
+ * allowed.
+ */
+ @Test
+ public void callingJMSConsumerCloseIsAllowed() throws Exception {
+ boolean pass = true;
+ try {
+
+ try {
+ // Setup for QUEUE
+ setupForQueue2();
+
+ // Create MessageListener
+ MyMessageListener listener = new MyMessageListener(jmsconsumer);
+
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = contextToCreateMsg.createTextMessage("Call JMSConsumer close method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "callingJMSConsumerCloseIsAllowed");
+
+ logger.log(Logger.Level.INFO, "Set MessageListener to receive async message");
+ jmsconsumer.setMessageListener(listener);
+
+ logger.log(Logger.Level.INFO, "Send async message to MessageListener");
+ logger.log(Logger.Level.INFO, "MessageListener will call JMSConsumer.close() which is allowed");
+ jmsproducer.send(destination, expTextMessage);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until complete");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Make sure JMSConsumer.close() was allowed");
+ if (!listener.gotException()) {
+ logger.log(Logger.Level.INFO, "JMSConsumer.close() was allowed");
+ } else {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.close() through an exception");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("callingJMSConsumerCloseIsAllowed", e);
+ }
+
+ if (!pass) {
+ throw new Exception("callingJMSConsumerCloseIsAllowed failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/MyCompletionListener.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/MyCompletionListener.java
index de356b1081..388c304b97 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/MyCompletionListener.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/MyCompletionListener.java
@@ -19,10 +19,9 @@
*/
package com.sun.ts.tests.jms.core20.appclient.listenerexceptiontests;
+import java.lang.System.Logger;
import java.util.ArrayList;
-import com.sun.ts.lib.util.TestUtil;
-
import jakarta.jms.CompletionListener;
import jakarta.jms.Connection;
import jakarta.jms.Message;
@@ -31,147 +30,145 @@
public class MyCompletionListener implements CompletionListener {
- private String name = null;
+ private String name = null;
+
+ private Message message = null;
- private Message message = null;
+ private Connection connection = null;
- private Connection connection = null;
+ private Session session = null;
- private Session session = null;
+ private ArrayList messages = new ArrayList();
- private ArrayList messages = new ArrayList();
+ private Exception exception = null;
- private Exception exception = null;
+ private int numMessages = 1;
- private int numMessages = 1;
+ private int countMessages = 0;
- private int countMessages = 0;
+ boolean complete = false;
- boolean complete = false;
+ boolean gotCorrectException = false;
- boolean gotCorrectException = false;
+ boolean gotException = false;
- boolean gotException = false;
+ private static final Logger logger = (Logger) System.getLogger(MyCompletionListener.class.getName());
- public MyCompletionListener() {
- this("MyCompletionListener");
- }
-
- public MyCompletionListener(String name) {
- this.name = name;
- }
-
- public MyCompletionListener(int numMessages) {
- this.numMessages = numMessages;
- messages.clear();
- }
-
- public MyCompletionListener(Connection connection) {
- this.connection = connection;
- }
-
- public MyCompletionListener(Session session) {
- this.session = session;
- }
-
- // getters/setters
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Message getMessage() {
- return message;
- }
-
- public Message getMessage(int index) {
- return messages.get(index);
- }
-
- public void setMessage(Message message) {
- this.message = message;
- }
-
- public Exception getException() {
- return exception;
- }
-
- public void setException(Exception exception) {
- this.exception = exception;
- }
-
- public boolean isComplete() {
- return complete;
- }
-
- public boolean gotCorrectException() {
- return gotCorrectException;
- }
-
- public boolean gotException() {
- return gotException;
- }
-
- public boolean gotAllMsgs() {
- return (messages.size() == numMessages) ? true : false;
- }
-
- public boolean haveMsg(int i) {
- return (messages.size() > i) ? true : false;
- }
-
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
-
- public void onCompletion(Message message) {
- try {
- TestUtil.logMsg(
- "onCompletion(): Got Message: " + ((TextMessage) message).getText());
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- this.message = message;
- messages.add(message);
- if (message instanceof TextMessage) {
- TextMessage tMsg = (TextMessage) message;
- try {
- if (tMsg.getText().equals("Call connection close method")) {
- TestUtil.logMsg(
- "Calling Connection.close() MUST throw IllegalStateException");
- if (connection != null)
- connection.close();
- } else if (tMsg.getText().equals("Call session close method")) {
- TestUtil.logMsg(
- "Calling Session.close() MUST throw IllegalStateException");
- if (session != null)
- session.close();
- }
- } catch (jakarta.jms.IllegalStateException e) {
- TestUtil
- .logMsg("onCompletion(): Caught expected IllegalStateException");
- gotCorrectException = true;
- gotException = true;
- } catch (Exception e) {
- TestUtil.logErr("onCompletion(): Caught unexpected exception: " + e);
- gotCorrectException = false;
- gotException = true;
- exception = e;
- }
- }
- complete = true;
- TestUtil.logMsg("onCompletion(): Leaving");
- }
-
- public void onException(Message message, Exception exception) {
- TestUtil.logMsg("Got Exception: " + exception);
- TestUtil.logMsg("With Message: " + message);
- this.exception = exception;
- this.message = message;
- complete = true;
- }
+ public MyCompletionListener() {
+ this("MyCompletionListener");
+ }
+
+ public MyCompletionListener(String name) {
+ this.name = name;
+ }
+
+ public MyCompletionListener(int numMessages) {
+ this.numMessages = numMessages;
+ messages.clear();
+ }
+
+ public MyCompletionListener(Connection connection) {
+ this.connection = connection;
+ }
+
+ public MyCompletionListener(Session session) {
+ this.session = session;
+ }
+
+ // getters/setters
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+
+ public Message getMessage(int index) {
+ return messages.get(index);
+ }
+
+ public void setMessage(Message message) {
+ this.message = message;
+ }
+
+ public Exception getException() {
+ return exception;
+ }
+
+ public void setException(Exception exception) {
+ this.exception = exception;
+ }
+
+ public boolean isComplete() {
+ return complete;
+ }
+
+ public boolean gotCorrectException() {
+ return gotCorrectException;
+ }
+
+ public boolean gotException() {
+ return gotException;
+ }
+
+ public boolean gotAllMsgs() {
+ return (messages.size() == numMessages) ? true : false;
+ }
+
+ public boolean haveMsg(int i) {
+ return (messages.size() > i) ? true : false;
+ }
+
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
+
+ public void onCompletion(Message message) {
+ try {
+ logger.log(Logger.Level.INFO, "onCompletion(): Got Message: " + ((TextMessage) message).getText());
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ this.message = message;
+ messages.add(message);
+ if (message instanceof TextMessage) {
+ TextMessage tMsg = (TextMessage) message;
+ try {
+ if (tMsg.getText().equals("Call connection close method")) {
+ logger.log(Logger.Level.INFO, "Calling Connection.close() MUST throw IllegalStateException");
+ if (connection != null)
+ connection.close();
+ } else if (tMsg.getText().equals("Call session close method")) {
+ logger.log(Logger.Level.INFO, "Calling Session.close() MUST throw IllegalStateException");
+ if (session != null)
+ session.close();
+ }
+ } catch (jakarta.jms.IllegalStateException e) {
+ logger.log(Logger.Level.INFO, "onCompletion(): Caught expected IllegalStateException");
+ gotCorrectException = true;
+ gotException = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "onCompletion(): Caught unexpected exception: " + e);
+ gotCorrectException = false;
+ gotException = true;
+ exception = e;
+ }
+ }
+ complete = true;
+ logger.log(Logger.Level.INFO, "onCompletion(): Leaving");
+ }
+
+ public void onException(Message message, Exception exception) {
+ logger.log(Logger.Level.INFO, "Got Exception: " + exception);
+ logger.log(Logger.Level.INFO, "With Message: " + message);
+ this.exception = exception;
+ this.message = message;
+ complete = true;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/MyMessageListener.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/MyMessageListener.java
index 0f37268bb3..589536197b 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/MyMessageListener.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/listenerexceptiontests/MyMessageListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,10 +19,9 @@
*/
package com.sun.ts.tests.jms.core20.appclient.listenerexceptiontests;
+import java.lang.System.Logger;
import java.util.ArrayList;
-import com.sun.ts.lib.util.TestUtil;
-
import jakarta.jms.Connection;
import jakarta.jms.JMSConsumer;
import jakarta.jms.Message;
@@ -33,173 +32,170 @@
public class MyMessageListener implements MessageListener {
- private String name = null;
+ private String name = null;
+
+ private Message message = null;
- private Message message = null;
+ private Connection connection = null;
- private Connection connection = null;
+ private Session session = null;
- private Session session = null;
+ private JMSConsumer jmsconsumer = null;
- private JMSConsumer jmsconsumer = null;
+ private MessageConsumer msgconsumer = null;
- private MessageConsumer msgconsumer = null;
+ private ArrayList messages = new ArrayList();
- private ArrayList messages = new ArrayList();
+ private Exception exception = null;
- private Exception exception = null;
+ private int numMessages = 1;
- private int numMessages = 1;
+ boolean complete = false;
- boolean complete = false;
+ boolean gotCorrectException = false;
- boolean gotCorrectException = false;
+ boolean gotException = false;
- boolean gotException = false;
+ private static final Logger logger = (Logger) System.getLogger(MyMessageListener.class.getName());
- public MyMessageListener() {
- this("MyMessageListener");
- }
+ public MyMessageListener() {
+ this("MyMessageListener");
+ }
- public MyMessageListener(String name) {
- this.name = name;
- }
+ public MyMessageListener(String name) {
+ this.name = name;
+ }
- public MyMessageListener(int numMessages) {
- this.numMessages = numMessages;
- messages.clear();
- }
-
- public MyMessageListener(Connection connection) {
- this.connection = connection;
- }
-
- public MyMessageListener(Session session) {
- this.session = session;
- }
-
- public MyMessageListener(JMSConsumer consumer) {
- this.jmsconsumer = consumer;
- }
-
- public MyMessageListener(MessageConsumer consumer) {
- this.msgconsumer = consumer;
- }
-
- // getters/setters
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Message getMessage() {
- return message;
- }
-
- public Message getMessage(int index) {
- return messages.get(index);
- }
-
- public void setMessage(Message message) {
- this.message = message;
- }
-
- public Exception getException() {
- return exception;
- }
-
- public void setException(Exception exception) {
- this.exception = exception;
- }
-
- public boolean isComplete() {
- return complete;
- }
-
- public boolean gotCorrectException() {
- return gotCorrectException;
- }
-
- public boolean gotException() {
- return gotException;
- }
-
- public boolean gotAllMsgs() {
- return (messages.size() == numMessages) ? true : false;
- }
-
- public boolean haveMsg(int i) {
- return (messages.size() > i) ? true : false;
- }
-
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
-
- public void onMessage(Message message) {
- try {
- TestUtil.logMsg(
- "onMessage(): Got Message: " + ((TextMessage) message).getText());
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- this.message = message;
- messages.add(message);
- if (message instanceof TextMessage) {
- TextMessage tMsg = (TextMessage) message;
- try {
- if (tMsg.getText().equals("Call connection close method")) {
- TestUtil.logMsg(
- "Calling Connection.close() MUST throw IllegalStateException");
- if (connection != null)
- connection.close();
- } else if (tMsg.getText().equals("Call connection stop method")) {
- TestUtil.logMsg(
- "Calling Connection.stop() MUST throw IllegalStateException");
- if (connection != null)
- connection.stop();
- } else if (tMsg.getText().equals("Call session close method")) {
- TestUtil.logMsg(
- "Calling Session.close() MUST throw IllegalStateException");
- if (session != null)
- session.close();
- } else if (tMsg.getText().equals("Call MessageConsumer close method")) {
- TestUtil.logMsg("Calling MessageConsumer.close() MUST be allowed");
- if (msgconsumer != null)
- msgconsumer.close();
- }
- } catch (jakarta.jms.IllegalStateException e) {
- TestUtil.logMsg("onMessage(): Caught expected IllegalStateException");
- gotCorrectException = true;
- gotException = true;
- } catch (Exception e) {
- TestUtil.logErr("onMessage(): Caught unexpected exception: " + e);
- gotCorrectException = false;
- gotException = true;
- exception = e;
- }
- try {
- if (tMsg.getText().equals("Call JMSConsumer close method")) {
- TestUtil.logMsg("Calling JMSConsumer.close() MUST be allowed");
- if (jmsconsumer != null)
- jmsconsumer.close();
- }
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- TestUtil.logMsg(
- "onMessage(): Caught expected IllegalStateRuntimeException");
- gotCorrectException = true;
- gotException = true;
- } catch (Exception e) {
- TestUtil.logErr("onMessage(): Caught unexpected exception: " + e);
- gotCorrectException = false;
- gotException = true;
- exception = e;
- }
- }
- complete = true;
- TestUtil.logMsg("onMessage(): Leaving");
- }
+ public MyMessageListener(int numMessages) {
+ this.numMessages = numMessages;
+ messages.clear();
+ }
+
+ public MyMessageListener(Connection connection) {
+ this.connection = connection;
+ }
+
+ public MyMessageListener(Session session) {
+ this.session = session;
+ }
+
+ public MyMessageListener(JMSConsumer consumer) {
+ this.jmsconsumer = consumer;
+ }
+
+ public MyMessageListener(MessageConsumer consumer) {
+ this.msgconsumer = consumer;
+ }
+
+ // getters/setters
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+
+ public Message getMessage(int index) {
+ return messages.get(index);
+ }
+
+ public void setMessage(Message message) {
+ this.message = message;
+ }
+
+ public Exception getException() {
+ return exception;
+ }
+
+ public void setException(Exception exception) {
+ this.exception = exception;
+ }
+
+ public boolean isComplete() {
+ return complete;
+ }
+
+ public boolean gotCorrectException() {
+ return gotCorrectException;
+ }
+
+ public boolean gotException() {
+ return gotException;
+ }
+
+ public boolean gotAllMsgs() {
+ return (messages.size() == numMessages) ? true : false;
+ }
+
+ public boolean haveMsg(int i) {
+ return (messages.size() > i) ? true : false;
+ }
+
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
+
+ public void onMessage(Message message) {
+ try {
+ logger.log(Logger.Level.INFO, "onMessage(): Got Message: " + ((TextMessage) message).getText());
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ this.message = message;
+ messages.add(message);
+ if (message instanceof TextMessage) {
+ TextMessage tMsg = (TextMessage) message;
+ try {
+ if (tMsg.getText().equals("Call connection close method")) {
+ logger.log(Logger.Level.INFO, "Calling Connection.close() MUST throw IllegalStateException");
+ if (connection != null)
+ connection.close();
+ } else if (tMsg.getText().equals("Call connection stop method")) {
+ logger.log(Logger.Level.INFO, "Calling Connection.stop() MUST throw IllegalStateException");
+ if (connection != null)
+ connection.stop();
+ } else if (tMsg.getText().equals("Call session close method")) {
+ logger.log(Logger.Level.INFO, "Calling Session.close() MUST throw IllegalStateException");
+ if (session != null)
+ session.close();
+ } else if (tMsg.getText().equals("Call MessageConsumer close method")) {
+ logger.log(Logger.Level.INFO, "Calling MessageConsumer.close() MUST be allowed");
+ if (msgconsumer != null)
+ msgconsumer.close();
+ }
+ } catch (jakarta.jms.IllegalStateException e) {
+ logger.log(Logger.Level.INFO, "onMessage(): Caught expected IllegalStateException");
+ gotCorrectException = true;
+ gotException = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "onMessage(): Caught unexpected exception: " + e);
+ gotCorrectException = false;
+ gotException = true;
+ exception = e;
+ }
+ try {
+ if (tMsg.getText().equals("Call JMSConsumer close method")) {
+ logger.log(Logger.Level.INFO, "Calling JMSConsumer.close() MUST be allowed");
+ if (jmsconsumer != null)
+ jmsconsumer.close();
+ }
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "onMessage(): Caught expected IllegalStateRuntimeException");
+ gotCorrectException = true;
+ gotException = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "onMessage(): Caught unexpected exception: " + e);
+ gotCorrectException = false;
+ gotException = true;
+ exception = e;
+ }
+ }
+ complete = true;
+ logger.log(Logger.Level.INFO, "onMessage(): Leaving");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageconsumertests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageconsumertests/Client.java
deleted file mode 100644
index 6741298668..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageconsumertests/Client.java
+++ /dev/null
@@ -1,370 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.appclient.messageconsumertests;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.common.TextMessageTestImpl;
-
-import jakarta.jms.Connection;
-import jakarta.jms.Destination;
-import jakarta.jms.MessageConsumer;
-import jakarta.jms.MessageListener;
-import jakarta.jms.MessageProducer;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.appclient.messageconsumertests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool toolForProducer = null;
-
- // JMS objects
- transient MessageProducer producer = null;
-
- transient MessageConsumer consumer = null;
-
- transient Connection connection = null;
-
- transient Session session = null;
-
- transient Destination destination = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- boolean queueTest = false;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- TestUtil.logMsg("Didn't get expected exception");
- throw new Exception("Didn't get expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Closing default Connection");
- tool.getDefaultConnection().close();
- if (queueTest) {
- TestUtil.logMsg("Flush any messages left on Queue");
- tool.flushDestination();
- }
- tool.closeAllResources();
-
- if (toolForProducer != null) {
- toolForProducer.getDefaultConnection().close();
- if (queueTest) {
- TestUtil.logMsg("Flush any messages left on Queue");
- toolForProducer.flushDestination();
- }
- toolForProducer.closeAllResources();
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * @testName: queueSendRecvMessageListenerTest
- *
- * @assertion_ids: JMS:JAVADOC:317; JMS:JAVADOC:328; JMS:JAVADOC:330;
- * JMS:SPEC:264.4; JMS:SPEC:264; JMS:SPEC:137;
- *
- * @test_Strategy: Creates a new consumer on the specified destination that
- * will deliver messages to the specified MessageListener. Tests the following
- * API method:
- *
- * MessageProducer.send(Message)
- * MessageConsumer.setMessageListener(MessageListener)
- * MessageConsumer.getMessageListener()
- *
- * 1 Setup MessageListener for the specified destination 2 Send a message to
- * the destination 3 Verify message received by listener
- */
- public void queueSendRecvMessageListenerTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- TestUtil.logMsg("Setup JmsTool for COMMON QUEUE");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- toolForProducer = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- logMsg("Initialize variables after JmsTool setup");
- producer = toolForProducer.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- // Creates a new consumer on the specified destination that
- // will deliver messages to the specified MessageListener.
- TestUtil.logMsg("Create message listener MyMessageListener");
- MyMessageListener listener = new MyMessageListener();
- TestUtil.logMsg(
- "Set message listener MyMessageListener on this MessageConsumer");
- consumer.setMessageListener(listener);
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- // TextMessage expTextMessage = session.createTextMessage(message);
- TextMessage expTextMessage = new TextMessageTestImpl();
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setText(message);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueSendRecvMessageListenerTest");
- TestUtil.logMsg("Calling MessageProducer.send(Message)");
- producer.send(expTextMessage);
-
- TestUtil.logMsg("Poll listener waiting for TestMessage to arrive");
- TextMessage actTextMessage = null;
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage (actTextMessage=NULL)");
- }
-
- TestUtil.logMsg("Check value of message returned");
- if (!actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logErr("Received [" + actTextMessage.getText() + "] expected ["
- + expTextMessage.getText() + "]");
- pass = false;
- }
-
- TestUtil.logMsg(
- "Retreive MessageListener by calling MessageConsumer.getMessageListener()");
- MessageListener messageListener = consumer.getMessageListener();
- if (messageListener == null) {
- TestUtil.logErr("getMessageListener() returned NULL");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("queueSendRecvMessageListenerTest", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueSendRecvMessageListenerTest failed");
- }
- }
-
- /*
- * @testName: topicSendRecvMessageListenerTest
- *
- * @assertion_ids: JMS:JAVADOC:317; JMS:JAVADOC:328; JMS:JAVADOC:330;
- * JMS:SPEC:264.4; JMS:SPEC:264;
- *
- * @test_Strategy: Creates a new consumer on the specified destination that
- * will deliver messages to the specified MessageListener. Tests the following
- * API method:
- *
- * MessageProducer.send(Message)
- * MessageConsumer.setMessageListener(MessageListener)
- * MessageConsumer.getMessageListener()
- *
- * 1 Setup MessageListener for the specified destination 2 Send a message to
- * the destination 3 Verify message received by listener
- */
- public void topicSendRecvMessageListenerTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- TestUtil.logMsg("Setup JmsTool for COMMON TOPIC");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- toolForProducer = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- logMsg("Initialize variables after JmsTool setup");
- producer = toolForProducer.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- // Creates a new consumer on the specified destination that
- // will deliver messages to the specified MessageListener.
- TestUtil.logMsg("Create message listener MyMessageListener");
- MyMessageListener listener = new MyMessageListener();
- TestUtil.logMsg(
- "Set message listener MyMessageListener on this MessageConsumer");
- consumer.setMessageListener(listener);
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- // TextMessage expTextMessage = session.createTextMessage(message);
- TextMessage expTextMessage = new TextMessageTestImpl();
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setText(message);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicSendRecvMessageListenerTest");
- TestUtil.logMsg("Calling MessageProducer.send(Message)");
- producer.send(expTextMessage);
-
- TestUtil.logMsg("Poll listener waiting for TestMessage to arrive");
- TextMessage actTextMessage = null;
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage (actTextMessage=NULL)");
- }
-
- TestUtil.logMsg("Check value of message returned");
- if (!actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logErr("Received [" + actTextMessage.getText() + "] expected ["
- + expTextMessage.getText() + "]");
- pass = false;
- }
-
- TestUtil.logMsg(
- "Retreive MessageListener by calling MessageConsumer.getMessageListener()");
- MessageListener messageListener = consumer.getMessageListener();
- if (messageListener == null) {
- TestUtil.logErr("getMessageListener() returned NULL");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("topicSendRecvMessageListenerTest", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicSendRecvMessageListenerTest failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageconsumertests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageconsumertests/ClientIT.java
new file mode 100644
index 0000000000..b7be3fe5d9
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageconsumertests/ClientIT.java
@@ -0,0 +1,360 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.appclient.messageconsumertests;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.common.TextMessageTestImpl;
+
+import jakarta.jms.Connection;
+import jakarta.jms.Destination;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageListener;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.appclient.messageconsumertests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null;
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool toolForProducer = null;
+
+ // JMS objects
+ transient MessageProducer producer = null;
+
+ transient MessageConsumer consumer = null;
+
+ transient Connection connection = null;
+
+ transient Session session = null;
+
+ transient Destination destination = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ boolean queueTest = false;
+
+ /* Utility methods for tests */
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't get expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Closing default Connection");
+ tool.getDefaultConnection().close();
+ if (queueTest) {
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ tool.flushDestination();
+ }
+ tool.closeAllResources();
+
+ if (toolForProducer != null) {
+ toolForProducer.getDefaultConnection().close();
+ if (queueTest) {
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ toolForProducer.flushDestination();
+ }
+ toolForProducer.closeAllResources();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: queueSendRecvMessageListenerTest
+ *
+ * @assertion_ids: JMS:JAVADOC:317; JMS:JAVADOC:328; JMS:JAVADOC:330;
+ * JMS:SPEC:264.4; JMS:SPEC:264; JMS:SPEC:137;
+ *
+ * @test_Strategy: Creates a new consumer on the specified destination that will
+ * deliver messages to the specified MessageListener. Tests the following API
+ * method:
+ *
+ * MessageProducer.send(Message)
+ * MessageConsumer.setMessageListener(MessageListener)
+ * MessageConsumer.getMessageListener()
+ *
+ * 1 Setup MessageListener for the specified destination 2 Send a message to the
+ * destination 3 Verify message received by listener
+ */
+ @Test
+ public void queueSendRecvMessageListenerTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON QUEUE");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ toolForProducer = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ logger.log(Logger.Level.INFO, "Initialize variables after JmsTool setup");
+ producer = toolForProducer.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ // Creates a new consumer on the specified destination that
+ // will deliver messages to the specified MessageListener.
+ logger.log(Logger.Level.INFO, "Create message listener MyMessageListener");
+ MyMessageListener listener = new MyMessageListener();
+ logger.log(Logger.Level.INFO, "Set message listener MyMessageListener on this MessageConsumer");
+ consumer.setMessageListener(listener);
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ // TextMessage expTextMessage = session.createTextMessage(message);
+ TextMessage expTextMessage = new TextMessageTestImpl();
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setText(message);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueSendRecvMessageListenerTest");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.send(Message)");
+ producer.send(expTextMessage);
+
+ logger.log(Logger.Level.INFO, "Poll listener waiting for TestMessage to arrive");
+ TextMessage actTextMessage = null;
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage (actTextMessage=NULL)");
+ }
+
+ logger.log(Logger.Level.INFO, "Check value of message returned");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + actTextMessage.getText() + "] expected [" + expTextMessage.getText() + "]");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO, "Retreive MessageListener by calling MessageConsumer.getMessageListener()");
+ MessageListener messageListener = consumer.getMessageListener();
+ if (messageListener == null) {
+ logger.log(Logger.Level.ERROR, "getMessageListener() returned NULL");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueSendRecvMessageListenerTest", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueSendRecvMessageListenerTest failed");
+ }
+ }
+
+ /*
+ * @testName: topicSendRecvMessageListenerTest
+ *
+ * @assertion_ids: JMS:JAVADOC:317; JMS:JAVADOC:328; JMS:JAVADOC:330;
+ * JMS:SPEC:264.4; JMS:SPEC:264;
+ *
+ * @test_Strategy: Creates a new consumer on the specified destination that will
+ * deliver messages to the specified MessageListener. Tests the following API
+ * method:
+ *
+ * MessageProducer.send(Message)
+ * MessageConsumer.setMessageListener(MessageListener)
+ * MessageConsumer.getMessageListener()
+ *
+ * 1 Setup MessageListener for the specified destination 2 Send a message to the
+ * destination 3 Verify message received by listener
+ */
+ @Test
+ public void topicSendRecvMessageListenerTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON TOPIC");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ toolForProducer = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ logger.log(Logger.Level.INFO, "Initialize variables after JmsTool setup");
+ producer = toolForProducer.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ // Creates a new consumer on the specified destination that
+ // will deliver messages to the specified MessageListener.
+ logger.log(Logger.Level.INFO, "Create message listener MyMessageListener");
+ MyMessageListener listener = new MyMessageListener();
+ logger.log(Logger.Level.INFO, "Set message listener MyMessageListener on this MessageConsumer");
+ consumer.setMessageListener(listener);
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ // TextMessage expTextMessage = session.createTextMessage(message);
+ TextMessage expTextMessage = new TextMessageTestImpl();
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setText(message);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicSendRecvMessageListenerTest");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.send(Message)");
+ producer.send(expTextMessage);
+
+ logger.log(Logger.Level.INFO, "Poll listener waiting for TestMessage to arrive");
+ TextMessage actTextMessage = null;
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage (actTextMessage=NULL)");
+ }
+
+ logger.log(Logger.Level.INFO, "Check value of message returned");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + actTextMessage.getText() + "] expected [" + expTextMessage.getText() + "]");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO, "Retreive MessageListener by calling MessageConsumer.getMessageListener()");
+ MessageListener messageListener = consumer.getMessageListener();
+ if (messageListener == null) {
+ logger.log(Logger.Level.ERROR, "getMessageListener() returned NULL");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicSendRecvMessageListenerTest", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicSendRecvMessageListenerTest failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageconsumertests/MyMessageListener.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageconsumertests/MyMessageListener.java
index a8c45f0a51..9d37b1632b 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageconsumertests/MyMessageListener.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageconsumertests/MyMessageListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,56 +19,58 @@
*/
package com.sun.ts.tests.jms.core20.appclient.messageconsumertests;
-import com.sun.ts.lib.util.TestUtil;
+import java.lang.System.Logger;
import jakarta.jms.Message;
import jakarta.jms.MessageListener;
public class MyMessageListener implements MessageListener {
- private String name = null;
+ private String name = null;
- private Message message = null;
+ private Message message = null;
- boolean complete = false;
+ boolean complete = false;
- public MyMessageListener() {
- this("MyMessageListener");
- }
+ private static final Logger logger = (Logger) System.getLogger(MyMessageListener.class.getName());
- public MyMessageListener(String name) {
- this.name = name;
- }
+ public MyMessageListener() {
+ this("MyMessageListener");
+ }
- // getters/setters
- public String getName() {
- return name;
- }
+ public MyMessageListener(String name) {
+ this.name = name;
+ }
- public void setName(String name) {
- this.name = name;
- }
+ // getters/setters
+ public String getName() {
+ return name;
+ }
- public Message getMessage() {
- return message;
- }
+ public void setName(String name) {
+ this.name = name;
+ }
- public void setMessage(Message message) {
- this.message = message;
- }
+ public Message getMessage() {
+ return message;
+ }
- public boolean isComplete() {
- return complete;
- }
+ public void setMessage(Message message) {
+ this.message = message;
+ }
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
+ public boolean isComplete() {
+ return complete;
+ }
- public void onMessage(Message message) {
- TestUtil.logMsg("Got Message: " + message);
- this.message = message;
- complete = true;
- }
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
+
+ public void onMessage(Message message) {
+ logger.log(Logger.Level.INFO, "Got Message: " + message);
+ this.message = message;
+ complete = true;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageproducertests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageproducertests/Client.java
deleted file mode 100644
index c78acbf027..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageproducertests/Client.java
+++ /dev/null
@@ -1,2646 +0,0 @@
-/*
- * Copyright (c) 2015, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.appclient.messageproducertests;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.InvalidTextMessageTestImpl;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.Connection;
-import jakarta.jms.DeliveryMode;
-import jakarta.jms.Destination;
-import jakarta.jms.InvalidDestinationException;
-import jakarta.jms.JMSException;
-import jakarta.jms.Message;
-import jakarta.jms.MessageConsumer;
-import jakarta.jms.MessageFormatException;
-import jakarta.jms.MessageProducer;
-import jakarta.jms.Queue;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.messageproducertests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool toolForProducer = null;
-
- // JMS objects
- transient MessageProducer producer = null;
-
- transient MessageConsumer consumer = null;
-
- transient Connection connection = null;
-
- transient Session session = null;
-
- transient Destination destination = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- boolean queueTest = false;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * Checks passed flag for negative tests and throws exception back to caller
- * which passes ot to harness.
- *
- * @param boolean Pass/Fail flag
- */
- private void checkExceptionPass(boolean passed) throws Exception {
- if (passed == false) {
- TestUtil.logMsg("Didn't get expected exception");
- throw new Exception("Didn't get expected exception");
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Closing default Connection");
- tool.getDefaultConnection().close();
- if (queueTest) {
- TestUtil.logMsg("Flush any messages left on Queue");
- tool.flushDestination();
- }
- tool.closeAllResources();
-
- if (toolForProducer != null) {
- toolForProducer.getDefaultConnection().close();
- if (queueTest) {
- TestUtil.logMsg("Flush any messages left on Queue");
- toolForProducer.flushDestination();
- }
- toolForProducer.closeAllResources();
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * @testName: queueSendRecvCompletionListenerTest1
- *
- * @assertion_ids: JMS:JAVADOC:898;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Destination, Message, CompletionListener)
- */
- public void queueSendRecvCompletionListenerTest1() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueSendRecvCompletionListenerTest1");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg("Calling send(Destination,Message,CompletionListener)");
- producer.send(destination, expTextMessage, listener);
-
- TestUtil.logMsg("Poll listener waiting for TestMessage to arrive");
- TextMessage actTextMessage = null;
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("queueSendRecvCompletionListenerTest1", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueSendRecvCompletionListenerTest1 failed");
- }
- }
-
- /*
- * @testName: queueSendRecvCompletionListenerTest2
- *
- * @assertion_ids: JMS:JAVADOC:903;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Destination, Message, int, int, long,
- * CompletionListener)
- */
- public void queueSendRecvCompletionListenerTest2() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueSendRecvCompletionListenerTest2");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg(
- "Calling send(Destination,Message,int,int,long,CompletionListener)");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, listener);
-
- TestUtil.logMsg("Poll listener waiting for TestMessage to arrive");
- TextMessage actTextMessage = null;
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Check the values in TextMessage, deliverymode, priority, time to live");
- if (!actTextMessage.getText().equals(expTextMessage.getText())
- || actTextMessage.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
- || actTextMessage.getJMSPriority() != Message.DEFAULT_PRIORITY
- || actTextMessage.getJMSExpiration() != 0L) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- TestUtil.logErr("DeliveryMode=" + actTextMessage.getJMSDeliveryMode()
- + ", expected " + expTextMessage.getJMSDeliveryMode());
- TestUtil.logErr("Priority=" + actTextMessage.getJMSPriority()
- + ", expected " + expTextMessage.getJMSPriority());
- TestUtil.logErr("TimeToLive=" + actTextMessage.getJMSExpiration()
- + ", expected " + expTextMessage.getJMSExpiration());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("queueSendRecvCompletionListenerTest2", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueSendRecvCompletionListenerTest2 failed");
- }
- }
-
- /*
- * @testName: queueSendRecvCompletionListenerTest3
- *
- * @assertion_ids: JMS:JAVADOC:888;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Message, CompletionListener)
- */
- public void queueSendRecvCompletionListenerTest3() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueSendRecvCompletionListenerTest3");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg("Calling send(Message,CompletionListener)");
- producer.send(expTextMessage, listener);
-
- TestUtil.logMsg("Poll listener waiting for TestMessage to arrive");
- TextMessage actTextMessage = null;
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("queueSendRecvCompletionListenerTest3", e);
- }
-
- if (!pass) {
- throw new Exception("queueSendRecvCompletionListenerTest3 failed");
- }
- }
-
- /*
- * @testName: queueSendRecvCompletionListenerTest4
- *
- * @assertion_ids: JMS:JAVADOC:893;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Message, int, int, long, CompletionListener)
- */
- public void queueSendRecvCompletionListenerTest4() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueSendRecvCompletionListeneTest4");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg("Calling send(Message,int,int,long,CompletionListener)");
- producer.send(expTextMessage, DeliveryMode.PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, listener);
-
- TestUtil.logMsg("Poll listener waiting for TestMessage to arrive");
- TextMessage actTextMessage = null;
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Check the values in TextMessage, deliverymode, priority, time to live");
- if (!actTextMessage.getText().equals(expTextMessage.getText())
- || actTextMessage.getJMSDeliveryMode() != DeliveryMode.PERSISTENT
- || actTextMessage.getJMSPriority() != Message.DEFAULT_PRIORITY
- || actTextMessage.getJMSExpiration() != 0L) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- TestUtil.logErr("DeliveryMode=" + actTextMessage.getJMSDeliveryMode()
- + ", expected " + expTextMessage.getJMSDeliveryMode());
- TestUtil.logErr("Priority=" + actTextMessage.getJMSPriority()
- + ", expected " + expTextMessage.getJMSPriority());
- TestUtil.logErr("TimeToLive=" + actTextMessage.getJMSExpiration()
- + ", expected " + expTextMessage.getJMSExpiration());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("queueSendRecvCompletionListenerTest4", e);
- }
-
- if (!pass) {
- throw new Exception("queueSendRecvCompletionListenerTest4 failed");
- }
- }
-
- /*
- * @testName: queueJMSExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:904;
- *
- * @test_Strategy: Test for JMSException from MessageProducer API's.
- */
- public void queueJMSExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- TestUtil.logMsg("Setup JmsTool for COMMON QUEUE");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueJMSExceptionTests");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- try {
- TestUtil.logMsg("Try and set an invalid mode of -1 on send");
- producer.send(destination, expTextMessage, -1, Message.DEFAULT_PRIORITY,
- 0L, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof JMSException) {
- TestUtil.logMsg("Exception is expected JMSException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected JMSException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and set an invalid priority of -1 on send");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- -1, 0L, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof JMSException) {
- TestUtil.logMsg("Exception is expected JMSException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected JMSException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("queueJMSExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("queueJMSExceptionTests failed");
- }
- }
-
- /*
- * @testName: queueInvalidDestinationExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:891; JMS:JAVADOC:896; JMS:JAVADOC:901;
- * JMS:JAVADOC:906;
- *
- * @test_Strategy: Test for InvalidDestinationException from MessageProducer
- * API's.
- */
- public void queueInvalidDestinationExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- TestUtil.logMsg("Setup JmsTool for COMMON QUEUE");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- toolForProducer = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = toolForProducer.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = null;
- connection.start();
- queueTest = true;
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueInvalidDestinationExceptionTests");
-
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(destination, expTextMessage, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof InvalidDestinationException) {
- TestUtil
- .logMsg("Exception is expected InvalidDestinationException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected InvalidDestinationException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Caught expected InvalidDestinationException");
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidDestinationException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof InvalidDestinationException) {
- TestUtil
- .logMsg("Exception is expected InvalidDestinationException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected InvalidDestinationException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Caught expected InvalidDestinationException");
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidDestinationException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("queueInvalidDestinationExceptionTests", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueInvalidDestinationExceptionTests failed");
- }
- }
-
- /*
- * @testName: queueUnsupportedOperationExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:892; JMS:JAVADOC:897; JMS:JAVADOC:902;
- * JMS:JAVADOC:1323;
- *
- * @test_Strategy: Test for UnsupportedOperationException from MessageProducer
- * API's.
- */
- public void queueUnsupportedOperationExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- TestUtil.logMsg("Setup JmsTool for COMMON QUEUE");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueUnsupportedOperationExceptionTests");
-
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(destination, expTextMessage, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof UnsupportedOperationException) {
- TestUtil
- .logMsg("Exception is expected UnsupportedOperationException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected UnsupportedOperationException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected UnsupportedOperationException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof UnsupportedOperationException) {
- TestUtil
- .logMsg("Exception is expected UnsupportedOperationException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected UnsupportedOperationException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected UnsupportedOperationException, received " + e);
- pass = false;
- }
-
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
-
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(expTextMessage, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof UnsupportedOperationException) {
- TestUtil
- .logMsg("Exception is expected UnsupportedOperationException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected UnsupportedOperationException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected UnsupportedOperationException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof UnsupportedOperationException) {
- TestUtil
- .logMsg("Exception is expected UnsupportedOperationException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected UnsupportedOperationException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected UnsupportedOperationException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("queueUnsupportedOperationExceptionTests", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueUnsupportedOperationExceptionTests failed");
- }
- }
-
- /*
- * @testName: queueIllegalArgumentExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1319; JMS:JAVADOC:1320; JMS:JAVADOC:1321;
- * JMS:JAVADOC:1322;
- *
- * @test_Strategy: Test for IllegalArgumentException from MessageProducer
- * API's.
- */
- public void queueIllegalArgumentExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- TestUtil.logMsg("Setup JmsTool for COMMON QUEUE");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueIllegalArgumentExceptionTests");
-
- try {
- TestUtil.logMsg("Send message with null CompletionListener");
- producer.send(destination, expTextMessage, null);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof IllegalArgumentException) {
- TestUtil.logMsg("Exception is expected IllegalArgumentException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected IllegalArgumentException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalArgumentException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Send message with null CompletionListener");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, null);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof IllegalArgumentException) {
- TestUtil.logMsg("Exception is expected IllegalArgumentException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected IllegalArgumentException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalArgumentException, received " + e);
- pass = false;
- }
-
- producer.close();
- producer = tool.getDefaultSession().createProducer(destination);
-
- try {
- TestUtil.logMsg("Send message with null CompletionListener");
- producer.send(expTextMessage, null);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof IllegalArgumentException) {
- TestUtil.logMsg("Exception is expected IllegalArgumentException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected IllegalArgumentException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalArgumentException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Send message with null CompletionListener");
- producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, null);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof IllegalArgumentException) {
- TestUtil.logMsg("Exception is expected IllegalArgumentException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected IllegalArgumentException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalArgumentException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("queueIllegalArgumentExceptionTests", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueIllegalArgumentExceptionTests failed");
- }
- }
-
- /*
- * @testName: queueMessageFormatExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:890; JMS:JAVADOC:895; JMS:JAVADOC:900;
- * JMS:JAVADOC:905;
- *
- * @test_Strategy: Test MessageFormatException conditions from API methods
- * with CompletionListener.
- *
- * MessageProducer.send(Message, CompletionListener)
- * MessageProducer.send(Message, int, int, long, CompletionListener)
- * MessageProducer.send(Destination, Message, CompletionListener)
- * MessageProducer.send(Destination, Message, int, int, long,
- * CompletionListener)
- *
- * Tests the following exception conditions:
- *
- * MessageFormatException
- */
- public void queueMessageFormatExceptionTests() throws Exception {
- boolean pass = true;
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- TextMessage invalidTMsg = new InvalidTextMessageTestImpl();
- invalidTMsg.setText("hello");
-
- // Create CompletionListener
- MyCompletionListener listener = new MyCompletionListener();
-
- try {
- TestUtil.logMsg(
- "Calling MessageProducer.send(Message, CompletionListener) -> expect MessageFormatException");
- producer.send(invalidTMsg, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof MessageFormatException) {
- TestUtil.logMsg("Exception is expected MessageFormatException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected MessageFormatException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Got MessageFormatException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected MessageFormatException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Calling MessageProducer.send(Message, int, int, long, CompletionListener) -> expect MessageFormatException");
- producer.send(invalidTMsg, Message.DEFAULT_DELIVERY_MODE,
- Message.DEFAULT_PRIORITY - 1, Message.DEFAULT_TIME_TO_LIVE,
- listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof MessageFormatException) {
- TestUtil.logMsg("Exception is expected MessageFormatException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected MessageFormatException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Got MessageFormatException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected MessageFormatException, received " + e);
- pass = false;
- }
-
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
-
- try {
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, CompletionListener) -> expect MessageFormatException");
- producer.send(destination, invalidTMsg, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof MessageFormatException) {
- TestUtil.logMsg("Exception is expected MessageFormatException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected MessageFormatException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Got MessageFormatException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected MessageFormatException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, int, int, long, CompletionListener) -> expect MessageFormatException");
- producer.send(destination, invalidTMsg, Message.DEFAULT_DELIVERY_MODE,
- Message.DEFAULT_PRIORITY - 1, Message.DEFAULT_TIME_TO_LIVE,
- listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 30; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof MessageFormatException) {
- TestUtil.logMsg("Exception is expected MessageFormatException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected MessageFormatException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Got MessageFormatException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected MessageFormatException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("queueMessageFormatExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("queueMessageFormatExceptionTests failed");
- }
- }
-
- /*
- * @testName: queueIllegalStateExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1355;
- *
- * @test_Strategy: Test IllegalStateException conditions. Calling
- * MessageProducer.close() in CompletionListener MUST throw
- * IllegalStateException.
- */
- public void queueIllegalStateExceptionTests() throws Exception {
- boolean pass = true;
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- // Create CompetionListener
- MyCompletionListener listener = new MyCompletionListener(producer);
-
- TestUtil.logMsg(
- "Testing MessageProducer.close() from CompletionListener (expect IllegalStateException)");
- try {
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session
- .createTextMessage("Call close method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueIllegalStateExceptionTests");
-
- TestUtil.logMsg(
- "Send async message specifying CompletionListener to recieve async message");
- TestUtil.logMsg(
- "CompletionListener will call MessageProducer.close() (expect IllegalStateException)");
- producer.send(destination, expTextMessage, listener);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until we receive exception");
- for (int i = 0; i < 30; i++) {
- if (listener.isComplete()) {
- listener.setComplete(false);
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil.logMsg(
- "Check if we got correct exception from MessageProducer.close()");
- if (listener.gotException()) {
- if (listener.gotCorrectException()) {
- TestUtil.logMsg("Got correct IllegalStateException");
- } else {
- TestUtil.logErr("Expected IllegalStateException, received: "
- + listener.getException());
- pass = false;
- }
- } else {
- TestUtil.logErr("Expected IllegalStateException, got no exception");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalStateException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("queueIllegalStateExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("queueIllegalStateExceptionTests failed");
- }
- }
-
- /*
- * @testName: topicSendRecvCompletionListenerTest1
- *
- * @assertion_ids: JMS:JAVADOC:898;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Destination, Message, CompletionListener)
- */
- public void topicSendRecvCompletionListenerTest1() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Topic) null);
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicSendRecvCompletionListenerTest1");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg("Calling send(Destination,Message,CompletionListener)");
- producer.send(destination, expTextMessage, listener);
-
- TestUtil.logMsg("Poll listener waiting for TestMessage to arrive");
- TextMessage actTextMessage = null;
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("topicSendRecvCompletionListenerTest1", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicSendRecvCompletionListenerTest1 failed");
- }
- }
-
- /*
- * @testName: topicSendRecvCompletionListenerTest2
- *
- * @assertion_ids: JMS:JAVADOC:903;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Destination, Message, int, int, long,
- * CompletionListener)
- */
- public void topicSendRecvCompletionListenerTest2() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Topic) null);
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicSendRecvCompletionListenerTest2");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg(
- "Calling send(Destination,Message,int,int,long,CompletionListener)");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, listener);
-
- TestUtil.logMsg("Poll listener waiting for TestMessage to arrive");
- TextMessage actTextMessage = null;
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Check the values in TextMessage, deliverymode, priority, time to live");
- if (!actTextMessage.getText().equals(expTextMessage.getText())
- || actTextMessage.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
- || actTextMessage.getJMSPriority() != Message.DEFAULT_PRIORITY
- || actTextMessage.getJMSExpiration() != 0L) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- TestUtil.logErr("DeliveryMode=" + actTextMessage.getJMSDeliveryMode()
- + ", expected " + expTextMessage.getJMSDeliveryMode());
- TestUtil.logErr("Priority=" + actTextMessage.getJMSPriority()
- + ", expected " + expTextMessage.getJMSPriority());
- TestUtil.logErr("TimeToLive=" + actTextMessage.getJMSExpiration()
- + ", expected " + expTextMessage.getJMSExpiration());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("topicSendRecvCompletionListenerTest2", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicSendRecvCompletionListenerTest2 failed");
- }
- }
-
- /*
- * @testName: topicSendRecvCompletionListenerTest3
- *
- * @assertion_ids: JMS:JAVADOC:888;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Message, CompletionListener)
- */
- public void topicSendRecvCompletionListenerTest3() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicSendRecvCompletionListenerTest3");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg("Calling send(Message,CompletionListener)");
- producer.send(expTextMessage, listener);
-
- TestUtil.logMsg("Poll listener waiting for TestMessage to arrive");
- TextMessage actTextMessage = null;
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("topicSendRecvCompletionListenerTest3", e);
- }
-
- if (!pass) {
- throw new Exception("topicSendRecvCompletionListenerTest3 failed");
- }
- }
-
- /*
- * @testName: topicSendRecvCompletionListenerTest4
- *
- * @assertion_ids: JMS:JAVADOC:893;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Message, int, int, long, CompletionListener)
- */
- public void topicSendRecvCompletionListenerTest4() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicSendRecvCompletionListeneTest4");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg("Calling send(Message,int,int,long,CompletionListener)");
- producer.send(expTextMessage, DeliveryMode.PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, listener);
-
- TestUtil.logMsg("Poll listener waiting for TestMessage to arrive");
- TextMessage actTextMessage = null;
- for (int i = 0; !listener.isComplete() && i < 60; i++) {
- TestUtil.logMsg("Loop " + i
- + ": sleep 2 seconds waiting for messages to arrive at listener");
- TestUtil.sleepSec(2);
- }
- if (listener.isComplete())
- actTextMessage = (TextMessage) listener.getMessage();
-
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Check the values in TextMessage, deliverymode, priority, time to live");
- if (!actTextMessage.getText().equals(expTextMessage.getText())
- || actTextMessage.getJMSDeliveryMode() != DeliveryMode.PERSISTENT
- || actTextMessage.getJMSPriority() != Message.DEFAULT_PRIORITY
- || actTextMessage.getJMSExpiration() != 0L) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- TestUtil.logErr("DeliveryMode=" + actTextMessage.getJMSDeliveryMode()
- + ", expected " + expTextMessage.getJMSDeliveryMode());
- TestUtil.logErr("Priority=" + actTextMessage.getJMSPriority()
- + ", expected " + expTextMessage.getJMSPriority());
- TestUtil.logErr("TimeToLive=" + actTextMessage.getJMSExpiration()
- + ", expected " + expTextMessage.getJMSExpiration());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("topicSendRecvCompletionListenerTest4", e);
- }
-
- if (!pass) {
- throw new Exception("topicSendRecvCompletionListenerTest4 failed");
- }
- }
-
- /*
- * @testName: topicJMSExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:904;
- *
- * @test_Strategy: Test for JMSException from MessageProducer API's.
- */
- public void topicJMSExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- TestUtil.logMsg("Setup JmsTool for COMMON TOPIC");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Topic) null);
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicJMSExceptionTests");
-
- // Create CompletionListener for Message to be sent
- MyCompletionListener listener = new MyCompletionListener();
-
- try {
- TestUtil.logMsg("Try and set an invalid mode of -1 on send");
- producer.send(destination, expTextMessage, -1, Message.DEFAULT_PRIORITY,
- 0L, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 10; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof JMSException) {
- TestUtil.logMsg("Exception is expected JMSException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected JMSException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and set an invalid priority of -1 on send");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- -1, 0L, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 10; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof JMSException) {
- TestUtil.logMsg("Exception is expected JMSException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected JMSException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("topicJMSExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("topicJMSExceptionTests failed");
- }
- }
-
- /*
- * @testName: topicInvalidDestinationExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:891; JMS:JAVADOC:896; JMS:JAVADOC:901;
- * JMS:JAVADOC:906;
- *
- * @test_Strategy: Test for InvalidDestinationException from MessageProducer
- * API's.
- */
- public void topicInvalidDestinationExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- TestUtil.logMsg("Setup JmsTool for COMMON TOPIC");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- toolForProducer = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = toolForProducer.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = null;
- connection.start();
- queueTest = false;
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueInvalidDestinationExceptionTests");
-
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(destination, expTextMessage, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 10; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof InvalidDestinationException) {
- TestUtil
- .logMsg("Exception is expected InvalidDestinationException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected InvalidDestinationException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Caught expected InvalidDestinationException");
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidDestinationException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 10; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof InvalidDestinationException) {
- TestUtil
- .logMsg("Exception is expected InvalidDestinationException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected InvalidDestinationException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Caught expected InvalidDestinationException");
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidDestinationException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("queueInvalidDestinationExceptionTests", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicInvalidDestinationExceptionTests failed");
- }
- }
-
- /*
- * @testName: topicUnsupportedOperationExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:892; JMS:JAVADOC:897; JMS:JAVADOC:902;
- * JMS:JAVADOC:1323;
- *
- * @test_Strategy: Test for UnsupportedOperationException from MessageProducer
- * API's.
- */
- public void topicUnsupportedOperationExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- TestUtil.logMsg("Setup JmsTool for COMMON TOPIC");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicUnsupportedOperationExceptionTests");
-
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(destination, expTextMessage, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 10; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof UnsupportedOperationException) {
- TestUtil
- .logMsg("Exception is expected UnsupportedOperationException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected UnsupportedOperationException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected UnsupportedOperationException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 10; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof UnsupportedOperationException) {
- TestUtil
- .logMsg("Exception is expected UnsupportedOperationException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected UnsupportedOperationException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected UnsupportedOperationException, received " + e);
- pass = false;
- }
-
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Topic) null);
-
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(expTextMessage, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 10; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof UnsupportedOperationException) {
- TestUtil
- .logMsg("Exception is expected UnsupportedOperationException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected UnsupportedOperationException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected UnsupportedOperationException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 10; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof UnsupportedOperationException) {
- TestUtil
- .logMsg("Exception is expected UnsupportedOperationException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected UnsupportedOperationException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected UnsupportedOperationException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("queueUnsupportedOperationExceptionTests", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicUnsupportedOperationExceptionTests failed");
- }
- }
-
- /*
- * @testName: topicIllegalArgumentExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1319; JMS:JAVADOC:1320; JMS:JAVADOC:1321;
- * JMS:JAVADOC:1322;
- *
- * @test_Strategy: Test for IllegalArgumentException from MessageProducer
- * API's.
- */
- public void topicIllegalArgumentExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- TestUtil.logMsg("Setup JmsTool for COMMON TOPIC");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Topic) null);
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
- MyCompletionListener listener = new MyCompletionListener();
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicIllegalArgumentExceptionTests");
-
- try {
- TestUtil.logMsg("Send message with null CompletionListener");
- producer.send(destination, expTextMessage, null);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 10; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof IllegalArgumentException) {
- TestUtil.logMsg("Exception is expected IllegalArgumentException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected IllegalArgumentException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalArgumentException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Send message with null CompletionListener");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, null);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 10; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof IllegalArgumentException) {
- TestUtil.logMsg("Exception is expected IllegalArgumentException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected IllegalArgumentException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalArgumentException, received " + e);
- pass = false;
- }
-
- producer.close();
- producer = tool.getDefaultSession().createProducer(destination);
-
- try {
- TestUtil.logMsg("Send message with null CompletionListener");
- producer.send(expTextMessage, null);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 10; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof IllegalArgumentException) {
- TestUtil.logMsg("Exception is expected IllegalArgumentException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected IllegalArgumentException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalArgumentException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Send message with null CompletionListener");
- producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L, null);
- TestUtil.logMsg("Poll listener until we receive exception");
- Exception exception = null;
- for (int i = 0; i < 10; i++) {
- TestUtil.sleepSec(2);
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- TestUtil.logMsg("Received Exception after polling loop " + (i + 1));
- break;
- }
- TestUtil.logMsg("Completed polling loop " + i);
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof IllegalArgumentException) {
- TestUtil.logMsg("Exception is expected IllegalArgumentException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected IllegalArgumentException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalArgumentException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("queueIllegalArgumentExceptionTests", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicIllegalArgumentExceptionTests failed");
- }
- }
-
- /*
- * @testName: topicMessageFormatExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:890; JMS:JAVADOC:895; JMS:JAVADOC:900;
- * JMS:JAVADOC:905;
- *
- * @test_Strategy: Test MessageFormatException conditions from API methods
- * with CompletionListener.
- *
- * MessageProducer.send(Message, CompletionListener)
- * MessageProducer.send(Message, int, int, long, CompletionListener)
- * MessageProducer.send(Destination, Message, CompletionListener)
- * MessageProducer.send(Destination, Message, int, int, long,
- * CompletionListener)
- *
- * Tests the following exception conditions:
- *
- * MessageFormatException
- */
- public void topicMessageFormatExceptionTests() throws Exception {
- boolean pass = true;
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- TextMessage invalidTMsg = new InvalidTextMessageTestImpl();
- invalidTMsg.setText("hello");
-
- // Create CompletionListener
- MyCompletionListener listener = new MyCompletionListener();
-
- try {
- TestUtil.logMsg(
- "Calling MessageProducer.send(Message, CompletionListener) -> expect MessageFormatException");
- producer.send(invalidTMsg, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- TestUtil.sleepSec(5);
- Exception exception = null;
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof MessageFormatException) {
- TestUtil.logMsg("Exception is expected MessageFormatException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected MessageFormatException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Got MessageFormatException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected MessageFormatException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Calling MessageProducer.send(Message, int, int, long, CompletionListener) -> expect MessageFormatException");
- producer.send(invalidTMsg, Message.DEFAULT_DELIVERY_MODE,
- Message.DEFAULT_PRIORITY - 1, Message.DEFAULT_TIME_TO_LIVE,
- listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- TestUtil.sleepSec(5);
- Exception exception = null;
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof MessageFormatException) {
- TestUtil.logMsg("Exception is expected MessageFormatException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected MessageFormatException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Got MessageFormatException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected MessageFormatException, received " + e);
- pass = false;
- }
-
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
-
- try {
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, CompletionListener) -> expect MessageFormatException");
- producer.send(destination, invalidTMsg, listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- TestUtil.sleepSec(5);
- Exception exception = null;
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof MessageFormatException) {
- TestUtil.logMsg("Exception is expected MessageFormatException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected MessageFormatException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Got MessageFormatException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected MessageFormatException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, int, int, long, CompletionListener) -> expect MessageFormatException");
- producer.send(destination, invalidTMsg, Message.DEFAULT_DELIVERY_MODE,
- Message.DEFAULT_PRIORITY - 1, Message.DEFAULT_TIME_TO_LIVE,
- listener);
- TestUtil.logMsg("Poll listener until we receive exception");
- TestUtil.sleepSec(5);
- Exception exception = null;
- if (listener.isComplete()) {
- listener.setComplete(false);
- exception = listener.getException();
- }
-
- if (exception == null) {
- pass = false;
- TestUtil.logErr("Didn't throw and exception");
- } else {
- TestUtil.logMsg("Check the value in Exception");
- if (exception instanceof MessageFormatException) {
- TestUtil.logMsg("Exception is expected MessageFormatException");
- } else {
- TestUtil.logErr(
- "Exception is incorrect expected MessageFormatException, received "
- + exception.getCause());
- pass = false;
- }
- }
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Got MessageFormatException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected MessageFormatException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("topicMessageFormatExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("topicMessageFormatExceptionTests failed");
- }
- }
-
- /*
- * @testName: topicIllegalStateExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1355;
- *
- * @test_Strategy: Test IllegalStateException conditions. Calling
- * MessageProducer.close() in CompletionListener MUST throw
- * IllegalStateException.
- */
- public void topicIllegalStateExceptionTests() throws Exception {
- boolean pass = true;
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Topic) null);
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- // Create CompetionListener
- MyCompletionListener listener = new MyCompletionListener(producer);
-
- TestUtil.logMsg(
- "Testing MessageProducer.close() from CompletionListener (expect IllegalStateException)");
- try {
- // Create TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session
- .createTextMessage("Call close method");
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicIllegalStateExceptionTests");
-
- TestUtil.logMsg(
- "Send async message specifying CompletionListener to recieve async message");
- TestUtil.logMsg(
- "CompletionListener will call MessageProducer.close() (expect IllegalStateException)");
- producer.send(destination, expTextMessage, listener);
- TextMessage actTextMessage = null;
- TestUtil.logMsg("Poll listener until we receive message or exception");
- for (int i = 0; i < 10; i++) {
- if (listener.isComplete()) {
- listener.setComplete(false);
- break;
- } else {
- TestUtil.sleepSec(2);
- }
- }
- TestUtil.logMsg(
- "Check if we got correct exception from MessageProducer.close()");
- if (listener.gotException()) {
- if (listener.gotCorrectException()) {
- TestUtil.logMsg("Got correct IllegalStateException");
- } else {
- TestUtil.logErr("Expected IllegalStateException, received: "
- + listener.getException());
- pass = false;
- }
- } else {
- TestUtil.logErr("Expected IllegalStateException, got no exception");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Expected IllegalStateException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("topicIllegalStateExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("topicIllegalStateExceptionTests failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageproducertests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageproducertests/ClientIT.java
new file mode 100644
index 0000000000..05fd5e5ec5
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageproducertests/ClientIT.java
@@ -0,0 +1,2588 @@
+/*
+ * Copyright (c) 2015, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.appclient.messageproducertests;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.InvalidTextMessageTestImpl;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.Connection;
+import jakarta.jms.DeliveryMode;
+import jakarta.jms.Destination;
+import jakarta.jms.InvalidDestinationException;
+import jakarta.jms.JMSException;
+import jakarta.jms.Message;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageFormatException;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Queue;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.messageproducertests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null;
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool toolForProducer = null;
+
+ // JMS objects
+ transient MessageProducer producer = null;
+
+ transient MessageConsumer consumer = null;
+
+ transient Connection connection = null;
+
+ transient Session session = null;
+
+ transient Destination destination = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ boolean queueTest = false;
+
+ /* Utility methods for tests */
+
+ /*
+ * Checks passed flag for negative tests and throws exception back to caller
+ * which passes ot to harness.
+ *
+ * @param boolean Pass/Fail flag
+ */
+ private void checkExceptionPass(boolean passed) throws Exception {
+ if (passed == false) {
+ logger.log(Logger.Level.INFO, "Didn't get expected exception");
+ throw new Exception("Didn't get expected exception");
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Closing default Connection");
+ tool.getDefaultConnection().close();
+ if (queueTest) {
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ tool.flushDestination();
+ }
+ tool.closeAllResources();
+
+ if (toolForProducer != null) {
+ toolForProducer.getDefaultConnection().close();
+ if (queueTest) {
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ toolForProducer.flushDestination();
+ }
+ toolForProducer.closeAllResources();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: queueSendRecvCompletionListenerTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:898;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Destination, Message, CompletionListener)
+ */
+ @Test
+ public void queueSendRecvCompletionListenerTest1() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueSendRecvCompletionListenerTest1");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Calling send(Destination,Message,CompletionListener)");
+ producer.send(destination, expTextMessage, listener);
+
+ logger.log(Logger.Level.INFO, "Poll listener waiting for TestMessage to arrive");
+ TextMessage actTextMessage = null;
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueSendRecvCompletionListenerTest1", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueSendRecvCompletionListenerTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: queueSendRecvCompletionListenerTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:903;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Destination, Message, int, int, long,
+ * CompletionListener)
+ */
+ @Test
+ public void queueSendRecvCompletionListenerTest2() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueSendRecvCompletionListenerTest2");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Calling send(Destination,Message,int,int,long,CompletionListener)");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L,
+ listener);
+
+ logger.log(Logger.Level.INFO, "Poll listener waiting for TestMessage to arrive");
+ TextMessage actTextMessage = null;
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage, deliverymode, priority, time to live");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())
+ || actTextMessage.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
+ || actTextMessage.getJMSPriority() != Message.DEFAULT_PRIORITY
+ || actTextMessage.getJMSExpiration() != 0L) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode=" + actTextMessage.getJMSDeliveryMode() + ", expected "
+ + expTextMessage.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority=" + actTextMessage.getJMSPriority() + ", expected "
+ + expTextMessage.getJMSPriority());
+ logger.log(Logger.Level.ERROR, "TimeToLive=" + actTextMessage.getJMSExpiration() + ", expected "
+ + expTextMessage.getJMSExpiration());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueSendRecvCompletionListenerTest2", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueSendRecvCompletionListenerTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: queueSendRecvCompletionListenerTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:888;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Message, CompletionListener)
+ */
+ @Test
+ public void queueSendRecvCompletionListenerTest3() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueSendRecvCompletionListenerTest3");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Calling send(Message,CompletionListener)");
+ producer.send(expTextMessage, listener);
+
+ logger.log(Logger.Level.INFO, "Poll listener waiting for TestMessage to arrive");
+ TextMessage actTextMessage = null;
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueSendRecvCompletionListenerTest3", e);
+ }
+
+ if (!pass) {
+ throw new Exception("queueSendRecvCompletionListenerTest3 failed");
+ }
+ }
+
+ /*
+ * @testName: queueSendRecvCompletionListenerTest4
+ *
+ * @assertion_ids: JMS:JAVADOC:893;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Message, int, int, long, CompletionListener)
+ */
+ @Test
+ public void queueSendRecvCompletionListenerTest4() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueSendRecvCompletionListeneTest4");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Calling send(Message,int,int,long,CompletionListener)");
+ producer.send(expTextMessage, DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, 0L, listener);
+
+ logger.log(Logger.Level.INFO, "Poll listener waiting for TestMessage to arrive");
+ TextMessage actTextMessage = null;
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage, deliverymode, priority, time to live");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())
+ || actTextMessage.getJMSDeliveryMode() != DeliveryMode.PERSISTENT
+ || actTextMessage.getJMSPriority() != Message.DEFAULT_PRIORITY
+ || actTextMessage.getJMSExpiration() != 0L) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode=" + actTextMessage.getJMSDeliveryMode() + ", expected "
+ + expTextMessage.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority=" + actTextMessage.getJMSPriority() + ", expected "
+ + expTextMessage.getJMSPriority());
+ logger.log(Logger.Level.ERROR, "TimeToLive=" + actTextMessage.getJMSExpiration() + ", expected "
+ + expTextMessage.getJMSExpiration());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueSendRecvCompletionListenerTest4", e);
+ }
+
+ if (!pass) {
+ throw new Exception("queueSendRecvCompletionListenerTest4 failed");
+ }
+ }
+
+ /*
+ * @testName: queueJMSExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:904;
+ *
+ * @test_Strategy: Test for JMSException from MessageProducer API's.
+ */
+ @Test
+ public void queueJMSExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON QUEUE");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueJMSExceptionTests");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ try {
+ logger.log(Logger.Level.INFO, "Try and set an invalid mode of -1 on send");
+ producer.send(destination, expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof JMSException) {
+ logger.log(Logger.Level.INFO, "Exception is expected JMSException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected JMSException, received " + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and set an invalid priority of -1 on send");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof JMSException) {
+ logger.log(Logger.Level.INFO, "Exception is expected JMSException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected JMSException, received " + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("queueJMSExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("queueJMSExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: queueInvalidDestinationExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:891; JMS:JAVADOC:896; JMS:JAVADOC:901;
+ * JMS:JAVADOC:906;
+ *
+ * @test_Strategy: Test for InvalidDestinationException from MessageProducer
+ * API's.
+ */
+ @Test
+ public void queueInvalidDestinationExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON QUEUE");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ toolForProducer = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = toolForProducer.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = null;
+ connection.start();
+ queueTest = true;
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueInvalidDestinationExceptionTests");
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(destination, expTextMessage, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof InvalidDestinationException) {
+ logger.log(Logger.Level.INFO, "Exception is expected InvalidDestinationException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected InvalidDestinationException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected InvalidDestinationException");
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L,
+ listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof InvalidDestinationException) {
+ logger.log(Logger.Level.INFO, "Exception is expected InvalidDestinationException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected InvalidDestinationException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected InvalidDestinationException");
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("queueInvalidDestinationExceptionTests", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueInvalidDestinationExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: queueUnsupportedOperationExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:892; JMS:JAVADOC:897; JMS:JAVADOC:902;
+ * JMS:JAVADOC:1323;
+ *
+ * @test_Strategy: Test for UnsupportedOperationException from MessageProducer
+ * API's.
+ */
+ @Test
+ public void queueUnsupportedOperationExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON QUEUE");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueUnsupportedOperationExceptionTests");
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(destination, expTextMessage, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof UnsupportedOperationException) {
+ logger.log(Logger.Level.INFO, "Exception is expected UnsupportedOperationException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected UnsupportedOperationException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L,
+ listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof UnsupportedOperationException) {
+ logger.log(Logger.Level.INFO, "Exception is expected UnsupportedOperationException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected UnsupportedOperationException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e);
+ pass = false;
+ }
+
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(expTextMessage, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof UnsupportedOperationException) {
+ logger.log(Logger.Level.INFO, "Exception is expected UnsupportedOperationException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected UnsupportedOperationException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof UnsupportedOperationException) {
+ logger.log(Logger.Level.INFO, "Exception is expected UnsupportedOperationException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected UnsupportedOperationException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("queueUnsupportedOperationExceptionTests", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueUnsupportedOperationExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: queueIllegalArgumentExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1319; JMS:JAVADOC:1320; JMS:JAVADOC:1321;
+ * JMS:JAVADOC:1322;
+ *
+ * @test_Strategy: Test for IllegalArgumentException from MessageProducer API's.
+ */
+ @Test
+ public void queueIllegalArgumentExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON QUEUE");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueIllegalArgumentExceptionTests");
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with null CompletionListener");
+ producer.send(destination, expTextMessage, null);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof IllegalArgumentException) {
+ logger.log(Logger.Level.INFO, "Exception is expected IllegalArgumentException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected IllegalArgumentException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalArgumentException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with null CompletionListener");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L,
+ null);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof IllegalArgumentException) {
+ logger.log(Logger.Level.INFO, "Exception is expected IllegalArgumentException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected IllegalArgumentException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalArgumentException, received " + e);
+ pass = false;
+ }
+
+ producer.close();
+ producer = tool.getDefaultSession().createProducer(destination);
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with null CompletionListener");
+ producer.send(expTextMessage, null);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof IllegalArgumentException) {
+ logger.log(Logger.Level.INFO, "Exception is expected IllegalArgumentException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected IllegalArgumentException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalArgumentException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with null CompletionListener");
+ producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L, null);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof IllegalArgumentException) {
+ logger.log(Logger.Level.INFO, "Exception is expected IllegalArgumentException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected IllegalArgumentException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalArgumentException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("queueIllegalArgumentExceptionTests", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueIllegalArgumentExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: queueMessageFormatExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:890; JMS:JAVADOC:895; JMS:JAVADOC:900;
+ * JMS:JAVADOC:905;
+ *
+ * @test_Strategy: Test MessageFormatException conditions from API methods with
+ * CompletionListener.
+ *
+ * MessageProducer.send(Message, CompletionListener)
+ * MessageProducer.send(Message, int, int, long, CompletionListener)
+ * MessageProducer.send(Destination, Message, CompletionListener)
+ * MessageProducer.send(Destination, Message, int, int, long,
+ * CompletionListener)
+ *
+ * Tests the following exception conditions:
+ *
+ * MessageFormatException
+ */
+ @Test
+ public void queueMessageFormatExceptionTests() throws Exception {
+ boolean pass = true;
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ TextMessage invalidTMsg = new InvalidTextMessageTestImpl();
+ invalidTMsg.setText("hello");
+
+ // Create CompletionListener
+ MyCompletionListener listener = new MyCompletionListener();
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Message, CompletionListener) -> expect MessageFormatException");
+ producer.send(invalidTMsg, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof MessageFormatException) {
+ logger.log(Logger.Level.INFO, "Exception is expected MessageFormatException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected MessageFormatException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Got MessageFormatException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Message, int, int, long, CompletionListener) -> expect MessageFormatException");
+ producer.send(invalidTMsg, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY - 1,
+ Message.DEFAULT_TIME_TO_LIVE, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof MessageFormatException) {
+ logger.log(Logger.Level.INFO, "Exception is expected MessageFormatException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected MessageFormatException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Got MessageFormatException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException, received " + e);
+ pass = false;
+ }
+
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Destination, Message, CompletionListener) -> expect MessageFormatException");
+ producer.send(destination, invalidTMsg, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof MessageFormatException) {
+ logger.log(Logger.Level.INFO, "Exception is expected MessageFormatException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected MessageFormatException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Got MessageFormatException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Destination, Message, int, int, long, CompletionListener) -> expect MessageFormatException");
+ producer.send(destination, invalidTMsg, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY - 1,
+ Message.DEFAULT_TIME_TO_LIVE, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 30; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof MessageFormatException) {
+ logger.log(Logger.Level.INFO, "Exception is expected MessageFormatException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected MessageFormatException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Got MessageFormatException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("queueMessageFormatExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("queueMessageFormatExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: queueIllegalStateExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1355;
+ *
+ * @test_Strategy: Test IllegalStateException conditions. Calling
+ * MessageProducer.close() in CompletionListener MUST throw
+ * IllegalStateException.
+ */
+ @Test
+ public void queueIllegalStateExceptionTests() throws Exception {
+ boolean pass = true;
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ // Create CompetionListener
+ MyCompletionListener listener = new MyCompletionListener(producer);
+
+ logger.log(Logger.Level.INFO,
+ "Testing MessageProducer.close() from CompletionListener (expect IllegalStateException)");
+ try {
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage("Call close method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueIllegalStateExceptionTests");
+
+ logger.log(Logger.Level.INFO,
+ "Send async message specifying CompletionListener to recieve async message");
+ logger.log(Logger.Level.INFO,
+ "CompletionListener will call MessageProducer.close() (expect IllegalStateException)");
+ producer.send(destination, expTextMessage, listener);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ for (int i = 0; i < 30; i++) {
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Check if we got correct exception from MessageProducer.close()");
+ if (listener.gotException()) {
+ if (listener.gotCorrectException()) {
+ logger.log(Logger.Level.INFO, "Got correct IllegalStateException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Expected IllegalStateException, received: " + listener.getException());
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, got no exception");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("queueIllegalStateExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("queueIllegalStateExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: topicSendRecvCompletionListenerTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:898;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Destination, Message, CompletionListener)
+ */
+ @Test
+ public void topicSendRecvCompletionListenerTest1() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Topic) null);
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicSendRecvCompletionListenerTest1");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Calling send(Destination,Message,CompletionListener)");
+ producer.send(destination, expTextMessage, listener);
+
+ logger.log(Logger.Level.INFO, "Poll listener waiting for TestMessage to arrive");
+ TextMessage actTextMessage = null;
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicSendRecvCompletionListenerTest1", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicSendRecvCompletionListenerTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: topicSendRecvCompletionListenerTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:903;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Destination, Message, int, int, long,
+ * CompletionListener)
+ */
+ @Test
+ public void topicSendRecvCompletionListenerTest2() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Topic) null);
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicSendRecvCompletionListenerTest2");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Calling send(Destination,Message,int,int,long,CompletionListener)");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L,
+ listener);
+
+ logger.log(Logger.Level.INFO, "Poll listener waiting for TestMessage to arrive");
+ TextMessage actTextMessage = null;
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage, deliverymode, priority, time to live");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())
+ || actTextMessage.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
+ || actTextMessage.getJMSPriority() != Message.DEFAULT_PRIORITY
+ || actTextMessage.getJMSExpiration() != 0L) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode=" + actTextMessage.getJMSDeliveryMode() + ", expected "
+ + expTextMessage.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority=" + actTextMessage.getJMSPriority() + ", expected "
+ + expTextMessage.getJMSPriority());
+ logger.log(Logger.Level.ERROR, "TimeToLive=" + actTextMessage.getJMSExpiration() + ", expected "
+ + expTextMessage.getJMSExpiration());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicSendRecvCompletionListenerTest2", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicSendRecvCompletionListenerTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: topicSendRecvCompletionListenerTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:888;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Message, CompletionListener)
+ */
+ @Test
+ public void topicSendRecvCompletionListenerTest3() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicSendRecvCompletionListenerTest3");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Calling send(Message,CompletionListener)");
+ producer.send(expTextMessage, listener);
+
+ logger.log(Logger.Level.INFO, "Poll listener waiting for TestMessage to arrive");
+ TextMessage actTextMessage = null;
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicSendRecvCompletionListenerTest3", e);
+ }
+
+ if (!pass) {
+ throw new Exception("topicSendRecvCompletionListenerTest3 failed");
+ }
+ }
+
+ /*
+ * @testName: topicSendRecvCompletionListenerTest4
+ *
+ * @assertion_ids: JMS:JAVADOC:893;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Message, int, int, long, CompletionListener)
+ */
+ @Test
+ public void topicSendRecvCompletionListenerTest4() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicSendRecvCompletionListeneTest4");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Calling send(Message,int,int,long,CompletionListener)");
+ producer.send(expTextMessage, DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, 0L, listener);
+
+ logger.log(Logger.Level.INFO, "Poll listener waiting for TestMessage to arrive");
+ TextMessage actTextMessage = null;
+ for (int i = 0; !listener.isComplete() && i < 60; i++) {
+ logger.log(Logger.Level.INFO,
+ "Loop " + i + ": sleep 2 seconds waiting for messages to arrive at listener");
+ TestUtil.sleepSec(2);
+ }
+ if (listener.isComplete())
+ actTextMessage = (TextMessage) listener.getMessage();
+
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage, deliverymode, priority, time to live");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())
+ || actTextMessage.getJMSDeliveryMode() != DeliveryMode.PERSISTENT
+ || actTextMessage.getJMSPriority() != Message.DEFAULT_PRIORITY
+ || actTextMessage.getJMSExpiration() != 0L) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode=" + actTextMessage.getJMSDeliveryMode() + ", expected "
+ + expTextMessage.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority=" + actTextMessage.getJMSPriority() + ", expected "
+ + expTextMessage.getJMSPriority());
+ logger.log(Logger.Level.ERROR, "TimeToLive=" + actTextMessage.getJMSExpiration() + ", expected "
+ + expTextMessage.getJMSExpiration());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicSendRecvCompletionListenerTest4", e);
+ }
+
+ if (!pass) {
+ throw new Exception("topicSendRecvCompletionListenerTest4 failed");
+ }
+ }
+
+ /*
+ * @testName: topicJMSExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:904;
+ *
+ * @test_Strategy: Test for JMSException from MessageProducer API's.
+ */
+ @Test
+ public void topicJMSExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON TOPIC");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Topic) null);
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicJMSExceptionTests");
+
+ // Create CompletionListener for Message to be sent
+ MyCompletionListener listener = new MyCompletionListener();
+
+ try {
+ logger.log(Logger.Level.INFO, "Try and set an invalid mode of -1 on send");
+ producer.send(destination, expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 10; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof JMSException) {
+ logger.log(Logger.Level.INFO, "Exception is expected JMSException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected JMSException, received " + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and set an invalid priority of -1 on send");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 10; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof JMSException) {
+ logger.log(Logger.Level.INFO, "Exception is expected JMSException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected JMSException, received " + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("topicJMSExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("topicJMSExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: topicInvalidDestinationExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:891; JMS:JAVADOC:896; JMS:JAVADOC:901;
+ * JMS:JAVADOC:906;
+ *
+ * @test_Strategy: Test for InvalidDestinationException from MessageProducer
+ * API's.
+ */
+ @Test
+ public void topicInvalidDestinationExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON TOPIC");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ toolForProducer = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = toolForProducer.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = null;
+ connection.start();
+ queueTest = false;
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueInvalidDestinationExceptionTests");
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(destination, expTextMessage, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 10; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof InvalidDestinationException) {
+ logger.log(Logger.Level.INFO, "Exception is expected InvalidDestinationException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected InvalidDestinationException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected InvalidDestinationException");
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L,
+ listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 10; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof InvalidDestinationException) {
+ logger.log(Logger.Level.INFO, "Exception is expected InvalidDestinationException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected InvalidDestinationException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected InvalidDestinationException");
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("queueInvalidDestinationExceptionTests", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicInvalidDestinationExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: topicUnsupportedOperationExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:892; JMS:JAVADOC:897; JMS:JAVADOC:902;
+ * JMS:JAVADOC:1323;
+ *
+ * @test_Strategy: Test for UnsupportedOperationException from MessageProducer
+ * API's.
+ */
+ @Test
+ public void topicUnsupportedOperationExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON TOPIC");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicUnsupportedOperationExceptionTests");
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(destination, expTextMessage, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 10; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof UnsupportedOperationException) {
+ logger.log(Logger.Level.INFO, "Exception is expected UnsupportedOperationException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected UnsupportedOperationException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L,
+ listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 10; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof UnsupportedOperationException) {
+ logger.log(Logger.Level.INFO, "Exception is expected UnsupportedOperationException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected UnsupportedOperationException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e);
+ pass = false;
+ }
+
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Topic) null);
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(expTextMessage, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 10; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof UnsupportedOperationException) {
+ logger.log(Logger.Level.INFO, "Exception is expected UnsupportedOperationException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected UnsupportedOperationException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 10; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof UnsupportedOperationException) {
+ logger.log(Logger.Level.INFO, "Exception is expected UnsupportedOperationException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected UnsupportedOperationException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("queueUnsupportedOperationExceptionTests", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicUnsupportedOperationExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: topicIllegalArgumentExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1319; JMS:JAVADOC:1320; JMS:JAVADOC:1321;
+ * JMS:JAVADOC:1322;
+ *
+ * @test_Strategy: Test for IllegalArgumentException from MessageProducer API's.
+ */
+ @Test
+ public void topicIllegalArgumentExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON TOPIC");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Topic) null);
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+ MyCompletionListener listener = new MyCompletionListener();
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicIllegalArgumentExceptionTests");
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with null CompletionListener");
+ producer.send(destination, expTextMessage, null);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 10; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof IllegalArgumentException) {
+ logger.log(Logger.Level.INFO, "Exception is expected IllegalArgumentException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected IllegalArgumentException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalArgumentException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with null CompletionListener");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L,
+ null);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 10; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof IllegalArgumentException) {
+ logger.log(Logger.Level.INFO, "Exception is expected IllegalArgumentException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected IllegalArgumentException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalArgumentException, received " + e);
+ pass = false;
+ }
+
+ producer.close();
+ producer = tool.getDefaultSession().createProducer(destination);
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with null CompletionListener");
+ producer.send(expTextMessage, null);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 10; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof IllegalArgumentException) {
+ logger.log(Logger.Level.INFO, "Exception is expected IllegalArgumentException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected IllegalArgumentException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalArgumentException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with null CompletionListener");
+ producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L, null);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ Exception exception = null;
+ for (int i = 0; i < 10; i++) {
+ TestUtil.sleepSec(2);
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ logger.log(Logger.Level.INFO, "Received Exception after polling loop " + (i + 1));
+ break;
+ }
+ logger.log(Logger.Level.INFO, "Completed polling loop " + i);
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof IllegalArgumentException) {
+ logger.log(Logger.Level.INFO, "Exception is expected IllegalArgumentException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected IllegalArgumentException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalArgumentException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("queueIllegalArgumentExceptionTests", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicIllegalArgumentExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: topicMessageFormatExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:890; JMS:JAVADOC:895; JMS:JAVADOC:900;
+ * JMS:JAVADOC:905;
+ *
+ * @test_Strategy: Test MessageFormatException conditions from API methods with
+ * CompletionListener.
+ *
+ * MessageProducer.send(Message, CompletionListener)
+ * MessageProducer.send(Message, int, int, long, CompletionListener)
+ * MessageProducer.send(Destination, Message, CompletionListener)
+ * MessageProducer.send(Destination, Message, int, int, long,
+ * CompletionListener)
+ *
+ * Tests the following exception conditions:
+ *
+ * MessageFormatException
+ */
+ @Test
+ public void topicMessageFormatExceptionTests() throws Exception {
+ boolean pass = true;
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ TextMessage invalidTMsg = new InvalidTextMessageTestImpl();
+ invalidTMsg.setText("hello");
+
+ // Create CompletionListener
+ MyCompletionListener listener = new MyCompletionListener();
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Message, CompletionListener) -> expect MessageFormatException");
+ producer.send(invalidTMsg, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ TestUtil.sleepSec(5);
+ Exception exception = null;
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof MessageFormatException) {
+ logger.log(Logger.Level.INFO, "Exception is expected MessageFormatException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected MessageFormatException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Got MessageFormatException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Message, int, int, long, CompletionListener) -> expect MessageFormatException");
+ producer.send(invalidTMsg, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY - 1,
+ Message.DEFAULT_TIME_TO_LIVE, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ TestUtil.sleepSec(5);
+ Exception exception = null;
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof MessageFormatException) {
+ logger.log(Logger.Level.INFO, "Exception is expected MessageFormatException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected MessageFormatException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Got MessageFormatException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException, received " + e);
+ pass = false;
+ }
+
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Destination, Message, CompletionListener) -> expect MessageFormatException");
+ producer.send(destination, invalidTMsg, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ TestUtil.sleepSec(5);
+ Exception exception = null;
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof MessageFormatException) {
+ logger.log(Logger.Level.INFO, "Exception is expected MessageFormatException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected MessageFormatException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Got MessageFormatException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Destination, Message, int, int, long, CompletionListener) -> expect MessageFormatException");
+ producer.send(destination, invalidTMsg, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY - 1,
+ Message.DEFAULT_TIME_TO_LIVE, listener);
+ logger.log(Logger.Level.INFO, "Poll listener until we receive exception");
+ TestUtil.sleepSec(5);
+ Exception exception = null;
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ exception = listener.getException();
+ }
+
+ if (exception == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw and exception");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in Exception");
+ if (exception instanceof MessageFormatException) {
+ logger.log(Logger.Level.INFO, "Exception is expected MessageFormatException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Exception is incorrect expected MessageFormatException, received "
+ + exception.getCause());
+ pass = false;
+ }
+ }
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Got MessageFormatException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("topicMessageFormatExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("topicMessageFormatExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: topicIllegalStateExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1355;
+ *
+ * @test_Strategy: Test IllegalStateException conditions. Calling
+ * MessageProducer.close() in CompletionListener MUST throw
+ * IllegalStateException.
+ */
+ @Test
+ public void topicIllegalStateExceptionTests() throws Exception {
+ boolean pass = true;
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Topic) null);
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ // Create CompetionListener
+ MyCompletionListener listener = new MyCompletionListener(producer);
+
+ logger.log(Logger.Level.INFO,
+ "Testing MessageProducer.close() from CompletionListener (expect IllegalStateException)");
+ try {
+ // Create TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage("Call close method");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicIllegalStateExceptionTests");
+
+ logger.log(Logger.Level.INFO,
+ "Send async message specifying CompletionListener to recieve async message");
+ logger.log(Logger.Level.INFO,
+ "CompletionListener will call MessageProducer.close() (expect IllegalStateException)");
+ producer.send(destination, expTextMessage, listener);
+ TextMessage actTextMessage = null;
+ logger.log(Logger.Level.INFO, "Poll listener until we receive message or exception");
+ for (int i = 0; i < 10; i++) {
+ if (listener.isComplete()) {
+ listener.setComplete(false);
+ break;
+ } else {
+ TestUtil.sleepSec(2);
+ }
+ }
+ logger.log(Logger.Level.INFO, "Check if we got correct exception from MessageProducer.close()");
+ if (listener.gotException()) {
+ if (listener.gotCorrectException()) {
+ logger.log(Logger.Level.INFO, "Got correct IllegalStateException");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Expected IllegalStateException, received: " + listener.getException());
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, got no exception");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected IllegalStateException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("topicIllegalStateExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("topicIllegalStateExceptionTests failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageproducertests/MyCompletionListener.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageproducertests/MyCompletionListener.java
index 49da26692b..c61404bfa3 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageproducertests/MyCompletionListener.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/appclient/messageproducertests/MyCompletionListener.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -19,10 +19,9 @@
*/
package com.sun.ts.tests.jms.core20.appclient.messageproducertests;
+import java.lang.System.Logger;
import java.util.ArrayList;
-import com.sun.ts.lib.util.TestUtil;
-
import jakarta.jms.CompletionListener;
import jakarta.jms.Message;
import jakarta.jms.MessageProducer;
@@ -30,133 +29,133 @@
public class MyCompletionListener implements CompletionListener {
- private String name = null;
+ private String name = null;
+
+ private Message message = null;
+
+ private MessageProducer producer = null;
- private Message message = null;
+ private ArrayList messages = new ArrayList();
- private MessageProducer producer = null;
+ private Exception exception = null;
- private ArrayList messages = new ArrayList();
+ private int numMessages = 1;
- private Exception exception = null;
+ boolean complete = false;
- private int numMessages = 1;
+ boolean gotCorrectException = false;
- boolean complete = false;
+ boolean gotException = false;
- boolean gotCorrectException = false;
-
- boolean gotException = false;
-
- public MyCompletionListener() {
- this("MyCompletionListener");
- }
-
- public MyCompletionListener(String name) {
- this.name = name;
- }
-
- public MyCompletionListener(int numMessages) {
- this.numMessages = numMessages;
- messages.clear();
- }
-
- public MyCompletionListener(MessageProducer producer) {
- this.producer = producer;
- }
-
- // getters/setters
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Message getMessage() {
- return message;
- }
-
- public Message getMessage(int index) {
- return messages.get(index);
- }
-
- public void setMessage(Message message) {
- this.message = message;
- }
-
- public Exception getException() {
- return exception;
- }
-
- public void setException(Exception exception) {
- this.exception = exception;
- }
-
- public boolean isComplete() {
- return complete;
- }
-
- public boolean gotCorrectException() {
- return gotCorrectException;
- }
-
- public boolean gotException() {
- return gotException;
- }
-
- public boolean gotAllMsgs() {
- return (messages.size() == numMessages) ? true : false;
- }
-
- public boolean haveMsg(int i) {
- return (messages.size() > i) ? true : false;
- }
-
- public void setComplete(boolean complete) {
- this.complete = complete;
- }
-
- public void onCompletion(Message message) {
- try {
- TestUtil.logMsg(
- "OnCompletion(): Got Message: " + ((TextMessage) message).getText());
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
-
- this.message = message;
- messages.add(message);
- if (message instanceof TextMessage) {
- TextMessage tMsg = (TextMessage) message;
- try {
- if (tMsg.getText().equals("Call close method")) {
- TestUtil.logMsg(
- "Calling MessageProducer.close() MUST throw IllegalStateException");
- if (producer != null)
- producer.close();
- }
- } catch (jakarta.jms.IllegalStateException e) {
- TestUtil.logMsg("Caught expected IllegalStateException");
- gotCorrectException = true;
- gotException = true;
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- gotCorrectException = false;
- gotException = true;
- exception = e;
- }
- }
- complete = true;
- }
-
- public void onException(Message message, Exception exception) {
- TestUtil.logMsg("Got Exception: " + exception);
- TestUtil.logMsg("With Message: " + message);
- this.exception = exception;
- this.message = message;
- complete = true;
- }
+ private static final Logger logger = (Logger) System.getLogger(MyCompletionListener.class.getName());
+
+ public MyCompletionListener() {
+ this("MyCompletionListener");
+ }
+
+ public MyCompletionListener(String name) {
+ this.name = name;
+ }
+
+ public MyCompletionListener(int numMessages) {
+ this.numMessages = numMessages;
+ messages.clear();
+ }
+
+ public MyCompletionListener(MessageProducer producer) {
+ this.producer = producer;
+ }
+
+ // getters/setters
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Message getMessage() {
+ return message;
+ }
+
+ public Message getMessage(int index) {
+ return messages.get(index);
+ }
+
+ public void setMessage(Message message) {
+ this.message = message;
+ }
+
+ public Exception getException() {
+ return exception;
+ }
+
+ public void setException(Exception exception) {
+ this.exception = exception;
+ }
+
+ public boolean isComplete() {
+ return complete;
+ }
+
+ public boolean gotCorrectException() {
+ return gotCorrectException;
+ }
+
+ public boolean gotException() {
+ return gotException;
+ }
+
+ public boolean gotAllMsgs() {
+ return (messages.size() == numMessages) ? true : false;
+ }
+
+ public boolean haveMsg(int i) {
+ return (messages.size() > i) ? true : false;
+ }
+
+ public void setComplete(boolean complete) {
+ this.complete = complete;
+ }
+
+ public void onCompletion(Message message) {
+ try {
+ logger.log(Logger.Level.INFO, "OnCompletion(): Got Message: " + ((TextMessage) message).getText());
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+
+ this.message = message;
+ messages.add(message);
+ if (message instanceof TextMessage) {
+ TextMessage tMsg = (TextMessage) message;
+ try {
+ if (tMsg.getText().equals("Call close method")) {
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.close() MUST throw IllegalStateException");
+ if (producer != null)
+ producer.close();
+ }
+ } catch (jakarta.jms.IllegalStateException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateException");
+ gotCorrectException = true;
+ gotException = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ gotCorrectException = false;
+ gotException = true;
+ exception = e;
+ }
+ }
+ complete = true;
+ }
+
+ public void onException(Message message, Exception exception) {
+ logger.log(Logger.Level.INFO, "Got Exception: " + exception);
+ logger.log(Logger.Level.INFO, "With Message: " + message);
+ this.exception = exception;
+ this.message = message;
+ complete = true;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/connectionfactorytests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/connectionfactorytests/Client.java
deleted file mode 100644
index 56dfeab43c..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/connectionfactorytests/Client.java
+++ /dev/null
@@ -1,581 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.connectionfactorytests;
-
-import java.util.ArrayList;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.Connection;
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.JMSContext;
-import jakarta.jms.JMSRuntimeException;
-import jakarta.jms.JMSSecurityException;
-import jakarta.jms.JMSSecurityRuntimeException;
-import jakarta.jms.QueueConnection;
-import jakarta.jms.QueueConnectionFactory;
-import jakarta.jms.TopicConnection;
-import jakarta.jms.TopicConnectionFactory;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.connectionfactorytests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null;
-
- // JMS objects
- private transient ConnectionFactory cf = null;
-
- private transient QueueConnectionFactory qcf = null;
-
- private transient TopicConnectionFactory tcf = null;
-
- private transient JMSContext context = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList connections = null;
-
- String vehicle = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * Utility method to return the session mode as a String
- */
- private String printSessionMode(int sessionMode) {
- switch (sessionMode) {
- case JMSContext.SESSION_TRANSACTED:
- return "SESSION_TRANSACTED";
- case JMSContext.AUTO_ACKNOWLEDGE:
- return "AUTO_ACKNOWLEDGE";
- case JMSContext.CLIENT_ACKNOWLEDGE:
- return "CLIENT_ACKNOWLEDGE";
- case JMSContext.DUPS_OK_ACKNOWLEDGE:
- return "DUPS_OK_ACKNOWLEDGE";
- default:
- return "UNEXPECTED_SESSIONMODE";
- }
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- connections = new ArrayList(5);
- vehicle = p.getProperty("vehicle");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- }
-
- /*
- * @testName: qcfCreateJMSContextTest1
- *
- * @assertion_ids: JMS:JAVADOC:841;
- *
- * @test_Strategy: Creates a JMSContext with the default user identity and an
- * unspecified sessionMode. Tests API:
- *
- * QueueConnectionFactory.createContext() JMSContext.getSessionMode()
- */
- public void qcfCreateJMSContextTest1() throws Exception {
- boolean pass = true;
- try {
- // set up JmsTool for QUEUE_FACTORY setup
- TestUtil.logMsg("Setup JmsTool for QUEUE_FACTORY");
- tool = new JmsTool(JmsTool.QUEUE_FACTORY, user, password, mode);
- qcf = tool.getQueueConnectionFactory();
-
- TestUtil.logMsg("Test QueueConnectionFactory.createContext()");
- context = qcf.createContext();
- TestUtil.logMsg(
- "Verify that JMSContext.getSessionMode() returns JMSContext.AUTO_ACKNOWLEDGE");
- int expSessionMode = JMSContext.AUTO_ACKNOWLEDGE;
- int actSessionMode = context.getSessionMode();
- if (actSessionMode != expSessionMode) {
- TestUtil.logErr(
- "getSessionMode() returned " + printSessionMode(actSessionMode)
- + ", expected " + printSessionMode(expSessionMode));
- pass = false;
- }
- context.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("qcfCreateJMSContextTest1");
- }
-
- if (!pass) {
- throw new Exception("qcfCreateJMSContextTest1 failed");
- }
- }
-
- /*
- * @testName: qcfCreateJMSContextTest3
- *
- * @assertion_ids: JMS:JAVADOC:844;
- *
- * @test_Strategy: Creates a JMSContext with the specified user identity and
- * an unspecified sessionMode. Tests API:
- *
- * QueueConnectionFactory.createContext(String, String)
- * JMSContext.getSessionMode()
- */
- public void qcfCreateJMSContextTest3() throws Exception {
- boolean pass = true;
- try {
- // set up JmsTool for QUEUE_FACTORY setup
- TestUtil.logMsg("Setup JmsTool for QUEUE_FACTORY");
- tool = new JmsTool(JmsTool.QUEUE_FACTORY, user, password, mode);
- qcf = tool.getQueueConnectionFactory();
-
- TestUtil
- .logMsg("Test QueueConnectionFactory.createContext(String, String)");
- context = qcf.createContext(user, password);
- TestUtil.logMsg(
- "Verify that JMSContext.getSessionMode() returns JMSContext.AUTO_ACKNOWLEDGE");
- int expSessionMode = JMSContext.AUTO_ACKNOWLEDGE;
- int actSessionMode = context.getSessionMode();
- if (actSessionMode != expSessionMode) {
- TestUtil.logErr(
- "getSessionMode() returned " + printSessionMode(actSessionMode)
- + ", expected " + printSessionMode(expSessionMode));
- pass = false;
- }
- context.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("qcfCreateJMSContextTest3");
- }
-
- if (!pass) {
- throw new Exception("qcfCreateJMSContextTest3 failed");
- }
- }
-
- /*
- * @testName: qcfCreateConnectionTest
- *
- * @assertion_ids: JMS:JAVADOC:502;JMS:JAVADOC:504;
- *
- * @test_Strategy: Create a connection with the default user identity. Create
- * a connection with the specified user identity. Tests the following API's:
- *
- * QueueConnectionFactory.createConnection()
- * QueueConnectionFactory.createConnection(String, String)
- * QueueConnectionFactory.createQueueConnection()
- * QueueConnectionFactory.createQueueConnection(String, String)
- */
- public void qcfCreateConnectionTest() throws Exception {
- boolean pass = true;
- try {
- // set up JmsTool for QUEUE_FACTORY setup
- TestUtil.logMsg("Setup JmsTool for QUEUE_FACTORY");
- tool = new JmsTool(JmsTool.QUEUE_FACTORY, user, password, mode);
- qcf = tool.getQueueConnectionFactory();
-
- TestUtil.logMsg("Test QueueConnectionFactory.createQueueConnection()");
- QueueConnection qc = qcf.createQueueConnection();
- qc.close();
-
- TestUtil.logMsg(
- "Test QueueConnectionFactory.createQueueConnection(String, String) with valid credentials");
- qc = qcf.createQueueConnection(user, password);
- qc.close();
-
- TestUtil.logMsg("Test QueueConnectionFactory.createConnection()");
- Connection c = qcf.createConnection();
- c.close();
-
- TestUtil.logMsg(
- "Test QueueConnectionFactory.createConnection(String, String) with valid credentials");
- c = qcf.createConnection(user, password);
- c.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("qcfCreateConnectionTest");
- }
-
- if (!pass) {
- throw new Exception("qcfCreateConnectionTest failed");
- }
- }
-
- /*
- * @testName: tcfCreateJMSContextTest1
- *
- * @assertion_ids: JMS:JAVADOC:841;
- *
- * @test_Strategy: Creates a JMSContext with the default user identity and an
- * unspecified sessionMode. Tests API:
- *
- * TopicConnectionFactory.createContext() JMSContext.getSessionMode()
- */
- public void tcfCreateJMSContextTest1() throws Exception {
- boolean pass = true;
- try {
- // set up JmsTool for TOPIC_FACTORY setup
- TestUtil.logMsg("Setup JmsTool for TOPIC_FACTORY");
- tool = new JmsTool(JmsTool.TOPIC_FACTORY, user, password, mode);
- tcf = tool.getTopicConnectionFactory();
-
- TestUtil.logMsg("Test TopicConnectionFactory.createContext()");
- context = tcf.createContext();
- TestUtil.logMsg(
- "Verify that JMSContext.getSessionMode() returns JMSContext.AUTO_ACKNOWLEDGE");
- int expSessionMode = JMSContext.AUTO_ACKNOWLEDGE;
- int actSessionMode = context.getSessionMode();
- if (actSessionMode != expSessionMode) {
- TestUtil.logErr(
- "getSessionMode() returned " + printSessionMode(actSessionMode)
- + ", expected " + printSessionMode(expSessionMode));
- pass = false;
- }
- context.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("tcfCreateJMSContextTest1");
- }
-
- if (!pass) {
- throw new Exception("tcfCreateJMSContextTest1 failed");
- }
- }
-
- /*
- * @testName: tcfCreateJMSContextTest3
- *
- * @assertion_ids: JMS:JAVADOC:844;
- *
- * @test_Strategy: Creates a JMSContext with the specified user identity and
- * an unspecified sessionMode. Tests API:
- *
- * TopicConnectionFactory.createContext(String, String)
- * JMSContext.getSessionMode()
- */
- public void tcfCreateJMSContextTest3() throws Exception {
- boolean pass = true;
- try {
- // set up JmsTool for TOPIC_FACTORY setup
- TestUtil.logMsg("Setup JmsTool for TOPIC_FACTORY");
- tool = new JmsTool(JmsTool.TOPIC_FACTORY, user, password, mode);
- tcf = tool.getTopicConnectionFactory();
-
- TestUtil
- .logMsg("Test TopicConnectionFactory.createContext(String, String)");
- context = tcf.createContext(user, password);
- TestUtil.logMsg(
- "Verify that JMSContext.getSessionMode() returns JMSContext.AUTO_ACKNOWLEDGE");
- int expSessionMode = JMSContext.AUTO_ACKNOWLEDGE;
- int actSessionMode = context.getSessionMode();
- if (actSessionMode != expSessionMode) {
- TestUtil.logErr(
- "getSessionMode() returned " + printSessionMode(actSessionMode)
- + ", expected " + printSessionMode(expSessionMode));
- pass = false;
- }
- context.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("tcfCreateJMSContextTest3");
- }
-
- if (!pass) {
- throw new Exception("tcfCreateJMSContextTest3 failed");
- }
- }
-
- /*
- * @testName: tcfCreateConnectionTest
- *
- * @assertion_ids: JMS:JAVADOC:502;JMS:JAVADOC:504;
- *
- * @test_Strategy: Create a connection with the default user identity. Create
- * a connection with the specified user identity. Tests tye following API's:
- *
- * TopicConnectionFactory.createConnection()
- * TopicConnectionFactory.createConnection(String, String)
- * TopicConnectionFactory.createTopicConnection()
- * TopicConnectionFactory.createTopicConnection(String, String)
- */
- public void tcfCreateConnectionTest() throws Exception {
- boolean pass = true;
- try {
- // set up JmsTool for TOPIC_FACTORY setup
- TestUtil.logMsg("Setup JmsTool for TOPIC_FACTORY");
- tool = new JmsTool(JmsTool.TOPIC_FACTORY, user, password, mode);
- tcf = tool.getTopicConnectionFactory();
-
- TestUtil.logMsg("Test TopicConnectionFactory.createTopicConnection()");
- TopicConnection tc = tcf.createTopicConnection();
- tc.close();
-
- TestUtil.logMsg(
- "Test TopicConnectionFactory.createTopicConnection(String, String) with valid credentials");
- tc = tcf.createTopicConnection(user, password);
- tc.close();
-
- TestUtil.logMsg("Test TopicConnectionFactory.createConnection()");
- Connection c = tcf.createConnection();
- c.close();
-
- TestUtil.logMsg(
- "Test TopicConnectionFactory.createConnection(String, String) with valid credentials");
- c = tcf.createConnection(user, password);
- c.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("tcfCreateConnectionTest");
- }
-
- if (!pass) {
- throw new Exception("tcfCreateConnectionTest failed");
- }
- }
-
- /*
- * @testName: createConnectionExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:596;
- *
- * @test_Strategy: Try and create a connection with invalid user credentials.
- * Tests for JMSSecurityException.
- *
- * QueueConnectionFactory.createQueueConnection(String, String)
- * TopicConnectionFactory.createTopicConnection(String, String)
- */
- public void createConnectionExceptionTests() throws Exception {
- boolean pass = true;
- try {
- // set up JmsTool for QUEUE_FACTORY setup
- TestUtil.logMsg("Setup JmsTool for QUEUE_FACTORY");
- tool = new JmsTool(JmsTool.QUEUE_FACTORY, user, password, mode);
- qcf = tool.getQueueConnectionFactory();
-
- TestUtil.logMsg(
- "Test QueueConnectionFactory.createQueueConnection(String, String) with invalid credentials");
- TestUtil.logMsg("Verify JMSSecurityException is thrown");
- QueueConnection c = qcf.createQueueConnection("invalid", "invalid");
- TestUtil.logErr("Didn't throw expected JMSSecurityException");
- pass = false;
- c.close();
- } catch (JMSSecurityException e) {
- TestUtil.logMsg("Caught expected JMSSecurityException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSSecurityException, received " + e);
- pass = false;
- }
-
- try {
- // set up JmsTool for TOPIC_FACTORY setup
- TestUtil.logMsg("Setup JmsTool for TOPIC_FACTORY");
- tool = new JmsTool(JmsTool.TOPIC_FACTORY, user, password, mode);
- tcf = tool.getTopicConnectionFactory();
-
- TestUtil.logMsg(
- "Test TopicConnectionFactory.createTopicConnection(String, String) with invalid credentials");
- TestUtil.logMsg("Verify JMSSecurityException is thrown");
- TopicConnection c = tcf.createTopicConnection("invalid", "invalid");
- TestUtil.logErr("Didn't throw expected JMSSecurityException");
- pass = false;
- c.close();
- } catch (JMSSecurityException e) {
- TestUtil.logMsg("Caught expected JMSSecurityException");
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("createConnectionExceptionTests failed");
- }
- }
-
- /*
- * @testName: createJMSContextExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:842; JMS:JAVADOC:843; JMS:JAVADOC:845;
- * JMS:JAVADOC:846; JMS:JAVADOC:848; JMS:JAVADOC:849; JMS:JAVADOC:850;
- * JMS:JAVADOC:851;
- *
- * @test_Strategy: Try and create a JMSContext with invalid user credentials
- * and invalid session mode. Tests for the exceptions: JMSRuntimeException and
- * JMSSecurityRuntimeException.
- *
- * QueueConnectionFactory.createContext(String, String)
- * QueueConnectionFactory.createContext(int)
- * TopicConnectionFactory.createContext(String, String)
- * TopicConnectionFactory.createContext(int)
- */
- public void createJMSContextExceptionTests() throws Exception {
- boolean pass = true;
- try {
- // set up JmsTool for QUEUE_FACTORY setup
- TestUtil.logMsg("Setup JmsTool for QUEUE_FACTORY");
- tool = new JmsTool(JmsTool.QUEUE_FACTORY, user, password, mode);
- qcf = tool.getQueueConnectionFactory();
-
- TestUtil.logMsg(
- "Test QueueConnectionFactory.createContext(String, String) with bad credentials");
- TestUtil.logMsg("Verify JMSRuntimeSecurityException is thrown");
- try {
- context = qcf.createContext("invalid", "invalid");
- TestUtil.logErr("Didn't throw expected JMSSecurityRuntimeException");
- pass = false;
- context.close();
- } catch (JMSSecurityRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeSecurityException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSSecurityRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Test QueueConnectionFactory.createContext(int) with bad session mode");
- TestUtil.logMsg("Verify JMSRuntimeException is thrown");
- try {
- context = qcf.createContext(-1);
- TestUtil.logErr("Didn't throw expected JMSRuntimeException");
- pass = false;
- context.close();
- } catch (JMSRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSRuntimeException, received " + e);
- pass = false;
- }
-
- // set up JmsTool for TOPIC_FACTORY setup
- TestUtil.logMsg("Setup JmsTool for TOPIC_FACTORY");
- tool = new JmsTool(JmsTool.TOPIC_FACTORY, user, password, mode);
- tcf = tool.getTopicConnectionFactory();
-
- TestUtil.logMsg(
- "Test TopicConnectionFactory.createContext(String, String) with bad credentials");
- TestUtil.logMsg("Verify JMSSecurityRuntimeException is thrown");
- try {
- context = tcf.createContext("invalid", "invalid");
- TestUtil.logErr("Didn't throw expected JMSSecurityRuntimeException");
- pass = false;
- context.close();
- } catch (JMSSecurityRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeSecurityException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Test TopicConnectionFactory.createContext(int) with bad session mode");
- TestUtil.logMsg("Verify JMSRuntimeException is thrown");
- try {
- context = tcf.createContext(-1);
- TestUtil.logErr("Didn't throw expected JMSRuntimeException");
- pass = false;
- context.close();
- } catch (JMSRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("createJMSContextExceptionTests");
- }
-
- if (!pass) {
- throw new Exception("createJMSContextExceptionTests failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/connectionfactorytests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/connectionfactorytests/ClientIT.java
new file mode 100644
index 0000000000..7e87ade86c
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/connectionfactorytests/ClientIT.java
@@ -0,0 +1,575 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.connectionfactorytests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.Connection;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSRuntimeException;
+import jakarta.jms.JMSSecurityException;
+import jakarta.jms.JMSSecurityRuntimeException;
+import jakarta.jms.QueueConnection;
+import jakarta.jms.QueueConnectionFactory;
+import jakarta.jms.TopicConnection;
+import jakarta.jms.TopicConnectionFactory;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.connectionfactorytests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null;
+
+ // JMS objects
+ private transient ConnectionFactory cf = null;
+
+ private transient QueueConnectionFactory qcf = null;
+
+ private transient TopicConnectionFactory tcf = null;
+
+ private transient JMSContext context = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList connections = null;
+
+ String vehicle = null;
+
+ /*
+ * Utility method to return the session mode as a String
+ */
+ private String printSessionMode(int sessionMode) {
+ switch (sessionMode) {
+ case JMSContext.SESSION_TRANSACTED:
+ return "SESSION_TRANSACTED";
+ case JMSContext.AUTO_ACKNOWLEDGE:
+ return "AUTO_ACKNOWLEDGE";
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ return "CLIENT_ACKNOWLEDGE";
+ case JMSContext.DUPS_OK_ACKNOWLEDGE:
+ return "DUPS_OK_ACKNOWLEDGE";
+ default:
+ return "UNEXPECTED_SESSIONMODE";
+ }
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ connections = new ArrayList(5);
+ vehicle = System.getProperty("vehicle");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ }
+
+ /*
+ * @testName: qcfCreateJMSContextTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:841;
+ *
+ * @test_Strategy: Creates a JMSContext with the default user identity and an
+ * unspecified sessionMode. Tests API:
+ *
+ * QueueConnectionFactory.createContext() JMSContext.getSessionMode()
+ */
+ @Test
+ public void qcfCreateJMSContextTest1() throws Exception {
+ boolean pass = true;
+ try {
+ // set up JmsTool for QUEUE_FACTORY setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for QUEUE_FACTORY");
+ tool = new JmsTool(JmsTool.QUEUE_FACTORY, user, password, mode);
+ qcf = tool.getQueueConnectionFactory();
+
+ logger.log(Logger.Level.INFO, "Test QueueConnectionFactory.createContext()");
+ context = qcf.createContext();
+ logger.log(Logger.Level.INFO,
+ "Verify that JMSContext.getSessionMode() returns JMSContext.AUTO_ACKNOWLEDGE");
+ int expSessionMode = JMSContext.AUTO_ACKNOWLEDGE;
+ int actSessionMode = context.getSessionMode();
+ if (actSessionMode != expSessionMode) {
+ logger.log(Logger.Level.ERROR, "getSessionMode() returned " + printSessionMode(actSessionMode)
+ + ", expected " + printSessionMode(expSessionMode));
+ pass = false;
+ }
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("qcfCreateJMSContextTest1");
+ }
+
+ if (!pass) {
+ throw new Exception("qcfCreateJMSContextTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: qcfCreateJMSContextTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:844;
+ *
+ * @test_Strategy: Creates a JMSContext with the specified user identity and an
+ * unspecified sessionMode. Tests API:
+ *
+ * QueueConnectionFactory.createContext(String, String)
+ * JMSContext.getSessionMode()
+ */
+ @Test
+ public void qcfCreateJMSContextTest3() throws Exception {
+ boolean pass = true;
+ try {
+ // set up JmsTool for QUEUE_FACTORY setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for QUEUE_FACTORY");
+ tool = new JmsTool(JmsTool.QUEUE_FACTORY, user, password, mode);
+ qcf = tool.getQueueConnectionFactory();
+
+ logger.log(Logger.Level.INFO, "Test QueueConnectionFactory.createContext(String, String)");
+ context = qcf.createContext(user, password);
+ logger.log(Logger.Level.INFO,
+ "Verify that JMSContext.getSessionMode() returns JMSContext.AUTO_ACKNOWLEDGE");
+ int expSessionMode = JMSContext.AUTO_ACKNOWLEDGE;
+ int actSessionMode = context.getSessionMode();
+ if (actSessionMode != expSessionMode) {
+ logger.log(Logger.Level.ERROR, "getSessionMode() returned " + printSessionMode(actSessionMode)
+ + ", expected " + printSessionMode(expSessionMode));
+ pass = false;
+ }
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("qcfCreateJMSContextTest3");
+ }
+
+ if (!pass) {
+ throw new Exception("qcfCreateJMSContextTest3 failed");
+ }
+ }
+
+ /*
+ * @testName: qcfCreateConnectionTest
+ *
+ * @assertion_ids: JMS:JAVADOC:502;JMS:JAVADOC:504;
+ *
+ * @test_Strategy: Create a connection with the default user identity. Create a
+ * connection with the specified user identity. Tests the following API's:
+ *
+ * QueueConnectionFactory.createConnection()
+ * QueueConnectionFactory.createConnection(String, String)
+ * QueueConnectionFactory.createQueueConnection()
+ * QueueConnectionFactory.createQueueConnection(String, String)
+ */
+ @Test
+ public void qcfCreateConnectionTest() throws Exception {
+ boolean pass = true;
+ try {
+ // set up JmsTool for QUEUE_FACTORY setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for QUEUE_FACTORY");
+ tool = new JmsTool(JmsTool.QUEUE_FACTORY, user, password, mode);
+ qcf = tool.getQueueConnectionFactory();
+
+ logger.log(Logger.Level.INFO, "Test QueueConnectionFactory.createQueueConnection()");
+ QueueConnection qc = qcf.createQueueConnection();
+ qc.close();
+
+ logger.log(Logger.Level.INFO,
+ "Test QueueConnectionFactory.createQueueConnection(String, String) with valid credentials");
+ qc = qcf.createQueueConnection(user, password);
+ qc.close();
+
+ logger.log(Logger.Level.INFO, "Test QueueConnectionFactory.createConnection()");
+ Connection c = qcf.createConnection();
+ c.close();
+
+ logger.log(Logger.Level.INFO,
+ "Test QueueConnectionFactory.createConnection(String, String) with valid credentials");
+ c = qcf.createConnection(user, password);
+ c.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("qcfCreateConnectionTest");
+ }
+
+ if (!pass) {
+ throw new Exception("qcfCreateConnectionTest failed");
+ }
+ }
+
+ /*
+ * @testName: tcfCreateJMSContextTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:841;
+ *
+ * @test_Strategy: Creates a JMSContext with the default user identity and an
+ * unspecified sessionMode. Tests API:
+ *
+ * TopicConnectionFactory.createContext() JMSContext.getSessionMode()
+ */
+ @Test
+ public void tcfCreateJMSContextTest1() throws Exception {
+ boolean pass = true;
+ try {
+ // set up JmsTool for TOPIC_FACTORY setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for TOPIC_FACTORY");
+ tool = new JmsTool(JmsTool.TOPIC_FACTORY, user, password, mode);
+ tcf = tool.getTopicConnectionFactory();
+
+ logger.log(Logger.Level.INFO, "Test TopicConnectionFactory.createContext()");
+ context = tcf.createContext();
+ logger.log(Logger.Level.INFO,
+ "Verify that JMSContext.getSessionMode() returns JMSContext.AUTO_ACKNOWLEDGE");
+ int expSessionMode = JMSContext.AUTO_ACKNOWLEDGE;
+ int actSessionMode = context.getSessionMode();
+ if (actSessionMode != expSessionMode) {
+ logger.log(Logger.Level.ERROR, "getSessionMode() returned " + printSessionMode(actSessionMode)
+ + ", expected " + printSessionMode(expSessionMode));
+ pass = false;
+ }
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("tcfCreateJMSContextTest1");
+ }
+
+ if (!pass) {
+ throw new Exception("tcfCreateJMSContextTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: tcfCreateJMSContextTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:844;
+ *
+ * @test_Strategy: Creates a JMSContext with the specified user identity and an
+ * unspecified sessionMode. Tests API:
+ *
+ * TopicConnectionFactory.createContext(String, String)
+ * JMSContext.getSessionMode()
+ */
+ @Test
+ public void tcfCreateJMSContextTest3() throws Exception {
+ boolean pass = true;
+ try {
+ // set up JmsTool for TOPIC_FACTORY setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for TOPIC_FACTORY");
+ tool = new JmsTool(JmsTool.TOPIC_FACTORY, user, password, mode);
+ tcf = tool.getTopicConnectionFactory();
+
+ logger.log(Logger.Level.INFO, "Test TopicConnectionFactory.createContext(String, String)");
+ context = tcf.createContext(user, password);
+ logger.log(Logger.Level.INFO,
+ "Verify that JMSContext.getSessionMode() returns JMSContext.AUTO_ACKNOWLEDGE");
+ int expSessionMode = JMSContext.AUTO_ACKNOWLEDGE;
+ int actSessionMode = context.getSessionMode();
+ if (actSessionMode != expSessionMode) {
+ logger.log(Logger.Level.ERROR, "getSessionMode() returned " + printSessionMode(actSessionMode)
+ + ", expected " + printSessionMode(expSessionMode));
+ pass = false;
+ }
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("tcfCreateJMSContextTest3");
+ }
+
+ if (!pass) {
+ throw new Exception("tcfCreateJMSContextTest3 failed");
+ }
+ }
+
+ /*
+ * @testName: tcfCreateConnectionTest
+ *
+ * @assertion_ids: JMS:JAVADOC:502;JMS:JAVADOC:504;
+ *
+ * @test_Strategy: Create a connection with the default user identity. Create a
+ * connection with the specified user identity. Tests tye following API's:
+ *
+ * TopicConnectionFactory.createConnection()
+ * TopicConnectionFactory.createConnection(String, String)
+ * TopicConnectionFactory.createTopicConnection()
+ * TopicConnectionFactory.createTopicConnection(String, String)
+ */
+ @Test
+ public void tcfCreateConnectionTest() throws Exception {
+ boolean pass = true;
+ try {
+ // set up JmsTool for TOPIC_FACTORY setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for TOPIC_FACTORY");
+ tool = new JmsTool(JmsTool.TOPIC_FACTORY, user, password, mode);
+ tcf = tool.getTopicConnectionFactory();
+
+ logger.log(Logger.Level.INFO, "Test TopicConnectionFactory.createTopicConnection()");
+ TopicConnection tc = tcf.createTopicConnection();
+ tc.close();
+
+ logger.log(Logger.Level.INFO,
+ "Test TopicConnectionFactory.createTopicConnection(String, String) with valid credentials");
+ tc = tcf.createTopicConnection(user, password);
+ tc.close();
+
+ logger.log(Logger.Level.INFO, "Test TopicConnectionFactory.createConnection()");
+ Connection c = tcf.createConnection();
+ c.close();
+
+ logger.log(Logger.Level.INFO,
+ "Test TopicConnectionFactory.createConnection(String, String) with valid credentials");
+ c = tcf.createConnection(user, password);
+ c.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("tcfCreateConnectionTest");
+ }
+
+ if (!pass) {
+ throw new Exception("tcfCreateConnectionTest failed");
+ }
+ }
+
+ /*
+ * @testName: createConnectionExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:596;
+ *
+ * @test_Strategy: Try and create a connection with invalid user credentials.
+ * Tests for JMSSecurityException.
+ *
+ * QueueConnectionFactory.createQueueConnection(String, String)
+ * TopicConnectionFactory.createTopicConnection(String, String)
+ */
+ @Test
+ public void createConnectionExceptionTests() throws Exception {
+ boolean pass = true;
+ try {
+ // set up JmsTool for QUEUE_FACTORY setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for QUEUE_FACTORY");
+ tool = new JmsTool(JmsTool.QUEUE_FACTORY, user, password, mode);
+ qcf = tool.getQueueConnectionFactory();
+
+ logger.log(Logger.Level.INFO,
+ "Test QueueConnectionFactory.createQueueConnection(String, String) with invalid credentials");
+ logger.log(Logger.Level.INFO, "Verify JMSSecurityException is thrown");
+ QueueConnection c = qcf.createQueueConnection("invalid", "invalid");
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSSecurityException");
+ pass = false;
+ c.close();
+ } catch (JMSSecurityException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSSecurityException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSSecurityException, received " + e);
+ pass = false;
+ }
+
+ try {
+ // set up JmsTool for TOPIC_FACTORY setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for TOPIC_FACTORY");
+ tool = new JmsTool(JmsTool.TOPIC_FACTORY, user, password, mode);
+ tcf = tool.getTopicConnectionFactory();
+
+ logger.log(Logger.Level.INFO,
+ "Test TopicConnectionFactory.createTopicConnection(String, String) with invalid credentials");
+ logger.log(Logger.Level.INFO, "Verify JMSSecurityException is thrown");
+ TopicConnection c = tcf.createTopicConnection("invalid", "invalid");
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSSecurityException");
+ pass = false;
+ c.close();
+ } catch (JMSSecurityException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSSecurityException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("createConnectionExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: createJMSContextExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:842; JMS:JAVADOC:843; JMS:JAVADOC:845;
+ * JMS:JAVADOC:846; JMS:JAVADOC:848; JMS:JAVADOC:849; JMS:JAVADOC:850;
+ * JMS:JAVADOC:851;
+ *
+ * @test_Strategy: Try and create a JMSContext with invalid user credentials and
+ * invalid session mode. Tests for the exceptions: JMSRuntimeException and
+ * JMSSecurityRuntimeException.
+ *
+ * QueueConnectionFactory.createContext(String, String)
+ * QueueConnectionFactory.createContext(int)
+ * TopicConnectionFactory.createContext(String, String)
+ * TopicConnectionFactory.createContext(int)
+ */
+ @Test
+ public void createJMSContextExceptionTests() throws Exception {
+ boolean pass = true;
+ try {
+ // set up JmsTool for QUEUE_FACTORY setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for QUEUE_FACTORY");
+ tool = new JmsTool(JmsTool.QUEUE_FACTORY, user, password, mode);
+ qcf = tool.getQueueConnectionFactory();
+
+ logger.log(Logger.Level.INFO,
+ "Test QueueConnectionFactory.createContext(String, String) with bad credentials");
+ logger.log(Logger.Level.INFO, "Verify JMSRuntimeSecurityException is thrown");
+ try {
+ context = qcf.createContext("invalid", "invalid");
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSSecurityRuntimeException");
+ pass = false;
+ context.close();
+ } catch (JMSSecurityRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeSecurityException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSSecurityRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO, "Test QueueConnectionFactory.createContext(int) with bad session mode");
+ logger.log(Logger.Level.INFO, "Verify JMSRuntimeException is thrown");
+ try {
+ context = qcf.createContext(-1);
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSRuntimeException");
+ pass = false;
+ context.close();
+ } catch (JMSRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSRuntimeException, received " + e);
+ pass = false;
+ }
+
+ // set up JmsTool for TOPIC_FACTORY setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for TOPIC_FACTORY");
+ tool = new JmsTool(JmsTool.TOPIC_FACTORY, user, password, mode);
+ tcf = tool.getTopicConnectionFactory();
+
+ logger.log(Logger.Level.INFO,
+ "Test TopicConnectionFactory.createContext(String, String) with bad credentials");
+ logger.log(Logger.Level.INFO, "Verify JMSSecurityRuntimeException is thrown");
+ try {
+ context = tcf.createContext("invalid", "invalid");
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSSecurityRuntimeException");
+ pass = false;
+ context.close();
+ } catch (JMSSecurityRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeSecurityException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO, "Test TopicConnectionFactory.createContext(int) with bad session mode");
+ logger.log(Logger.Level.INFO, "Verify JMSRuntimeException is thrown");
+ try {
+ context = tcf.createContext(-1);
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSRuntimeException");
+ pass = false;
+ context.close();
+ } catch (JMSRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("createJMSContextExceptionTests");
+ }
+
+ if (!pass) {
+ throw new Exception("createJMSContextExceptionTests failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsconsumertests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsconsumertests/Client.java
deleted file mode 100644
index 10854b2205..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsconsumertests/Client.java
+++ /dev/null
@@ -1,1544 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.jmsconsumertests;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.EOFException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.Destination;
-import jakarta.jms.JMSConsumer;
-import jakarta.jms.JMSContext;
-import jakarta.jms.JMSProducer;
-import jakarta.jms.JMSRuntimeException;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.MessageFormatRuntimeException;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.Queue;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.jmsconsumertests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null;
-
- // JMS objects
- private transient ConnectionFactory cf = null;
-
- private transient Queue queue = null;
-
- private transient Topic topic = null;
-
- private transient Destination destination = null;
-
- private transient JMSContext context = null;
-
- private transient JMSConsumer consumer = null;
-
- private transient JMSProducer producer = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- boolean queueTest = false;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(3);
- connections = new ArrayList(5);
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Close JMSContext");
- if (context != null)
- context.close();
- if (queueTest) {
- TestUtil.logMsg("Flush any messages left on Queue");
- tool.flushDestination();
- }
- TestUtil.logMsg("Close all connections and resources");
- tool.closeAllConnections(connections);
- tool.closeAllResources();
- producer = null;
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * @testName: queueReceiveTests
- *
- * @assertion_ids: JMS:JAVADOC:1102; JMS:JAVADOC:1104; JMS:JAVADOC:1106;
- *
- * @test_Strategy: Test the JMSConsumer receive API's. Tests the following
- * API's:
- *
- * JMSConsumer.receive() JMSConsumer.receive(long timeout)
- * JMSConsumer.receiveNoWait()
- *
- */
- public void queueReceiveTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up JmsTool for COMMON_Q setup
- TestUtil.logMsg("Setup JmsTool for COMMON_Q");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- queue = (Queue) destination;
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- queueTest = true;
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Create JMSProducer");
- producer = context.createProducer();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueReceiveTests");
- TestUtil.logMsg("Send and receive the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Call JMSConsumer.receive() to receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive();
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
-
- // send and receive TextMessage again
- TestUtil.logMsg("Send and receive the TextMessage again");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg(
- "Call JMSConsumer.receive(long timeout) to receive TextMessage");
- actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
-
- // send and receive TextMessage again
- TestUtil.logMsg("Send and receive the TextMessage again");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil
- .logMsg("Call JMSConsumer.receiveNoWait() to receive TextMessage");
- actTextMessage = (TextMessage) consumer.receiveNoWait();
- if (actTextMessage == null) {
- TestUtil.logMsg("Did not receive message (THIS IS OK)");
- TestUtil
- .logMsg("Now block and wait for message via JMSConsumer.receive()");
- actTextMessage = (TextMessage) consumer.receive();
- }
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage on blocking receive");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- TestUtil.logMsg("Now don't send a message at all");
- TestUtil.logMsg("Calling receiveNoWait() again to receive TextMessage");
- actTextMessage = (TextMessage) consumer.receiveNoWait();
- if (actTextMessage != null) {
- TestUtil
- .logErr("actTextMessage != NULL (expected actTextMessage=NULL)");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("queueReceiveTests", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueReceiveTests failed");
- }
- }
-
- /*
- * @testName: queueReceiveBodyTests
- *
- * @assertion_ids: JMS:JAVADOC:1369; JMS:JAVADOC:1372; JMS:JAVADOC:1375;
- *
- * @test_Strategy: Send and receive messages of the following types:
- * BytesMessage, MapMessage, ObjectMessage, TextMessage. Test the following
- * API's: JMSConsumer.receiveBody(Class), JMSConsumer.receiveBody(Class,
- * long), and JMSConsumer.recieveBodyNoWait(Class)
- *
- * T = JMSConsumer.receiveBody(Class) T =
- * JMSConsumer.receiveBody(Class, long) T =
- * JMSConsumer.receiveBodyNoWait(Class)
- *
- * Test the following:
- *
- * String message = JMSConsumer.receiveBody(String.class) StringBuffer message
- * = JMSConsumer.receiveBody(StringBuffer.class, long); byte[] message =
- * JMSConsumer.receiveBody(byte[].class, long); Map message =
- * JMSConsumer.receiveBodyNoWait(Map.class);
- *
- */
- public void queueReceiveBodyTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- StringBuffer expSbuffer = new StringBuffer("This is it!");
- try {
- // set up JmsTool for COMMON_Q setup
- TestUtil.logMsg("Setup JmsTool for COMMON_Q");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- queue = (Queue) destination;
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- queueTest = true;
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Create JMSProducer");
- producer = context.createProducer();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueReceiveBodyTests");
- TestUtil.logMsg("Send and receive the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody(String.class) to receive message as a String");
- String actMessage = consumer.receiveBody(String.class);
- if (actMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in String");
- if (actMessage.equals(message)) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect expected " + message
- + ", received " + actMessage);
- pass = false;
- }
-
- // Send and receive ObjectMessage
- TestUtil.logMsg("Create ObjectMessage");
- ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
- TestUtil.logMsg("Set some values in ObjectMessage");
- expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueReceiveBodyTests");
- TestUtil.logMsg("Send and receive the ObjectMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expObjectMessage);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody(StringBuffer.class, long) to receive message as a StringBuffer");
- StringBuffer actSbuffer = consumer.receiveBody(StringBuffer.class,
- timeout);
- if (actSbuffer == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- TestUtil.logMsg("Check the value in StringBuffer");
- if (actSbuffer.toString().equals(expSbuffer.toString())) {
- TestUtil.logMsg("ObjectMessage is correct");
- } else {
- TestUtil.logErr("ObjectMessage is incorrect expected " + expSbuffer
- + ", received " + actSbuffer);
- pass = false;
- }
-
- // Send and receive BytesMessage
- TestUtil.logMsg("Create BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveBodyTests");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- TestUtil.logMsg("Send and receive the BytesMessage");
- producer.send(destination, bMsg);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody(byte[].class, long) to receive message as a byte array");
- byte[] bytes = consumer.receiveBody(byte[].class, timeout);
- if (bytes == null) {
- throw new Exception("Did not receive BytesMessage");
- } else {
- try {
- DataInputStream di = new DataInputStream(
- new ByteArrayInputStream(bytes));
- TestUtil.logMsg("Check the values in BytesMessage");
- if (di.readByte() == (byte) 1) {
- TestUtil.logMsg("bytevalue is correct");
- } else {
- TestUtil.logMsg("bytevalue is incorrect");
- pass = false;
- }
- if (di.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- try {
- byte b = di.readByte();
- } catch (EOFException e) {
- TestUtil.logMsg("Caught expected EOFException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- }
-
- // Send and receive MapMessage
- TestUtil.logMsg("Create MapMessage");
- MapMessage mMsg = context.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveBodyTests");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- TestUtil.logMsg("Send and receive the MapMessage");
- producer.send(destination, mMsg);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBodyNoWait(Map.class) to receive message as a Map");
- Map map = consumer.receiveBodyNoWait(Map.class);
- if (map == null) {
- for (int i = 0; i < 5; i++) {
- TestUtil.sleepSec(1);
- map = consumer.receiveBodyNoWait(Map.class);
- if (map != null)
- break;
- }
- }
- if (map == null) {
- TestUtil.logErr("Did not receive MapMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in MapMessage");
- TestUtil.logMsg("map.size()=" + map.size());
- if (map.size() != 2) {
- TestUtil.logErr("Map size is " + map.size() + ", expected 2");
- pass = false;
- }
- Iterator it = map.keySet().iterator();
- String name = null;
- while (it.hasNext()) {
- name = (String) it.next();
- if (name.equals("booleanvalue")) {
- if ((boolean) map.get(name) == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logErr("booleanvalue is incorrect");
- pass = false;
- }
- } else if (name.equals("intvalue")) {
- if ((int) map.get(name) == 10) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logErr("intvalue is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Unexpected name of [" + name + "] in MapMessage");
- pass = false;
- }
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("queueReceiveBodyTests", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueReceiveBodyTests failed");
- }
- }
-
- /*
- * @testName: queueReceiveBodyExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1371; JMS:JAVADOC:1374; JMS:JAVADOC:1377;
- *
- * @test_Strategy: Test exception cases for JMSConsumer.receiveBody(Class),
- * JMSConsumer.receiveBody(Class, long), and
- * JMSConsumer.recieveBodyNoWait(Class).
- *
- * Test for exception MessageFormatRuntimeException.
- *
- */
- public void queueReceiveBodyExceptionTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- StringBuffer expSbuffer = new StringBuffer("This is it!");
- try {
- // set up JmsTool for COMMON_Q setup
- TestUtil.logMsg("Setup JmsTool for COMMON_Q");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- queue = (Queue) destination;
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- queueTest = true;
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Create JMSProducer");
- producer = context.createProducer();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueReceiveBodyExceptionTests");
- TestUtil.logMsg("Send and receive the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody(Class) to receive message as wrong type");
- TestUtil.logMsg(
- "Pass Boolean.class as parameter to receiveBody() expect MessageFormatRuntimeException");
- try {
- consumer.receiveBody(Boolean.class);
- TestUtil.logErr("Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive ObjectMessage
- TestUtil.logMsg("Create ObjectMessage of type StringBuffer");
- ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
- TestUtil.logMsg("Set some values in ObjectMessage");
- expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueReceiveBodyExceptionTests");
- TestUtil.logMsg("Send and receive the ObjectMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expObjectMessage);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody(Class) to receive message as wrong type");
- TestUtil.logMsg(
- "Pass HashMap.class as parameter to receiveBody() expect MessageFormatRuntimeException");
- try {
- consumer.receiveBody(Boolean.class);
- TestUtil.logErr("Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive BytesMessage
- TestUtil.logMsg("Create BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueReceiveBodyExceptionTests");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- TestUtil.logMsg("Send and receive the BytesMessage");
- producer.send(destination, bMsg);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBodyNoWait(Class) to receive message as wrong type");
- TestUtil.logMsg(
- "Pass Boolean.class as parameter to receiveBodyNoWait() expect MessageFormatRuntimeException");
- try {
- for (int i = 0; i < 5; i++) {
- TestUtil.sleepSec(1);
- if (consumer.receiveBodyNoWait(Boolean.class) != null)
- break;
- }
- TestUtil.logErr("Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive MapMessage
- TestUtil.logMsg("Send MapMessage");
- MapMessage mMsg = context.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueReceiveBodyExceptionTests");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- producer.send(destination, mMsg);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody(Map.class, long) to receive message as wrong type");
- TestUtil.logMsg(
- "Pass Boolean.class as parameter to receiveBody() expect MessageFormatRuntimeException");
- try {
- consumer.receiveBody(Boolean.class, timeout);
- TestUtil.logErr("Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // send and receive StreamMessage
- TestUtil.logMsg("Send StreamMessage");
- StreamMessage sMsg = context.createStreamMessage();
- TestUtil.logMsg("Set some values in StreamMessage");
- sMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueReceiveBodyExceptionTests");
- sMsg.writeBoolean(true);
- sMsg.writeInt((int) 22);
- producer.send(destination, sMsg);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody() on a StreamMessage expect MessageFormatRuntimeException");
- try {
- consumer.receiveBody(Boolean.class, timeout);
- TestUtil.logErr("Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // send and receive Message
- TestUtil.logMsg("Send Message");
- Message msg = context.createMessage();
- TestUtil.logMsg("Set some values in Message");
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueReceiveBodyExceptionTests");
- msg.setBooleanProperty("booleanProperty", true);
- producer.send(destination, msg);
- long deliveryTime = msg.getJMSDeliveryTime();
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody() on a Message expect MessageFormatRuntimeException");
- try {
- consumer.receiveBody(Boolean.class, timeout);
- TestUtil.logErr("Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("queueReceiveBodyExceptionTests", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueReceiveBodyExceptionTests failed");
- }
- }
-
- /*
- * @testName: queueGetMessageSelectorTest
- *
- * @assertion_ids: JMS:JAVADOC:1100;
- *
- * @test_Strategy: Test the JMSConsumer getMessageSelector API:
- *
- * JMSConsumer.getMessageSelector()
- *
- */
- public void queueGetMessageSelectorTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up JmsTool for COMMON_Q setup
- TestUtil.logMsg("Setup JmsTool for COMMON_Q");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- queue = (Queue) destination;
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- queueTest = true;
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Create JMSProducer");
- producer = context.createProducer();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Get Message selector expression
- TestUtil.logMsg(
- "Get message selector expression by calling getMessageSelector() API");
- String msgsel = consumer.getMessageSelector();
-
- TestUtil.logMsg(
- "Expecting message selector to be NULL since we didn't set it");
- if (msgsel != null) {
- TestUtil.logErr("Message selector is NOT NULL (unexpected): , expected NULL");
- pass = false;
- }
- consumer.close();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg(
- "Create JMSConsumer with message selector 'lastMessage = TRUE'");
- consumer = context.createConsumer(destination, "lastMessage = TRUE");
-
- // Get Message selector expression
- TestUtil.logMsg(
- "Get message selector expression by calling getMessageSelector() API");
- msgsel = consumer.getMessageSelector();
-
- TestUtil.logMsg(
- "Expecting message selector to be NOT NULL since we set it to 'lastMessage = TRUE'");
- if (msgsel == null) {
- TestUtil.logErr(
- "Message selector is NULL (unexpected): , expected 'lastMessage = TRUE'");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("queueGetMessageSelectorTest", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueGetMessageSelectorTest failed");
- }
- }
-
- /*
- * @testName: queueCloseTest
- *
- * @assertion_ids: JMS:JAVADOC:1098;
- *
- * @test_Strategy: Test the JMSConsumer close API.
- *
- * JMSConsumer.close()
- *
- */
- public void queueCloseTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up JmsTool for COMMON_Q setup
- TestUtil.logMsg("Setup JmsTool for COMMON_Q");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- queue = (Queue) destination;
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- queueTest = true;
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Create JMSProducer");
- producer = context.createProducer();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // send TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueCloseTest");
- TestUtil.logMsg("Send the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
-
- TestUtil.logMsg("Close the JMSConsumer");
- consumer.close();
-
- TestUtil.logMsg(
- "Try receiving a message on a closed JMSConsumer (expect JMSRuntimeException or no message)");
- try {
- TextMessage actTextMessage = (TextMessage) consumer.receive();
- if (actTextMessage != null) {
- TestUtil.logErr("Received a message (expected no message), ");
- pass = false;
- } else {
- TestUtil.logMsg("Did not receive a message (correct)");
- }
- } catch (JMSRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeException: " + e);
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("queueCloseTest", e);
- }
-
- if (!pass) {
- throw new Exception("queueCloseTest failed");
- }
- }
-
- /*
- * @testName: topicReceiveTests
- *
- * @assertion_ids: JMS:JAVADOC:1102; JMS:JAVADOC:1104; JMS:JAVADOC:1106;
- *
- * @test_Strategy: Test the JMSConsumer receive API's. Tests the following
- * API's:
- *
- * JMSConsumer.receive() JMSConsumer.receive(long timeout)
- * JMSConsumer.receiveNoWait()
- *
- */
- public void topicReceiveTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up JmsTool for COMMON_T setup
- TestUtil.logMsg("Setup JmsTool for COMMON_T");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- topic = (Topic) destination;
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- queueTest = false;
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Create JMSProducer");
- producer = context.createProducer();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicReceiveTests");
- TestUtil.logMsg("Send and receive the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Call JMSConsumer.receive() to receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive();
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
-
- // send and receive TextMessage again
- TestUtil.logMsg("Send and receive the TextMessage again");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg(
- "Call JMSConsumer.receive(long timeout) to receive TextMessage");
- actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
-
- // send and receive TextMessage again
- TestUtil.logMsg("Send and receive the TextMessage again");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil
- .logMsg("Call JMSConsumer.receiveNoWait() to receive TextMessage");
- actTextMessage = (TextMessage) consumer.receiveNoWait();
- if (actTextMessage == null) {
- TestUtil.logMsg("Did not receive message (THIS IS OK)");
- TestUtil
- .logMsg("Now block and wait for message via JMSConsumer.receive()");
- actTextMessage = (TextMessage) consumer.receive();
- }
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage on blocking receive");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- TestUtil.logMsg("Now don't send a message at all");
- TestUtil.logMsg("Calling receiveNoWait() again to receive TextMessage");
- actTextMessage = (TextMessage) consumer.receiveNoWait();
- if (actTextMessage != null) {
- TestUtil
- .logErr("actTextMessage != NULL (expected actTextMessage=NULL)");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("topicReceiveTests", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicReceiveTests failed");
- }
- }
-
- /*
- * @testName: topicReceiveBodyTests
- *
- * @assertion_ids: JMS:JAVADOC:1369; JMS:JAVADOC:1372; JMS:JAVADOC:1375;
- *
- * @test_Strategy: Send and receive messages of the following types:
- * BytesMessage, MapMessage, ObjectMessage, TextMessage. Test the following
- * API's: JMSConsumer.receiveBody(Class), JMSConsumer.receiveBody(Class,
- * long), and JMSConsumer.recieveBodyNoWait(Class)
- *
- * T = JMSConsumer.receiveBody(Class) T =
- * JMSConsumer.receiveBody(Class, long) T =
- * JMSConsumer.receiveBodyNoWait(Class)
- *
- * Test the following:
- *
- * String message = JMSConsumer.receiveBody(String.class) StringBuffer message
- * = JMSConsumer.receiveBody(StringBuffer.class, long); byte[] message =
- * JMSConsumer.receiveBody(byte[].class, long); Map message =
- * JMSConsumer.receiveBodyNoWait(Map.class);
- *
- */
- public void topicReceiveBodyTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- StringBuffer expSbuffer = new StringBuffer("This is it!");
- try {
- // set up JmsTool for COMMON_T setup
- TestUtil.logMsg("Setup JmsTool for COMMON_T");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- topic = (Topic) destination;
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- queueTest = false;
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Create JMSProducer");
- producer = context.createProducer();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicReceiveBodyTests");
- TestUtil.logMsg("Send and receive the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody(String.class) to receive message as a String");
- String actMessage = consumer.receiveBody(String.class);
- if (actMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in String");
- if (actMessage.equals(message)) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect expected " + message
- + ", received " + actMessage);
- pass = false;
- }
-
- // Send and receive ObjectMessage
- TestUtil.logMsg("Create ObjectMessage");
- ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
- TestUtil.logMsg("Set some values in ObjectMessage");
- expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicReceiveBodyTests");
- TestUtil.logMsg("Send and receive the ObjectMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expObjectMessage);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody(StringBuffer.class, long) to receive message as a StringBuffer");
- StringBuffer actSbuffer = consumer.receiveBody(StringBuffer.class,
- timeout);
- if (actSbuffer == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- TestUtil.logMsg("Check the value in StringBuffer");
- if (actSbuffer.toString().equals(expSbuffer.toString())) {
- TestUtil.logMsg("ObjectMessage is correct");
- } else {
- TestUtil.logErr("ObjectMessage is incorrect expected " + expSbuffer
- + ", received " + actSbuffer);
- pass = false;
- }
-
- // Send and receive BytesMessage
- TestUtil.logMsg("Create BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveBodyTests");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- TestUtil.logMsg("Send and receive the BytesMessage");
- producer.send(destination, bMsg);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody(byte[].class, long) to receive message as a byte array");
- byte[] bytes = consumer.receiveBody(byte[].class, timeout);
- if (bytes == null) {
- throw new Exception("Did not receive BytesMessage");
- } else {
- try {
- DataInputStream di = new DataInputStream(
- new ByteArrayInputStream(bytes));
- TestUtil.logMsg("Check the values in BytesMessage");
- if (di.readByte() == (byte) 1) {
- TestUtil.logMsg("bytevalue is correct");
- } else {
- TestUtil.logMsg("bytevalue is incorrect");
- pass = false;
- }
- if (di.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- try {
- byte b = di.readByte();
- } catch (EOFException e) {
- TestUtil.logMsg("Caught expected EOFException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- }
-
- // Send and receive MapMessage
- TestUtil.logMsg("Create MapMessage");
- MapMessage mMsg = context.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveBodyTests");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- TestUtil.logMsg("Send and receive the MapMessage");
- producer.send(destination, mMsg);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBodyNoWait(Map.class) to receive message as a Map");
- Map map = consumer.receiveBodyNoWait(Map.class);
- if (map == null) {
- for (int i = 0; i < 5; i++) {
- TestUtil.sleepSec(1);
- map = consumer.receiveBodyNoWait(Map.class);
- if (map != null)
- break;
- }
- }
- if (map == null) {
- TestUtil.logErr("Did not receive MapMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in MapMessage");
- TestUtil.logMsg("map.size()=" + map.size());
- if (map.size() != 2) {
- TestUtil.logErr("Map size is " + map.size() + ", expected 2");
- pass = false;
- }
- Iterator it = map.keySet().iterator();
- String name = null;
- while (it.hasNext()) {
- name = (String) it.next();
- if (name.equals("booleanvalue")) {
- if ((boolean) map.get(name) == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logErr("booleanvalue is incorrect");
- pass = false;
- }
- } else if (name.equals("intvalue")) {
- if ((int) map.get(name) == 10) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logErr("intvalue is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Unexpected name of [" + name + "] in MapMessage");
- pass = false;
- }
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("topicReceiveBodyTests", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicReceiveBodyTests failed");
- }
- }
-
- /*
- * @testName: topicReceiveBodyExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1371; JMS:JAVADOC:1374; JMS:JAVADOC:1377;
- *
- * @test_Strategy: Test exception cases for JMSConsumer.receiveBody(Class),
- * JMSConsumer.receiveBody(Class, long), and
- * JMSConsumer.recieveBodyNoWait(Class).
- *
- * Test for exception MessageFormatRuntimeException.
- *
- */
- public void topicReceiveBodyExceptionTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- StringBuffer expSbuffer = new StringBuffer("This is it!");
- try {
- // set up JmsTool for COMMON_T setup
- TestUtil.logMsg("Setup JmsTool for COMMON_T");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- topic = (Topic) destination;
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- queueTest = false;
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Create JMSProducer");
- producer = context.createProducer();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicReceiveBodyExceptionTests");
- TestUtil.logMsg("Send and receive the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody(Class) to receive message as wrong type");
- TestUtil.logMsg(
- "Pass Boolean.class as parameter to receiveBody() expect MessageFormatRuntimeException");
- try {
- consumer.receiveBody(Boolean.class);
- TestUtil.logErr("Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive ObjectMessage
- TestUtil.logMsg("Create ObjectMessage of type StringBuffer");
- ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
- TestUtil.logMsg("Set some values in ObjectMessage");
- expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicReceiveBodyExceptionTests");
- TestUtil.logMsg("Send and receive the ObjectMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expObjectMessage);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody(Class) to receive message as wrong type");
- TestUtil.logMsg(
- "Pass HashMap.class as parameter to receiveBody() expect MessageFormatRuntimeException");
- try {
- consumer.receiveBody(Boolean.class);
- TestUtil.logErr("Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive BytesMessage
- TestUtil.logMsg("Create BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicReceiveBodyExceptionTests");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- TestUtil.logMsg("Send and receive the BytesMessage");
- producer.send(destination, bMsg);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBodyNoWait(Class) to receive message as wrong type");
- TestUtil.logMsg(
- "Pass Boolean.class as parameter to receiveBodyNoWait() expect MessageFormatRuntimeException");
- try {
- for (int i = 0; i < 5; i++) {
- TestUtil.sleepSec(1);
- if (consumer.receiveBodyNoWait(Boolean.class) != null)
- break;
- }
- TestUtil.logErr("Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive MapMessage
- TestUtil.logMsg("Send MapMessage");
- MapMessage mMsg = context.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicReceiveBodyExceptionTests");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- producer.send(destination, mMsg);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody(Map.class, long) to receive message as wrong type");
- TestUtil.logMsg(
- "Pass Boolean.class as parameter to receiveBody() expect MessageFormatRuntimeException");
- try {
- consumer.receiveBody(Boolean.class, timeout);
- TestUtil.logErr("Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // send and receive StreamMessage
- TestUtil.logMsg("Send StreamMessage");
- StreamMessage sMsg = context.createStreamMessage();
- TestUtil.logMsg("Set some values in StreamMessage");
- sMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicReceiveBodyExceptionTests");
- sMsg.writeBoolean(true);
- sMsg.writeInt((int) 22);
- producer.send(destination, sMsg);
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody() on a StreamMessage expect MessageFormatRuntimeException");
- try {
- consumer.receiveBody(Boolean.class, timeout);
- TestUtil.logErr("Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // send and receive Message
- TestUtil.logMsg("Send Message");
- Message msg = context.createMessage();
- TestUtil.logMsg("Set some values in Message");
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicReceiveBodyExceptionTests");
- msg.setBooleanProperty("booleanProperty", true);
- producer.send(destination, msg);
- long deliveryTime = msg.getJMSDeliveryTime();
- TestUtil.logMsg(
- "Call JMSConsumer.receiveBody() on a Message expect MessageFormatRuntimeException");
- try {
- consumer.receiveBody(Boolean.class, timeout);
- TestUtil.logErr("Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("topicReceiveBodyExceptionTests", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicReceiveBodyExceptionTests failed");
- }
- }
-
- /*
- * @testName: topicGetMessageSelectorTest
- *
- * @assertion_ids: JMS:JAVADOC:1100;
- *
- * @test_Strategy: Test the JMSConsumer getMessageSelector API:
- *
- * JMSConsumer.getMessageSelector()
- *
- */
- public void topicGetMessageSelectorTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up JmsTool for COMMON_T setup
- TestUtil.logMsg("Setup JmsTool for COMMON_T");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- topic = (Topic) destination;
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- queueTest = false;
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Create JMSProducer");
- producer = context.createProducer();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Get Message selector expression
- TestUtil.logMsg(
- "Get message selector expression by calling getMessageSelector() API");
- String msgsel = consumer.getMessageSelector();
-
- TestUtil.logMsg(
- "Expecting message selector to be NULL since we didn't set it");
- if (msgsel != null) {
- TestUtil.logErr("Message selector is NOT NULL (unexpected): , expected NULL");
- pass = false;
- }
- consumer.close();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg(
- "Create JMSConsumer with message selector 'lastMessage = TRUE'");
- consumer = context.createConsumer(destination, "lastMessage = TRUE");
-
- // Get Message selector expression
- TestUtil.logMsg(
- "Get message selector expression by calling getMessageSelector() API");
- msgsel = consumer.getMessageSelector();
-
- TestUtil.logMsg(
- "Expecting message selector to be NOT NULL since we set it to 'lastMessage = TRUE'");
- if (msgsel == null) {
- TestUtil.logErr(
- "Message selector is NULL (unexpected): , expected 'lastMessage = TRUE'");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("topicGetMessageSelectorTest", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicGetMessageSelectorTest failed");
- }
- }
-
- /*
- * @testName: topicCloseTest
- *
- * @assertion_ids: JMS:JAVADOC:1098;
- *
- * @test_Strategy: Test the JMSConsumer close API.
- *
- * JMSConsumer.close()
- *
- */
- public void topicCloseTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up JmsTool for COMMON_T setup
- TestUtil.logMsg("Setup JmsTool for COMMON_T");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- topic = (Topic) destination;
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- queueTest = false;
-
- // Create JMSProducer from JMSContext
- TestUtil.logMsg("Create JMSProducer");
- producer = context.createProducer();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg("Create JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // send TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicCloseTest");
- TestUtil.logMsg("Send the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
-
- TestUtil.logMsg("Close the JMSConsumer");
- consumer.close();
-
- TestUtil.logMsg(
- "Try receiving a message on a closed JMSConsumer (expect JMSRuntimeException or no message)");
- try {
- TextMessage actTextMessage = (TextMessage) consumer.receive();
- if (actTextMessage != null) {
- TestUtil.logErr("Received a message (expected no message), ");
- pass = false;
- } else {
- TestUtil.logMsg("Did not receive a message (correct)");
- }
- } catch (JMSRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeException: " + e);
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("topicCloseTest", e);
- }
-
- if (!pass) {
- throw new Exception("topicCloseTest failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsconsumertests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsconsumertests/ClientIT.java
new file mode 100644
index 0000000000..a344409090
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsconsumertests/ClientIT.java
@@ -0,0 +1,1494 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.jmsconsumertests;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.EOFException;
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.Destination;
+import jakarta.jms.JMSConsumer;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSProducer;
+import jakarta.jms.JMSRuntimeException;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.MessageFormatRuntimeException;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.Queue;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.jmsconsumertests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null;
+
+ // JMS objects
+ private transient ConnectionFactory cf = null;
+
+ private transient Queue queue = null;
+
+ private transient Topic topic = null;
+
+ private transient Destination destination = null;
+
+ private transient JMSContext context = null;
+
+ private transient JMSConsumer consumer = null;
+
+ private transient JMSProducer producer = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ boolean queueTest = false;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(3);
+ connections = new ArrayList(5);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Close JMSContext");
+ if (context != null)
+ context.close();
+ if (queueTest) {
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ tool.flushDestination();
+ }
+ logger.log(Logger.Level.INFO, "Close all connections and resources");
+ tool.closeAllConnections(connections);
+ tool.closeAllResources();
+ producer = null;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: queueReceiveTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1102; JMS:JAVADOC:1104; JMS:JAVADOC:1106;
+ *
+ * @test_Strategy: Test the JMSConsumer receive API's. Tests the following
+ * API's:
+ *
+ * JMSConsumer.receive() JMSConsumer.receive(long timeout)
+ * JMSConsumer.receiveNoWait()
+ *
+ */
+ @Test
+ public void queueReceiveTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up JmsTool for COMMON_Q setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_Q");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ queue = (Queue) destination;
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ queueTest = true;
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSProducer");
+ producer = context.createProducer();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveTests");
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive() to receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive();
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+
+ // send and receive TextMessage again
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage again");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long timeout) to receive TextMessage");
+ actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+
+ // send and receive TextMessage again
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage again");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receiveNoWait() to receive TextMessage");
+ actTextMessage = (TextMessage) consumer.receiveNoWait();
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.INFO, "Did not receive message (THIS IS OK)");
+ logger.log(Logger.Level.INFO, "Now block and wait for message via JMSConsumer.receive()");
+ actTextMessage = (TextMessage) consumer.receive();
+ }
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage on blocking receive");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Now don't send a message at all");
+ logger.log(Logger.Level.INFO, "Calling receiveNoWait() again to receive TextMessage");
+ actTextMessage = (TextMessage) consumer.receiveNoWait();
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "actTextMessage != NULL (expected actTextMessage=NULL)");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueReceiveTests", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueReceiveTests failed");
+ }
+ }
+
+ /*
+ * @testName: queueReceiveBodyTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1369; JMS:JAVADOC:1372; JMS:JAVADOC:1375;
+ *
+ * @test_Strategy: Send and receive messages of the following types:
+ * BytesMessage, MapMessage, ObjectMessage, TextMessage. Test the following
+ * API's: JMSConsumer.receiveBody(Class), JMSConsumer.receiveBody(Class,
+ * long), and JMSConsumer.recieveBodyNoWait(Class)
+ *
+ * T = JMSConsumer.receiveBody(Class) T =
+ * JMSConsumer.receiveBody(Class, long) T =
+ * JMSConsumer.receiveBodyNoWait(Class)
+ *
+ * Test the following:
+ *
+ * String message = JMSConsumer.receiveBody(String.class) StringBuffer message =
+ * JMSConsumer.receiveBody(StringBuffer.class, long); byte[] message =
+ * JMSConsumer.receiveBody(byte[].class, long); Map message =
+ * JMSConsumer.receiveBodyNoWait(Map.class);
+ *
+ */
+ @Test
+ public void queueReceiveBodyTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ StringBuffer expSbuffer = new StringBuffer("This is it!");
+ try {
+ // set up JmsTool for COMMON_Q setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_Q");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ queue = (Queue) destination;
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ queueTest = true;
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSProducer");
+ producer = context.createProducer();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveBodyTests");
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receiveBody(String.class) to receive message as a String");
+ String actMessage = consumer.receiveBody(String.class);
+ if (actMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in String");
+ if (actMessage.equals(message)) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "TextMessage is incorrect expected " + message + ", received " + actMessage);
+ pass = false;
+ }
+
+ // Send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Create ObjectMessage");
+ ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveBodyTests");
+ logger.log(Logger.Level.INFO, "Send and receive the ObjectMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expObjectMessage);
+ logger.log(Logger.Level.INFO,
+ "Call JMSConsumer.receiveBody(StringBuffer.class, long) to receive message as a StringBuffer");
+ StringBuffer actSbuffer = consumer.receiveBody(StringBuffer.class, timeout);
+ if (actSbuffer == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in StringBuffer");
+ if (actSbuffer.toString().equals(expSbuffer.toString())) {
+ logger.log(Logger.Level.INFO, "ObjectMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "ObjectMessage is incorrect expected " + expSbuffer + ", received " + actSbuffer);
+ pass = false;
+ }
+
+ // Send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Create BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveBodyTests");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ logger.log(Logger.Level.INFO, "Send and receive the BytesMessage");
+ producer.send(destination, bMsg);
+ logger.log(Logger.Level.INFO,
+ "Call JMSConsumer.receiveBody(byte[].class, long) to receive message as a byte array");
+ byte[] bytes = consumer.receiveBody(byte[].class, timeout);
+ if (bytes == null) {
+ throw new Exception("Did not receive BytesMessage");
+ } else {
+ try {
+ DataInputStream di = new DataInputStream(new ByteArrayInputStream(bytes));
+ logger.log(Logger.Level.INFO, "Check the values in BytesMessage");
+ if (di.readByte() == (byte) 1) {
+ logger.log(Logger.Level.INFO, "bytevalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "bytevalue is incorrect");
+ pass = false;
+ }
+ if (di.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ try {
+ byte b = di.readByte();
+ } catch (EOFException e) {
+ logger.log(Logger.Level.INFO, "Caught expected EOFException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ }
+
+ // Send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Create MapMessage");
+ MapMessage mMsg = context.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveBodyTests");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ logger.log(Logger.Level.INFO, "Send and receive the MapMessage");
+ producer.send(destination, mMsg);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receiveBodyNoWait(Map.class) to receive message as a Map");
+ Map map = consumer.receiveBodyNoWait(Map.class);
+ if (map == null) {
+ for (int i = 0; i < 5; i++) {
+ TestUtil.sleepSec(1);
+ map = consumer.receiveBodyNoWait(Map.class);
+ if (map != null)
+ break;
+ }
+ }
+ if (map == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive MapMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in MapMessage");
+ logger.log(Logger.Level.INFO, "map.size()=" + map.size());
+ if (map.size() != 2) {
+ logger.log(Logger.Level.ERROR, "Map size is " + map.size() + ", expected 2");
+ pass = false;
+ }
+ Iterator it = map.keySet().iterator();
+ String name = null;
+ while (it.hasNext()) {
+ name = (String) it.next();
+ if (name.equals("booleanvalue")) {
+ if ((boolean) map.get(name) == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "booleanvalue is incorrect");
+ pass = false;
+ }
+ } else if (name.equals("intvalue")) {
+ if ((int) map.get(name) == 10) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "intvalue is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected name of [" + name + "] in MapMessage");
+ pass = false;
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueReceiveBodyTests", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueReceiveBodyTests failed");
+ }
+ }
+
+ /*
+ * @testName: queueReceiveBodyExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1371; JMS:JAVADOC:1374; JMS:JAVADOC:1377;
+ *
+ * @test_Strategy: Test exception cases for JMSConsumer.receiveBody(Class),
+ * JMSConsumer.receiveBody(Class, long), and
+ * JMSConsumer.recieveBodyNoWait(Class).
+ *
+ * Test for exception MessageFormatRuntimeException.
+ *
+ */
+ @Test
+ public void queueReceiveBodyExceptionTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ StringBuffer expSbuffer = new StringBuffer("This is it!");
+ try {
+ // set up JmsTool for COMMON_Q setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_Q");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ queue = (Queue) destination;
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ queueTest = true;
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSProducer");
+ producer = context.createProducer();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveBodyExceptionTests");
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receiveBody(Class) to receive message as wrong type");
+ logger.log(Logger.Level.INFO,
+ "Pass Boolean.class as parameter to receiveBody() expect MessageFormatRuntimeException");
+ try {
+ consumer.receiveBody(Boolean.class);
+ logger.log(Logger.Level.ERROR, "Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Create ObjectMessage of type StringBuffer");
+ ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveBodyExceptionTests");
+ logger.log(Logger.Level.INFO, "Send and receive the ObjectMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expObjectMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receiveBody(Class) to receive message as wrong type");
+ logger.log(Logger.Level.INFO,
+ "Pass HashMap.class as parameter to receiveBody() expect MessageFormatRuntimeException");
+ try {
+ consumer.receiveBody(Boolean.class);
+ logger.log(Logger.Level.ERROR, "Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Create BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveBodyExceptionTests");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ logger.log(Logger.Level.INFO, "Send and receive the BytesMessage");
+ producer.send(destination, bMsg);
+ logger.log(Logger.Level.INFO,
+ "Call JMSConsumer.receiveBodyNoWait(Class) to receive message as wrong type");
+ logger.log(Logger.Level.INFO,
+ "Pass Boolean.class as parameter to receiveBodyNoWait() expect MessageFormatRuntimeException");
+ try {
+ for (int i = 0; i < 5; i++) {
+ TestUtil.sleepSec(1);
+ if (consumer.receiveBodyNoWait(Boolean.class) != null)
+ break;
+ }
+ logger.log(Logger.Level.ERROR, "Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send MapMessage");
+ MapMessage mMsg = context.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveBodyExceptionTests");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ producer.send(destination, mMsg);
+ logger.log(Logger.Level.INFO,
+ "Call JMSConsumer.receiveBody(Map.class, long) to receive message as wrong type");
+ logger.log(Logger.Level.INFO,
+ "Pass Boolean.class as parameter to receiveBody() expect MessageFormatRuntimeException");
+ try {
+ consumer.receiveBody(Boolean.class, timeout);
+ logger.log(Logger.Level.ERROR, "Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // send and receive StreamMessage
+ logger.log(Logger.Level.INFO, "Send StreamMessage");
+ StreamMessage sMsg = context.createStreamMessage();
+ logger.log(Logger.Level.INFO, "Set some values in StreamMessage");
+ sMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveBodyExceptionTests");
+ sMsg.writeBoolean(true);
+ sMsg.writeInt((int) 22);
+ producer.send(destination, sMsg);
+ logger.log(Logger.Level.INFO,
+ "Call JMSConsumer.receiveBody() on a StreamMessage expect MessageFormatRuntimeException");
+ try {
+ consumer.receiveBody(Boolean.class, timeout);
+ logger.log(Logger.Level.ERROR, "Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // send and receive Message
+ logger.log(Logger.Level.INFO, "Send Message");
+ Message msg = context.createMessage();
+ logger.log(Logger.Level.INFO, "Set some values in Message");
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "queueReceiveBodyExceptionTests");
+ msg.setBooleanProperty("booleanProperty", true);
+ producer.send(destination, msg);
+ long deliveryTime = msg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO,
+ "Call JMSConsumer.receiveBody() on a Message expect MessageFormatRuntimeException");
+ try {
+ consumer.receiveBody(Boolean.class, timeout);
+ logger.log(Logger.Level.ERROR, "Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueReceiveBodyExceptionTests", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueReceiveBodyExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: queueGetMessageSelectorTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1100;
+ *
+ * @test_Strategy: Test the JMSConsumer getMessageSelector API:
+ *
+ * JMSConsumer.getMessageSelector()
+ *
+ */
+ @Test
+ public void queueGetMessageSelectorTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up JmsTool for COMMON_Q setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_Q");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ queue = (Queue) destination;
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ queueTest = true;
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSProducer");
+ producer = context.createProducer();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Get Message selector expression
+ logger.log(Logger.Level.INFO, "Get message selector expression by calling getMessageSelector() API");
+ String msgsel = consumer.getMessageSelector();
+
+ logger.log(Logger.Level.INFO, "Expecting message selector to be NULL since we didn't set it");
+ if (msgsel != null) {
+ logger.log(Logger.Level.ERROR,
+ "Message selector is NOT NULL (unexpected): , expected NULL");
+ pass = false;
+ }
+ consumer.close();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer with message selector 'lastMessage = TRUE'");
+ consumer = context.createConsumer(destination, "lastMessage = TRUE");
+
+ // Get Message selector expression
+ logger.log(Logger.Level.INFO, "Get message selector expression by calling getMessageSelector() API");
+ msgsel = consumer.getMessageSelector();
+
+ logger.log(Logger.Level.INFO,
+ "Expecting message selector to be NOT NULL since we set it to 'lastMessage = TRUE'");
+ if (msgsel == null) {
+ logger.log(Logger.Level.ERROR,
+ "Message selector is NULL (unexpected): , expected 'lastMessage = TRUE'");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueGetMessageSelectorTest", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueGetMessageSelectorTest failed");
+ }
+ }
+
+ /*
+ * @testName: queueCloseTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1098;
+ *
+ * @test_Strategy: Test the JMSConsumer close API.
+ *
+ * JMSConsumer.close()
+ *
+ */
+ @Test
+ public void queueCloseTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up JmsTool for COMMON_Q setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_Q");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ queue = (Queue) destination;
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ queueTest = true;
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSProducer");
+ producer = context.createProducer();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // send TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueCloseTest");
+ logger.log(Logger.Level.INFO, "Send the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+
+ logger.log(Logger.Level.INFO, "Close the JMSConsumer");
+ consumer.close();
+
+ logger.log(Logger.Level.INFO,
+ "Try receiving a message on a closed JMSConsumer (expect JMSRuntimeException or no message)");
+ try {
+ TextMessage actTextMessage = (TextMessage) consumer.receive();
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR,
+ "Received a message (expected no message), ");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Did not receive a message (correct)");
+ }
+ } catch (JMSRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeException: " + e);
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("queueCloseTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("queueCloseTest failed");
+ }
+ }
+
+ /*
+ * @testName: topicReceiveTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1102; JMS:JAVADOC:1104; JMS:JAVADOC:1106;
+ *
+ * @test_Strategy: Test the JMSConsumer receive API's. Tests the following
+ * API's:
+ *
+ * JMSConsumer.receive() JMSConsumer.receive(long timeout)
+ * JMSConsumer.receiveNoWait()
+ *
+ */
+ @Test
+ public void topicReceiveTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up JmsTool for COMMON_T setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_T");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ topic = (Topic) destination;
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ queueTest = false;
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSProducer");
+ producer = context.createProducer();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveTests");
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive() to receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive();
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+
+ // send and receive TextMessage again
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage again");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long timeout) to receive TextMessage");
+ actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+
+ // send and receive TextMessage again
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage again");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receiveNoWait() to receive TextMessage");
+ actTextMessage = (TextMessage) consumer.receiveNoWait();
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.INFO, "Did not receive message (THIS IS OK)");
+ logger.log(Logger.Level.INFO, "Now block and wait for message via JMSConsumer.receive()");
+ actTextMessage = (TextMessage) consumer.receive();
+ }
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage on blocking receive");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Now don't send a message at all");
+ logger.log(Logger.Level.INFO, "Calling receiveNoWait() again to receive TextMessage");
+ actTextMessage = (TextMessage) consumer.receiveNoWait();
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "actTextMessage != NULL (expected actTextMessage=NULL)");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicReceiveTests", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicReceiveTests failed");
+ }
+ }
+
+ /*
+ * @testName: topicReceiveBodyTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1369; JMS:JAVADOC:1372; JMS:JAVADOC:1375;
+ *
+ * @test_Strategy: Send and receive messages of the following types:
+ * BytesMessage, MapMessage, ObjectMessage, TextMessage. Test the following
+ * API's: JMSConsumer.receiveBody(Class), JMSConsumer.receiveBody(Class,
+ * long), and JMSConsumer.recieveBodyNoWait(Class)
+ *
+ * T = JMSConsumer.receiveBody(Class) T =
+ * JMSConsumer.receiveBody(Class, long) T =
+ * JMSConsumer.receiveBodyNoWait(Class)
+ *
+ * Test the following:
+ *
+ * String message = JMSConsumer.receiveBody(String.class) StringBuffer message =
+ * JMSConsumer.receiveBody(StringBuffer.class, long); byte[] message =
+ * JMSConsumer.receiveBody(byte[].class, long); Map message =
+ * JMSConsumer.receiveBodyNoWait(Map.class);
+ *
+ */
+ @Test
+ public void topicReceiveBodyTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ StringBuffer expSbuffer = new StringBuffer("This is it!");
+ try {
+ // set up JmsTool for COMMON_T setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_T");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ topic = (Topic) destination;
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ queueTest = false;
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSProducer");
+ producer = context.createProducer();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveBodyTests");
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receiveBody(String.class) to receive message as a String");
+ String actMessage = consumer.receiveBody(String.class);
+ if (actMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in String");
+ if (actMessage.equals(message)) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "TextMessage is incorrect expected " + message + ", received " + actMessage);
+ pass = false;
+ }
+
+ // Send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Create ObjectMessage");
+ ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveBodyTests");
+ logger.log(Logger.Level.INFO, "Send and receive the ObjectMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expObjectMessage);
+ logger.log(Logger.Level.INFO,
+ "Call JMSConsumer.receiveBody(StringBuffer.class, long) to receive message as a StringBuffer");
+ StringBuffer actSbuffer = consumer.receiveBody(StringBuffer.class, timeout);
+ if (actSbuffer == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in StringBuffer");
+ if (actSbuffer.toString().equals(expSbuffer.toString())) {
+ logger.log(Logger.Level.INFO, "ObjectMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "ObjectMessage is incorrect expected " + expSbuffer + ", received " + actSbuffer);
+ pass = false;
+ }
+
+ // Send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Create BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveBodyTests");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ logger.log(Logger.Level.INFO, "Send and receive the BytesMessage");
+ producer.send(destination, bMsg);
+ logger.log(Logger.Level.INFO,
+ "Call JMSConsumer.receiveBody(byte[].class, long) to receive message as a byte array");
+ byte[] bytes = consumer.receiveBody(byte[].class, timeout);
+ if (bytes == null) {
+ throw new Exception("Did not receive BytesMessage");
+ } else {
+ try {
+ DataInputStream di = new DataInputStream(new ByteArrayInputStream(bytes));
+ logger.log(Logger.Level.INFO, "Check the values in BytesMessage");
+ if (di.readByte() == (byte) 1) {
+ logger.log(Logger.Level.INFO, "bytevalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "bytevalue is incorrect");
+ pass = false;
+ }
+ if (di.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ try {
+ byte b = di.readByte();
+ } catch (EOFException e) {
+ logger.log(Logger.Level.INFO, "Caught expected EOFException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ }
+
+ // Send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Create MapMessage");
+ MapMessage mMsg = context.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveBodyTests");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ logger.log(Logger.Level.INFO, "Send and receive the MapMessage");
+ producer.send(destination, mMsg);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receiveBodyNoWait(Map.class) to receive message as a Map");
+ Map map = consumer.receiveBodyNoWait(Map.class);
+ if (map == null) {
+ for (int i = 0; i < 5; i++) {
+ TestUtil.sleepSec(1);
+ map = consumer.receiveBodyNoWait(Map.class);
+ if (map != null)
+ break;
+ }
+ }
+ if (map == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive MapMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in MapMessage");
+ logger.log(Logger.Level.INFO, "map.size()=" + map.size());
+ if (map.size() != 2) {
+ logger.log(Logger.Level.ERROR, "Map size is " + map.size() + ", expected 2");
+ pass = false;
+ }
+ Iterator it = map.keySet().iterator();
+ String name = null;
+ while (it.hasNext()) {
+ name = (String) it.next();
+ if (name.equals("booleanvalue")) {
+ if ((boolean) map.get(name) == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "booleanvalue is incorrect");
+ pass = false;
+ }
+ } else if (name.equals("intvalue")) {
+ if ((int) map.get(name) == 10) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "intvalue is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected name of [" + name + "] in MapMessage");
+ pass = false;
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicReceiveBodyTests", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicReceiveBodyTests failed");
+ }
+ }
+
+ /*
+ * @testName: topicReceiveBodyExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1371; JMS:JAVADOC:1374; JMS:JAVADOC:1377;
+ *
+ * @test_Strategy: Test exception cases for JMSConsumer.receiveBody(Class),
+ * JMSConsumer.receiveBody(Class, long), and
+ * JMSConsumer.recieveBodyNoWait(Class).
+ *
+ * Test for exception MessageFormatRuntimeException.
+ *
+ */
+ @Test
+ public void topicReceiveBodyExceptionTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ StringBuffer expSbuffer = new StringBuffer("This is it!");
+ try {
+ // set up JmsTool for COMMON_T setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_T");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ topic = (Topic) destination;
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ queueTest = false;
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSProducer");
+ producer = context.createProducer();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveBodyExceptionTests");
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receiveBody(Class) to receive message as wrong type");
+ logger.log(Logger.Level.INFO,
+ "Pass Boolean.class as parameter to receiveBody() expect MessageFormatRuntimeException");
+ try {
+ consumer.receiveBody(Boolean.class);
+ logger.log(Logger.Level.ERROR, "Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Create ObjectMessage of type StringBuffer");
+ ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveBodyExceptionTests");
+ logger.log(Logger.Level.INFO, "Send and receive the ObjectMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expObjectMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receiveBody(Class) to receive message as wrong type");
+ logger.log(Logger.Level.INFO,
+ "Pass HashMap.class as parameter to receiveBody() expect MessageFormatRuntimeException");
+ try {
+ consumer.receiveBody(Boolean.class);
+ logger.log(Logger.Level.ERROR, "Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Create BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveBodyExceptionTests");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ logger.log(Logger.Level.INFO, "Send and receive the BytesMessage");
+ producer.send(destination, bMsg);
+ logger.log(Logger.Level.INFO,
+ "Call JMSConsumer.receiveBodyNoWait(Class) to receive message as wrong type");
+ logger.log(Logger.Level.INFO,
+ "Pass Boolean.class as parameter to receiveBodyNoWait() expect MessageFormatRuntimeException");
+ try {
+ for (int i = 0; i < 5; i++) {
+ TestUtil.sleepSec(1);
+ if (consumer.receiveBodyNoWait(Boolean.class) != null)
+ break;
+ }
+ logger.log(Logger.Level.ERROR, "Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send MapMessage");
+ MapMessage mMsg = context.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveBodyExceptionTests");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ producer.send(destination, mMsg);
+ logger.log(Logger.Level.INFO,
+ "Call JMSConsumer.receiveBody(Map.class, long) to receive message as wrong type");
+ logger.log(Logger.Level.INFO,
+ "Pass Boolean.class as parameter to receiveBody() expect MessageFormatRuntimeException");
+ try {
+ consumer.receiveBody(Boolean.class, timeout);
+ logger.log(Logger.Level.ERROR, "Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // send and receive StreamMessage
+ logger.log(Logger.Level.INFO, "Send StreamMessage");
+ StreamMessage sMsg = context.createStreamMessage();
+ logger.log(Logger.Level.INFO, "Set some values in StreamMessage");
+ sMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveBodyExceptionTests");
+ sMsg.writeBoolean(true);
+ sMsg.writeInt((int) 22);
+ producer.send(destination, sMsg);
+ logger.log(Logger.Level.INFO,
+ "Call JMSConsumer.receiveBody() on a StreamMessage expect MessageFormatRuntimeException");
+ try {
+ consumer.receiveBody(Boolean.class, timeout);
+ logger.log(Logger.Level.ERROR, "Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // send and receive Message
+ logger.log(Logger.Level.INFO, "Send Message");
+ Message msg = context.createMessage();
+ logger.log(Logger.Level.INFO, "Set some values in Message");
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "topicReceiveBodyExceptionTests");
+ msg.setBooleanProperty("booleanProperty", true);
+ producer.send(destination, msg);
+ long deliveryTime = msg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO,
+ "Call JMSConsumer.receiveBody() on a Message expect MessageFormatRuntimeException");
+ try {
+ consumer.receiveBody(Boolean.class, timeout);
+ logger.log(Logger.Level.ERROR, "Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicReceiveBodyExceptionTests", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicReceiveBodyExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: topicGetMessageSelectorTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1100;
+ *
+ * @test_Strategy: Test the JMSConsumer getMessageSelector API:
+ *
+ * JMSConsumer.getMessageSelector()
+ *
+ */
+ @Test
+ public void topicGetMessageSelectorTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up JmsTool for COMMON_T setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_T");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ topic = (Topic) destination;
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ queueTest = false;
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSProducer");
+ producer = context.createProducer();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Get Message selector expression
+ logger.log(Logger.Level.INFO, "Get message selector expression by calling getMessageSelector() API");
+ String msgsel = consumer.getMessageSelector();
+
+ logger.log(Logger.Level.INFO, "Expecting message selector to be NULL since we didn't set it");
+ if (msgsel != null) {
+ logger.log(Logger.Level.ERROR,
+ "Message selector is NOT NULL (unexpected): , expected NULL");
+ pass = false;
+ }
+ consumer.close();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer with message selector 'lastMessage = TRUE'");
+ consumer = context.createConsumer(destination, "lastMessage = TRUE");
+
+ // Get Message selector expression
+ logger.log(Logger.Level.INFO, "Get message selector expression by calling getMessageSelector() API");
+ msgsel = consumer.getMessageSelector();
+
+ logger.log(Logger.Level.INFO,
+ "Expecting message selector to be NOT NULL since we set it to 'lastMessage = TRUE'");
+ if (msgsel == null) {
+ logger.log(Logger.Level.ERROR,
+ "Message selector is NULL (unexpected): , expected 'lastMessage = TRUE'");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicGetMessageSelectorTest", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicGetMessageSelectorTest failed");
+ }
+ }
+
+ /*
+ * @testName: topicCloseTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1098;
+ *
+ * @test_Strategy: Test the JMSConsumer close API.
+ *
+ * JMSConsumer.close()
+ *
+ */
+ @Test
+ public void topicCloseTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up JmsTool for COMMON_T setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_T");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ topic = (Topic) destination;
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ queueTest = false;
+
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSProducer");
+ producer = context.createProducer();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // send TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicCloseTest");
+ logger.log(Logger.Level.INFO, "Send the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+
+ logger.log(Logger.Level.INFO, "Close the JMSConsumer");
+ consumer.close();
+
+ logger.log(Logger.Level.INFO,
+ "Try receiving a message on a closed JMSConsumer (expect JMSRuntimeException or no message)");
+ try {
+ TextMessage actTextMessage = (TextMessage) consumer.receive();
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR,
+ "Received a message (expected no message), ");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Did not receive a message (correct)");
+ }
+ } catch (JMSRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeException: " + e);
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("topicCloseTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("topicCloseTest failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmscontextqueuetests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmscontextqueuetests/Client.java
deleted file mode 100644
index 21dc6fef0e..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmscontextqueuetests/Client.java
+++ /dev/null
@@ -1,1329 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.jmscontextqueuetests;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.ConnectionMetaData;
-import jakarta.jms.Destination;
-import jakarta.jms.InvalidDestinationRuntimeException;
-import jakarta.jms.InvalidSelectorRuntimeException;
-import jakarta.jms.JMSConsumer;
-import jakarta.jms.JMSContext;
-import jakarta.jms.JMSException;
-import jakarta.jms.JMSProducer;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueBrowser;
-import jakarta.jms.TemporaryQueue;
-import jakarta.jms.TextMessage;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.jmscontextqueuetests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null;
-
- // JMS objects
- private transient ConnectionFactory cf = null;
-
- private transient Queue queue = null;
-
- private transient Destination destination = null;
-
- private transient JMSContext context = null;
-
- private transient JMSContext contextToSendMsg = null;
-
- private transient JMSProducer producer = null;
-
- private transient JMSConsumer consumer = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- String vehicle = null;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * helper method verifies that the ConnectionMetaData
- *
- * @param ConnectionMetaData returned from getJMSMessageID
- *
- * @return boolean true if ConnectionMetaData is as expected
- */
- private boolean verifyMetaData(ConnectionMetaData data) {
- boolean pass = true;
-
- try {
- String tmp = data.getJMSVersion();
- TestUtil.logMsg("JMSVersion=" + tmp);
-
- if (!tmp.equals(JmsTool.JMS_VERSION)) {
- TestUtil.logErr("Error: incorrect JMSVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getJMSMajorVersion();
- TestUtil.logMsg("JMSMajorVersion=" + tmp);
-
- if (tmp != JmsTool.JMS_MAJOR_VERSION) {
- TestUtil.logErr("Error: incorrect JMSMajorVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSMajorVersion: ",
- e);
- pass = false;
- }
-
- try {
- int tmp = data.getJMSMinorVersion();
- TestUtil.logMsg("JMSMinorVersion=" + tmp);
-
- if (tmp != JmsTool.JMS_MINOR_VERSION) {
- TestUtil.logErr("Error: incorrect JMSMinorVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSMinorVersion: ",
- e);
- pass = false;
- }
-
- try {
- String tmp = data.getJMSProviderName();
- TestUtil.logMsg("JMSProviderName=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSProviderName: ",
- e);
- pass = false;
- }
-
- try {
- String tmp = data.getProviderVersion();
- TestUtil.logMsg("JMSProviderVersion=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for ProviderVersion: ",
- e);
- pass = false;
- }
-
- try {
- int tmp = data.getProviderMajorVersion();
- TestUtil.logMsg("ProviderMajorVersion=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: incorrect type returned for ProviderMajorVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getProviderMinorVersion();
- TestUtil.logMsg("ProviderMinorVersion=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: incorrect type returned for ProviderMinorVersion: ", e);
- pass = false;
- }
- return pass;
- }
-
- /*
- * helper method verifies that the JMSMessageID starts with ID:
- *
- * @param String returned from getJMSMessageID
- *
- * @return boolean true if id correctly starts with ID:
- */
- private boolean chkMessageID(String id) {
- String status[] = { "Pass", "Fail" };
- boolean retcode = true;
-
- // message id must start with ID: - unless it is null
- int index = 0;
-
- if (id == null) {
- ;
- } else if (id.startsWith("ID:")) {
- ;
- } else {
- index = 1;
- retcode = false;
- }
- logMsg("Results: " + status[index]);
- return retcode;
- }
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- vehicle = p.getProperty("vehicle");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(3);
- connections = new ArrayList(5);
-
- // set up JmsTool for COMMON_Q setup
- TestUtil.logMsg("Setup JmsTool for COMMON_Q setup");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- cf = tool.getConnectionFactory();
- destination = tool.getDefaultDestination();
- queue = (Queue) destination;
- tool.getDefaultConnection().close();
- TestUtil.logMsg("Create JMSContext with AUTO_ACKNOWLEDGE");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- contextToSendMsg = cf.createContext(user, password,
- JMSContext.AUTO_ACKNOWLEDGE);
- producer = contextToSendMsg.createProducer();
- consumer = context.createConsumer(destination);
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("Close JMSContext Objects");
- if (context != null)
- context.close();
- context = null;
- if (contextToSendMsg != null)
- contextToSendMsg.close();
- contextToSendMsg = null;
- producer = null;
- TestUtil.logMsg("Flush any messages left on Queue");
- tool.flushDestination();
- TestUtil.logMsg("Close JMSConsumer objects");
- if (consumer != null)
- consumer.close();
- consumer = null;
- tool.closeAllResources();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
-
- if (!pass)
- throw new Exception("cleanup failed!");
- }
-
- /*
- * @testName: createTemporayQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:960;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.createTemporaryQueue()
- *
- * Send and receive a message to temporary queue. Compare send and recv
- * message for equality.
- */
- public void createTemporayQueueTest() throws Exception {
- boolean pass = true;
- try {
-
- String sendMessage = "a text message";
-
- // create a TemporaryQueue
- TestUtil.logMsg("Creating TemporaryQueue");
- TemporaryQueue tempQueue = context.createTemporaryQueue();
-
- // Create a JMSConsumer for this Temporary Queue
- TestUtil.logMsg("Create JMSConsumer");
- JMSConsumer smc = context.createConsumer(tempQueue);
-
- // Send message to temporary queue
- TestUtil.logMsg("Send message to temporaty queue using JMSProducer");
- producer.send(tempQueue, sendMessage);
-
- // Receive message from temporary queue
- TestUtil.logMsg("Receive message from temporaty queue");
- String recvMessage = smc.receiveBody(String.class, timeout);
-
- TestUtil.logMsg("Checking received message");
- if (recvMessage == null) {
- throw new Exception("Did not receive Message");
- }
-
- if (!recvMessage.equals(sendMessage)) {
- TestUtil.logErr("Unexpected message: received " + recvMessage
- + " , expected " + sendMessage);
- pass = false;
- } else {
- TestUtil.logMsg(
- "received correct message: " + recvMessage + " as expected");
- }
-
- TestUtil.logMsg(
- "Attempting to delete temporary queue with an open consumer should not be allowed");
- try {
- tempQueue.delete();
- pass = false;
- TestUtil
- .logErr("TemporaryQueue.delete() didn't throw expected Exception");
- } catch (JMSException em) {
- TestUtil.logMsg("Received expected JMSException: ");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- TestUtil.logMsg("Close JMSConsumer");
- smc.close();
-
- TestUtil.logMsg(
- "Attempting to delete temporary queue with no open consumer should be allowed");
- try {
- tempQueue.delete();
- } catch (Exception e) {
- pass = false;
- TestUtil.logErr("Received unexpected Exception: ", e);
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("createTemporayQueueTest");
- }
-
- if (!pass) {
- throw new Exception("createTemporayQueueTest failed");
- }
- }
-
- /*
- * @testName: createQueueBrowserTest
- *
- * @assertion_ids: JMS:JAVADOC:918; JMS:JAVADOC:921;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.createBrowser(Queue) JMSContext.createBrowser(Queue, String)
- *
- * 1. Send x text messages to a Queue. 2. Create a QueueBrowser with selector
- * to browse just the last message in the Queue. 3. Create a QueueBrowser
- * again to browse all the messages in the queue.
- */
- public void createQueueBrowserTest() throws Exception {
- boolean pass = true;
- try {
- TextMessage tempMsg = null;
- QueueBrowser qBrowser = null;
- Enumeration msgs = null;
-
- // Close consumer created in setup() method
- consumer.close();
- consumer = null;
-
- // send "numMessages" messages to Queue plus end of stream message
- TestUtil.logMsg("Send " + numMessages + " messages to Queue");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createQueueBrowserTest" + i);
- String tmp = null;
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- tmp = "with boolean property lastMessage=true";
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- tmp = "with boolean property lastMessage=false";
- }
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent " + tmp);
- }
-
- // create QueueBrowser to peek at last message in Queue using message
- // selector
- TestUtil.logMsg(
- "Create QueueBrowser to peek at last message in Queue using message selector (lastMessage = TRUE)");
- qBrowser = context.createBrowser(queue, "lastMessage = TRUE");
-
- // check that browser just has the last message in the Queue
- TestUtil.logMsg("Check that browser has just the last message");
- int msgCount = 0;
- msgs = qBrowser.getEnumeration();
- while (msgs.hasMoreElements()) {
- tempMsg = (TextMessage) msgs.nextElement();
- TestUtil.logMsg("Text=" + tempMsg.getText() + ", lastMessage="
- + tempMsg.getBooleanProperty("lastMessage"));
- if (!tempMsg.getText().equals("Message " + numMessages)) {
- TestUtil.logErr("Found [" + tempMsg.getText()
- + "] in browser expected only [Message 3]");
- pass = false;
- } else {
- TestUtil.logMsg("Found [Message " + numMessages + "] in browser");
- }
- msgCount++;
- }
- if (msgCount != 1) {
- TestUtil
- .logErr("Found " + msgCount + " messages in browser expected 1");
- pass = false;
- } else {
- TestUtil.logMsg("Found 1 message in browser (correct)");
- }
- qBrowser.close();
-
- // create QueueBrowser to peek at all messages in the Queue
- TestUtil
- .logMsg("Create QueueBrowser to browse all messages in the Queue");
- qBrowser = context.createBrowser(queue);
-
- // check for messages
- TestUtil.logMsg(
- "Check that browser contains all " + numMessages + " messages");
- msgCount = 0;
- int msgIndex = 1;
- msgs = qBrowser.getEnumeration();
- while (msgs.hasMoreElements()) {
- tempMsg = (TextMessage) msgs.nextElement();
- if (!tempMsg.getText().equals("Message " + msgIndex)) {
- TestUtil.logErr("Found [" + tempMsg.getText()
- + "] in browser expected [Message " + msgIndex + "]");
- pass = false;
- } else {
- TestUtil
- .logMsg("Found [Message " + msgIndex + "] in browser (correct)");
- }
- msgCount++;
- msgIndex++;
- }
- if (msgCount != numMessages) {
- TestUtil.logErr("Found " + msgCount + " messages in browser expected "
- + numMessages);
- pass = false;
- } else {
- TestUtil
- .logMsg("Found " + numMessages + " messages in browser (correct)");
- }
- qBrowser.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("createQueueBrowserTest");
- }
-
- if (!pass) {
- throw new Exception("createQueueBrowserTest failed");
- }
- }
-
- /*
- * @testName: createConsumerTest
- *
- * @assertion_ids: JMS:JAVADOC:942; JMS:JAVADOC:945; JMS:JAVADOC:949;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.createConsumer(Destination)
- * JMSContext.createConsumer(Destination, String)
- * JMSContext.createConsumer(Destination, String, boolean)
- *
- * 1. Send x text messages to a Queue. 2. Create a JMSConsumer with selector
- * to consume just the last message in the Queue. 3. Create a JMSConsumer
- * again to consume the rest of the messages in the Queue.
- */
- public void createConsumerTest() throws Exception {
- boolean pass = true;
- JMSConsumer consumerSelect = null;
- try {
- TextMessage tempMsg = null;
- Enumeration msgs = null;
-
- // Close normal JMSConsumer created in setup() method
- consumer.close();
- consumer = null;
-
- // Create selective JMSConsumer with message selector (lastMessage=TRUE)
- TestUtil.logMsg(
- "Create selective JMSConsumer with selector [\"lastMessage=TRUE\"]");
- consumerSelect = context.createConsumer(destination, "lastMessage=TRUE");
-
- // send "numMessages" messages to Queue plus end of stream message
- TestUtil.logMsg("Send " + numMessages + " messages to Queue");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createConsumerTest" + i);
- String tmp = null;
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- tmp = "with boolean property lastMessage=true";
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- tmp = "with boolean property lastMessage=false";
- }
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent " + tmp);
- }
-
- // Receive last message with selective consumer
- TestUtil.logMsg(
- "Receive last message with selective JMSConsumer and boolean property (lastMessage=TRUE)");
- tempMsg = (TextMessage) consumerSelect.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("JMSConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + numMessages + " missing from Queue");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + numMessages)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + numMessages + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received expected message: " + tempMsg.getText());
- }
-
- // Try to receive one more message (should return null)
- TestUtil.logMsg("Try receiving one more message (should get none)");
- tempMsg = (TextMessage) consumerSelect.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("JMSConsumer.receive() returned a message ["
- + tempMsg.getText() + "]");
- TestUtil.logErr(
- "JMSConsumer with selector should have returned just 1 message");
- pass = false;
- } else {
- TestUtil.logMsg("Received no message (CORRECT)");
- }
-
- // Close selective JMSConsumer
- TestUtil.logMsg("Close selective JMSConsumer");
- consumerSelect.close();
- consumerSelect = null;
-
- // Create normal JMSConsumer
- TestUtil.logMsg("Create normal JMSConsumer");
- consumer = context.createConsumer(destination);
-
- // Receive rest of messages with normal JMSConsumer
- TestUtil.logMsg("Receive rest of messages with normal JMSConsumer");
- for (int msgCount = 1; msgCount < numMessages; msgCount++) {
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("JMSConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + msgCount + " missing from Queue");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + msgCount)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + msgCount + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received message: " + tempMsg.getText());
- }
- }
-
- // Try to receive one more message (should return null)
- TestUtil.logMsg("Try receiving one more message (should get none)");
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("JMSConsumer returned message " + tempMsg.getText()
- + " (expected None)");
- pass = false;
- } else {
- TestUtil.logMsg("Received no message (CORRECT)");
- }
-
- // Close normal consumer
- TestUtil.logMsg("Close normal JMSConsumer");
- consumer.close();
- consumer = null;
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("createConsumerTest");
- } finally {
- try {
- if (consumerSelect != null)
- consumerSelect.close();
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- if (!pass) {
- throw new Exception("createConsumerTest failed");
- }
- }
-
- /*
- * @testName: getMetaDataTest
- *
- * @assertion_ids: JMS:JAVADOC:982;
- *
- * @test_Strategy: Call JMSContext.getMetaData() to retrieve the
- * ConnectionMetaData and then verify the ConnectionMetaData for correctness.
- *
- */
- public void getMetaDataTest() throws Exception {
- boolean pass = true;
- ConnectionMetaData data = null;
-
- try {
- data = context.getMetaData();
-
- if (!verifyMetaData(data))
- pass = false;
-
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("getMetaDataTest failed");
- }
- }
-
- /*
- * @testName: getSessionModeTest
- *
- * @assertion_ids: JMS:JAVADOC:986;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.getSessionMode().
- *
- * Cycle through all session modes to create each JMSContext with each mode
- * and verify that each session mode is set correctly.
- */
- public void getSessionModeTest() throws Exception {
- boolean pass = true;
- JMSContext context = null;
-
- // Test default case
- try {
- context = cf.createContext(user, password);
- int expSessionMode = JMSContext.AUTO_ACKNOWLEDGE;
- TestUtil.logMsg("Calling getSessionMode and expect " + expSessionMode
- + " to be returned");
- int actSessionMode = context.getSessionMode();
- if (actSessionMode != expSessionMode) {
- TestUtil.logErr("getSessionMode() returned " + actSessionMode
- + ", expected " + expSessionMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getSessionModeTest");
- } finally {
- try {
- if (context != null)
- context.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- // Test non-default case
- int expSessionMode[] = { JMSContext.SESSION_TRANSACTED,
- JMSContext.AUTO_ACKNOWLEDGE, JMSContext.CLIENT_ACKNOWLEDGE,
- JMSContext.DUPS_OK_ACKNOWLEDGE, };
-
- // Cycle through all session modes
- for (int i = 0; i < expSessionMode.length; i++) {
- if ((vehicle.equals("ejb") || vehicle.equals("jsp")
- || vehicle.equals("servlet"))) {
- if (expSessionMode[i] == JMSContext.SESSION_TRANSACTED
- || expSessionMode[i] == JMSContext.CLIENT_ACKNOWLEDGE)
- continue;
- }
- try {
- TestUtil.logMsg(
- "Creating context with session mode (" + expSessionMode[i] + ")");
- context = cf.createContext(user, password, expSessionMode[i]);
- TestUtil.logMsg("Calling getSessionMode and expect " + expSessionMode[i]
- + " to be returned");
- int actSessionMode = context.getSessionMode();
- if (actSessionMode != expSessionMode[i]) {
- TestUtil.logErr("getSessionMode() returned " + actSessionMode
- + ", expected " + expSessionMode[i]);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getSessionModeTest");
- } finally {
- try {
- if (context != null)
- context.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
- }
-
- if (!pass) {
- throw new Exception("getSessionModeTest failed");
- }
- }
-
- /*
- * @testName: getTransactedTest
- *
- * @assertion_ids: JMS:JAVADOC:990;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.getTransacted().
- *
- * Create a JMSContext with JMSContext.AUTO_ACKNOWLEDGE and verify that
- * JMSContext.getTransacted() returns false.
- *
- * Create a JMSContext with JMSContext.SESSION_TRANSACTED and verify that
- * JMSContext.getTransacted() returns true.
- */
- public void getTransactedTest() throws Exception {
- boolean pass = true;
- JMSContext context = null;
-
- // Test for transacted mode false
- try {
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- TestUtil.logMsg("Calling getTransacted and expect false to be returned");
- boolean transacted = context.getTransacted();
- if (transacted) {
- TestUtil.logErr("getTransacted() returned true expected false");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- if (context != null)
- context.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- // Test for transacted mode true
- if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
- try {
- context = cf.createContext(user, password,
- JMSContext.SESSION_TRANSACTED);
- TestUtil.logMsg("Calling getTransacted and expect true to be returned");
- boolean transacted = context.getTransacted();
- if (!transacted) {
- TestUtil.logErr("getTransacted() returned false expected true");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getTransactedTest");
- } finally {
- try {
- if (context != null)
- context.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
- }
-
- if (!pass) {
- throw new Exception("getTransactedTest failed");
- }
- }
-
- /*
- * @testName: getClientIDTest
- *
- * @assertion_ids: JMS:JAVADOC:970;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.getClientID()
- */
- public void getClientIDTest() throws Exception {
- boolean pass = true;
- try {
- String cid = context.getClientID();
- TestUtil.logErr("getClientID() returned " + cid + ", expected clientid");
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getClientIDTest");
- }
-
- if (!pass) {
- throw new Exception("getClientIDTest failed");
- }
- }
-
- /*
- * @testName: setGetAutoStartTest
- *
- * @assertion_ids: JMS:JAVADOC:1138; JMS:JAVADOC:1129;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.setAutoStart(boolean). JMSContext.getAutoStart().
- */
- public void setGetAutoStartTest() throws Exception {
- boolean pass = true;
- // Test default case
- try {
- boolean expAutoStart = true;
- TestUtil.logMsg("Calling getAutoStart and expect " + expAutoStart
- + " to be returned");
- boolean actAutoStart = context.getAutoStart();
- if (actAutoStart != expAutoStart) {
- TestUtil.logErr("getAutoStart() returned " + actAutoStart
- + ", expected " + expAutoStart);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
-
- // Test non-default case
- try {
- boolean expAutoStart = false;
- TestUtil.logMsg("Calling setAutoStart(" + expAutoStart + ")");
- context.setAutoStart(expAutoStart);
- TestUtil.logMsg("Calling getAutoStart and expect " + expAutoStart
- + " to be returned");
- boolean actAutoStart = context.getAutoStart();
- if (actAutoStart != expAutoStart) {
- TestUtil.logErr("getAutoStart() returned " + actAutoStart
- + ", expected " + expAutoStart);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetAutoStartTest");
- }
-
- if (!pass) {
- throw new Exception("setGetAutoStartTest failed");
- }
- }
-
- /*
- * @testName: multipleCloseContextTest
- *
- * @assertion_ids: JMS:JAVADOC:912; JMS:SPEC:108;
- *
- * @test_Strategy: Call close() twice on a JMSContext. This MUST NOT throw an
- * exception.
- */
- public void multipleCloseContextTest() throws Exception {
- try {
- TestUtil.logMsg("Call close on JMSContext created in setup.");
- context.close();
- TestUtil.logMsg("Call close on a JMSContext a second time");
- context.close();
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- throw new Exception("multipleCloseContextTest");
- }
- }
-
- /*
- * @testName: invalidDestinationRuntimeExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:944; JMS:JAVADOC:947; JMS:JAVADOC:951;
- * JMS:JAVADOC:920; JMS:JAVADOC:923; JMS:JAVADOC:1254; JMS:JAVADOC:1237;
- * JMS:JAVADOC:1242; JMS:JAVADOC:1246; JMS:JAVADOC:1250;
- *
- * @test_Strategy: Test InvalidDestinationRuntimeException conditions from
- * various API methods.
- *
- * JMSProducer.send(Destination, Message) JMSProducer.send(Destination,
- * String) JMSProducer.send(Destination, Serializable)
- * JMSProducer.send(Destination, byte[]) JMSProducer.send(Destination, Map)
- * JMSContext.createConsumer(Destination)
- * JMSContext.createConsumer(Destination, String)
- * JMSContext.createConsumer(Destination, String, boolean)
- * JMSContext.createBrowser(Queue, String) JMSContext.createBrowser(Queue)
- */
- public void invalidDestinationRuntimeExceptionTests() throws Exception {
- boolean pass = true;
- Destination invalidDestination = null;
- Queue invalidQueue = null;
- String message = "Where are you!";
- byte[] bytesMsgSend = message.getBytes();
- Map mapMsgSend = new HashMap();
- mapMsgSend.put("StringValue", "sendAndRecvTest7");
- mapMsgSend.put("BooleanValue", true);
- mapMsgSend.put("IntValue", (int) 10);
- try {
- // send to an invalid destination
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "invalidDestinationRuntimeExceptionTests");
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Message) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling send(Destination, Message) -> expect InvalidDestinationRuntimeException");
- producer.send(invalidDestination, expTextMessage);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, String) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling send(Destination, String) -> expect InvalidDestinationRuntimeException");
- producer.send(invalidDestination, message);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Serializable) for InvalidDestinationRuntimeException");
- TestUtil.logMsg("Send ObjectMessage");
- TestUtil.logMsg("Set some values in ObjectMessage");
- ObjectMessage om = context.createObjectMessage();
- StringBuffer sb = new StringBuffer(message);
- om.setObject(sb);
- om.setStringProperty("COM_SUN_JMS_TESTNAME",
- "invalidDestinationRuntimeExceptionTests");
- try {
- TestUtil.logMsg(
- "Calling send(Destination, Serializable) -> expect InvalidDestinationRuntimeException");
- producer.send(invalidDestination, om);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, byte[]) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling send(Destination, byte[]) -> expect InvalidDestinationRuntimeException");
- producer.send(invalidDestination, bytesMsgSend);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Map) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling send(Destination, Map) -> expect InvalidDestinationRuntimeException");
- producer.send(invalidDestination, mapMsgSend);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createConsumer(Destination) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createConsumer(Destination) -> expect InvalidDestinationRuntimeException");
- context.createConsumer(invalidDestination);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createConsumer(Destination, String) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createConsumer(Destination, String) -> expect InvalidDestinationRuntimeException");
- context.createConsumer(invalidDestination, "lastMessage = TRUE");
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createConsumer(Destination, String, boolean) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createConsumer(Destination, String, boolean) -> expect InvalidDestinationRuntimeException");
- context.createConsumer(invalidDestination, "lastMessage = TRUE", false);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createBrowser(Queue, String) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createBrowser(Queue, String) -> expect InvalidDestinationRuntimeException");
- context.createBrowser(invalidQueue, "lastMessage = TRUE");
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createBrowser(Queue) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createBrowser(Queue) -> expect InvalidDestinationRuntimeException");
- context.createBrowser(invalidQueue);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("invalidDestinationRuntimeExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("invalidDestinationRuntimeExceptionTests failed");
- }
- }
-
- /*
- * @testName: invalidSelectorRuntimeExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:948; JMS:JAVADOC:952; JMS:JAVADOC:924;
- *
- * @test_Strategy: Test InvalidSelectorRuntimeException conditions from
- * various API methods.
- *
- * JMSContext.createConsumer(Destination, String)
- * JMSContext.createConsumer(Destination, String, boolean)
- * JMSContext.createQueue(Queue, String)
- */
- public void invalidSelectorRuntimeExceptionTests() throws Exception {
- boolean pass = true;
- String invalidMessageSelector = "=TEST 'test'";
- try {
-
- TestUtil.logMsg(
- "Testing JMSContext.createConsumer(Destination, String) for InvalidSelectorRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createConsumer(Destination, String) -> expect InvalidSelectorRuntimeException");
- context.createConsumer(destination, invalidMessageSelector);
- } catch (InvalidSelectorRuntimeException e) {
- TestUtil.logMsg("Got InvalidSelectorRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected InvalidSelectorRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createConsumer(Destination, String, boolean) for InvalidSelectorRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createConsumer(Destination, String, boolean) -> expect InvalidSelectorRuntimeException");
- context.createConsumer(destination, invalidMessageSelector, false);
- } catch (InvalidSelectorRuntimeException e) {
- TestUtil.logMsg("Got InvalidSelectorRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected InvalidSelectorRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createBrowser(Queue, String) for InvalidSelectorRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createBrowser(Queue, String) -> expect InvalidSelectorRuntimeException");
- context.createBrowser(queue, invalidMessageSelector);
- } catch (InvalidSelectorRuntimeException e) {
- TestUtil.logMsg("Got InvalidSelectorRuntimeException, as expected.");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected InvalidSelectorRuntimeException,, received " + e);
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("invalidSelectorRuntimeExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("invalidSelectorRuntimeExceptionTests failed");
- }
- }
-
- /*
- * @testName: illegalStateRuntimeExceptionTest
- *
- * @assertion_ids: JMS:JAVADOC:917; JMS:JAVADOC:994; JMS:JAVADOC:997;
- * JMS:JAVADOC:1340;
- *
- * @test_Strategy: 1. Create a TextMessages and send to Queue 2. Then invoke
- * JMSContext.commit() on a non-transacted session Verify that
- * IllegalStateRuntimeException is thrown 3. Then test invoke
- * JMSContext.rollback() on a non-transacted session Verify that
- * IllegalStateRuntimeException is thrown 3. Then test invoke
- * JMSContext.recover() on a transacted session Verify that
- * IllegalStateRuntimeException is thrown 4. Create JMSContext with
- * CLIENT_ACKNOWLEDGE then close JMSContext. Then test invoke
- * JMSContext.acknowledge() on the JMSContext. Verify that
- * IllegalStateRuntimeException is thrown
- *
- * JMSContext.commit(); JMSContext.rollback(); JMSContext.recover();
- * JMSContext.acknowledge();
- */
- public void illegalStateRuntimeExceptionTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
-
- try {
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateRuntimeExceptionTest");
- // send the message to the Queue
- TestUtil.logMsg("Sending message to the Queue");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
-
- try {
- TestUtil.logMsg(
- "JMSContext.commit() on non-transacted session must throw IllegalStateRuntimeException");
- context.commit();
- pass = false;
- TestUtil.logErr(
- "Error: JMSContext.commit() didn't throw expected IllegalStateRuntimeException");
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- logMsg(
- "Got expected IllegalStateRuntimeException from JMSContext.commit()");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateRuntimeExceptionTest");
- // send the message to the Queue
- TestUtil.logMsg("Sending message to the Queue");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
-
- try {
- TestUtil.logMsg(
- "JMSContext.rollback() on non-transacted session must throw IllegalStateRuntimeException");
- context.rollback();
- pass = false;
- TestUtil.logErr(
- "Error: JMSContext.rollback() didn't throw expected IllegalStateRuntimeException");
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- logMsg(
- "Got expected IllegalStateRuntimeException from JMSContext.rollback()");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
- // create JMSContext with SESSION_TRANSACTED then create producer
- JMSContext contextTX = cf.createContext(user, password,
- JMSContext.SESSION_TRANSACTED);
- JMSProducer producerTX = contextTX.createProducer();
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- expTextMessage = contextTX.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateRuntimeExceptionTest");
- // send the message to the Queue
- TestUtil.logMsg("Sending message to the Queue");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producerTX.send(destination, expTextMessage);
-
- try {
- TestUtil.logMsg(
- "JMSContext.recover() on a transacted session must throw IllegalStateRuntimeException");
- contextTX.recover();
- pass = false;
- TestUtil.logErr(
- "Error: JMSContext.recover() didn't throw expected IllegalStateRuntimeException");
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- logMsg(
- "Got expected IllegalStateRuntimeException from JMSContext.recover()");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- contextTX.close();
-
- try {
- TestUtil.logMsg("Create JMSContext with CLIENT_ACKNOWLEDGE");
- JMSContext msgcontext = cf.createContext(user, password,
- JMSContext.CLIENT_ACKNOWLEDGE);
- TestUtil.logMsg("Close JMSContext");
- msgcontext.close();
- TestUtil.logMsg(
- "Call JMSContext.acknowledge() on a closed session which is illegal");
- msgcontext.acknowledge();
- TestUtil.logErr("Didn't throw IllegalStateRuntimeException");
- pass = false;
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- logMsg(
- "Got expected IllegalStateRuntimeException from JMSContext.acknowledge()");
- } catch (Exception e) {
- TestUtil.logMsg("Caught expected exception" + e);
- }
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- throw new Exception("illegalStateRuntimeExceptionTest");
- }
-
- if (!pass) {
- throw new Exception("illegalStateRuntimeExceptionTest");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmscontextqueuetests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmscontextqueuetests/ClientIT.java
new file mode 100644
index 0000000000..bf31e96185
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmscontextqueuetests/ClientIT.java
@@ -0,0 +1,1280 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.jmscontextqueuetests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.ConnectionMetaData;
+import jakarta.jms.Destination;
+import jakarta.jms.InvalidDestinationRuntimeException;
+import jakarta.jms.InvalidSelectorRuntimeException;
+import jakarta.jms.JMSConsumer;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSException;
+import jakarta.jms.JMSProducer;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueBrowser;
+import jakarta.jms.TemporaryQueue;
+import jakarta.jms.TextMessage;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.jmscontextqueuetests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null;
+
+ // JMS objects
+ private transient ConnectionFactory cf = null;
+
+ private transient Queue queue = null;
+
+ private transient Destination destination = null;
+
+ private transient JMSContext context = null;
+
+ private transient JMSContext contextToSendMsg = null;
+
+ private transient JMSProducer producer = null;
+
+ private transient JMSConsumer consumer = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ String vehicle = null;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * helper method verifies that the ConnectionMetaData
+ *
+ * @param ConnectionMetaData returned from getJMSMessageID
+ *
+ * @return boolean true if ConnectionMetaData is as expected
+ */
+ private boolean verifyMetaData(ConnectionMetaData data) {
+ boolean pass = true;
+
+ try {
+ String tmp = data.getJMSVersion();
+ logger.log(Logger.Level.INFO, "JMSVersion=" + tmp);
+
+ if (!tmp.equals(JmsTool.JMS_VERSION)) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getJMSMajorVersion();
+ logger.log(Logger.Level.INFO, "JMSMajorVersion=" + tmp);
+
+ if (tmp != JmsTool.JMS_MAJOR_VERSION) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSMajorVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSMajorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getJMSMinorVersion();
+ logger.log(Logger.Level.INFO, "JMSMinorVersion=" + tmp);
+
+ if (tmp != JmsTool.JMS_MINOR_VERSION) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSMinorVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSMinorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = data.getJMSProviderName();
+ logger.log(Logger.Level.INFO, "JMSProviderName=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSProviderName: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = data.getProviderVersion();
+ logger.log(Logger.Level.INFO, "JMSProviderVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getProviderMajorVersion();
+ logger.log(Logger.Level.INFO, "ProviderMajorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderMajorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getProviderMinorVersion();
+ logger.log(Logger.Level.INFO, "ProviderMinorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderMinorVersion: ", e);
+ pass = false;
+ }
+ return pass;
+ }
+
+ /*
+ * helper method verifies that the JMSMessageID starts with ID:
+ *
+ * @param String returned from getJMSMessageID
+ *
+ * @return boolean true if id correctly starts with ID:
+ */
+ private boolean chkMessageID(String id) {
+ String status[] = { "Pass", "Fail" };
+ boolean retcode = true;
+
+ // message id must start with ID: - unless it is null
+ int index = 0;
+
+ if (id == null) {
+ ;
+ } else if (id.startsWith("ID:")) {
+ ;
+ } else {
+ index = 1;
+ retcode = false;
+ }
+ logger.log(Logger.Level.INFO, "Results: " + status[index]);
+ return retcode;
+ }
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ vehicle = System.getProperty("vehicle");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(3);
+ connections = new ArrayList(5);
+
+ // set up JmsTool for COMMON_Q setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_Q setup");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ cf = tool.getConnectionFactory();
+ destination = tool.getDefaultDestination();
+ queue = (Queue) destination;
+ tool.getDefaultConnection().close();
+ logger.log(Logger.Level.INFO, "Create JMSContext with AUTO_ACKNOWLEDGE");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ contextToSendMsg = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ producer = contextToSendMsg.createProducer();
+ consumer = context.createConsumer(destination);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "Close JMSContext Objects");
+ if (context != null)
+ context.close();
+ context = null;
+ if (contextToSendMsg != null)
+ contextToSendMsg.close();
+ contextToSendMsg = null;
+ producer = null;
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ tool.flushDestination();
+ logger.log(Logger.Level.INFO, "Close JMSConsumer objects");
+ if (consumer != null)
+ consumer.close();
+ consumer = null;
+ tool.closeAllResources();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+
+ if (!pass)
+ throw new Exception("cleanup failed!");
+ }
+
+ /*
+ * @testName: createTemporayQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:960;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.createTemporaryQueue()
+ *
+ * Send and receive a message to temporary queue. Compare send and recv message
+ * for equality.
+ */
+ @Test
+ public void createTemporayQueueTest() throws Exception {
+ boolean pass = true;
+ try {
+
+ String sendMessage = "a text message";
+
+ // create a TemporaryQueue
+ logger.log(Logger.Level.INFO, "Creating TemporaryQueue");
+ TemporaryQueue tempQueue = context.createTemporaryQueue();
+
+ // Create a JMSConsumer for this Temporary Queue
+ logger.log(Logger.Level.INFO, "Create JMSConsumer");
+ JMSConsumer smc = context.createConsumer(tempQueue);
+
+ // Send message to temporary queue
+ logger.log(Logger.Level.INFO, "Send message to temporaty queue using JMSProducer");
+ producer.send(tempQueue, sendMessage);
+
+ // Receive message from temporary queue
+ logger.log(Logger.Level.INFO, "Receive message from temporaty queue");
+ String recvMessage = smc.receiveBody(String.class, timeout);
+
+ logger.log(Logger.Level.INFO, "Checking received message");
+ if (recvMessage == null) {
+ throw new Exception("Did not receive Message");
+ }
+
+ if (!recvMessage.equals(sendMessage)) {
+ logger.log(Logger.Level.ERROR,
+ "Unexpected message: received " + recvMessage + " , expected " + sendMessage);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "received correct message: " + recvMessage + " as expected");
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Attempting to delete temporary queue with an open consumer should not be allowed");
+ try {
+ tempQueue.delete();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TemporaryQueue.delete() didn't throw expected Exception");
+ } catch (JMSException em) {
+ logger.log(Logger.Level.INFO, "Received expected JMSException: ");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO, "Close JMSConsumer");
+ smc.close();
+
+ logger.log(Logger.Level.INFO,
+ "Attempting to delete temporary queue with no open consumer should be allowed");
+ try {
+ tempQueue.delete();
+ } catch (Exception e) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received unexpected Exception: ", e);
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("createTemporayQueueTest");
+ }
+
+ if (!pass) {
+ throw new Exception("createTemporayQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: createQueueBrowserTest
+ *
+ * @assertion_ids: JMS:JAVADOC:918; JMS:JAVADOC:921;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.createBrowser(Queue) JMSContext.createBrowser(Queue, String)
+ *
+ * 1. Send x text messages to a Queue. 2. Create a QueueBrowser with selector to
+ * browse just the last message in the Queue. 3. Create a QueueBrowser again to
+ * browse all the messages in the queue.
+ */
+ @Test
+ public void createQueueBrowserTest() throws Exception {
+ boolean pass = true;
+ try {
+ TextMessage tempMsg = null;
+ QueueBrowser qBrowser = null;
+ Enumeration msgs = null;
+
+ // Close consumer created in setup() method
+ consumer.close();
+ consumer = null;
+
+ // send "numMessages" messages to Queue plus end of stream message
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Queue");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createQueueBrowserTest" + i);
+ String tmp = null;
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ tmp = "with boolean property lastMessage=true";
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ tmp = "with boolean property lastMessage=false";
+ }
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent " + tmp);
+ }
+
+ // create QueueBrowser to peek at last message in Queue using message
+ // selector
+ logger.log(Logger.Level.INFO,
+ "Create QueueBrowser to peek at last message in Queue using message selector (lastMessage = TRUE)");
+ qBrowser = context.createBrowser(queue, "lastMessage = TRUE");
+
+ // check that browser just has the last message in the Queue
+ logger.log(Logger.Level.INFO, "Check that browser has just the last message");
+ int msgCount = 0;
+ msgs = qBrowser.getEnumeration();
+ while (msgs.hasMoreElements()) {
+ tempMsg = (TextMessage) msgs.nextElement();
+ logger.log(Logger.Level.INFO,
+ "Text=" + tempMsg.getText() + ", lastMessage=" + tempMsg.getBooleanProperty("lastMessage"));
+ if (!tempMsg.getText().equals("Message " + numMessages)) {
+ logger.log(Logger.Level.ERROR,
+ "Found [" + tempMsg.getText() + "] in browser expected only [Message 3]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Found [Message " + numMessages + "] in browser");
+ }
+ msgCount++;
+ }
+ if (msgCount != 1) {
+ logger.log(Logger.Level.ERROR, "Found " + msgCount + " messages in browser expected 1");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Found 1 message in browser (correct)");
+ }
+ qBrowser.close();
+
+ // create QueueBrowser to peek at all messages in the Queue
+ logger.log(Logger.Level.INFO, "Create QueueBrowser to browse all messages in the Queue");
+ qBrowser = context.createBrowser(queue);
+
+ // check for messages
+ logger.log(Logger.Level.INFO, "Check that browser contains all " + numMessages + " messages");
+ msgCount = 0;
+ int msgIndex = 1;
+ msgs = qBrowser.getEnumeration();
+ while (msgs.hasMoreElements()) {
+ tempMsg = (TextMessage) msgs.nextElement();
+ if (!tempMsg.getText().equals("Message " + msgIndex)) {
+ logger.log(Logger.Level.ERROR,
+ "Found [" + tempMsg.getText() + "] in browser expected [Message " + msgIndex + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Found [Message " + msgIndex + "] in browser (correct)");
+ }
+ msgCount++;
+ msgIndex++;
+ }
+ if (msgCount != numMessages) {
+ logger.log(Logger.Level.ERROR, "Found " + msgCount + " messages in browser expected " + numMessages);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Found " + numMessages + " messages in browser (correct)");
+ }
+ qBrowser.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("createQueueBrowserTest");
+ }
+
+ if (!pass) {
+ throw new Exception("createQueueBrowserTest failed");
+ }
+ }
+
+ /*
+ * @testName: createConsumerTest
+ *
+ * @assertion_ids: JMS:JAVADOC:942; JMS:JAVADOC:945; JMS:JAVADOC:949;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.createConsumer(Destination) JMSContext.createConsumer(Destination,
+ * String) JMSContext.createConsumer(Destination, String, boolean)
+ *
+ * 1. Send x text messages to a Queue. 2. Create a JMSConsumer with selector to
+ * consume just the last message in the Queue. 3. Create a JMSConsumer again to
+ * consume the rest of the messages in the Queue.
+ */
+ @Test
+ public void createConsumerTest() throws Exception {
+ boolean pass = true;
+ JMSConsumer consumerSelect = null;
+ try {
+ TextMessage tempMsg = null;
+ Enumeration msgs = null;
+
+ // Close normal JMSConsumer created in setup() method
+ consumer.close();
+ consumer = null;
+
+ // Create selective JMSConsumer with message selector (lastMessage=TRUE)
+ logger.log(Logger.Level.INFO, "Create selective JMSConsumer with selector [\"lastMessage=TRUE\"]");
+ consumerSelect = context.createConsumer(destination, "lastMessage=TRUE");
+
+ // send "numMessages" messages to Queue plus end of stream message
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Queue");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createConsumerTest" + i);
+ String tmp = null;
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ tmp = "with boolean property lastMessage=true";
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ tmp = "with boolean property lastMessage=false";
+ }
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent " + tmp);
+ }
+
+ // Receive last message with selective consumer
+ logger.log(Logger.Level.INFO,
+ "Receive last message with selective JMSConsumer and boolean property (lastMessage=TRUE)");
+ tempMsg = (TextMessage) consumerSelect.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + numMessages + " missing from Queue");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + numMessages)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + numMessages + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received expected message: " + tempMsg.getText());
+ }
+
+ // Try to receive one more message (should return null)
+ logger.log(Logger.Level.INFO, "Try receiving one more message (should get none)");
+ tempMsg = (TextMessage) consumerSelect.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() returned a message [" + tempMsg.getText() + "]");
+ logger.log(Logger.Level.ERROR, "JMSConsumer with selector should have returned just 1 message");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received no message (CORRECT)");
+ }
+
+ // Close selective JMSConsumer
+ logger.log(Logger.Level.INFO, "Close selective JMSConsumer");
+ consumerSelect.close();
+ consumerSelect = null;
+
+ // Create normal JMSConsumer
+ logger.log(Logger.Level.INFO, "Create normal JMSConsumer");
+ consumer = context.createConsumer(destination);
+
+ // Receive rest of messages with normal JMSConsumer
+ logger.log(Logger.Level.INFO, "Receive rest of messages with normal JMSConsumer");
+ for (int msgCount = 1; msgCount < numMessages; msgCount++) {
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + msgCount + " missing from Queue");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + msgCount)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + msgCount + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message: " + tempMsg.getText());
+ }
+ }
+
+ // Try to receive one more message (should return null)
+ logger.log(Logger.Level.INFO, "Try receiving one more message (should get none)");
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR,
+ "JMSConsumer returned message " + tempMsg.getText() + " (expected None)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received no message (CORRECT)");
+ }
+
+ // Close normal consumer
+ logger.log(Logger.Level.INFO, "Close normal JMSConsumer");
+ consumer.close();
+ consumer = null;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("createConsumerTest");
+ } finally {
+ try {
+ if (consumerSelect != null)
+ consumerSelect.close();
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createConsumerTest failed");
+ }
+ }
+
+ /*
+ * @testName: getMetaDataTest
+ *
+ * @assertion_ids: JMS:JAVADOC:982;
+ *
+ * @test_Strategy: Call JMSContext.getMetaData() to retrieve the
+ * ConnectionMetaData and then verify the ConnectionMetaData for correctness.
+ *
+ */
+ @Test
+ public void getMetaDataTest() throws Exception {
+ boolean pass = true;
+ ConnectionMetaData data = null;
+
+ try {
+ data = context.getMetaData();
+
+ if (!verifyMetaData(data))
+ pass = false;
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("getMetaDataTest failed");
+ }
+ }
+
+ /*
+ * @testName: getSessionModeTest
+ *
+ * @assertion_ids: JMS:JAVADOC:986;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.getSessionMode().
+ *
+ * Cycle through all session modes to create each JMSContext with each mode and
+ * verify that each session mode is set correctly.
+ */
+ @Test
+ public void getSessionModeTest() throws Exception {
+ boolean pass = true;
+ JMSContext context = null;
+
+ // Test default case
+ try {
+ context = cf.createContext(user, password);
+ int expSessionMode = JMSContext.AUTO_ACKNOWLEDGE;
+ logger.log(Logger.Level.INFO, "Calling getSessionMode and expect " + expSessionMode + " to be returned");
+ int actSessionMode = context.getSessionMode();
+ if (actSessionMode != expSessionMode) {
+ logger.log(Logger.Level.ERROR,
+ "getSessionMode() returned " + actSessionMode + ", expected " + expSessionMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getSessionModeTest");
+ } finally {
+ try {
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ // Test non-default case
+ int expSessionMode[] = { JMSContext.SESSION_TRANSACTED, JMSContext.AUTO_ACKNOWLEDGE,
+ JMSContext.CLIENT_ACKNOWLEDGE, JMSContext.DUPS_OK_ACKNOWLEDGE, };
+
+ // Cycle through all session modes
+ for (int i = 0; i < expSessionMode.length; i++) {
+ if ((vehicle.equals("ejb") || vehicle.equals("jsp") || vehicle.equals("servlet"))) {
+ if (expSessionMode[i] == JMSContext.SESSION_TRANSACTED
+ || expSessionMode[i] == JMSContext.CLIENT_ACKNOWLEDGE)
+ continue;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Creating context with session mode (" + expSessionMode[i] + ")");
+ context = cf.createContext(user, password, expSessionMode[i]);
+ logger.log(Logger.Level.INFO,
+ "Calling getSessionMode and expect " + expSessionMode[i] + " to be returned");
+ int actSessionMode = context.getSessionMode();
+ if (actSessionMode != expSessionMode[i]) {
+ logger.log(Logger.Level.ERROR,
+ "getSessionMode() returned " + actSessionMode + ", expected " + expSessionMode[i]);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getSessionModeTest");
+ } finally {
+ try {
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("getSessionModeTest failed");
+ }
+ }
+
+ /*
+ * @testName: getTransactedTest
+ *
+ * @assertion_ids: JMS:JAVADOC:990;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.getTransacted().
+ *
+ * Create a JMSContext with JMSContext.AUTO_ACKNOWLEDGE and verify that
+ * JMSContext.getTransacted() returns false.
+ *
+ * Create a JMSContext with JMSContext.SESSION_TRANSACTED and verify that
+ * JMSContext.getTransacted() returns true.
+ */
+ @Test
+ public void getTransactedTest() throws Exception {
+ boolean pass = true;
+ JMSContext context = null;
+
+ // Test for transacted mode false
+ try {
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ logger.log(Logger.Level.INFO, "Calling getTransacted and expect false to be returned");
+ boolean transacted = context.getTransacted();
+ if (transacted) {
+ logger.log(Logger.Level.ERROR, "getTransacted() returned true expected false");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ // Test for transacted mode true
+ if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
+ try {
+ context = cf.createContext(user, password, JMSContext.SESSION_TRANSACTED);
+ logger.log(Logger.Level.INFO, "Calling getTransacted and expect true to be returned");
+ boolean transacted = context.getTransacted();
+ if (!transacted) {
+ logger.log(Logger.Level.ERROR, "getTransacted() returned false expected true");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getTransactedTest");
+ } finally {
+ try {
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("getTransactedTest failed");
+ }
+ }
+
+ /*
+ * @testName: getClientIDTest
+ *
+ * @assertion_ids: JMS:JAVADOC:970;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.getClientID()
+ */
+ @Test
+ public void getClientIDTest() throws Exception {
+ boolean pass = true;
+ try {
+ String cid = context.getClientID();
+ logger.log(Logger.Level.ERROR, "getClientID() returned " + cid + ", expected clientid");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getClientIDTest");
+ }
+
+ if (!pass) {
+ throw new Exception("getClientIDTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetAutoStartTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1138; JMS:JAVADOC:1129;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.setAutoStart(boolean). JMSContext.getAutoStart().
+ */
+ @Test
+ public void setGetAutoStartTest() throws Exception {
+ boolean pass = true;
+ // Test default case
+ try {
+ boolean expAutoStart = true;
+ logger.log(Logger.Level.INFO, "Calling getAutoStart and expect " + expAutoStart + " to be returned");
+ boolean actAutoStart = context.getAutoStart();
+ if (actAutoStart != expAutoStart) {
+ logger.log(Logger.Level.ERROR,
+ "getAutoStart() returned " + actAutoStart + ", expected " + expAutoStart);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+
+ // Test non-default case
+ try {
+ boolean expAutoStart = false;
+ logger.log(Logger.Level.INFO, "Calling setAutoStart(" + expAutoStart + ")");
+ context.setAutoStart(expAutoStart);
+ logger.log(Logger.Level.INFO, "Calling getAutoStart and expect " + expAutoStart + " to be returned");
+ boolean actAutoStart = context.getAutoStart();
+ if (actAutoStart != expAutoStart) {
+ logger.log(Logger.Level.ERROR,
+ "getAutoStart() returned " + actAutoStart + ", expected " + expAutoStart);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetAutoStartTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetAutoStartTest failed");
+ }
+ }
+
+ /*
+ * @testName: multipleCloseContextTest
+ *
+ * @assertion_ids: JMS:JAVADOC:912; JMS:SPEC:108;
+ *
+ * @test_Strategy: Call close() twice on a JMSContext. This MUST NOT throw an
+ * exception.
+ */
+ @Test
+ public void multipleCloseContextTest() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Call close on JMSContext created in setup.");
+ context.close();
+ logger.log(Logger.Level.INFO, "Call close on a JMSContext a second time");
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("multipleCloseContextTest");
+ }
+ }
+
+ /*
+ * @testName: invalidDestinationRuntimeExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:944; JMS:JAVADOC:947; JMS:JAVADOC:951;
+ * JMS:JAVADOC:920; JMS:JAVADOC:923; JMS:JAVADOC:1254; JMS:JAVADOC:1237;
+ * JMS:JAVADOC:1242; JMS:JAVADOC:1246; JMS:JAVADOC:1250;
+ *
+ * @test_Strategy: Test InvalidDestinationRuntimeException conditions from
+ * various API methods.
+ *
+ * JMSProducer.send(Destination, Message) JMSProducer.send(Destination, String)
+ * JMSProducer.send(Destination, Serializable) JMSProducer.send(Destination,
+ * byte[]) JMSProducer.send(Destination, Map)
+ * JMSContext.createConsumer(Destination) JMSContext.createConsumer(Destination,
+ * String) JMSContext.createConsumer(Destination, String, boolean)
+ * JMSContext.createBrowser(Queue, String) JMSContext.createBrowser(Queue)
+ */
+ @Test
+ public void invalidDestinationRuntimeExceptionTests() throws Exception {
+ boolean pass = true;
+ Destination invalidDestination = null;
+ Queue invalidQueue = null;
+ String message = "Where are you!";
+ byte[] bytesMsgSend = message.getBytes();
+ Map mapMsgSend = new HashMap();
+ mapMsgSend.put("StringValue", "sendAndRecvTest7");
+ mapMsgSend.put("BooleanValue", true);
+ mapMsgSend.put("IntValue", (int) 10);
+ try {
+ // send to an invalid destination
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "invalidDestinationRuntimeExceptionTests");
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Message) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling send(Destination, Message) -> expect InvalidDestinationRuntimeException");
+ producer.send(invalidDestination, expTextMessage);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, String) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling send(Destination, String) -> expect InvalidDestinationRuntimeException");
+ producer.send(invalidDestination, message);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Serializable) for InvalidDestinationRuntimeException");
+ logger.log(Logger.Level.INFO, "Send ObjectMessage");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ ObjectMessage om = context.createObjectMessage();
+ StringBuffer sb = new StringBuffer(message);
+ om.setObject(sb);
+ om.setStringProperty("COM_SUN_JMS_TESTNAME", "invalidDestinationRuntimeExceptionTests");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling send(Destination, Serializable) -> expect InvalidDestinationRuntimeException");
+ producer.send(invalidDestination, om);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, byte[]) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling send(Destination, byte[]) -> expect InvalidDestinationRuntimeException");
+ producer.send(invalidDestination, bytesMsgSend);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Map) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling send(Destination, Map) -> expect InvalidDestinationRuntimeException");
+ producer.send(invalidDestination, mapMsgSend);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createConsumer(Destination) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createConsumer(Destination) -> expect InvalidDestinationRuntimeException");
+ context.createConsumer(invalidDestination);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createConsumer(Destination, String) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createConsumer(Destination, String) -> expect InvalidDestinationRuntimeException");
+ context.createConsumer(invalidDestination, "lastMessage = TRUE");
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createConsumer(Destination, String, boolean) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createConsumer(Destination, String, boolean) -> expect InvalidDestinationRuntimeException");
+ context.createConsumer(invalidDestination, "lastMessage = TRUE", false);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createBrowser(Queue, String) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createBrowser(Queue, String) -> expect InvalidDestinationRuntimeException");
+ context.createBrowser(invalidQueue, "lastMessage = TRUE");
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createBrowser(Queue) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createBrowser(Queue) -> expect InvalidDestinationRuntimeException");
+ context.createBrowser(invalidQueue);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("invalidDestinationRuntimeExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("invalidDestinationRuntimeExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: invalidSelectorRuntimeExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:948; JMS:JAVADOC:952; JMS:JAVADOC:924;
+ *
+ * @test_Strategy: Test InvalidSelectorRuntimeException conditions from various
+ * API methods.
+ *
+ * JMSContext.createConsumer(Destination, String)
+ * JMSContext.createConsumer(Destination, String, boolean)
+ * JMSContext.createQueue(Queue, String)
+ */
+ @Test
+ public void invalidSelectorRuntimeExceptionTests() throws Exception {
+ boolean pass = true;
+ String invalidMessageSelector = "=TEST 'test'";
+ try {
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createConsumer(Destination, String) for InvalidSelectorRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createConsumer(Destination, String) -> expect InvalidSelectorRuntimeException");
+ context.createConsumer(destination, invalidMessageSelector);
+ } catch (InvalidSelectorRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidSelectorRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidSelectorRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createConsumer(Destination, String, boolean) for InvalidSelectorRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createConsumer(Destination, String, boolean) -> expect InvalidSelectorRuntimeException");
+ context.createConsumer(destination, invalidMessageSelector, false);
+ } catch (InvalidSelectorRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidSelectorRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidSelectorRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createBrowser(Queue, String) for InvalidSelectorRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createBrowser(Queue, String) -> expect InvalidSelectorRuntimeException");
+ context.createBrowser(queue, invalidMessageSelector);
+ } catch (InvalidSelectorRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidSelectorRuntimeException, as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidSelectorRuntimeException,, received " + e);
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("invalidSelectorRuntimeExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("invalidSelectorRuntimeExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: illegalStateRuntimeExceptionTest
+ *
+ * @assertion_ids: JMS:JAVADOC:917; JMS:JAVADOC:994; JMS:JAVADOC:997;
+ * JMS:JAVADOC:1340;
+ *
+ * @test_Strategy: 1. Create a TextMessages and send to Queue 2. Then invoke
+ * JMSContext.commit() on a non-transacted session Verify that
+ * IllegalStateRuntimeException is thrown 3. Then test invoke
+ * JMSContext.rollback() on a non-transacted session Verify that
+ * IllegalStateRuntimeException is thrown 3. Then test invoke
+ * JMSContext.recover() on a transacted session Verify that
+ * IllegalStateRuntimeException is thrown 4. Create JMSContext with
+ * CLIENT_ACKNOWLEDGE then close JMSContext. Then test invoke
+ * JMSContext.acknowledge() on the JMSContext. Verify that
+ * IllegalStateRuntimeException is thrown
+ *
+ * JMSContext.commit(); JMSContext.rollback(); JMSContext.recover();
+ * JMSContext.acknowledge();
+ */
+ @Test
+ public void illegalStateRuntimeExceptionTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+
+ try {
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateRuntimeExceptionTest");
+ // send the message to the Queue
+ logger.log(Logger.Level.INFO, "Sending message to the Queue");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "JMSContext.commit() on non-transacted session must throw IllegalStateRuntimeException");
+ context.commit();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: JMSContext.commit() didn't throw expected IllegalStateRuntimeException");
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateRuntimeException from JMSContext.commit()");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateRuntimeExceptionTest");
+ // send the message to the Queue
+ logger.log(Logger.Level.INFO, "Sending message to the Queue");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "JMSContext.rollback() on non-transacted session must throw IllegalStateRuntimeException");
+ context.rollback();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: JMSContext.rollback() didn't throw expected IllegalStateRuntimeException");
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateRuntimeException from JMSContext.rollback()");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
+ // create JMSContext with SESSION_TRANSACTED then create producer
+ JMSContext contextTX = cf.createContext(user, password, JMSContext.SESSION_TRANSACTED);
+ JMSProducer producerTX = contextTX.createProducer();
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ expTextMessage = contextTX.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateRuntimeExceptionTest");
+ // send the message to the Queue
+ logger.log(Logger.Level.INFO, "Sending message to the Queue");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producerTX.send(destination, expTextMessage);
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "JMSContext.recover() on a transacted session must throw IllegalStateRuntimeException");
+ contextTX.recover();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: JMSContext.recover() didn't throw expected IllegalStateRuntimeException");
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateRuntimeException from JMSContext.recover()");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ contextTX.close();
+
+ try {
+ logger.log(Logger.Level.INFO, "Create JMSContext with CLIENT_ACKNOWLEDGE");
+ JMSContext msgcontext = cf.createContext(user, password, JMSContext.CLIENT_ACKNOWLEDGE);
+ logger.log(Logger.Level.INFO, "Close JMSContext");
+ msgcontext.close();
+ logger.log(Logger.Level.INFO, "Call JMSContext.acknowledge() on a closed session which is illegal");
+ msgcontext.acknowledge();
+ logger.log(Logger.Level.ERROR, "Didn't throw IllegalStateRuntimeException");
+ pass = false;
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateRuntimeException from JMSContext.acknowledge()");
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught expected exception" + e);
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("illegalStateRuntimeExceptionTest");
+ }
+
+ if (!pass) {
+ throw new Exception("illegalStateRuntimeExceptionTest");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmscontexttopictests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmscontexttopictests/Client.java
deleted file mode 100644
index 52bf35b8be..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmscontexttopictests/Client.java
+++ /dev/null
@@ -1,3258 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2022 Contributors to Eclipse Foundation. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id: Client.java 68661 2012-11-21 22:51:15Z adf $
- */
-package com.sun.ts.tests.jms.core20.jmscontexttopictests;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.ConnectionMetaData;
-import jakarta.jms.Destination;
-import jakarta.jms.InvalidDestinationRuntimeException;
-import jakarta.jms.InvalidSelectorRuntimeException;
-import jakarta.jms.JMSConsumer;
-import jakarta.jms.JMSContext;
-import jakarta.jms.JMSException;
-import jakarta.jms.JMSProducer;
-import jakarta.jms.JMSRuntimeException;
-import jakarta.jms.Message;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.TemporaryTopic;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.jmscontexttopictests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null, tool2 = null;
-
- // JMS objects
- private transient ConnectionFactory cf = null;
-
- private transient ConnectionFactory cf2 = null;
-
- private transient Topic topic = null;
-
- private transient Destination destination = null;
-
- private transient Topic topic2 = null;
-
- private transient Destination destination2 = null;
-
- private transient JMSContext context = null;
-
- private transient JMSContext context2 = null;
-
- private transient JMSProducer producer = null;
-
- private transient JMSProducer producer2 = null;
-
- private transient JMSConsumer consumer = null;
-
- private transient JMSConsumer consumer2 = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- String vehicle;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * helper method verifies that the ConnectionMetaData
- *
- * @param ConnectionMetaData returned from getJMSMessageID
- *
- * @return boolean true if ConnectionMetaData is as expected
- */
- private boolean verifyMetaData(ConnectionMetaData data) {
- boolean pass = true;
-
- try {
- String tmp = data.getJMSVersion();
- TestUtil.logTrace("JMSVersion=" + tmp);
-
- if (!tmp.equals(JmsTool.JMS_VERSION)) {
- TestUtil.logErr("Error: incorrect JMSVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getJMSMajorVersion();
- TestUtil.logTrace("JMSMajorVersion=" + tmp);
-
- if (tmp != JmsTool.JMS_MAJOR_VERSION) {
- TestUtil.logErr("Error: incorrect JMSMajorVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSMajorVersion: ",
- e);
- pass = false;
- }
-
- try {
- int tmp = data.getJMSMinorVersion();
- TestUtil.logTrace("JMSMinorVersion=" + tmp);
-
- if (tmp != JmsTool.JMS_MINOR_VERSION) {
- TestUtil.logErr("Error: incorrect JMSMinorVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSMinorVersion: ",
- e);
- pass = false;
- }
-
- try {
- String tmp = data.getJMSProviderName();
- TestUtil.logTrace("JMSProviderName=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSProviderName: ",
- e);
- pass = false;
- }
-
- try {
- String tmp = data.getProviderVersion();
- TestUtil.logTrace("JMSProviderVersion=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for ProviderVersion: ",
- e);
- pass = false;
- }
-
- try {
- int tmp = data.getProviderMajorVersion();
- TestUtil.logTrace("ProviderMajorVersion=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: incorrect type returned for ProviderMajorVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getProviderMinorVersion();
- TestUtil.logTrace("ProviderMinorVersion=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: incorrect type returned for ProviderMinorVersion: ", e);
- pass = false;
- }
- return pass;
- }
-
- /*
- * helper method verifies that the JMSMessageID starts with ID:
- *
- * @param String returned from getJMSMessageID
- *
- * @return boolean true if id correctly starts with ID:
- */
- private boolean chkMessageID(String id) {
- String status[] = { "Pass", "Fail" };
- boolean retcode = true;
-
- // message id must start with ID: - unless it is null
- int index = 0;
-
- if (id == null) {
- ;
- } else if (id.startsWith("ID:")) {
- ;
- } else {
- index = 1;
- retcode = false;
- }
- logTrace("Results: " + status[index]);
- return retcode;
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- String lookupDurableTopicFactory = "DURABLE_SUB_CONNECTION_FACTORY";
- String lookupNormalTopicFactory = "MyTopicConnectionFactory";
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- vehicle = p.getProperty("vehicle");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- connections = new ArrayList(5);
-
- // set up JmsTool for COMMON_T setup
- TestUtil.logMsg(
- "Setup JmsTool for COMMON_T and normal topic connection factory");
- tool = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupNormalTopicFactory, mode);
- cf = tool.getConnectionFactory();
- tool.getDefaultConnection().close(); // Close connection (Create
- // JMSContext to use instead)
- destination = tool.getDefaultDestination();
- topic = (Topic) destination;
-
- // create JMSContext with AUTO_ACKNOWLEDGE then create consumer/producer
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- producer = context.createProducer();
- consumer = context.createConsumer(topic);
-
- // set up JmsTool for COMMON_T setup
- TestUtil.logMsg(
- "Setup JmsTool for COMMON_T and durable topic connection factory");
- tool2 = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupDurableTopicFactory, mode);
- tool2.getDefaultConnection().close(); // Close connection (Create
- // JMSContext to use instead)
- cf2 = tool2.getConnectionFactory();
- destination2 = tool2.getDefaultDestination();
- topic2 = (Topic) destination2;
-
- // create second JMSContext with AUTO_ACKNOWLEDGE, then create producer
- context2 = cf2.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- producer2 = context2.createProducer();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Close JMSContext Objects");
- if (context != null) {
- context.close();
- context = null;
- }
- if (context2 != null) {
- context2.close();
- context2 = null;
- }
- producer = producer2 = null;
- TestUtil.logMsg("Close JMSConsumer Objects");
- if (consumer != null) {
- consumer.close();
- consumer = null;
- }
- if (tool != null) {
- tool.closeAllResources();
- tool = null;
- }
- if (tool2 != null) {
- tool2.closeAllResources();
- tool2 = null;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * Cleanup method for tests that use durable subscriptions
- */
- private void cleanupSubscription(JMSConsumer consumer, JMSContext context,
- String subName) {
- if (consumer != null) {
- try {
- TestUtil.logTrace("Closing durable consumer: " + consumer);
- consumer.close();
- consumer = null;
- } catch (Exception e) {
- TestUtil.logErr("Exception during JMSConsumer.close: ", e);
- }
- }
-
- if (context != null) {
- try {
- TestUtil.logTrace("Unsubscribing \"" + subName + "\"");
- context.unsubscribe(subName);
- } catch (Exception e) {
- TestUtil.logErr("Exception during JMSContext.unsubscribe: ", e);
- }
- }
- }
-
- /*
- * @testName: createTemporayTopicTest
- *
- * @assertion_ids: JMS:JAVADOC:962;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.createTemporaryTopic().
- *
- * Send and receive a message to temporary topic. Compare send and recv
- * message for equality.
- */
- public void createTemporayTopicTest() throws Exception {
- boolean pass = true;
- JMSConsumer consumer = null;
- try {
-
- String sendMessage = "a text message";
-
- // create a TemporaryTopic
- TestUtil.logMsg("Creating TemporaryTopic");
- TemporaryTopic tempTopic = context.createTemporaryTopic();
-
- // Create a JMSConsumer for this Temporary Topic
- TestUtil.logMsg("Create JMSConsumer for TemporaryTopic.");
- consumer = context.createConsumer(tempTopic);
-
- // Send message to temporary topic
- TestUtil.logMsg("Send message to temporary topic");
- producer.send(tempTopic, sendMessage);
-
- // Receive message from temporary topic
- TestUtil.logMsg("Receive message from temporaty topic");
- String recvMessage = consumer.receiveBody(String.class, timeout);
-
- TestUtil.logMsg("Checking received message");
- if (recvMessage == null) {
- throw new Exception("Did not receive Message");
- }
-
- TestUtil.logMsg("Verify correct message received.");
- if (!recvMessage.equals(sendMessage)) {
- TestUtil.logErr("unexpected message: received " + recvMessage
- + " , expected " + sendMessage);
- pass = false;
- } else {
- TestUtil.logMsg(
- "received correct message: " + recvMessage + " as expected");
- }
-
- TestUtil.logMsg(
- "Attempting to delete temporary topic with an open consumer should not be allowed");
- try {
- tempTopic.delete();
- pass = false;
- TestUtil
- .logErr("TemporaryTopic.delete() didn't throw expected Exception");
- } catch (JMSException em) {
- TestUtil.logTrace("Received expected JMSException: ");
- }
-
- TestUtil.logMsg("Now close the open consumer");
- try {
- consumer.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception closing JMSConsumer: " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Attempting to delete temporary topic with no open consumer should be allowed");
- try {
- tempTopic.delete();
- } catch (Exception e) {
- pass = false;
- TestUtil.logErr("Received unexpected Exception: ", e);
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("createTemporayTopicTest");
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("createTemporayTopicTest failed");
- }
- }
-
- /*
- * @testName: getMetaDataTest
- *
- * @assertion_ids: JMS:JAVADOC:982;
- *
- * @test_Strategy: Call JMSContext.getMetaData() to retrieve the
- * ConnectionMetaData and then verify the ConnectionMetaData for correctness.
- */
- public void getMetaDataTest() throws Exception {
- boolean pass = true;
- ConnectionMetaData data = null;
-
- try {
- data = context.getMetaData();
-
- if (!verifyMetaData(data))
- pass = false;
-
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("getMetaDataTest failed");
- }
- }
-
- /*
- * @testName: getSessionModeTest
- *
- * @assertion_ids: JMS:JAVADOC:986;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.getSessionMode().
- *
- * Cycle through all session modes to create each JMSContext with each mode
- * and verify that each session mode is set correctly.
- */
- public void getSessionModeTest() throws Exception {
- boolean pass = true;
- JMSContext context = null;
-
- // Test default case
- try {
- context = cf.createContext(user, password);
- int expSessionMode = JMSContext.AUTO_ACKNOWLEDGE;
- TestUtil.logMsg("Calling getSessionMode and expect " + expSessionMode
- + " to be returned");
- int actSessionMode = context.getSessionMode();
- if (actSessionMode != expSessionMode) {
- TestUtil.logErr("getSessionMode() returned " + actSessionMode
- + ", expected " + expSessionMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getSessionModeTest");
- } finally {
- try {
- if (context != null)
- context.close();
- } catch (Exception e) {
- }
- }
-
- // Test non-default case
- int expSessionMode[] = { JMSContext.SESSION_TRANSACTED,
- JMSContext.AUTO_ACKNOWLEDGE, JMSContext.CLIENT_ACKNOWLEDGE,
- JMSContext.DUPS_OK_ACKNOWLEDGE, };
-
- // Cycle through all session modes
- for (int i = 0; i < expSessionMode.length; i++) {
- if ((vehicle.equals("ejb") || vehicle.equals("jsp")
- || vehicle.equals("servlet"))) {
- if (expSessionMode[i] == JMSContext.SESSION_TRANSACTED
- || expSessionMode[i] == JMSContext.CLIENT_ACKNOWLEDGE)
- continue;
- }
- try {
- TestUtil.logMsg(
- "Creating context with session mode (" + expSessionMode[i] + ")");
- context = cf.createContext(user, password, expSessionMode[i]);
- TestUtil.logMsg("Calling getSessionMode and expect " + expSessionMode[i]
- + " to be returned");
- int actSessionMode = context.getSessionMode();
- if (actSessionMode != expSessionMode[i]) {
- TestUtil.logErr("getSessionMode() returned " + actSessionMode
- + ", expected " + expSessionMode[i]);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getSessionModeTest");
- } finally {
- try {
- if (context != null)
- context.close();
- } catch (Exception e) {
- }
- }
- }
-
- if (!pass) {
- throw new Exception("getSessionModeTest failed");
- }
- }
-
- /*
- * @testName: getTransactedTest
- *
- * @assertion_ids: JMS:JAVADOC:990;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.getTransacted().
- *
- * Create a JMSContext with JMSContext.AUTO_ACKNOWLEDGE and verify that
- * JMSContext.getTransacted() returns false.
- *
- * Create a JMSContext with JMSContext.SESSION_TRANSACTED and verify that
- * JMSContext.getTransacted() returns true.
- */
- public void getTransactedTest() throws Exception {
- boolean pass = true;
- JMSContext context = null;
-
- // Test for transacted mode false
- try {
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- boolean expTransacted = false;
- TestUtil.logMsg("Calling getTransacted and expect " + expTransacted
- + " to be returned");
- boolean actTransacted = context.getTransacted();
- if (actTransacted != expTransacted) {
- TestUtil.logErr("getTransacted() returned " + actTransacted
- + ", expected " + expTransacted);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- if (context != null)
- context.close();
- } catch (Exception e) {
- }
- }
-
- // Test for transacted mode true
- if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
- try {
- context = cf.createContext(user, password,
- JMSContext.SESSION_TRANSACTED);
- boolean expTransacted = true;
- TestUtil.logMsg("Calling getTransacted and expect " + expTransacted
- + " to be returned");
- boolean actTransacted = context.getTransacted();
- if (actTransacted != expTransacted) {
- TestUtil.logErr("getTransacted() returned " + actTransacted
- + ", expected " + expTransacted);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getTransactedTest");
- } finally {
- try {
- if (context != null)
- context.close();
- } catch (Exception e) {
- }
- }
- }
-
- if (!pass) {
- throw new Exception("getTransactedTest failed");
- }
- }
-
- /*
- * @testName: setGetAutoStartTest
- *
- * @assertion_ids: JMS:JAVADOC:1138; JMS:JAVADOC:1129;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.setAutoStart(boolean). JMSContext.getAutoStart().
- */
- public void setGetAutoStartTest() throws Exception {
- boolean pass = true;
- // Test default case
- try {
- boolean expAutoStart = true;
- TestUtil.logMsg("Calling getAutoStart and expect " + expAutoStart
- + " to be returned");
- boolean actAutoStart = context.getAutoStart();
- if (actAutoStart != expAutoStart) {
- TestUtil.logErr("getAutoStart() returned " + actAutoStart
- + ", expected " + expAutoStart);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
-
- // Test non-default case
- try {
- boolean expAutoStart = false;
- TestUtil.logMsg("Calling setAutoStart(" + expAutoStart + ")");
- context.setAutoStart(expAutoStart);
- TestUtil.logMsg("Calling getAutoStart and expect " + expAutoStart
- + " to be returned");
- boolean actAutoStart = context.getAutoStart();
- if (actAutoStart != expAutoStart) {
- TestUtil.logErr("getAutoStart() returned " + actAutoStart
- + ", expected " + expAutoStart);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetAutoStartTest");
- }
-
- if (!pass) {
- throw new Exception("setGetAutoStartTest failed");
- }
- }
-
- /*
- * @testName: createConsumerTest
- *
- * @assertion_ids: JMS:JAVADOC:942; JMS:JAVADOC:945; JMS:JAVADOC:949;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.createConsumer(Destination)
- * JMSContext.createConsumer(Destination, String)
- * JMSContext.createConsumer(Destination, String, boolean)
- *
- * 1. Send x text messages to a Topic. 2. Create a JMSConsumer with selector
- * to consume just the last message in the Topic. 3. Create a JMSConsumer
- * again to consume the rest of the messages in the Topic. 4. Test
- * createConsumer with noLocal=false case 5. Test createConsumer with
- * noLocal=true case
- */
- public void createConsumerTest() throws Exception {
- boolean pass = true;
- JMSConsumer consumerSelect = null;
- try {
- TextMessage tempMsg = null;
- Enumeration msgs = null;
-
- // Create selective consumer
- TestUtil.logMsg(
- "Create selective JMSConsumer with selector [\"lastMessage=TRUE\"]");
- consumerSelect = context.createConsumer(destination, "lastMessage=TRUE");
-
- // Send "numMessages" messages to Topic plus end of stream message
- TestUtil.logMsg("Send " + numMessages + " to Topic");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createConsumerTest" + i);
- if (i == numMessages) {
- TestUtil.logMsg("Set boolean property lastMessage=true");
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- TestUtil.logMsg("Set boolean property lastMessage=false");
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- // Receive last message in Topic using selective consumer
- TestUtil.logMsg(
- "Receive last message with selective JMSConsumer and boolean property lastMessage=true");
- tempMsg = (TextMessage) consumerSelect.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("JMSConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + numMessages + " missing from Topic");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + numMessages)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + numMessages + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received expected message: " + tempMsg.getText());
- }
-
- // Try to receive one more message (should return null)
- TestUtil.logMsg("Try receiving one more message (should get none)");
- tempMsg = (TextMessage) consumerSelect.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("JMSConsumer received message " + tempMsg.getText()
- + " (Expected None)");
- TestUtil.logErr(
- "JMSConsumer with selector should have returned just 1 message");
- pass = false;
- } else {
- TestUtil.logMsg("Received no more messages (CORRECT)");
- }
- consumerSelect.close();
- consumerSelect = null;
-
- // Receive rest of messages in Topic with normal JMSConsumer
- TestUtil.logMsg("Receive rest of messages with normal JMSConsumer");
- for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("JMSConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + msgCount + " missing from Topic");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + msgCount)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + msgCount + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received message: " + tempMsg.getText());
- }
- }
-
- // Try to receive one more message (should return null)
- tempMsg = (TextMessage) consumer.receive(timeout);
- TestUtil.logMsg("Try receiving one more message (should get none)");
- if (tempMsg != null) {
- TestUtil.logErr("JMSConsumer received message " + tempMsg.getText()
- + " (Expected None)");
- TestUtil.logErr("JMSConsumer should have returned just "
- + (numMessages - 1) + " messages");
- pass = false;
- } else {
- TestUtil.logMsg("Received no more messages (CORRECT)");
- }
-
- // Create selective JMSConsumer to consume last message in Topic using
- // message
- // selector and noLocal=false
- TestUtil.logMsg(
- "Create selective JMSConsumer with selector [\"lastMessage=TRUE\"] and noLocal=false");
- consumerSelect = context.createConsumer(topic, "lastMessage=TRUE", false);
-
- // send "numMessages" messages to Topic plus end of stream message
- TestUtil.logMsg("Send " + numMessages + " to Topic");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createConsumerTest" + i);
- if (i == numMessages) {
- TestUtil.logMsg("Set boolean property lastMessage=true");
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- TestUtil.logMsg("Set boolean property lastMessage=false");
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg(
- "Receive last message with selective JMSConsumer and boolean property lastMessage=true");
- tempMsg = (TextMessage) consumerSelect.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("JMSConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + numMessages + " missing from Topic");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + numMessages)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + numMessages + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received expected message: " + tempMsg.getText());
- }
-
- // Try to receive one more message (should return null)
- TestUtil.logMsg("Try receiving one more message (should get none)");
- tempMsg = (TextMessage) consumerSelect.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("JMSConsumer received message " + tempMsg.getText()
- + " (Expected None)");
- TestUtil.logErr(
- "JMSConsumer with selector should have returned just 1 message");
- pass = false;
- } else {
- TestUtil.logMsg("Received no more messages (CORRECT)");
- }
- consumerSelect.close();
- consumerSelect = null;
-
- TestUtil.logMsg(
- "Create selective JMSConsumer with selector [\"lastMessage=TRUE\"] and noLocal=true");
- consumerSelect = context.createConsumer(topic, "lastMessage=TRUE", true);
-
- // Test noLocal=true case
- // send "numMessages" messages to Topic plus end of stream message
- TestUtil.logMsg("Send " + numMessages + " to Topic");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createConsumerTest" + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- // Receive last message in Topic using message selector and noLocal=true
- TestUtil.logMsg(
- "Try receiving a message with selective JMSConsumer (should get none)");
- tempMsg = (TextMessage) consumerSelect.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logMsg("Received no message (CORRECT)");
- } else {
- TestUtil.logErr("JMSConsumer received message " + tempMsg.getText()
- + " (Expected None)");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("createConsumerTest");
- } finally {
- try {
- if (consumerSelect != null)
- consumerSelect.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("createConsumerTest failed");
- }
- }
-
- /*
- * @testName: createDurableConsumerTest1
- *
- * @assertion_ids: JMS:JAVADOC:953;
- *
- * @test_Strategy: Creates a durable subscription with the specified name on
- * the specified topic and creates a MessageConsumer on that durable
- * subscription.
- *
- * This uses a connection factory WITH client identifier set.
- *
- * Tests the following API method:
- *
- * JMSContext.createDurableConsumer(Topic, String)
- *
- * 1. Create a durable subscription with the specified name on the specified
- * topic and create a durable MessageConsumer on that durable subscription.
- * This uses a connection factory WITH client identifier set. 2. Send
- * TextMessage (message1) to the Topic. 3. Consume message via MessageConsumer
- * created. Verify message1 received. 4. Close consumer. 5. Send another
- * TextMessage (message2) to the Topic. 6. Recreate the durable
- * MessageConsumer on that durable subscription. 7. Consume message via
- * MessageConsumer created. Verify message2 received.
- */
- public void createDurableConsumerTest1() throws Exception {
- boolean pass = true;
- String message1 = "Where are you!";
- String message2 = "Who are you!";
- String durableSubscriptionName = "createDurableConsumerTest1";
- try {
- TextMessage expTextMessage = null;
-
- // Create Durable Subscription and a MessageConsumer for it
- TestUtil
- .logMsg("Create a Durable Subscription and a MessageConsumer for it");
- consumer2 = context2.createDurableConsumer(topic,
- durableSubscriptionName);
-
- TestUtil.logMsg("Send TextMessage message1 to Topic");
- expTextMessage = context2.createTextMessage(message1);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createDurableConsumerTest1");
- producer2.send(destination2, expTextMessage);
- TestUtil.logMsg("TextMessage message1 sent");
-
- TestUtil.logMsg("Receive TextMessage message1");
- TextMessage actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage message1");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- TestUtil.logMsg("Close durable MessageConsumer");
- consumer2.close();
-
- TestUtil.logMsg("Send TextMessage message2 to Topic");
- expTextMessage = context2.createTextMessage(message1);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createDurableConsumerTest1");
- producer2.send(destination2, expTextMessage);
- TestUtil.logMsg("TextMessage message2 sent");
-
- // Recreate Durable Subscription and a MessageConsumer for it
- TestUtil.logMsg(
- "Recreate a Durable Subscription and a MessageConsumer for it");
- consumer2 = context2.createDurableConsumer(topic,
- durableSubscriptionName);
-
- TestUtil.logMsg("Receive TextMessage message2");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage message2");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("createDurableConsumerTest1", e);
- } finally {
- try {
- cleanupSubscription(consumer2, context2, durableSubscriptionName);
- producer2 = null;
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("createDurableConsumerTest1 failed");
- }
- }
-
- /*
- * @testName: createDurableConsumerTest2
- *
- * @assertion_ids: JMS:JAVADOC:956;
- *
- * @test_Strategy: Creates a durable subscription with the specified name on
- * the specified topic and creates a MessageConsumer on that durable
- * subscription, specifying a message selector and whether messages published
- * by its own connection should be delivered to it.
- *
- * This uses a connection factory WITH client identifier set.
- *
- * Tests the following API method:
- *
- * JMSContext.createDurableConsumer(Topic,String,String,boolean)
- *
- * 1. Create a durable subscription with the specified name on the specified
- * topic and create a durable MessageConsumer on that durable subscription
- * specifing a message selector and whether messages published by its own
- * connection should be delivered to it. This uses a connection factory WITH
- * client identifier set. 2. Send a number of messages to the Topic. 3. Test
- * both noLocal=true and noLocal=false cases. 4. Verify message with specified
- * selector received by MessageConsumer in the noLocal=false case only.
- *
- */
- public void createDurableConsumerTest2() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- String durableSubscriptionName = "createDurableConsumerTest2";
- try {
- // Create Durable Subscription and a MessageConsumer for it
- // Test the noLocal=false case with message selector
- TestUtil.logMsg(
- "Create a Durable Subscription and a MessageConsumer with message selector, noLocal=false");
- consumer2 = context2.createDurableConsumer(topic, durableSubscriptionName,
- "lastMessage = TRUE", false);
-
- // send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " messages to Topic");
- for (int i = 1; i <= numMessages; i++) {
- TextMessage tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createDurableConsumerTest2" + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer2.send(destination2, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg("Receive TextMessage");
- TestUtil.logMsg(
- "This is noLacal=false case so expect to get just last message");
- TextMessage expTextMessage = context2
- .createTextMessage("Message " + numMessages);
- TextMessage actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("createDurableConsumerTest2", e);
- } finally {
- try {
- if (consumer2 != null)
- consumer2.close();
- } catch (Exception e) {
- }
- }
-
- try {
- // Create Durable Subscription and a MessageConsumer for it
- // Test the noLocal=true case with message selector
- TestUtil.logMsg(
- "Create a Durable Subscription and a MessageConsumer with message selector, noLocal=true");
- consumer2 = context2.createDurableConsumer(topic, durableSubscriptionName,
- "lastMessage = TRUE", true);
-
- // send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " messages to Topic");
- for (int i = 1; i <= numMessages; i++) {
- TextMessage tempMsg = context2.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createDurableConsumerTest2" + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer2.send(destination2, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer2.receive(timeout);
-
- if (actTextMessage != null) {
- TestUtil.logErr("Message was delivered when noLocal=true");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createDurableConsumerTest2", e);
- } finally {
- try {
- cleanupSubscription(consumer2, context2, durableSubscriptionName);
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("createDurableConsumerTest2 failed");
- }
- }
-
- /*
- * @testName: createSharedDurableConsumerTest1
- *
- * @assertion_ids: JMS:JAVADOC:1382;
- *
- * @test_Strategy: Creates a shared durable subscription with the specified
- * name on the specified topic and creates a JMSConsumer on that durable
- * subscription.
- *
- * This uses a connection factory WITH client identifier set.
- *
- * Tests the following API method:
- *
- * JMSContext.createSharedDurableConsumer(Topic, String)
- *
- * 1. Create a shared durable subscription with the specified name on the
- * specified topic and create a durable JMSConsumer on that durable
- * subscription. This uses a connection factory WITH client identifier set. 2.
- * Create a 2nd JMSConsumer for it. 3. Send TextMessage (message1) to the
- * Topic. 3. Consume message via 1st JMSConsumer created. Verify message1
- * received. 4. Close 1st consumer. 5. Send another TextMessage (message2) to
- * the Topic. 6. Consume message via 2nd JMSConsumer created. Verify message2
- * received.
- */
- public void createSharedDurableConsumerTest1() throws Exception {
- boolean pass = true;
- String message1 = "Message1!";
- String message2 = "Message2!";
- String durableSubscriptionName = "createSharedDurableConsumerTest1";
- try {
- // Close default consumer
- consumer.close();
-
- TextMessage expTextMessage = null;
-
- // Create a shared Durable Subscription and a JMSConsumer for it
- TestUtil.logMsg(
- "Create a shared Durable Subscription and 1st JMSConsumer for it");
- consumer = context2.createSharedDurableConsumer(topic,
- durableSubscriptionName);
-
- // Create 2nd JMSConsumer for it
- TestUtil.logMsg("Create 2nd JMSConsumer for it");
- consumer2 = context2.createSharedDurableConsumer(topic,
- durableSubscriptionName);
-
- TestUtil.logMsg("Send TextMessage message1 to Topic");
- expTextMessage = context2.createTextMessage(message1);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createSharedDurableConsumerTest1");
- producer2.send(destination2, expTextMessage);
- TestUtil.logMsg("TextMessage message1 sent");
-
- TestUtil.logMsg("Receive TextMessage message1 from consumer1");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage message1");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- TestUtil.logMsg("Close 1st shared durable JMSConsumer");
- consumer.close();
-
- TestUtil.logMsg("Send TextMessage message2 to Topic");
- expTextMessage = context2.createTextMessage(message2);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createSharedDurableConsumerTest1");
- producer2.send(destination2, expTextMessage);
- TestUtil.logMsg("TextMessage message2 sent");
-
- TestUtil.logMsg("Receive TextMessage message2 from consumer2");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage message2");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
-
- TestUtil
- .logMsg("Now there should be no more messages to receive from topic");
-
- TestUtil
- .logMsg("Recreate Durable Subscription and 1st JMSConsumer for it");
- consumer = context2.createSharedDurableConsumer(topic,
- durableSubscriptionName);
-
- TestUtil
- .logMsg("Try and receive a message from consumer1 (should get NONE)");
- actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage != null) {
- TestUtil.logErr("Consumer1 received a message (FAIL)");
- pass = false;
- } else {
- TestUtil.logMsg("Consumer1 didn't receive a message (PASS)");
- }
-
- TestUtil
- .logMsg("Try and receive a message from consumer2 (should get NONE)");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage != null) {
- TestUtil.logErr("Consumer2 received a message (FAIL)");
- pass = false;
- } else {
- TestUtil.logMsg("Consumer2 didn't receive a message (PASS)");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createSharedDurableConsumerTest1", e);
- } finally {
- try {
- producer2 = null;
- if (consumer != null)
- consumer.close();
- cleanupSubscription(consumer2, context2, durableSubscriptionName);
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- if (!pass) {
- throw new Exception("createSharedDurableConsumerTest1 failed");
- }
- }
-
- /*
- * @testName: createSharedDurableConsumerTest2
- *
- * @assertion_ids: JMS:JAVADOC:1385;
- *
- * @test_Strategy: Creates a shared durable subscription with the specified
- * name on the specified topic and creates a JMSConsumer on that durable
- * subscription, specifying a message selector and whether messages published
- * by its own connection should be delivered to it.
- *
- * This uses a connection factory WITH client identifier set.
- *
- * Tests the following API method:
- *
- * JMSContext.createSharedDurableConsumer(Topic,String,String)
- *
- * 1. Create a shared durable subscription with the specified name on the
- * specified topic and create a durable JMSConsumer on that durable
- * subscription specifing a message selector and whether messages published by
- * its own connection should be delivered to it. This uses a connection
- * factory WITH client identifier set. 2. Create a 2nd JMSConsumer for it. 3.
- * Send a number of messages to the Topic.
- *
- */
- public void createSharedDurableConsumerTest2() throws Exception {
- boolean pass = true;
- String durableSubscriptionName = "createSharedDurableConsumerTest2";
- try {
- // Close default consumer
- consumer.close();
-
- // Create a shared Durable Subscription and a JMSConsumer for it
- TestUtil.logMsg(
- "Create shared Durable Subscription and 1st JMSConsumer with message selector");
- consumer = context2.createSharedDurableConsumer(topic,
- durableSubscriptionName, "lastMessage = TRUE");
- // Create 2nd JMSConsumer for it
- TestUtil.logMsg("Create 2nd JMSConsumer with message selector");
- consumer2 = context2.createSharedDurableConsumer(topic,
- durableSubscriptionName, "lastMessage = TRUE");
-
- // send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " messages to Topic");
- for (int i = 1; i <= numMessages; i++) {
- TextMessage tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createSharedDurableConsumerTest2" + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer2.send(destination2, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg("Receive TextMessage from consumer1");
- TextMessage expTextMessage = context2
- .createTextMessage("Message " + numMessages);
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createSharedDurableConsumerTest2", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- if (consumer2 != null)
- consumer2.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- if (!pass) {
- throw new Exception("createSharedDurableConsumerTest2 failed");
- }
- }
-
- /*
- * @testName: createSharedDurableConsumerTest3
- *
- * @assertion_ids: JMS:JAVADOC:1382;
- *
- * @test_Strategy: Creates a shared durable subscription with the specified
- * name on the specified topic and creates a JMSConsumer on that durable
- * subscription.
- *
- * This uses a connection factory WITH client identifier unset.
- *
- * Tests the following API method:
- *
- * JMSContext.createSharedDurableConsumer(Topic, String)
- *
- * 1. Create a shared durable subscription with the specified name on the
- * specified topic and create a durable JMSConsumer on that durable
- * subscription. This uses a connection factory WITH client identifier unset.
- * 2. Create a 2nd JMSConsumer for it. 3. Send TextMessage (message1) to the
- * Topic. 3. Consume message via 1st JMSConsumer created. Verify message1
- * received. 4. Close 1st consumer. 5. Send another TextMessage (message2) to
- * the Topic. 6. Consume message via 2nd JMSConsumer created. Verify message2
- * received.
- */
- public void createSharedDurableConsumerTest3() throws Exception {
- boolean pass = true;
- String message1 = "Message1!";
- String message2 = "Message2!";
- String durableSubscriptionName = "createSharedDurableConsumerTest3";
- try {
- // Close default consumer
- consumer.close();
-
- TextMessage expTextMessage = null;
-
- // Create a shared Durable Subscription and a JMSConsumer for it
- TestUtil.logMsg(
- "Create a shared Durable Subscription and 1st JMSConsumer for it");
- consumer = context.createSharedDurableConsumer(topic,
- durableSubscriptionName);
-
- // Create 2nd JMSConsumer for it
- TestUtil.logMsg("Create 2nd JMSConsumer for it");
- consumer2 = context.createSharedDurableConsumer(topic,
- durableSubscriptionName);
-
- TestUtil.logMsg("Send TextMessage message1 to Topic");
- expTextMessage = context.createTextMessage(message1);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createSharedDurableConsumerTest3");
- producer2.send(destination, expTextMessage);
- TestUtil.logMsg("TextMessage message1 sent");
-
- TestUtil.logMsg("Receive TextMessage message1 from consumer1");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage message1");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- TestUtil.logMsg("Close 1st shared durable JMSConsumer");
- consumer.close();
-
- TestUtil.logMsg("Send TextMessage message2 to Topic");
- expTextMessage = context.createTextMessage(message2);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createSharedDurableConsumerTest3");
- producer2.send(destination, expTextMessage);
- TestUtil.logMsg("TextMessage message2 sent");
-
- TestUtil.logMsg("Receive TextMessage message2 from consumer2");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage message2");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
-
- TestUtil
- .logMsg("Now there should be no more messages to receive from topic");
-
- TestUtil
- .logMsg("Recreate Durable Subscription and 1st JMSConsumer for it");
- consumer = context.createSharedDurableConsumer(topic,
- durableSubscriptionName);
-
- TestUtil
- .logMsg("Try and receive a message from consumer1 (should get NONE)");
- actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage != null) {
- TestUtil.logErr("Consumer1 received a message (FAIL)");
- pass = false;
- } else {
- TestUtil.logMsg("Consumer1 didn't receive a message (PASS)");
- }
-
- TestUtil
- .logMsg("Try and receive a message from consumer2 (should get NONE)");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage != null) {
- TestUtil.logErr("Consumer2 received a message (FAIL)");
- pass = false;
- } else {
- TestUtil.logMsg("Consumer2 didn't receive a message (PASS)");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createSharedDurableConsumerTest3", e);
- } finally {
- try {
- producer2 = null;
- if (consumer != null)
- consumer.close();
- cleanupSubscription(consumer2, context, durableSubscriptionName);
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- if (!pass) {
- throw new Exception("createSharedDurableConsumerTest3 failed");
- }
- }
-
- /*
- * @testName: createSharedConsumerTest1
- *
- * @assertion_ids: JMS:JAVADOC:1151; JMS:SPEC:269;
- *
- * @test_Strategy: Creates a shared non-durable subscription with the
- * specified name on the specified topic, and creates a JMSConsumer on that
- * subscription.
- *
- * Tests the following API method:
- *
- * JMSContext.createSharedConsumer(Topic, String)
- *
- * 1. Creates a shared non-durable subscription with the specified name on the
- * specified topic, and creates a JMSConsumer on that subscription. 2. Create
- * a second JMSConsumer on that subscription. 3. Send a text message to the
- * Topic. 4. Consume message via the first JMSConsumer and message should be
- * received. 5. Attempt to consume message via second JMSConsumer and no
- * message should be received. 6. Re-Send a text message to the Topic. 7.
- * Consume message via the second JMSConsumer and message should be received.
- * 8. Attempt to consume message via first JMSConsumer and no message should
- * be received.
- */
- public void createSharedConsumerTest1() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- String sharedSubscriptionName = "createSharedConsumerTest1";
- try {
- TextMessage expTextMessage = null;
-
- // Create shared non-durable Subscription and a JMSConsumer for it
- TestUtil.logMsg(
- "Create a shared non-durable Subscription and a JMSConsumer for it");
- consumer.close();
- consumer = context.createSharedConsumer(topic, sharedSubscriptionName);
-
- // Create a second JMSConsumer for the subscription
- TestUtil.logMsg("Create a second JMSConsumer for the Subscription");
- consumer2 = context.createSharedConsumer(topic, sharedSubscriptionName);
-
- TestUtil.logMsg("Send message to Topic");
- expTextMessage = context.createTextMessage(message);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- sharedSubscriptionName);
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Message sent");
-
- TestUtil.logMsg("Receive TextMessage from consumer1");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- TestUtil.logMsg(
- "Attempt to Receive TextMessage from consumer2 - there should be none");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage != null) {
- throw new Exception("Did receive TextMessage - unexpected.");
- } else
- TestUtil.logMsg("Did not receive TextMessage - expected.");
-
- TestUtil.logMsg("Send another message to Topic");
- expTextMessage = context.createTextMessage(message);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- sharedSubscriptionName);
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Message sent");
-
- TestUtil.logMsg("Receive TextMessage from consumer2");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- TestUtil.logMsg(
- "Attempt to Receive TextMessage from consumer1 - there should be none");
- actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage != null) {
- throw new Exception("Did receive TextMessage - unexpected.");
- } else
- TestUtil.logMsg("Did not receive TextMessage - expected.");
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createSharedConsumerTest1", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- if (consumer2 != null)
- consumer2.close();
- } catch (Exception e) {
- TestUtil.logMsg("Ignoring exception closing consumers: " + e);
- }
- }
-
- if (!pass) {
- throw new Exception("createSharedConsumerTest1 failed");
- }
- }
-
- /*
- * @testName: createSharedConsumerTest2
- *
- * @assertion_ids: JMS:JAVADOC:1155; JMS:SPEC:269; JMS:SPEC:270;
- *
- * @test_Strategy: Creates a shared non-durable subscription with the
- * specified name on the specified topic and creates a JMSConsumer on that
- * subscription, specifying a message selector.
- *
- * Tests the following API method:
- *
- * JMSContext.createSharedConsumer(Topic, String, String)
- *
- * 1. Create a shared non-durable subscription with the specified name on the
- * specified topic, and creates a JMSConsumer on that subscription, specifying
- * a message selector. 2. Create a second JMSConsumer on that subscription. 3.
- * Send a text message to the Topic. 4. Consume message via first JMSConsumer
- * and msg selector and message should be received. 5. Attempt to consume
- * message via second JMSConsumer and msg selector and no message received. 6.
- * Re-Send a text message to the Topic. 7. Consume message via second
- * JMSConsumer and msg selector and message should be received. 8. Attempt to
- * consume message via first JMSConsumer and msg selector and no message
- * received.
- *
- */
- public void createSharedConsumerTest2() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- String sharedSubscriptionName = "createSharedConsumerTest2";
- try {
- // Create shared non-durable Subscription and a JMSConsumer for it
- TestUtil.logMsg(
- "Create a shared non-durable Subscription and a JMSConsumer for it");
- consumer.close();
- consumer = context.createSharedConsumer(topic, sharedSubscriptionName,
- "lastMessage = TRUE");
-
- // Create a second JMSConsumer for the subscription
- TestUtil.logMsg("Create a second JMSConsumer for the Subscription");
- consumer2 = context.createSharedConsumer(topic, sharedSubscriptionName,
- "lastMessage = TRUE");
-
- // send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " to Topic");
- for (int i = 1; i <= numMessages; i++) {
- TextMessage tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- sharedSubscriptionName + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg("Receive TextMessage from consumer1");
- TextMessage expTextMessage = context
- .createTextMessage("Message " + numMessages);
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- TestUtil.logMsg(
- "Attempt to Receive TextMessage from consumer2 - there should be none");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage != null) {
- throw new Exception("Did receive TextMessage - unexpected.");
- } else
- TestUtil.logMsg("Did not receive TextMessage - expected.");
-
- // send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " to Topic");
- for (int i = 1; i <= numMessages; i++) {
- TextMessage tempMsg = context.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- sharedSubscriptionName + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(destination, tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg("Receive TextMessage from consumer2");
- expTextMessage = context.createTextMessage("Message " + numMessages);
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- TestUtil.logMsg(
- "Attempt to Receive TextMessage from consumer1 - there should be none");
- actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage != null) {
- throw new Exception("Did receive TextMessage - unexpected.");
- } else
- TestUtil.logMsg("Did not receive TextMessage - expected.");
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createSharedConsumerTest2", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- if (consumer2 != null)
- consumer2.close();
- } catch (Exception e) {
- TestUtil.logMsg("Ignoring exception closing consumers: " + e);
- }
- }
-
- if (!pass) {
- throw new Exception("createSharedConsumerTest2 failed");
- }
- }
-
- /*
- * @testName: multipleCloseContextTest
- *
- * @assertion_ids: JMS:JAVADOC:912; JMS:SPEC:108;
- *
- * @test_Strategy: Call close() twice on a JMSContext. This MUST NOT throw an
- * exception.
- */
- public void multipleCloseContextTest() throws Exception {
- try {
- TestUtil.logTrace("Call close on JMSContext created in setup.");
- context.close();
- TestUtil.logTrace("Call close on a JMSContext a second time");
- context.close();
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- throw new Exception("multipleCloseContextTest");
- }
- }
-
- /*
- * @testName: simpleDurableConsumerTest
- *
- * @assertion_ids: JMS:JAVADOC:1084; JMS:JAVADOC:953;
- *
- * @test_Strategy: Send single message to a topic and verify receipt of it
- * with a durable subscriber. This uses a connection factory WITHOUT client
- * identifier set. Tests the use of the following API's:
- *
- * o JMSContext.createDurableConsumer(Topic, String) o
- * JMSContext.unsubscribe(String)
- */
- public void simpleDurableConsumerTest() throws Exception {
- String durableSubscriptionName = "simpleDurableConsumerTest";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- TestUtil.logMsg("Create DurableConsumer with subscriber name");
- consumer2 = context2.createDurableConsumer(topic,
- durableSubscriptionName);
-
- TestUtil.logMsg("Creating and sending 1 message");
- messageSent = context2.createTextMessage("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- durableSubscriptionName);
- producer.send(destination, messageSent);
- TestUtil.logMsg("Receiving message");
- messageReceived = (TextMessage) consumer2.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logMsg("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- throw new Exception("simpleDurableConsumerTest");
- } finally {
- try {
- cleanupSubscription(consumer2, context2, durableSubscriptionName);
- } catch (Exception e) {
- }
- }
- }
-
- /*
- * @testName: inactiveDurableConsumerTopicRecTest
- *
- * @assertion_ids: JMS:JAVADOC:953; JMS:JAVADOC:1084; JMS:JAVADOC:1098;
- *
- * @test_Strategy: Send and receive a message from a topic. Inactivate the
- * subscriber, send another message. Verify that when the subscriber is
- * activated the message is received. This uses a connection factory WITH
- * client identifier set.
- *
- * o JMSContext.createDurableConsumer(Topic, String) o JMSConsumer.close() o
- * JMSContext.unsubscribe(String)
- */
- public void inactiveDurableConsumerTopicRecTest() throws Exception {
- String durableSubscriptionName = "inactiveDurableConsumerTopicRecTest";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageSent2 = null;
- TextMessage messageReceived = null;
-
- // Create Durable Subscription and a JMSConsumer for it
- TestUtil.logMsg("Create a Durable Subscription and a JMSConsumer for it");
- consumer2 = context2.createDurableConsumer(topic2,
- durableSubscriptionName);
-
- // send message
- TestUtil.logTrace("Creating and sending 1 message");
- messageSent = context2.createTextMessage("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- durableSubscriptionName);
- producer2.send(destination2, messageSent);
-
- TestUtil.logTrace("Receiving message");
- messageReceived = (TextMessage) consumer2.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logMsg("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // make the durable subscriber inactive
- consumer2.close();
-
- // send more messages
- TestUtil.logTrace("Creating and sending another message");
- messageSent2 = context2
- .createTextMessage("test that messages are durable");
- messageSent2.setStringProperty("COM_SUN_JMS_TESTNAME",
- durableSubscriptionName);
- producer2.send(destination2, messageSent2);
-
- // Create Durable Subscription and a JMSConsumer for it
- TestUtil.logMsg("Create a Durable Subscription and a JMSConsumer for it");
- consumer2 = context2.createDurableConsumer(topic2,
- durableSubscriptionName);
-
- messageReceived = (TextMessage) consumer2.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent2.getText())) {
- TestUtil
- .logTrace("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logTrace("Received correct message");
- } else {
- throw new Exception("Received incorrect message.");
- }
-
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- throw new Exception("inactiveDurableConsumerTopicRecTest");
- } finally {
- try {
- cleanupSubscription(consumer2, context2, durableSubscriptionName);
- } catch (Exception e) {
- }
- }
- }
-
- /*
- * @testName: durableConsumerTopicNoLocalTest
- *
- * @assertion_ids: JMS:SPEC:161; JMS:SPEC:164; JMS:SPEC:165; JMS:JAVADOC:256;
- * JMS:JAVADOC:99; JMS:JAVADOC:334;
- *
- *
- * @test_Strategy: 1) Create topic connection with normal consumer and
- * (no_local=true) durable consumer. 2) Publish x messages to topic and
- * receive them with normal consumer. 3) Try and receive messages with
- * (no_local=true) durable consumer and verify that you cannot receive them.
- * 4) Publish x more messages to topic. 4) Close the (no_local=true) durable
- * consumer. 5) Create a new (no_local=false) durable consumer with the same
- * subscription name and same topic as (no_local=true) durable consumer. 6)
- * Try and receive messages with (no_local=false) durable consumer. Verify
- * that you cannot receive any messages. Recreating a durable consumer with a
- * change to (no_local setting) causes previous durable subscription to become
- * invalid so all the old messages are deleted and you start anew with a clean
- * slate.
- *
- * A client can change an existing durable subscription by creating a durable
- * JMSConsumer with the same name and topic but different (no_local setting).
- * Changing a durable consumer is equivalent to unsubscribing (deleting) the
- * old one and creating a new one.
- *
- * So if a client subsequently changes the no_local setting, all the existing
- * messages stored in the durable subscription become invalid since they are
- * inconsistent with the new no_local setting. The only safe thing to do is to
- * delete all the old messages and start anew.
- *
- * This uses a connection factory WITH client identifier set.
- */
- public void durableConsumerTopicNoLocalTest() throws Exception {
- JMSConsumer tConNoLocal = null;
- String subscriptionName = "DurableConsumerTopicNoLocalTestSubscription";
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- int num = 10;
- Message messageSent = null;
- Message messageReceived = null;
-
- // create normal Consumer from JMSContext
- TestUtil.logMsg("Create normal Consumer");
- consumer2 = context2.createConsumer(topic);
-
- // create DurableConsumer with no_local=true from JMSContext
- TestUtil.logMsg("Create DurableConsumer with no_local=true");
- tConNoLocal = context2.createDurableConsumer(topic, subscriptionName, "",
- true);
-
- // publish messages to topic
- TestUtil.logMsg("Sending " + num + " messages to topic");
- messageSent = context2.createMessage();
- messageSent.setBooleanProperty("lastMessage", false);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableConsumerTopicNoLocalTest");
- for (int i = 0; i < num; i++) {
- producer2.send(destination2, messageSent);
- }
-
- // receive messages with default normal consumer
- TestUtil.logMsg("Attempting to receive messages from normal consumer");
- for (int i = 0; i < num; i++) {
- messageReceived = consumer2.receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Should have received message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
- TestUtil.logMsg("Received correct message lastMessage=false");
- } else {
- throw new Exception("Received incorrect message lastMessage=true");
- }
- }
-
- // try and receive with (no_local=true) consumer (should not receive any
- // messages)
- TestUtil.logMsg(
- "Attempting to receive messages from (no_local=true) consumer");
- messageReceived = tConNoLocal.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logMsg("Did not receive message (correct)");
- } else {
- throw new Exception("Received unexpected message (incorrect)");
- }
-
- // publish more messages to topic
- TestUtil.logMsg("Sending " + num + " messages to topic");
- for (int i = 0; i < num; i++) {
- producer2.send(destination2, messageSent);
- }
-
- // need to inactivate durable consumer before creating new durable
- // consumer
- TestUtil.logMsg("Close DurableConsumer with no_local=true");
- tConNoLocal.close();
-
- // create new DurableConsumer with no_local=false
- TestUtil.logMsg("Create DurableConsumer with no_local=false");
- tConNoLocal = context2.createDurableConsumer(topic, subscriptionName, "",
- false);
-
- // try and receive a message from this new durable consumer with
- // (no_local=false)
- // should not receive any messages because creating a new DurableConsumer
- // with a
- // different (no_local=false) setting will delete the previous
- // subscription and any
- // messages that were queued
- messageReceived = tConNoLocal.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logMsg(
- "No_local=false consumer did not receive any message (expected)");
- } else {
- throw new Exception(
- "No_local=false consumer received message (unexpected)");
- }
-
- // publish more messages to topic
- TestUtil.logMsg("Sending " + num + " messages to topic");
- messageSent = context2.createMessage();
- messageSent.setBooleanProperty("lastMessage", false);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableConsumerTopicNoLocalTest");
- for (int i = 0; i < num; i++) {
- producer2.send(destination2, messageSent);
- }
-
- // receive messages with (no_local=false) consumer (should receive all
- // messages)
- TestUtil.logMsg(
- "Attempting to receive messages from (no_local=false) consumer");
- for (int i = 0; i < num; i++) {
- messageReceived = tConNoLocal.receive(timeout);
- if (messageReceived == null) {
- throw new Exception("Should have received message");
- } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
- TestUtil.logMsg("Received correct message lastMessage=false");
- } else {
- throw new Exception("Received incorrect message lastMessage=true");
- }
- }
-
- // try and receive one more message (there should be none at this point)
- messageReceived = tConNoLocal.receive(timeout);
- if (messageReceived != null) {
- throw new Exception("Received unexpected final message");
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- throw new Exception("durableConsumerTopicNoLocalTest2");
- } finally {
- try {
- if (consumer2 != null)
- consumer2.close();
- cleanupSubscription(tConNoLocal, context2, subscriptionName);
- } catch (Exception e) {
- }
- }
- }
-
- /*
- * @testName: durableConsumerChangeSelectorTest
- *
- * @assertion_ids: JMS:SPEC:164; JMS:SPEC:165; JMS:JAVADOC:122;
- * JMS:JAVADOC:256; JMS:JAVADOC:99; JMS:JAVADOC:334;
- *
- * @test_Strategy: Create a durable consumer for the default topic. Create a
- * durable topic consumer again, use the same name as the above but change the
- * selector.
- *
- * This uses a connection factory WITH client identifier set.
- */
- public void durableConsumerChangeSelectorTest() throws Exception {
- Topic newTestTopic;
- JMSConsumer durableCon = null;
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // Create a durable consumer with a specified message selector
- TestUtil.logMsg(
- "Create DurableConsumer with MessageSelector=TEST='test' and no_local=false");
- durableCon = context2.createDurableConsumer(topic,
- "durableConsumerChangeSelectorTest", "TEST = 'test'", false);
-
- // publish and receive message with specified message selector
- TestUtil.logMsg("Send and receive the message");
- messageSent = context2.createTextMessage();
- messageSent.setStringProperty("TEST", "test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableConsumerChangeSelectorTest");
- messageSent.setText("For default topic ");
- producer2.send(destination2, messageSent);
- TestUtil.logMsg("Receiving message");
- messageReceived = (TextMessage) durableCon.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logMsg("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
-
- // need to inactivate topic consumer before switching to selector
- durableCon.close();
-
- // Create new durable consumer with a different message selector specified
- TestUtil.logMsg(
- "Create DurableConsumer with new MessageSelector=TEST='new one' and no_local=false");
- durableCon = context2.createDurableConsumer(topic,
- "durableConsumerChangeSelectorTest", "TEST = 'new one'", false);
-
- // Publish message with old message selector
- messageSent.setBooleanProperty("lastMessage", false);
- producer2.send(destination2, messageSent);
-
- // Create and Publish a message with the new message selector
- messageSent = context2.createTextMessage();
- messageSent.setStringProperty("TEST", "new one");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableConsumerChangeSelectorTest");
- messageSent.setText("For new topic");
- messageSent.setBooleanProperty("lastMessage", true);
- producer2.send(destination2, messageSent);
-
- // receive message
- messageReceived = (TextMessage) durableCon.receive(timeout);
- if (messageReceived != null) {
- if (messageReceived.getText().equals(messageSent.getText())
- && messageReceived.getBooleanProperty("lastMessage") == true) {
- TestUtil
- .logMsg("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logMsg("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
- } else {
- throw new Exception("didn't get any message");
- }
-
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- throw new Exception("durableConsumerChangeSelectorTest");
- } finally {
- try {
- cleanupSubscription(durableCon, context2,
- "durableConsumerChangeSelectorTest");
- } catch (Exception e) {
- }
- }
- }
-
- /*
- * @testName: durableConsumerChangeSelectorTest2
- *
- * @assertion_ids: JMS:SPEC:164; JMS:SPEC:165; JMS:JAVADOC:122;
- * JMS:JAVADOC:256; JMS:JAVADOC:99; JMS:JAVADOC:334;
- *
- * @test_Strategy: 1) Create a durable subscription with a message selector
- * string property of (TEST="test") for the default topic. 2) Publish first
- * message with string property that matches the message selector
- * (TEST="test"). 3) Publish second message with string property that does not
- * match the message selector (TEST="test again"). 4) Verify that you can
- * receive the first message. 5) Verify that you cannot receive the second
- * message. 6) Close durable subscription. 7) Create a new durable
- * subscription with the same default topic and subscription name but with a
- * different message selector (TEST="test again") which matches the string
- * property of the second message that was published. 8) Try to receive this
- * second message. It should not recieve the second message. Verify that is
- * does not receive the second message. 9) Close durable subscription.
- *
- * A client can change an existing durable subscription by creating a durable
- * JMSConsumer with the same name and a new topic and/or message selector.
- * Changing a durable consumer is equivalent to unsubscribing (deleting) the
- * old one and creating a new one.
- *
- * So if a client subsequently changes the message selector, all the existing
- * messages stored in the durable subscription become invalid since they are
- * inconsistent with the new message selector. The only safe thing to do is to
- * delete all the old messages and start anew.
- *
- * This uses a connection factory WITH client identifier set.
- */
- public void durableConsumerChangeSelectorTest2() throws Exception {
- Topic newTestTopic;
- JMSConsumer durableCon = null;
- String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageSent2 = null;
- TextMessage messageReceived = null;
-
- // Create a durable consumer with a specified message selector
- TestUtil.logMsg(
- "Create durable subscription with MessageSelector=\"TEST='test'\",");
- TestUtil.logMsg("TopicName=" + topic.getTopicName()
- + " and SubscriptionName=" + "durableConsumerChangeSelectorTest2");
- durableCon = context2.createDurableConsumer(topic,
- "durableConsumerChangeSelectorTest2", "TEST = 'test'", false);
-
- TestUtil.logMsg(
- "Create/Send first message with string property \"TEST = 'test'\"");
- messageSent = context2.createTextMessage();
- messageSent.setStringProperty("TEST", "test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableConsumerChangeSelectorTest2");
- messageSent.setText("Message #1 with string property TEST='test'");
- producer2.send(destination, messageSent);
-
- TestUtil.logMsg(
- "Create/Send second message with string property \"TEST = 'test again'\"");
- messageSent2 = context2.createTextMessage();
- messageSent2.setStringProperty("TEST", "test again");
- messageSent2.setStringProperty("COM_SUN_JMS_TESTNAME",
- "durableConsumerChangeSelectorTest2");
- messageSent2.setText("Message #2 with string property TEST='test again'");
- producer2.send(destination, messageSent2);
-
- // Check and verify that first message is received
- TestUtil.logMsg("Try receiving first message (should get message)");
- messageReceived = (TextMessage) durableCon.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logMsg("Did not receive any message (incorrect)");
- throw new Exception("didn't receive any message");
- } else if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Message text: \"" + messageReceived.getText() + "\"");
- TestUtil.logMsg("Received correct first message");
- } else {
- TestUtil.logMsg("Message text: \"" + messageReceived.getText() + "\"");
- throw new Exception("didn't get the right message");
- }
-
- // Check and verify that seconde message is not received
- TestUtil.logMsg("Try receiving second message (should not get message)");
- messageReceived = (TextMessage) durableCon.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logMsg("Did not receive second message (correct)");
- } else if (messageReceived.getText().equals(messageSent2.getText())) {
- TestUtil.logMsg("Message text: \"" + messageReceived.getText() + "\"");
- throw new Exception("received second message (unexpected)");
- } else {
- TestUtil.logMsg("Message text: \"" + messageReceived.getText() + "\"");
- throw new Exception("received unexpected message");
- }
-
- // need to inactivate topic consumer before switching new consumer
- TestUtil.logMsg("Close durable subscription");
- durableCon.close();
-
- // change selector
- TestUtil.logMsg(
- "Create new durable subscription with MessageSelector=\"TEST='test again'\",");
- TestUtil.logMsg("TopicName=" + topic.getTopicName()
- + " and SubscriptionName=" + "durableConsumerChangeSelectorTest2");
- durableCon = context2.createDurableConsumer(topic,
- "durableConsumerChangeSelectorTest2", "TEST = 'test again'", false);
-
- // receive message
- messageReceived = (TextMessage) durableCon.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logMsg("Did not receive any messages (correct)");
- } else {
- TestUtil.logMsg("Message text: \"" + messageReceived.getText() + "\"");
- throw new Exception("received unexpected message");
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- throw new Exception("durableConsumerChangeSelectorTest2");
- } finally {
- try {
- cleanupSubscription(durableCon, context2,
- "durableConsumerChangeSelectorTest2");
- } catch (Exception e) {
- }
- }
- }
-
- /*
- * @testName: verifyClientIDOnAdminConfiguredIDTest
- *
- * @assertion_ids: JMS:JAVADOC:970; JMS:JAVADOC:1040; JMS:SPEC:264.5;
- * JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:91;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSContext.getClientID()
- *
- * Check and verify the client id of an administratively configured client id.
- */
- public void verifyClientIDOnAdminConfiguredIDTest() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg(
- "Get client id from an administratively configured client id");
- String cid = context2.getClientID();
- if (cid == null) {
- TestUtil.logErr("getClientID returned null (expected cts)");
- pass = false;
- } else if (!cid.equals("cts")) {
- TestUtil.logErr("getClientID() returned " + cid + ", expected cts");
- pass = false;
- } else {
- TestUtil.logMsg("getClientID returned cts (Correct)");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected: " + e);
- throw new Exception("verifyClientIDOnAdminConfiguredIDTest");
- }
-
- if (!pass) {
- throw new Exception("verifyClientIDOnAdminConfiguredIDTest failed");
- }
- }
-
- /*
- * @testName: invalidDestinationRuntimeExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:944; JMS:JAVADOC:947; JMS:JAVADOC:951;
- * JMS:JAVADOC:955; JMS:JAVADOC:958; JMS:JAVADOC:1086; JMS:JAVADOC:1153;
- * JMS:JAVADOC:1157; JMS:JAVADOC:1254; JMS:JAVADOC:1237; JMS:JAVADOC:1242;
- * JMS:JAVADOC:1246; JMS:JAVADOC:1250; JMS:JAVADOC:958; JMS:JAVADOC:1383;
- * JMS:JAVADOC:1161;
- *
- * @test_Strategy: Test InvalidDestinationRuntimeException conditions from
- * various API methods.
- *
- * JMSProducer.send(Destination, Message) JMSProducer.send(Destination,
- * String) JMSProducer.send(Destination, Serializable)
- * JMSProducer.send(Destination, byte[]) JMSProducer.send(Destination, Map)
- * JMSContext.createConsumer(Destination)
- * JMSContext.createConsumer(Destination, String)
- * JMSContext.createConsumer(Destination, String, boolean)
- * JMSContext.createDurableConsumer(Topic, String)
- * JMSContext.createDurableConsumer(Topic, String, String, boolean)
- * JMSContext.createSharedConsumer(Topic, String)
- * JMSContext.createSharedConsumer(Topic, String, String)
- * JMSContext.createSharedDurableConsumer(Topic, String)
- * JMSContext.createSharedDurableConsumer(Topic, String, String)
- * JMSContext.unsubscribe(String)
- */
- public void invalidDestinationRuntimeExceptionTests() throws Exception {
- boolean pass = true;
- Destination invalidDestination = null;
- Topic invalidTopic = null;
- String message = "Where are you!";
- byte[] bytesMsgSend = message.getBytes();
- Map mapMsgSend = new HashMap();
- mapMsgSend.put("StringValue", "sendAndRecvTest7");
- mapMsgSend.put("BooleanValue", true);
- mapMsgSend.put("IntValue", (int) 10);
- try {
- // send to an invalid topic
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "invalidDestinationRuntimeExceptionTests");
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Message) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling send(Destination, Message) -> expect InvalidDestinationRuntimeException");
- producer.send(invalidDestination, expTextMessage);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, String) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling send(Destination, String) -> expect InvalidDestinationRuntimeException");
- producer.send(invalidDestination, message);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Serializable) for InvalidDestinationRuntimeException");
- TestUtil.logMsg("Send ObjectMessage");
- TestUtil.logMsg("Set some values in ObjectMessage");
- ObjectMessage om = context.createObjectMessage();
- StringBuffer sb = new StringBuffer(message);
- om.setObject(sb);
- om.setStringProperty("COM_SUN_JMS_TESTNAME",
- "invalidDestinationRuntimeExceptionTests");
- try {
- TestUtil.logMsg(
- "Calling send(Destination, Serializable) -> expect InvalidDestinationRuntimeException");
- producer.send(invalidDestination, om);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, byte[]) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling send(Destination, byte[]) -> expect InvalidDestinationRuntimeException");
- producer.send(invalidDestination, bytesMsgSend);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Map) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling send(Destination, Map) -> expect InvalidDestinationRuntimeException");
- producer.send(invalidDestination, mapMsgSend);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createConsumer(Destination) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createConsumer(Destination) -> expect InvalidDestinationRuntimeException");
- context.createConsumer(invalidDestination);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createConsumer(Destination, String) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createConsumer(Destination, String) -> expect InvalidDestinationRuntimeException");
- context.createConsumer(invalidDestination, "lastMessage = TRUE");
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createConsumer(Destination, String, boolean) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createConsumer(Destination, String, boolean) -> expect InvalidDestinationRuntimeException");
- context.createConsumer(invalidDestination, "lastMessage = TRUE", false);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createDurableConsumer(Topic, String) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createDurableConsumer(Topic, String) -> expect InvalidDestinationRuntimeException");
- context.createDurableConsumer(invalidTopic,
- "InvalidDestinationRuntimeException");
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createDurableConsumer(Topic, String, String, boolean) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createDurableConsumer(Topic, String, String, boolean) -> expect InvalidDestinationRuntimeException");
- context.createDurableConsumer(invalidTopic,
- "InvalidDestinationRuntimeException", "lastMessage = TRUE", false);
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createSharedDurableConsumer(Topic, String) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createSharedDurableConsumer(Topic, String) -> expect InvalidDestinationRuntimeException");
- context.createSharedDurableConsumer(invalidTopic,
- "InvalidDestinationRuntimeException");
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createSharedDurableConsumer(Topic, String, String) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createSharedDurableConsumer(Topic, String, String) -> expect InvalidDestinationRuntimeException");
- context.createSharedDurableConsumer(invalidTopic,
- "InvalidDestinationRuntimeException", "lastMessage = TRUE");
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.unsubscribe(String) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.unsubscribe(String) -> expect InvalidDestinationRuntimeException");
- context.unsubscribe("InvalidSubscriptionName");
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createSharedConsumer(Topic, String) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createSharedConsumer(Topic, String) for InvalidDestinationRuntimeException");
- context.createSharedConsumer(invalidTopic,
- "InvalidDestinationRuntimeException");
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createSharedConsumer(Topic, String, String) for InvalidDestinationRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createSharedConsumer(Topic, String, String) for InvalidDestinationRuntimeException");
- context.createSharedConsumer(invalidTopic,
- "InvalidDestinationRuntimeException", "lastMessage = TRUE");
- } catch (InvalidDestinationRuntimeException e) {
- TestUtil.logMsg("Got InvalidDestinationRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationRuntimeException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("invalidDestinationRuntimeExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("invalidDestinationRuntimeExceptionTests failed");
- }
- }
-
- /*
- * @testName: invalidSelectorRuntimeExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:948; JMS:JAVADOC:952; JMS:JAVADOC:959;
- * JMS:JAVADOC:1154; JMS:JAVADOC:1158; JMS:JAVADOC:959; JMS:JAVADOC:1162;
- *
- * @test_Strategy: Test InvalidSelectorRuntimeException conditions from
- * various API methods.
- *
- * JMSContext.createConsumer(Destination, String)
- * JMSContext.createConsumer(Destination, String, boolean)
- * JMSContext.createDurableConsumer(Topic, String, String, boolean)
- * JMSContext.createSharedConsumer(Topic, String, String)
- * JMSContext.createSharedDurableConsumer(Topic, String, String)
- *
- */
- public void invalidSelectorRuntimeExceptionTests() throws Exception {
- boolean pass = true;
- String invalidMessageSelector = "=TEST 'test'";
- try {
-
- TestUtil.logMsg(
- "Testing JMSContext.createConsumer(Destination, String) for InvalidSelectorRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createConsumer(Destination, String) -> expect InvalidSelectorRuntimeException");
- context.createConsumer(topic, invalidMessageSelector);
- } catch (InvalidSelectorRuntimeException e) {
- TestUtil.logMsg("Got InvalidSelectorRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected InvalidSelectorRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createConsumer(Destination, String, boolean) for InvalidSelectorRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createConsumer(Destination, String, boolean) -> expect InvalidSelectorRuntimeException");
- context.createConsumer(topic, invalidMessageSelector, false);
- } catch (InvalidSelectorRuntimeException e) {
- TestUtil.logMsg("Got InvalidSelectorRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected InvalidSelectorRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createDurableConsumer(Topic, String, String, boolean) for InvalidSelectorRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createDurableConsumer(Topic, String, String, boolean) -> expect InvalidSelectorRuntimeException");
- context2.createDurableConsumer(topic, "InvalidSelectorRuntimeException",
- invalidMessageSelector, false);
- } catch (InvalidSelectorRuntimeException e) {
- TestUtil.logMsg("Got InvalidSelectorRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected InvalidSelectorRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createSharedDurableConsumer(Topic, String, String) for InvalidSelectorRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createSharedDurableConsumer(Topic, String, String) -> expect InvalidSelectorRuntimeException");
- context.createSharedDurableConsumer(topic,
- "InvalidSelectorRuntimeException", invalidMessageSelector);
- } catch (InvalidSelectorRuntimeException e) {
- TestUtil.logMsg("Got InvalidSelectorRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected InvalidSelectorRuntimeException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing JMSContext.createSharedConsumer(Topic, String, String) for InvalidSelectorRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.createSharedConsumer(Topic, String, String) for InvalidSelectorRuntimeException");
- context.createSharedConsumer(topic, "InvalidSelectorRuntimeException",
- invalidMessageSelector);
- } catch (InvalidSelectorRuntimeException e) {
- TestUtil.logMsg("Got InvalidSelectorRuntimeException as expected.");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected InvalidSelectorRuntimeException, received " + e);
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("invalidSelectorRuntimeExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("invalidSelectorRuntimeExceptionTests failed");
- }
- }
-
- /*
- * @testName: jMSRuntimeExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:932; JMS:SPEC:264.2; JMS:JAVADOC:1274;
- * JMS:JAVADOC:1260; JMS:JAVADOC:1384; JMS:JAVADOC:954; JMS:JAVADOC:1160;
- * JMS:JAVADOC:957; JMS:JAVADOC:1152; JMS:JAVADOC:1156;
- *
- * @test_Strategy: Test JMSRuntimeException conditions from various API
- * methods.
- *
- * JMSContext.createContext(int); JMSProducer.setPriority(int);
- * JMSProducer.setDeliveryMode(long); JMSContext.createDurableConsumer(Topic,
- * String) JMSContext.createDurableConsumer(Topic, String. String, boolean)
- * JMSContext.createSharedConsumer(Topic, String)
- * JMSContext.createSharedConsumer(Topic, String, String)
- * JMSContext.createSharedDurableConsumer(Topic, String)
- * JMSContext.createSharedDurableConsumer(Topic, String. String)
- */
- public void jMSRuntimeExceptionTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- if ((vehicle.equals("ejb") || vehicle.equals("jsp")
- || vehicle.equals("servlet"))) {
- try {
- TestUtil.logMsg(
- "Calling createContext must throw JMSRuntimeException for EJB/WEB container");
- context.createContext(JMSContext.AUTO_ACKNOWLEDGE);
- TestUtil.logErr("Didn't throw JMSRuntimeException");
- pass = false;
- } catch (JMSRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSRuntimeException, received " + e);
- pass = false;
- }
- }
-
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
-
- try {
- TestUtil.logMsg("Try and set an invalid priority of -1");
- producer.setPriority(-1);
- TestUtil.logErr("Didn't throw JMSRuntimeException");
- pass = false;
- } catch (JMSRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSRuntimeException, received " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and set an delivery mode to live of -1");
- producer.setDeliveryMode(-1);
- TestUtil.logErr("Didn't throw JMSRuntimeException");
- pass = false;
- } catch (JMSRuntimeException e) {
- TestUtil.logMsg("Caught expected JMSRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSRuntimeException, received " + e);
- pass = false;
- }
-
- // Create shared consumer specifying topic and name
- // Create second shared consumer with same name but specifying different
- // topic,
- // Verify JMSRuntimeException is thrown.
- try {
- TestUtil.logMsg("Create shared consumer");
- TestUtil.logMsg("Calling JMSContext.createSharedConsumer(Topic, String)");
- consumer = context2.createSharedConsumer(topic, "dummySubSCJMSRuntime");
- TestUtil.logMsg(
- "Create second shared consumer with same name but different topic");
- TestUtil.logMsg("Calling JMSContext.createSharedConsumer(Topic, String)");
- Topic mytopic = (Topic) tool.createNewTopic("MY_TOPIC2");
- consumer2 = context2.createSharedConsumer(mytopic,
- "dummySubSCJMSRuntime");
- TestUtil.logMsg("Verify that JMSRuntimeException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSRuntimeException");
- } catch (JMSRuntimeException ex) {
- TestUtil.logMsg("Got expected JMSRuntimeException from "
- + "JMSContext.createSharedConsumer(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- if (consumer2 != null)
- consumer2.close();
- } catch (Exception e) {
- }
- }
-
- // Create shared consumer specifying topic and name and message selector
- // Create second shared consumer with same name but specifying different
- // topic and message selector
- // Verify JMSRuntimeException is thrown.
- try {
- TestUtil.logMsg("Create shared consumer");
- TestUtil.logMsg(
- "Calling JMSContext.createSharedConsumer(Topic, String, String)");
- consumer = context2.createSharedConsumer(topic, "dummySubSCJMSRuntime",
- "TEST = 'test'");
- TestUtil.logMsg(
- "Create second shared consumer with same name but different topic");
- TestUtil.logMsg(
- "Calling JMSContext.createSharedConsumer(Topic, String, String)");
- Topic mytopic = (Topic) tool.createNewTopic("MY_TOPIC2");
- consumer2 = context2.createSharedConsumer(mytopic, "dummySubSCJMSRuntime",
- "TEST = 'test'");
- TestUtil.logMsg("Verify that JMSRuntimeException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSRuntimeException");
- } catch (JMSRuntimeException ex) {
- TestUtil.logMsg("Got expected JMSRuntimeException from "
- + "JMSContext.createSharedConsumer(Topic, String, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- if (consumer2 != null)
- consumer2.close();
- } catch (Exception e) {
- }
- }
-
- // Create shared durable subscription specifying topic, name. selector.
- // Create second
- // shared durable subscription with same name but specifying different
- // topic, selector.
- // Verify JMSRuntimeException is thrown.
- try {
- TestUtil.logMsg("Create shared durable subscription");
- TestUtil.logMsg(
- "Calling JMSContext.createSharedDurableConsumer(Topic, String, String)");
- consumer = context2.createSharedDurableConsumer(topic,
- "dummySubSJMSRuntime", "TEST = 'test'");
- TestUtil.logMsg(
- "Create second shared durable subscription with same name but different other args");
- TestUtil.logMsg(
- "Calling JMSContext.createSharedDurableConsumer(Topic, String, String)");
- consumer2 = context2.createSharedDurableConsumer(topic,
- "dummySubSJMSRuntime", "TEST = 'test2'");
- TestUtil.logMsg("Verify that JMSRuntimeException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSRuntimeException");
- } catch (JMSRuntimeException ex) {
- TestUtil.logMsg("Got expected JMSRuntimeException from "
- + "JMSContext.createSharedDurableConsumer(Topic, String, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer2 != null)
- consumer2.close();
- cleanupSubscription(consumer, context2, "dummySubSJMSRuntime");
- } catch (Exception e) {
- }
- }
-
- // Create durable subscription specifying topic and name
- // Create second durable subscription with same name but specifying
- // different topic,
- // Verify JMSRuntimeException is thrown.
- try {
- TestUtil.logMsg("Create durable subscription");
- TestUtil
- .logMsg("Calling JMSContext.createDurableConsumer(Topic, String)");
- consumer = context2.createDurableConsumer(topic, "dummySubDJMSRuntime");
- TestUtil.logMsg(
- "Create second durable subscription with same name but different topic");
- TestUtil
- .logMsg("Calling JMSContext.createDurableConsumer(Topic, String)");
- Topic mytopic = (Topic) tool.createNewTopic("MY_TOPIC2");
- consumer2 = context2.createDurableConsumer(mytopic,
- "dummySubDJMSRuntime");
- TestUtil.logMsg("Verify that JMSRuntimeException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSRuntimeException");
- } catch (JMSRuntimeException ex) {
- TestUtil.logMsg("Got expected JMSRuntimeException from "
- + "JMSContext.createDurableConsumer(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer2 != null)
- consumer2.close();
- cleanupSubscription(consumer, context2, "dummySubDJMSRuntime");
- } catch (Exception e) {
- }
- }
-
- // Create shared durable subscription specifying topic and name
- // Create second shared durable subscription with same name but specifying
- // different topic,
- // Verify JMSRuntimeException is thrown.
- try {
- TestUtil.logMsg("Create shared durable subscription");
- TestUtil.logMsg(
- "Calling JMSContext.createSharedDurableConsumer(Topic, String)");
- consumer = context2.createSharedDurableConsumer(topic,
- "dummySubSDJMSRuntime");
- TestUtil.logMsg(
- "Create second shared durable subscription with same name but different topic");
- TestUtil.logMsg(
- "Calling JMSContext.createSharedDurableConsumer(Topic, String)");
- Topic mytopic = (Topic) tool.createNewTopic("MY_TOPIC2");
- consumer2 = context2.createSharedDurableConsumer(mytopic,
- "dummySubSDJMSRuntime");
- TestUtil.logMsg("Verify that JMSRuntimeException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSRuntimeException");
- } catch (JMSRuntimeException ex) {
- TestUtil.logMsg("Got expected JMSRuntimeException from "
- + "JMSContext.createSharedDurableConsumer(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer2 != null)
- consumer2.close();
- cleanupSubscription(consumer, context2, "dummySubSDJMSRuntime");
- } catch (Exception e) {
- }
- }
-
- // Create durable subscription specifying topic, name. selector, and nolocal
- // value.
- // Create second durable subscription with same name but specifying
- // different topic,
- // selector, or nolocal value. Verify JMSRuntimeException is thrown.
- try {
- TestUtil.logMsg("Create durable subscription");
- TestUtil.logMsg(
- "Calling JMSContext.createDurableConsumer(Topic, String, String, boolean)");
- consumer = context2.createDurableConsumer(topic, "dummySubDJMSRuntime",
- "TEST = 'test'", true);
- TestUtil.logMsg(
- "Create second durable subscription with same name but different other args");
- TestUtil.logMsg(
- "Calling JMSContext.createDurableConsumer(Topic, String, String, boolean)");
- consumer2 = context2.createDurableConsumer(topic, "dummySubDJMSRuntime",
- "TEST = 'test2'", false);
- TestUtil.logMsg("Verify that JMSRuntimeException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSRuntimeException");
- } catch (JMSRuntimeException ex) {
- TestUtil.logMsg("Got expected JMSRuntimeException from "
- + "JMSContext.createDurableConsumer(Topic, String, String, boolean)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer2 != null)
- consumer2.close();
- cleanupSubscription(consumer, context2, "dummySubDJMSRuntime");
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("jMSRuntimeExceptionTests failed");
- }
- }
-
- /*
- * @testName: illegalStateRuntimeExceptionTest
- *
- * @assertion_ids: JMS:JAVADOC:917; JMS:JAVADOC:994; JMS:JAVADOC:997;
- * JMS:JAVADOC:1340; JMS:JAVADOC:1341; JMS:JAVADOC:1378;
- *
- * @test_Strategy: 1. Create a TextMessages and send to Topic 2. Then invoke
- * JMSContext.commit() on a non-transacted session Verify that
- * IllegalStateRuntimeException is thrown 3. Then test invoke
- * JMSContext.rollback() on a non-transacted session Verify that
- * IllegalStateRuntimeException is thrown 3. Then test invoke
- * JMSContext.recover() on a transacted session Verify that
- * IllegalStateRuntimeException is thrown 4. Create JMSContext with
- * CLIENT_ACKNOWLEDGE then close JMSContext. Then test invoke
- * JMSContext.acknowledge() on the JMSContext. Verify that
- * IllegalStateRuntimeException is thrown 5. Verify that
- * IllegalStateRuntimeException is thrown if nolocal=true and client id is
- * unset for JMSContext.createSharedConsumer(...) and
- * JMSContext.createSharedDurableConsumer(...) methods. 6. Verify that
- * IllegalStateRuntimeException is thrown if client id is unset for
- * JMSContext.createDurableConsumer(...) methods.
- *
- * JMSContext.commit(); JMSContext.rollback(); JMSContext.recover();
- * JMSContext.acknowledge(); JMSContext.createDurableConsumer(Topic, String)
- * JMSContext.createDurableConsumer(Topic, String. String, boolean)
- */
- public void illegalStateRuntimeExceptionTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
-
- try {
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateRuntimeExceptionTest");
- // send the message to the Topic
- TestUtil.logTrace("Sending message to the Topic");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
-
- try {
- TestUtil.logTrace(
- "JMSContext.commit() on non-transacted session must throw IllegalStateRuntimeException");
- context.commit();
- pass = false;
- TestUtil.logErr(
- "Error: JMSContext.commit() didn't throw expected IllegalStateRuntimeException");
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- logMsg(
- "Got expected IllegalStateRuntimeException from JMSContext.commit()");
- } catch (Exception e) {
- logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateRuntimeExceptionTest");
- // send the message to the Topic
- TestUtil.logTrace("Sending message to the Topic");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
-
- try {
- TestUtil.logTrace(
- "JMSContext.rollback() on non-transacted session must throw IllegalStateRuntimeException");
- context.rollback();
- pass = false;
- TestUtil.logErr(
- "Error: JMSContext.rollback() didn't throw expected IllegalStateRuntimeException");
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- logMsg(
- "Got expected IllegalStateRuntimeException from JMSContext.rollback()");
- } catch (Exception e) {
- logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateRuntimeExceptionTest");
- // send the message to the Topic
- TestUtil.logTrace("Sending message to the Topic");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
-
- if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
- // create JMSContext with SESSION_TRANSACTED then create producer
- JMSContext contextTX = cf.createContext(user, password,
- JMSContext.SESSION_TRANSACTED);
- JMSProducer producerTX = contextTX.createProducer();
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- expTextMessage = contextTX.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "illegalStateRuntimeExceptionTest");
- // send the message to the Queue
- TestUtil.logMsg("Sending message to the Queue");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producerTX.send(destination, expTextMessage);
-
- try {
- TestUtil.logMsg(
- "JMSContext.recover() on a transacted session must throw IllegalStateRuntimeException");
- contextTX.recover();
- pass = false;
- TestUtil.logErr(
- "Error: JMSContext.recover() didn't throw expected IllegalStateRuntimeException");
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- logMsg(
- "Got expected IllegalStateRuntimeException from JMSContext.recover()");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- contextTX.close();
-
- try {
- TestUtil.logMsg("Create JMSContext with CLIENT_ACKNOWLEDGE");
- JMSContext msgcontext = cf.createContext(user, password,
- JMSContext.CLIENT_ACKNOWLEDGE);
- TestUtil.logMsg("Close JMSContext");
- msgcontext.close();
- TestUtil.logMsg(
- "Call JMSContext.acknowledge() on a closed session which is illegal");
- msgcontext.acknowledge();
- TestUtil.logErr("Didn't throw IllegalStateRuntimeException");
- pass = false;
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- logMsg(
- "Got expected IllegalStateRuntimeException from JMSContext.acknowledge()");
- } catch (Exception e) {
- TestUtil.logErr("Caught expected exception" + e);
- pass = false;
- }
- }
-
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
-
- // Create durable consumer with client identifier unset
- // Must throw IllegalStateRuntimeException
- try {
- consumer = null;
- TestUtil
- .logMsg("Calling JMSContext.createDurableConsumer(Topic, String)");
- TestUtil.logMsg(
- "Create Durable Consumer with client id unset (expect IllegalStateRuntimeException)");
- consumer = context.createDurableConsumer(topic,
- "dummySubDIllegalState1");
- TestUtil.logErr(
- "No exception occurred - expected IllegalStateRuntimeException");
- pass = false;
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- TestUtil.logMsg("Got expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer != null)
- cleanupSubscription(consumer, context, "dummySubDIllegalState1");
- } catch (Exception e) {
- }
- }
-
- // Create durable consumer with client identifier unset (nolocal=false)
- // Must throw IllegalStateRuntimeException
- try {
- consumer = null;
- TestUtil.logMsg(
- "Calling JMSContext.createDurableConsumer(Topic, String, String, boolean)");
- TestUtil.logMsg(
- "Create Durable Consumer with client id unset, nolocal=false (expect IllegalStateRuntimeException)");
- consumer = context.createDurableConsumer(topic,
- "dummySubDIllegalState2", "lastMessage = TRUE", false);
- TestUtil.logErr(
- "No exception occurred - expected IllegalStateRuntimeException");
- pass = false;
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- TestUtil.logMsg("Got expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception" + e);
- pass = false;
- } finally {
- try {
- if (consumer != null)
- cleanupSubscription(consumer, context, "dummySubDIllegalState2");
- } catch (Exception e) {
- }
- }
-
- // Create durable consumer with client identifier unset (nolocal=true)
- // Must throw IllegalStateRuntimeException
- try {
- consumer = null;
- TestUtil.logMsg(
- "Calling JMSContext.createDurableConsumer(Topic, String, String, boolean)");
- TestUtil.logMsg(
- "Create Durable Consumer with client id unset, nolocal=true (expect IllegalStateRuntimeException)");
- consumer = context.createDurableConsumer(topic,
- "dummySubDIllegalState2", "lastMessage = TRUE", true);
- TestUtil.logErr(
- "No exception occurred - expected IllegalStateRuntimeException");
- pass = false;
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- TestUtil.logMsg("Got expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception" + e);
- pass = false;
- } finally {
- try {
- if (consumer != null)
- cleanupSubscription(consumer, context, "dummySubDIllegalState2");
- } catch (Exception e) {
- }
- }
-
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- throw new Exception("illegalStateRuntimeExceptionTest");
- }
-
- if (!pass) {
- throw new Exception("illegalStateRuntimeExceptionTest");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmscontexttopictests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmscontexttopictests/ClientIT.java
new file mode 100644
index 0000000000..c33e4ea8f6
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmscontexttopictests/ClientIT.java
@@ -0,0 +1,3074 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022 Contributors to Eclipse Foundation. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id: Client.java 68661 2012-11-21 22:51:15Z adf $
+ */
+package com.sun.ts.tests.jms.core20.jmscontexttopictests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.ConnectionMetaData;
+import jakarta.jms.Destination;
+import jakarta.jms.InvalidDestinationRuntimeException;
+import jakarta.jms.InvalidSelectorRuntimeException;
+import jakarta.jms.JMSConsumer;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSException;
+import jakarta.jms.JMSProducer;
+import jakarta.jms.JMSRuntimeException;
+import jakarta.jms.Message;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.TemporaryTopic;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.jmscontexttopictests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null, tool2 = null;
+
+ // JMS objects
+ private transient ConnectionFactory cf = null;
+
+ private transient ConnectionFactory cf2 = null;
+
+ private transient Topic topic = null;
+
+ private transient Destination destination = null;
+
+ private transient Topic topic2 = null;
+
+ private transient Destination destination2 = null;
+
+ private transient JMSContext context = null;
+
+ private transient JMSContext context2 = null;
+
+ private transient JMSProducer producer = null;
+
+ private transient JMSProducer producer2 = null;
+
+ private transient JMSConsumer consumer = null;
+
+ private transient JMSConsumer consumer2 = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ String vehicle;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * helper method verifies that the ConnectionMetaData
+ *
+ * @param ConnectionMetaData returned from getJMSMessageID
+ *
+ * @return boolean true if ConnectionMetaData is as expected
+ */
+ private boolean verifyMetaData(ConnectionMetaData data) {
+ boolean pass = true;
+
+ try {
+ String tmp = data.getJMSVersion();
+ logger.log(Logger.Level.TRACE, "JMSVersion=" + tmp);
+
+ if (!tmp.equals(JmsTool.JMS_VERSION)) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getJMSMajorVersion();
+ logger.log(Logger.Level.TRACE, "JMSMajorVersion=" + tmp);
+
+ if (tmp != JmsTool.JMS_MAJOR_VERSION) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSMajorVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSMajorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getJMSMinorVersion();
+ logger.log(Logger.Level.TRACE, "JMSMinorVersion=" + tmp);
+
+ if (tmp != JmsTool.JMS_MINOR_VERSION) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSMinorVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSMinorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = data.getJMSProviderName();
+ logger.log(Logger.Level.TRACE, "JMSProviderName=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSProviderName: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = data.getProviderVersion();
+ logger.log(Logger.Level.TRACE, "JMSProviderVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getProviderMajorVersion();
+ logger.log(Logger.Level.TRACE, "ProviderMajorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderMajorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getProviderMinorVersion();
+ logger.log(Logger.Level.TRACE, "ProviderMinorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderMinorVersion: ", e);
+ pass = false;
+ }
+ return pass;
+ }
+
+ /*
+ * helper method verifies that the JMSMessageID starts with ID:
+ *
+ * @param String returned from getJMSMessageID
+ *
+ * @return boolean true if id correctly starts with ID:
+ */
+ private boolean chkMessageID(String id) {
+ String status[] = { "Pass", "Fail" };
+ boolean retcode = true;
+
+ // message id must start with ID: - unless it is null
+ int index = 0;
+
+ if (id == null) {
+ ;
+ } else if (id.startsWith("ID:")) {
+ ;
+ } else {
+ index = 1;
+ retcode = false;
+ }
+ logger.log(Logger.Level.TRACE, "Results: " + status[index]);
+ return retcode;
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ String lookupDurableTopicFactory = "DURABLE_SUB_CONNECTION_FACTORY";
+ String lookupNormalTopicFactory = "MyTopicConnectionFactory";
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ vehicle = System.getProperty("vehicle");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ connections = new ArrayList(5);
+
+ // set up JmsTool for COMMON_T setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_T and normal topic connection factory");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, lookupNormalTopicFactory, mode);
+ cf = tool.getConnectionFactory();
+ tool.getDefaultConnection().close(); // Close connection (Create
+ // JMSContext to use instead)
+ destination = tool.getDefaultDestination();
+ topic = (Topic) destination;
+
+ // create JMSContext with AUTO_ACKNOWLEDGE then create consumer/producer
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ producer = context.createProducer();
+ consumer = context.createConsumer(topic);
+
+ // set up JmsTool for COMMON_T setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_T and durable topic connection factory");
+ tool2 = new JmsTool(JmsTool.COMMON_T, user, password, lookupDurableTopicFactory, mode);
+ tool2.getDefaultConnection().close(); // Close connection (Create
+ // JMSContext to use instead)
+ cf2 = tool2.getConnectionFactory();
+ destination2 = tool2.getDefaultDestination();
+ topic2 = (Topic) destination2;
+
+ // create second JMSContext with AUTO_ACKNOWLEDGE, then create producer
+ context2 = cf2.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ producer2 = context2.createProducer();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Close JMSContext Objects");
+ if (context != null) {
+ context.close();
+ context = null;
+ }
+ if (context2 != null) {
+ context2.close();
+ context2 = null;
+ }
+ producer = producer2 = null;
+ logger.log(Logger.Level.INFO, "Close JMSConsumer Objects");
+ if (consumer != null) {
+ consumer.close();
+ consumer = null;
+ }
+ if (tool != null) {
+ tool.closeAllResources();
+ tool = null;
+ }
+ if (tool2 != null) {
+ tool2.closeAllResources();
+ tool2 = null;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * Cleanup method for tests that use durable subscriptions
+ */
+ private void cleanupSubscription(JMSConsumer consumer, JMSContext context, String subName) {
+ if (consumer != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Closing durable consumer: " + consumer);
+ consumer.close();
+ consumer = null;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception during JMSConsumer.close: ", e);
+ }
+ }
+
+ if (context != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Unsubscribing \"" + subName + "\"");
+ context.unsubscribe(subName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception during JMSContext.unsubscribe: ", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: createTemporayTopicTest
+ *
+ * @assertion_ids: JMS:JAVADOC:962;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.createTemporaryTopic().
+ *
+ * Send and receive a message to temporary topic. Compare send and recv message
+ * for equality.
+ */
+ @Test
+ public void createTemporayTopicTest() throws Exception {
+ boolean pass = true;
+ JMSConsumer consumer = null;
+ try {
+
+ String sendMessage = "a text message";
+
+ // create a TemporaryTopic
+ logger.log(Logger.Level.INFO, "Creating TemporaryTopic");
+ TemporaryTopic tempTopic = context.createTemporaryTopic();
+
+ // Create a JMSConsumer for this Temporary Topic
+ logger.log(Logger.Level.INFO, "Create JMSConsumer for TemporaryTopic.");
+ consumer = context.createConsumer(tempTopic);
+
+ // Send message to temporary topic
+ logger.log(Logger.Level.INFO, "Send message to temporary topic");
+ producer.send(tempTopic, sendMessage);
+
+ // Receive message from temporary topic
+ logger.log(Logger.Level.INFO, "Receive message from temporaty topic");
+ String recvMessage = consumer.receiveBody(String.class, timeout);
+
+ logger.log(Logger.Level.INFO, "Checking received message");
+ if (recvMessage == null) {
+ throw new Exception("Did not receive Message");
+ }
+
+ logger.log(Logger.Level.INFO, "Verify correct message received.");
+ if (!recvMessage.equals(sendMessage)) {
+ logger.log(Logger.Level.ERROR,
+ "unexpected message: received " + recvMessage + " , expected " + sendMessage);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "received correct message: " + recvMessage + " as expected");
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Attempting to delete temporary topic with an open consumer should not be allowed");
+ try {
+ tempTopic.delete();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TemporaryTopic.delete() didn't throw expected Exception");
+ } catch (JMSException em) {
+ logger.log(Logger.Level.TRACE, "Received expected JMSException: ");
+ }
+
+ logger.log(Logger.Level.INFO, "Now close the open consumer");
+ try {
+ consumer.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception closing JMSConsumer: " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Attempting to delete temporary topic with no open consumer should be allowed");
+ try {
+ tempTopic.delete();
+ } catch (Exception e) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received unexpected Exception: ", e);
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("createTemporayTopicTest");
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createTemporayTopicTest failed");
+ }
+ }
+
+ /*
+ * @testName: getMetaDataTest
+ *
+ * @assertion_ids: JMS:JAVADOC:982;
+ *
+ * @test_Strategy: Call JMSContext.getMetaData() to retrieve the
+ * ConnectionMetaData and then verify the ConnectionMetaData for correctness.
+ */
+ @Test
+ public void getMetaDataTest() throws Exception {
+ boolean pass = true;
+ ConnectionMetaData data = null;
+
+ try {
+ data = context.getMetaData();
+
+ if (!verifyMetaData(data))
+ pass = false;
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("getMetaDataTest failed");
+ }
+ }
+
+ /*
+ * @testName: getSessionModeTest
+ *
+ * @assertion_ids: JMS:JAVADOC:986;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.getSessionMode().
+ *
+ * Cycle through all session modes to create each JMSContext with each mode and
+ * verify that each session mode is set correctly.
+ */
+ @Test
+ public void getSessionModeTest() throws Exception {
+ boolean pass = true;
+ JMSContext context = null;
+
+ // Test default case
+ try {
+ context = cf.createContext(user, password);
+ int expSessionMode = JMSContext.AUTO_ACKNOWLEDGE;
+ logger.log(Logger.Level.INFO, "Calling getSessionMode and expect " + expSessionMode + " to be returned");
+ int actSessionMode = context.getSessionMode();
+ if (actSessionMode != expSessionMode) {
+ logger.log(Logger.Level.ERROR,
+ "getSessionMode() returned " + actSessionMode + ", expected " + expSessionMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getSessionModeTest");
+ } finally {
+ try {
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ }
+ }
+
+ // Test non-default case
+ int expSessionMode[] = { JMSContext.SESSION_TRANSACTED, JMSContext.AUTO_ACKNOWLEDGE,
+ JMSContext.CLIENT_ACKNOWLEDGE, JMSContext.DUPS_OK_ACKNOWLEDGE, };
+
+ // Cycle through all session modes
+ for (int i = 0; i < expSessionMode.length; i++) {
+ if ((vehicle.equals("ejb") || vehicle.equals("jsp") || vehicle.equals("servlet"))) {
+ if (expSessionMode[i] == JMSContext.SESSION_TRANSACTED
+ || expSessionMode[i] == JMSContext.CLIENT_ACKNOWLEDGE)
+ continue;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Creating context with session mode (" + expSessionMode[i] + ")");
+ context = cf.createContext(user, password, expSessionMode[i]);
+ logger.log(Logger.Level.INFO,
+ "Calling getSessionMode and expect " + expSessionMode[i] + " to be returned");
+ int actSessionMode = context.getSessionMode();
+ if (actSessionMode != expSessionMode[i]) {
+ logger.log(Logger.Level.ERROR,
+ "getSessionMode() returned " + actSessionMode + ", expected " + expSessionMode[i]);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getSessionModeTest");
+ } finally {
+ try {
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("getSessionModeTest failed");
+ }
+ }
+
+ /*
+ * @testName: getTransactedTest
+ *
+ * @assertion_ids: JMS:JAVADOC:990;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.getTransacted().
+ *
+ * Create a JMSContext with JMSContext.AUTO_ACKNOWLEDGE and verify that
+ * JMSContext.getTransacted() returns false.
+ *
+ * Create a JMSContext with JMSContext.SESSION_TRANSACTED and verify that
+ * JMSContext.getTransacted() returns true.
+ */
+ @Test
+ public void getTransactedTest() throws Exception {
+ boolean pass = true;
+ JMSContext context = null;
+
+ // Test for transacted mode false
+ try {
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ boolean expTransacted = false;
+ logger.log(Logger.Level.INFO, "Calling getTransacted and expect " + expTransacted + " to be returned");
+ boolean actTransacted = context.getTransacted();
+ if (actTransacted != expTransacted) {
+ logger.log(Logger.Level.ERROR,
+ "getTransacted() returned " + actTransacted + ", expected " + expTransacted);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ }
+ }
+
+ // Test for transacted mode true
+ if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
+ try {
+ context = cf.createContext(user, password, JMSContext.SESSION_TRANSACTED);
+ boolean expTransacted = true;
+ logger.log(Logger.Level.INFO, "Calling getTransacted and expect " + expTransacted + " to be returned");
+ boolean actTransacted = context.getTransacted();
+ if (actTransacted != expTransacted) {
+ logger.log(Logger.Level.ERROR,
+ "getTransacted() returned " + actTransacted + ", expected " + expTransacted);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getTransactedTest");
+ } finally {
+ try {
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("getTransactedTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetAutoStartTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1138; JMS:JAVADOC:1129;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.setAutoStart(boolean). JMSContext.getAutoStart().
+ */
+ @Test
+ public void setGetAutoStartTest() throws Exception {
+ boolean pass = true;
+ // Test default case
+ try {
+ boolean expAutoStart = true;
+ logger.log(Logger.Level.INFO, "Calling getAutoStart and expect " + expAutoStart + " to be returned");
+ boolean actAutoStart = context.getAutoStart();
+ if (actAutoStart != expAutoStart) {
+ logger.log(Logger.Level.ERROR,
+ "getAutoStart() returned " + actAutoStart + ", expected " + expAutoStart);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+
+ // Test non-default case
+ try {
+ boolean expAutoStart = false;
+ logger.log(Logger.Level.INFO, "Calling setAutoStart(" + expAutoStart + ")");
+ context.setAutoStart(expAutoStart);
+ logger.log(Logger.Level.INFO, "Calling getAutoStart and expect " + expAutoStart + " to be returned");
+ boolean actAutoStart = context.getAutoStart();
+ if (actAutoStart != expAutoStart) {
+ logger.log(Logger.Level.ERROR,
+ "getAutoStart() returned " + actAutoStart + ", expected " + expAutoStart);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetAutoStartTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetAutoStartTest failed");
+ }
+ }
+
+ /*
+ * @testName: createConsumerTest
+ *
+ * @assertion_ids: JMS:JAVADOC:942; JMS:JAVADOC:945; JMS:JAVADOC:949;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.createConsumer(Destination) JMSContext.createConsumer(Destination,
+ * String) JMSContext.createConsumer(Destination, String, boolean)
+ *
+ * 1. Send x text messages to a Topic. 2. Create a JMSConsumer with selector to
+ * consume just the last message in the Topic. 3. Create a JMSConsumer again to
+ * consume the rest of the messages in the Topic. 4. Test createConsumer with
+ * noLocal=false case 5. Test createConsumer with noLocal=true case
+ */
+ @Test
+ public void createConsumerTest() throws Exception {
+ boolean pass = true;
+ JMSConsumer consumerSelect = null;
+ try {
+ TextMessage tempMsg = null;
+ Enumeration msgs = null;
+
+ // Create selective consumer
+ logger.log(Logger.Level.INFO, "Create selective JMSConsumer with selector [\"lastMessage=TRUE\"]");
+ consumerSelect = context.createConsumer(destination, "lastMessage=TRUE");
+
+ // Send "numMessages" messages to Topic plus end of stream message
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createConsumerTest" + i);
+ if (i == numMessages) {
+ logger.log(Logger.Level.INFO, "Set boolean property lastMessage=true");
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ logger.log(Logger.Level.INFO, "Set boolean property lastMessage=false");
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ // Receive last message in Topic using selective consumer
+ logger.log(Logger.Level.INFO,
+ "Receive last message with selective JMSConsumer and boolean property lastMessage=true");
+ tempMsg = (TextMessage) consumerSelect.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + numMessages + " missing from Topic");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + numMessages)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + numMessages + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received expected message: " + tempMsg.getText());
+ }
+
+ // Try to receive one more message (should return null)
+ logger.log(Logger.Level.INFO, "Try receiving one more message (should get none)");
+ tempMsg = (TextMessage) consumerSelect.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR,
+ "JMSConsumer received message " + tempMsg.getText() + " (Expected None)");
+ logger.log(Logger.Level.ERROR, "JMSConsumer with selector should have returned just 1 message");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received no more messages (CORRECT)");
+ }
+ consumerSelect.close();
+ consumerSelect = null;
+
+ // Receive rest of messages in Topic with normal JMSConsumer
+ logger.log(Logger.Level.INFO, "Receive rest of messages with normal JMSConsumer");
+ for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + msgCount + " missing from Topic");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + msgCount)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + msgCount + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message: " + tempMsg.getText());
+ }
+ }
+
+ // Try to receive one more message (should return null)
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ logger.log(Logger.Level.INFO, "Try receiving one more message (should get none)");
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR,
+ "JMSConsumer received message " + tempMsg.getText() + " (Expected None)");
+ logger.log(Logger.Level.ERROR,
+ "JMSConsumer should have returned just " + (numMessages - 1) + " messages");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received no more messages (CORRECT)");
+ }
+
+ // Create selective JMSConsumer to consume last message in Topic using
+ // message
+ // selector and noLocal=false
+ logger.log(Logger.Level.INFO,
+ "Create selective JMSConsumer with selector [\"lastMessage=TRUE\"] and noLocal=false");
+ consumerSelect = context.createConsumer(topic, "lastMessage=TRUE", false);
+
+ // send "numMessages" messages to Topic plus end of stream message
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createConsumerTest" + i);
+ if (i == numMessages) {
+ logger.log(Logger.Level.INFO, "Set boolean property lastMessage=true");
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ logger.log(Logger.Level.INFO, "Set boolean property lastMessage=false");
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Receive last message with selective JMSConsumer and boolean property lastMessage=true");
+ tempMsg = (TextMessage) consumerSelect.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "JMSConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + numMessages + " missing from Topic");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + numMessages)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + numMessages + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received expected message: " + tempMsg.getText());
+ }
+
+ // Try to receive one more message (should return null)
+ logger.log(Logger.Level.INFO, "Try receiving one more message (should get none)");
+ tempMsg = (TextMessage) consumerSelect.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR,
+ "JMSConsumer received message " + tempMsg.getText() + " (Expected None)");
+ logger.log(Logger.Level.ERROR, "JMSConsumer with selector should have returned just 1 message");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received no more messages (CORRECT)");
+ }
+ consumerSelect.close();
+ consumerSelect = null;
+
+ logger.log(Logger.Level.INFO,
+ "Create selective JMSConsumer with selector [\"lastMessage=TRUE\"] and noLocal=true");
+ consumerSelect = context.createConsumer(topic, "lastMessage=TRUE", true);
+
+ // Test noLocal=true case
+ // send "numMessages" messages to Topic plus end of stream message
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createConsumerTest" + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ // Receive last message in Topic using message selector and noLocal=true
+ logger.log(Logger.Level.INFO, "Try receiving a message with selective JMSConsumer (should get none)");
+ tempMsg = (TextMessage) consumerSelect.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.INFO, "Received no message (CORRECT)");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "JMSConsumer received message " + tempMsg.getText() + " (Expected None)");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("createConsumerTest");
+ } finally {
+ try {
+ if (consumerSelect != null)
+ consumerSelect.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createConsumerTest failed");
+ }
+ }
+
+ /*
+ * @testName: createDurableConsumerTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:953;
+ *
+ * @test_Strategy: Creates a durable subscription with the specified name on the
+ * specified topic and creates a MessageConsumer on that durable subscription.
+ *
+ * This uses a connection factory WITH client identifier set.
+ *
+ * Tests the following API method:
+ *
+ * JMSContext.createDurableConsumer(Topic, String)
+ *
+ * 1. Create a durable subscription with the specified name on the specified
+ * topic and create a durable MessageConsumer on that durable subscription. This
+ * uses a connection factory WITH client identifier set. 2. Send TextMessage
+ * (message1) to the Topic. 3. Consume message via MessageConsumer created.
+ * Verify message1 received. 4. Close consumer. 5. Send another TextMessage
+ * (message2) to the Topic. 6. Recreate the durable MessageConsumer on that
+ * durable subscription. 7. Consume message via MessageConsumer created. Verify
+ * message2 received.
+ */
+ @Test
+ public void createDurableConsumerTest1() throws Exception {
+ boolean pass = true;
+ String message1 = "Where are you!";
+ String message2 = "Who are you!";
+ String durableSubscriptionName = "createDurableConsumerTest1";
+ try {
+ TextMessage expTextMessage = null;
+
+ // Create Durable Subscription and a MessageConsumer for it
+ logger.log(Logger.Level.INFO, "Create a Durable Subscription and a MessageConsumer for it");
+ consumer2 = context2.createDurableConsumer(topic, durableSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Send TextMessage message1 to Topic");
+ expTextMessage = context2.createTextMessage(message1);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createDurableConsumerTest1");
+ producer2.send(destination2, expTextMessage);
+ logger.log(Logger.Level.INFO, "TextMessage message1 sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage message1");
+ TextMessage actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage message1");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Close durable MessageConsumer");
+ consumer2.close();
+
+ logger.log(Logger.Level.INFO, "Send TextMessage message2 to Topic");
+ expTextMessage = context2.createTextMessage(message1);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createDurableConsumerTest1");
+ producer2.send(destination2, expTextMessage);
+ logger.log(Logger.Level.INFO, "TextMessage message2 sent");
+
+ // Recreate Durable Subscription and a MessageConsumer for it
+ logger.log(Logger.Level.INFO, "Recreate a Durable Subscription and a MessageConsumer for it");
+ consumer2 = context2.createDurableConsumer(topic, durableSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage message2");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage message2");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("createDurableConsumerTest1", e);
+ } finally {
+ try {
+ cleanupSubscription(consumer2, context2, durableSubscriptionName);
+ producer2 = null;
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createDurableConsumerTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: createDurableConsumerTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:956;
+ *
+ * @test_Strategy: Creates a durable subscription with the specified name on the
+ * specified topic and creates a MessageConsumer on that durable subscription,
+ * specifying a message selector and whether messages published by its own
+ * connection should be delivered to it.
+ *
+ * This uses a connection factory WITH client identifier set.
+ *
+ * Tests the following API method:
+ *
+ * JMSContext.createDurableConsumer(Topic,String,String,boolean)
+ *
+ * 1. Create a durable subscription with the specified name on the specified
+ * topic and create a durable MessageConsumer on that durable subscription
+ * specifing a message selector and whether messages published by its own
+ * connection should be delivered to it. This uses a connection factory WITH
+ * client identifier set. 2. Send a number of messages to the Topic. 3. Test
+ * both noLocal=true and noLocal=false cases. 4. Verify message with specified
+ * selector received by MessageConsumer in the noLocal=false case only.
+ *
+ */
+ @Test
+ public void createDurableConsumerTest2() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ String durableSubscriptionName = "createDurableConsumerTest2";
+ try {
+ // Create Durable Subscription and a MessageConsumer for it
+ // Test the noLocal=false case with message selector
+ logger.log(Logger.Level.INFO,
+ "Create a Durable Subscription and a MessageConsumer with message selector, noLocal=false");
+ consumer2 = context2.createDurableConsumer(topic, durableSubscriptionName, "lastMessage = TRUE", false);
+
+ // send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ TextMessage tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createDurableConsumerTest2" + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer2.send(destination2, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ logger.log(Logger.Level.INFO, "This is noLacal=false case so expect to get just last message");
+ TextMessage expTextMessage = context2.createTextMessage("Message " + numMessages);
+ TextMessage actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("createDurableConsumerTest2", e);
+ } finally {
+ try {
+ if (consumer2 != null)
+ consumer2.close();
+ } catch (Exception e) {
+ }
+ }
+
+ try {
+ // Create Durable Subscription and a MessageConsumer for it
+ // Test the noLocal=true case with message selector
+ logger.log(Logger.Level.INFO,
+ "Create a Durable Subscription and a MessageConsumer with message selector, noLocal=true");
+ consumer2 = context2.createDurableConsumer(topic, durableSubscriptionName, "lastMessage = TRUE", true);
+
+ // send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ TextMessage tempMsg = context2.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createDurableConsumerTest2" + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer2.send(destination2, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer2.receive(timeout);
+
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "Message was delivered when noLocal=true");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createDurableConsumerTest2", e);
+ } finally {
+ try {
+ cleanupSubscription(consumer2, context2, durableSubscriptionName);
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createDurableConsumerTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: createSharedDurableConsumerTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1382;
+ *
+ * @test_Strategy: Creates a shared durable subscription with the specified name
+ * on the specified topic and creates a JMSConsumer on that durable
+ * subscription.
+ *
+ * This uses a connection factory WITH client identifier set.
+ *
+ * Tests the following API method:
+ *
+ * JMSContext.createSharedDurableConsumer(Topic, String)
+ *
+ * 1. Create a shared durable subscription with the specified name on the
+ * specified topic and create a durable JMSConsumer on that durable
+ * subscription. This uses a connection factory WITH client identifier set. 2.
+ * Create a 2nd JMSConsumer for it. 3. Send TextMessage (message1) to the Topic.
+ * 3. Consume message via 1st JMSConsumer created. Verify message1 received. 4.
+ * Close 1st consumer. 5. Send another TextMessage (message2) to the Topic. 6.
+ * Consume message via 2nd JMSConsumer created. Verify message2 received.
+ */
+ @Test
+ public void createSharedDurableConsumerTest1() throws Exception {
+ boolean pass = true;
+ String message1 = "Message1!";
+ String message2 = "Message2!";
+ String durableSubscriptionName = "createSharedDurableConsumerTest1";
+ try {
+ // Close default consumer
+ consumer.close();
+
+ TextMessage expTextMessage = null;
+
+ // Create a shared Durable Subscription and a JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create a shared Durable Subscription and 1st JMSConsumer for it");
+ consumer = context2.createSharedDurableConsumer(topic, durableSubscriptionName);
+
+ // Create 2nd JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create 2nd JMSConsumer for it");
+ consumer2 = context2.createSharedDurableConsumer(topic, durableSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Send TextMessage message1 to Topic");
+ expTextMessage = context2.createTextMessage(message1);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createSharedDurableConsumerTest1");
+ producer2.send(destination2, expTextMessage);
+ logger.log(Logger.Level.INFO, "TextMessage message1 sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage message1 from consumer1");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage message1");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Close 1st shared durable JMSConsumer");
+ consumer.close();
+
+ logger.log(Logger.Level.INFO, "Send TextMessage message2 to Topic");
+ expTextMessage = context2.createTextMessage(message2);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createSharedDurableConsumerTest1");
+ producer2.send(destination2, expTextMessage);
+ logger.log(Logger.Level.INFO, "TextMessage message2 sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage message2 from consumer2");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage message2");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Now there should be no more messages to receive from topic");
+
+ logger.log(Logger.Level.INFO, "Recreate Durable Subscription and 1st JMSConsumer for it");
+ consumer = context2.createSharedDurableConsumer(topic, durableSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Try and receive a message from consumer1 (should get NONE)");
+ actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "Consumer1 received a message (FAIL)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Consumer1 didn't receive a message (PASS)");
+ }
+
+ logger.log(Logger.Level.INFO, "Try and receive a message from consumer2 (should get NONE)");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "Consumer2 received a message (FAIL)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Consumer2 didn't receive a message (PASS)");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createSharedDurableConsumerTest1", e);
+ } finally {
+ try {
+ producer2 = null;
+ if (consumer != null)
+ consumer.close();
+ cleanupSubscription(consumer2, context2, durableSubscriptionName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createSharedDurableConsumerTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: createSharedDurableConsumerTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1385;
+ *
+ * @test_Strategy: Creates a shared durable subscription with the specified name
+ * on the specified topic and creates a JMSConsumer on that durable
+ * subscription, specifying a message selector and whether messages published by
+ * its own connection should be delivered to it.
+ *
+ * This uses a connection factory WITH client identifier set.
+ *
+ * Tests the following API method:
+ *
+ * JMSContext.createSharedDurableConsumer(Topic,String,String)
+ *
+ * 1. Create a shared durable subscription with the specified name on the
+ * specified topic and create a durable JMSConsumer on that durable subscription
+ * specifing a message selector and whether messages published by its own
+ * connection should be delivered to it. This uses a connection factory WITH
+ * client identifier set. 2. Create a 2nd JMSConsumer for it. 3. Send a number
+ * of messages to the Topic.
+ *
+ */
+ @Test
+ public void createSharedDurableConsumerTest2() throws Exception {
+ boolean pass = true;
+ String durableSubscriptionName = "createSharedDurableConsumerTest2";
+ try {
+ // Close default consumer
+ consumer.close();
+
+ // Create a shared Durable Subscription and a JMSConsumer for it
+ logger.log(Logger.Level.INFO,
+ "Create shared Durable Subscription and 1st JMSConsumer with message selector");
+ consumer = context2.createSharedDurableConsumer(topic, durableSubscriptionName, "lastMessage = TRUE");
+ // Create 2nd JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create 2nd JMSConsumer with message selector");
+ consumer2 = context2.createSharedDurableConsumer(topic, durableSubscriptionName, "lastMessage = TRUE");
+
+ // send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ TextMessage tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createSharedDurableConsumerTest2" + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer2.send(destination2, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage from consumer1");
+ TextMessage expTextMessage = context2.createTextMessage("Message " + numMessages);
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createSharedDurableConsumerTest2", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ if (consumer2 != null)
+ consumer2.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createSharedDurableConsumerTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: createSharedDurableConsumerTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:1382;
+ *
+ * @test_Strategy: Creates a shared durable subscription with the specified name
+ * on the specified topic and creates a JMSConsumer on that durable
+ * subscription.
+ *
+ * This uses a connection factory WITH client identifier unset.
+ *
+ * Tests the following API method:
+ *
+ * JMSContext.createSharedDurableConsumer(Topic, String)
+ *
+ * 1. Create a shared durable subscription with the specified name on the
+ * specified topic and create a durable JMSConsumer on that durable
+ * subscription. This uses a connection factory WITH client identifier unset. 2.
+ * Create a 2nd JMSConsumer for it. 3. Send TextMessage (message1) to the Topic.
+ * 3. Consume message via 1st JMSConsumer created. Verify message1 received. 4.
+ * Close 1st consumer. 5. Send another TextMessage (message2) to the Topic. 6.
+ * Consume message via 2nd JMSConsumer created. Verify message2 received.
+ */
+ @Test
+ public void createSharedDurableConsumerTest3() throws Exception {
+ boolean pass = true;
+ String message1 = "Message1!";
+ String message2 = "Message2!";
+ String durableSubscriptionName = "createSharedDurableConsumerTest3";
+ try {
+ // Close default consumer
+ consumer.close();
+
+ TextMessage expTextMessage = null;
+
+ // Create a shared Durable Subscription and a JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create a shared Durable Subscription and 1st JMSConsumer for it");
+ consumer = context.createSharedDurableConsumer(topic, durableSubscriptionName);
+
+ // Create 2nd JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create 2nd JMSConsumer for it");
+ consumer2 = context.createSharedDurableConsumer(topic, durableSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Send TextMessage message1 to Topic");
+ expTextMessage = context.createTextMessage(message1);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createSharedDurableConsumerTest3");
+ producer2.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "TextMessage message1 sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage message1 from consumer1");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage message1");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Close 1st shared durable JMSConsumer");
+ consumer.close();
+
+ logger.log(Logger.Level.INFO, "Send TextMessage message2 to Topic");
+ expTextMessage = context.createTextMessage(message2);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createSharedDurableConsumerTest3");
+ producer2.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "TextMessage message2 sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage message2 from consumer2");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage message2");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Now there should be no more messages to receive from topic");
+
+ logger.log(Logger.Level.INFO, "Recreate Durable Subscription and 1st JMSConsumer for it");
+ consumer = context.createSharedDurableConsumer(topic, durableSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Try and receive a message from consumer1 (should get NONE)");
+ actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "Consumer1 received a message (FAIL)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Consumer1 didn't receive a message (PASS)");
+ }
+
+ logger.log(Logger.Level.INFO, "Try and receive a message from consumer2 (should get NONE)");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "Consumer2 received a message (FAIL)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Consumer2 didn't receive a message (PASS)");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createSharedDurableConsumerTest3", e);
+ } finally {
+ try {
+ producer2 = null;
+ if (consumer != null)
+ consumer.close();
+ cleanupSubscription(consumer2, context, durableSubscriptionName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createSharedDurableConsumerTest3 failed");
+ }
+ }
+
+ /*
+ * @testName: createSharedConsumerTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1151; JMS:SPEC:269;
+ *
+ * @test_Strategy: Creates a shared non-durable subscription with the specified
+ * name on the specified topic, and creates a JMSConsumer on that subscription.
+ *
+ * Tests the following API method:
+ *
+ * JMSContext.createSharedConsumer(Topic, String)
+ *
+ * 1. Creates a shared non-durable subscription with the specified name on the
+ * specified topic, and creates a JMSConsumer on that subscription. 2. Create a
+ * second JMSConsumer on that subscription. 3. Send a text message to the Topic.
+ * 4. Consume message via the first JMSConsumer and message should be received.
+ * 5. Attempt to consume message via second JMSConsumer and no message should be
+ * received. 6. Re-Send a text message to the Topic. 7. Consume message via the
+ * second JMSConsumer and message should be received. 8. Attempt to consume
+ * message via first JMSConsumer and no message should be received.
+ */
+ @Test
+ public void createSharedConsumerTest1() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ String sharedSubscriptionName = "createSharedConsumerTest1";
+ try {
+ TextMessage expTextMessage = null;
+
+ // Create shared non-durable Subscription and a JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create a shared non-durable Subscription and a JMSConsumer for it");
+ consumer.close();
+ consumer = context.createSharedConsumer(topic, sharedSubscriptionName);
+
+ // Create a second JMSConsumer for the subscription
+ logger.log(Logger.Level.INFO, "Create a second JMSConsumer for the Subscription");
+ consumer2 = context.createSharedConsumer(topic, sharedSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Send message to Topic");
+ expTextMessage = context.createTextMessage(message);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", sharedSubscriptionName);
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Message sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage from consumer1");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Attempt to Receive TextMessage from consumer2 - there should be none");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage != null) {
+ throw new Exception("Did receive TextMessage - unexpected.");
+ } else
+ logger.log(Logger.Level.INFO, "Did not receive TextMessage - expected.");
+
+ logger.log(Logger.Level.INFO, "Send another message to Topic");
+ expTextMessage = context.createTextMessage(message);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", sharedSubscriptionName);
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Message sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage from consumer2");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Attempt to Receive TextMessage from consumer1 - there should be none");
+ actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage != null) {
+ throw new Exception("Did receive TextMessage - unexpected.");
+ } else
+ logger.log(Logger.Level.INFO, "Did not receive TextMessage - expected.");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createSharedConsumerTest1", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ if (consumer2 != null)
+ consumer2.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Ignoring exception closing consumers: " + e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createSharedConsumerTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: createSharedConsumerTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1155; JMS:SPEC:269; JMS:SPEC:270;
+ *
+ * @test_Strategy: Creates a shared non-durable subscription with the specified
+ * name on the specified topic and creates a JMSConsumer on that subscription,
+ * specifying a message selector.
+ *
+ * Tests the following API method:
+ *
+ * JMSContext.createSharedConsumer(Topic, String, String)
+ *
+ * 1. Create a shared non-durable subscription with the specified name on the
+ * specified topic, and creates a JMSConsumer on that subscription, specifying a
+ * message selector. 2. Create a second JMSConsumer on that subscription. 3.
+ * Send a text message to the Topic. 4. Consume message via first JMSConsumer
+ * and msg selector and message should be received. 5. Attempt to consume
+ * message via second JMSConsumer and msg selector and no message received. 6.
+ * Re-Send a text message to the Topic. 7. Consume message via second
+ * JMSConsumer and msg selector and message should be received. 8. Attempt to
+ * consume message via first JMSConsumer and msg selector and no message
+ * received.
+ *
+ */
+ @Test
+ public void createSharedConsumerTest2() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ String sharedSubscriptionName = "createSharedConsumerTest2";
+ try {
+ // Create shared non-durable Subscription and a JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create a shared non-durable Subscription and a JMSConsumer for it");
+ consumer.close();
+ consumer = context.createSharedConsumer(topic, sharedSubscriptionName, "lastMessage = TRUE");
+
+ // Create a second JMSConsumer for the subscription
+ logger.log(Logger.Level.INFO, "Create a second JMSConsumer for the Subscription");
+ consumer2 = context.createSharedConsumer(topic, sharedSubscriptionName, "lastMessage = TRUE");
+
+ // send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ TextMessage tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", sharedSubscriptionName + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage from consumer1");
+ TextMessage expTextMessage = context.createTextMessage("Message " + numMessages);
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Attempt to Receive TextMessage from consumer2 - there should be none");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage != null) {
+ throw new Exception("Did receive TextMessage - unexpected.");
+ } else
+ logger.log(Logger.Level.INFO, "Did not receive TextMessage - expected.");
+
+ // send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ TextMessage tempMsg = context.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", sharedSubscriptionName + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(destination, tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage from consumer2");
+ expTextMessage = context.createTextMessage("Message " + numMessages);
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Attempt to Receive TextMessage from consumer1 - there should be none");
+ actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage != null) {
+ throw new Exception("Did receive TextMessage - unexpected.");
+ } else
+ logger.log(Logger.Level.INFO, "Did not receive TextMessage - expected.");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createSharedConsumerTest2", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ if (consumer2 != null)
+ consumer2.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Ignoring exception closing consumers: " + e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createSharedConsumerTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: multipleCloseContextTest
+ *
+ * @assertion_ids: JMS:JAVADOC:912; JMS:SPEC:108;
+ *
+ * @test_Strategy: Call close() twice on a JMSContext. This MUST NOT throw an
+ * exception.
+ */
+ @Test
+ public void multipleCloseContextTest() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, "Call close on JMSContext created in setup.");
+ context.close();
+ logger.log(Logger.Level.TRACE, "Call close on a JMSContext a second time");
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("multipleCloseContextTest");
+ }
+ }
+
+ /*
+ * @testName: simpleDurableConsumerTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1084; JMS:JAVADOC:953;
+ *
+ * @test_Strategy: Send single message to a topic and verify receipt of it with
+ * a durable subscriber. This uses a connection factory WITHOUT client
+ * identifier set. Tests the use of the following API's:
+ *
+ * o JMSContext.createDurableConsumer(Topic, String) o
+ * JMSContext.unsubscribe(String)
+ */
+ @Test
+ public void simpleDurableConsumerTest() throws Exception {
+ String durableSubscriptionName = "simpleDurableConsumerTest";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ logger.log(Logger.Level.INFO, "Create DurableConsumer with subscriber name");
+ consumer2 = context2.createDurableConsumer(topic, durableSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Creating and sending 1 message");
+ messageSent = context2.createTextMessage("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", durableSubscriptionName);
+ producer.send(destination, messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) consumer2.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("simpleDurableConsumerTest");
+ } finally {
+ try {
+ cleanupSubscription(consumer2, context2, durableSubscriptionName);
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ /*
+ * @testName: inactiveDurableConsumerTopicRecTest
+ *
+ * @assertion_ids: JMS:JAVADOC:953; JMS:JAVADOC:1084; JMS:JAVADOC:1098;
+ *
+ * @test_Strategy: Send and receive a message from a topic. Inactivate the
+ * subscriber, send another message. Verify that when the subscriber is
+ * activated the message is received. This uses a connection factory WITH client
+ * identifier set.
+ *
+ * o JMSContext.createDurableConsumer(Topic, String) o JMSConsumer.close() o
+ * JMSContext.unsubscribe(String)
+ */
+ @Test
+ public void inactiveDurableConsumerTopicRecTest() throws Exception {
+ String durableSubscriptionName = "inactiveDurableConsumerTopicRecTest";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageSent2 = null;
+ TextMessage messageReceived = null;
+
+ // Create Durable Subscription and a JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create a Durable Subscription and a JMSConsumer for it");
+ consumer2 = context2.createDurableConsumer(topic2, durableSubscriptionName);
+
+ // send message
+ logger.log(Logger.Level.TRACE, "Creating and sending 1 message");
+ messageSent = context2.createTextMessage("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", durableSubscriptionName);
+ producer2.send(destination2, messageSent);
+
+ logger.log(Logger.Level.TRACE, "Receiving message");
+ messageReceived = (TextMessage) consumer2.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // make the durable subscriber inactive
+ consumer2.close();
+
+ // send more messages
+ logger.log(Logger.Level.TRACE, "Creating and sending another message");
+ messageSent2 = context2.createTextMessage("test that messages are durable");
+ messageSent2.setStringProperty("COM_SUN_JMS_TESTNAME", durableSubscriptionName);
+ producer2.send(destination2, messageSent2);
+
+ // Create Durable Subscription and a JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create a Durable Subscription and a JMSConsumer for it");
+ consumer2 = context2.createDurableConsumer(topic2, durableSubscriptionName);
+
+ messageReceived = (TextMessage) consumer2.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent2.getText())) {
+ logger.log(Logger.Level.TRACE, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.TRACE, "Received correct message");
+ } else {
+ throw new Exception("Received incorrect message.");
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("inactiveDurableConsumerTopicRecTest");
+ } finally {
+ try {
+ cleanupSubscription(consumer2, context2, durableSubscriptionName);
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ /*
+ * @testName: durableConsumerTopicNoLocalTest
+ *
+ * @assertion_ids: JMS:SPEC:161; JMS:SPEC:164; JMS:SPEC:165; JMS:JAVADOC:256;
+ * JMS:JAVADOC:99; JMS:JAVADOC:334;
+ *
+ *
+ * @test_Strategy: 1) Create topic connection with normal consumer and
+ * (no_local=true) durable consumer. 2) Publish x messages to topic and receive
+ * them with normal consumer. 3) Try and receive messages with (no_local=true)
+ * durable consumer and verify that you cannot receive them. 4) Publish x more
+ * messages to topic. 4) Close the (no_local=true) durable consumer. 5) Create a
+ * new (no_local=false) durable consumer with the same subscription name and
+ * same topic as (no_local=true) durable consumer. 6) Try and receive messages
+ * with (no_local=false) durable consumer. Verify that you cannot receive any
+ * messages. Recreating a durable consumer with a change to (no_local setting)
+ * causes previous durable subscription to become invalid so all the old
+ * messages are deleted and you start anew with a clean slate.
+ *
+ * A client can change an existing durable subscription by creating a durable
+ * JMSConsumer with the same name and topic but different (no_local setting).
+ * Changing a durable consumer is equivalent to unsubscribing (deleting) the old
+ * one and creating a new one.
+ *
+ * So if a client subsequently changes the no_local setting, all the existing
+ * messages stored in the durable subscription become invalid since they are
+ * inconsistent with the new no_local setting. The only safe thing to do is to
+ * delete all the old messages and start anew.
+ *
+ * This uses a connection factory WITH client identifier set.
+ */
+ @Test
+ public void durableConsumerTopicNoLocalTest() throws Exception {
+ JMSConsumer tConNoLocal = null;
+ String subscriptionName = "DurableConsumerTopicNoLocalTestSubscription";
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ int num = 10;
+ Message messageSent = null;
+ Message messageReceived = null;
+
+ // create normal Consumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create normal Consumer");
+ consumer2 = context2.createConsumer(topic);
+
+ // create DurableConsumer with no_local=true from JMSContext
+ logger.log(Logger.Level.INFO, "Create DurableConsumer with no_local=true");
+ tConNoLocal = context2.createDurableConsumer(topic, subscriptionName, "", true);
+
+ // publish messages to topic
+ logger.log(Logger.Level.INFO, "Sending " + num + " messages to topic");
+ messageSent = context2.createMessage();
+ messageSent.setBooleanProperty("lastMessage", false);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableConsumerTopicNoLocalTest");
+ for (int i = 0; i < num; i++) {
+ producer2.send(destination2, messageSent);
+ }
+
+ // receive messages with default normal consumer
+ logger.log(Logger.Level.INFO, "Attempting to receive messages from normal consumer");
+ for (int i = 0; i < num; i++) {
+ messageReceived = consumer2.receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Should have received message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
+ logger.log(Logger.Level.INFO, "Received correct message lastMessage=false");
+ } else {
+ throw new Exception("Received incorrect message lastMessage=true");
+ }
+ }
+
+ // try and receive with (no_local=true) consumer (should not receive any
+ // messages)
+ logger.log(Logger.Level.INFO, "Attempting to receive messages from (no_local=true) consumer");
+ messageReceived = tConNoLocal.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.INFO, "Did not receive message (correct)");
+ } else {
+ throw new Exception("Received unexpected message (incorrect)");
+ }
+
+ // publish more messages to topic
+ logger.log(Logger.Level.INFO, "Sending " + num + " messages to topic");
+ for (int i = 0; i < num; i++) {
+ producer2.send(destination2, messageSent);
+ }
+
+ // need to inactivate durable consumer before creating new durable
+ // consumer
+ logger.log(Logger.Level.INFO, "Close DurableConsumer with no_local=true");
+ tConNoLocal.close();
+
+ // create new DurableConsumer with no_local=false
+ logger.log(Logger.Level.INFO, "Create DurableConsumer with no_local=false");
+ tConNoLocal = context2.createDurableConsumer(topic, subscriptionName, "", false);
+
+ // try and receive a message from this new durable consumer with
+ // (no_local=false)
+ // should not receive any messages because creating a new DurableConsumer
+ // with a
+ // different (no_local=false) setting will delete the previous
+ // subscription and any
+ // messages that were queued
+ messageReceived = tConNoLocal.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.INFO, "No_local=false consumer did not receive any message (expected)");
+ } else {
+ throw new Exception("No_local=false consumer received message (unexpected)");
+ }
+
+ // publish more messages to topic
+ logger.log(Logger.Level.INFO, "Sending " + num + " messages to topic");
+ messageSent = context2.createMessage();
+ messageSent.setBooleanProperty("lastMessage", false);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableConsumerTopicNoLocalTest");
+ for (int i = 0; i < num; i++) {
+ producer2.send(destination2, messageSent);
+ }
+
+ // receive messages with (no_local=false) consumer (should receive all
+ // messages)
+ logger.log(Logger.Level.INFO, "Attempting to receive messages from (no_local=false) consumer");
+ for (int i = 0; i < num; i++) {
+ messageReceived = tConNoLocal.receive(timeout);
+ if (messageReceived == null) {
+ throw new Exception("Should have received message");
+ } else if (messageReceived.getBooleanProperty("lastMessage") == false) {
+ logger.log(Logger.Level.INFO, "Received correct message lastMessage=false");
+ } else {
+ throw new Exception("Received incorrect message lastMessage=true");
+ }
+ }
+
+ // try and receive one more message (there should be none at this point)
+ messageReceived = tConNoLocal.receive(timeout);
+ if (messageReceived != null) {
+ throw new Exception("Received unexpected final message");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("durableConsumerTopicNoLocalTest2");
+ } finally {
+ try {
+ if (consumer2 != null)
+ consumer2.close();
+ cleanupSubscription(tConNoLocal, context2, subscriptionName);
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ /*
+ * @testName: durableConsumerChangeSelectorTest
+ *
+ * @assertion_ids: JMS:SPEC:164; JMS:SPEC:165; JMS:JAVADOC:122; JMS:JAVADOC:256;
+ * JMS:JAVADOC:99; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Create a durable consumer for the default topic. Create a
+ * durable topic consumer again, use the same name as the above but change the
+ * selector.
+ *
+ * This uses a connection factory WITH client identifier set.
+ */
+ @Test
+ public void durableConsumerChangeSelectorTest() throws Exception {
+ Topic newTestTopic;
+ JMSConsumer durableCon = null;
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // Create a durable consumer with a specified message selector
+ logger.log(Logger.Level.INFO, "Create DurableConsumer with MessageSelector=TEST='test' and no_local=false");
+ durableCon = context2.createDurableConsumer(topic, "durableConsumerChangeSelectorTest", "TEST = 'test'",
+ false);
+
+ // publish and receive message with specified message selector
+ logger.log(Logger.Level.INFO, "Send and receive the message");
+ messageSent = context2.createTextMessage();
+ messageSent.setStringProperty("TEST", "test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableConsumerChangeSelectorTest");
+ messageSent.setText("For default topic ");
+ producer2.send(destination2, messageSent);
+ logger.log(Logger.Level.INFO, "Receiving message");
+ messageReceived = (TextMessage) durableCon.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+
+ // need to inactivate topic consumer before switching to selector
+ durableCon.close();
+
+ // Create new durable consumer with a different message selector specified
+ logger.log(Logger.Level.INFO,
+ "Create DurableConsumer with new MessageSelector=TEST='new one' and no_local=false");
+ durableCon = context2.createDurableConsumer(topic, "durableConsumerChangeSelectorTest", "TEST = 'new one'",
+ false);
+
+ // Publish message with old message selector
+ messageSent.setBooleanProperty("lastMessage", false);
+ producer2.send(destination2, messageSent);
+
+ // Create and Publish a message with the new message selector
+ messageSent = context2.createTextMessage();
+ messageSent.setStringProperty("TEST", "new one");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableConsumerChangeSelectorTest");
+ messageSent.setText("For new topic");
+ messageSent.setBooleanProperty("lastMessage", true);
+ producer2.send(destination2, messageSent);
+
+ // receive message
+ messageReceived = (TextMessage) durableCon.receive(timeout);
+ if (messageReceived != null) {
+ if (messageReceived.getText().equals(messageSent.getText())
+ && messageReceived.getBooleanProperty("lastMessage") == true) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+ } else {
+ throw new Exception("didn't get any message");
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("durableConsumerChangeSelectorTest");
+ } finally {
+ try {
+ cleanupSubscription(durableCon, context2, "durableConsumerChangeSelectorTest");
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ /*
+ * @testName: durableConsumerChangeSelectorTest2
+ *
+ * @assertion_ids: JMS:SPEC:164; JMS:SPEC:165; JMS:JAVADOC:122; JMS:JAVADOC:256;
+ * JMS:JAVADOC:99; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: 1) Create a durable subscription with a message selector
+ * string property of (TEST="test") for the default topic. 2) Publish first
+ * message with string property that matches the message selector (TEST="test").
+ * 3) Publish second message with string property that does not match the
+ * message selector (TEST="test again"). 4) Verify that you can receive the
+ * first message. 5) Verify that you cannot receive the second message. 6) Close
+ * durable subscription. 7) Create a new durable subscription with the same
+ * default topic and subscription name but with a different message selector
+ * (TEST="test again") which matches the string property of the second message
+ * that was published. 8) Try to receive this second message. It should not
+ * recieve the second message. Verify that is does not receive the second
+ * message. 9) Close durable subscription.
+ *
+ * A client can change an existing durable subscription by creating a durable
+ * JMSConsumer with the same name and a new topic and/or message selector.
+ * Changing a durable consumer is equivalent to unsubscribing (deleting) the old
+ * one and creating a new one.
+ *
+ * So if a client subsequently changes the message selector, all the existing
+ * messages stored in the durable subscription become invalid since they are
+ * inconsistent with the new message selector. The only safe thing to do is to
+ * delete all the old messages and start anew.
+ *
+ * This uses a connection factory WITH client identifier set.
+ */
+ @Test
+ public void durableConsumerChangeSelectorTest2() throws Exception {
+ Topic newTestTopic;
+ JMSConsumer durableCon = null;
+ String lookup = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageSent2 = null;
+ TextMessage messageReceived = null;
+
+ // Create a durable consumer with a specified message selector
+ logger.log(Logger.Level.INFO, "Create durable subscription with MessageSelector=\"TEST='test'\",");
+ logger.log(Logger.Level.INFO, "TopicName=" + topic.getTopicName() + " and SubscriptionName="
+ + "durableConsumerChangeSelectorTest2");
+ durableCon = context2.createDurableConsumer(topic, "durableConsumerChangeSelectorTest2", "TEST = 'test'",
+ false);
+
+ logger.log(Logger.Level.INFO, "Create/Send first message with string property \"TEST = 'test'\"");
+ messageSent = context2.createTextMessage();
+ messageSent.setStringProperty("TEST", "test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "durableConsumerChangeSelectorTest2");
+ messageSent.setText("Message #1 with string property TEST='test'");
+ producer2.send(destination, messageSent);
+
+ logger.log(Logger.Level.INFO, "Create/Send second message with string property \"TEST = 'test again'\"");
+ messageSent2 = context2.createTextMessage();
+ messageSent2.setStringProperty("TEST", "test again");
+ messageSent2.setStringProperty("COM_SUN_JMS_TESTNAME", "durableConsumerChangeSelectorTest2");
+ messageSent2.setText("Message #2 with string property TEST='test again'");
+ producer2.send(destination, messageSent2);
+
+ // Check and verify that first message is received
+ logger.log(Logger.Level.INFO, "Try receiving first message (should get message)");
+ messageReceived = (TextMessage) durableCon.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.INFO, "Did not receive any message (incorrect)");
+ throw new Exception("didn't receive any message");
+ } else if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Received correct first message");
+ } else {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ throw new Exception("didn't get the right message");
+ }
+
+ // Check and verify that seconde message is not received
+ logger.log(Logger.Level.INFO, "Try receiving second message (should not get message)");
+ messageReceived = (TextMessage) durableCon.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.INFO, "Did not receive second message (correct)");
+ } else if (messageReceived.getText().equals(messageSent2.getText())) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ throw new Exception("received second message (unexpected)");
+ } else {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ throw new Exception("received unexpected message");
+ }
+
+ // need to inactivate topic consumer before switching new consumer
+ logger.log(Logger.Level.INFO, "Close durable subscription");
+ durableCon.close();
+
+ // change selector
+ logger.log(Logger.Level.INFO,
+ "Create new durable subscription with MessageSelector=\"TEST='test again'\",");
+ logger.log(Logger.Level.INFO, "TopicName=" + topic.getTopicName() + " and SubscriptionName="
+ + "durableConsumerChangeSelectorTest2");
+ durableCon = context2.createDurableConsumer(topic, "durableConsumerChangeSelectorTest2",
+ "TEST = 'test again'", false);
+
+ // receive message
+ messageReceived = (TextMessage) durableCon.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.INFO, "Did not receive any messages (correct)");
+ } else {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived.getText() + "\"");
+ throw new Exception("received unexpected message");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("durableConsumerChangeSelectorTest2");
+ } finally {
+ try {
+ cleanupSubscription(durableCon, context2, "durableConsumerChangeSelectorTest2");
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ /*
+ * @testName: verifyClientIDOnAdminConfiguredIDTest
+ *
+ * @assertion_ids: JMS:JAVADOC:970; JMS:JAVADOC:1040; JMS:SPEC:264.5;
+ * JMS:SPEC:173; JMS:SPEC:198; JMS:SPEC:91;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSContext.getClientID()
+ *
+ * Check and verify the client id of an administratively configured client id.
+ */
+ @Test
+ public void verifyClientIDOnAdminConfiguredIDTest() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "Get client id from an administratively configured client id");
+ String cid = context2.getClientID();
+ if (cid == null) {
+ logger.log(Logger.Level.ERROR, "getClientID returned null (expected cts)");
+ pass = false;
+ } else if (!cid.equals("cts")) {
+ logger.log(Logger.Level.ERROR, "getClientID() returned " + cid + ", expected cts");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "getClientID returned cts (Correct)");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected: " + e);
+ throw new Exception("verifyClientIDOnAdminConfiguredIDTest");
+ }
+
+ if (!pass) {
+ throw new Exception("verifyClientIDOnAdminConfiguredIDTest failed");
+ }
+ }
+
+ /*
+ * @testName: invalidDestinationRuntimeExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:944; JMS:JAVADOC:947; JMS:JAVADOC:951;
+ * JMS:JAVADOC:955; JMS:JAVADOC:958; JMS:JAVADOC:1086; JMS:JAVADOC:1153;
+ * JMS:JAVADOC:1157; JMS:JAVADOC:1254; JMS:JAVADOC:1237; JMS:JAVADOC:1242;
+ * JMS:JAVADOC:1246; JMS:JAVADOC:1250; JMS:JAVADOC:958; JMS:JAVADOC:1383;
+ * JMS:JAVADOC:1161;
+ *
+ * @test_Strategy: Test InvalidDestinationRuntimeException conditions from
+ * various API methods.
+ *
+ * JMSProducer.send(Destination, Message) JMSProducer.send(Destination, String)
+ * JMSProducer.send(Destination, Serializable) JMSProducer.send(Destination,
+ * byte[]) JMSProducer.send(Destination, Map)
+ * JMSContext.createConsumer(Destination) JMSContext.createConsumer(Destination,
+ * String) JMSContext.createConsumer(Destination, String, boolean)
+ * JMSContext.createDurableConsumer(Topic, String)
+ * JMSContext.createDurableConsumer(Topic, String, String, boolean)
+ * JMSContext.createSharedConsumer(Topic, String)
+ * JMSContext.createSharedConsumer(Topic, String, String)
+ * JMSContext.createSharedDurableConsumer(Topic, String)
+ * JMSContext.createSharedDurableConsumer(Topic, String, String)
+ * JMSContext.unsubscribe(String)
+ */
+ @Test
+ public void invalidDestinationRuntimeExceptionTests() throws Exception {
+ boolean pass = true;
+ Destination invalidDestination = null;
+ Topic invalidTopic = null;
+ String message = "Where are you!";
+ byte[] bytesMsgSend = message.getBytes();
+ Map mapMsgSend = new HashMap();
+ mapMsgSend.put("StringValue", "sendAndRecvTest7");
+ mapMsgSend.put("BooleanValue", true);
+ mapMsgSend.put("IntValue", (int) 10);
+ try {
+ // send to an invalid topic
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "invalidDestinationRuntimeExceptionTests");
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Message) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling send(Destination, Message) -> expect InvalidDestinationRuntimeException");
+ producer.send(invalidDestination, expTextMessage);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, String) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling send(Destination, String) -> expect InvalidDestinationRuntimeException");
+ producer.send(invalidDestination, message);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Serializable) for InvalidDestinationRuntimeException");
+ logger.log(Logger.Level.INFO, "Send ObjectMessage");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ ObjectMessage om = context.createObjectMessage();
+ StringBuffer sb = new StringBuffer(message);
+ om.setObject(sb);
+ om.setStringProperty("COM_SUN_JMS_TESTNAME", "invalidDestinationRuntimeExceptionTests");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling send(Destination, Serializable) -> expect InvalidDestinationRuntimeException");
+ producer.send(invalidDestination, om);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, byte[]) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling send(Destination, byte[]) -> expect InvalidDestinationRuntimeException");
+ producer.send(invalidDestination, bytesMsgSend);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Map) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling send(Destination, Map) -> expect InvalidDestinationRuntimeException");
+ producer.send(invalidDestination, mapMsgSend);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createConsumer(Destination) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createConsumer(Destination) -> expect InvalidDestinationRuntimeException");
+ context.createConsumer(invalidDestination);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createConsumer(Destination, String) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createConsumer(Destination, String) -> expect InvalidDestinationRuntimeException");
+ context.createConsumer(invalidDestination, "lastMessage = TRUE");
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createConsumer(Destination, String, boolean) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createConsumer(Destination, String, boolean) -> expect InvalidDestinationRuntimeException");
+ context.createConsumer(invalidDestination, "lastMessage = TRUE", false);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createDurableConsumer(Topic, String) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createDurableConsumer(Topic, String) -> expect InvalidDestinationRuntimeException");
+ context.createDurableConsumer(invalidTopic, "InvalidDestinationRuntimeException");
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createDurableConsumer(Topic, String, String, boolean) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createDurableConsumer(Topic, String, String, boolean) -> expect InvalidDestinationRuntimeException");
+ context.createDurableConsumer(invalidTopic, "InvalidDestinationRuntimeException", "lastMessage = TRUE",
+ false);
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createSharedDurableConsumer(Topic, String) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createSharedDurableConsumer(Topic, String) -> expect InvalidDestinationRuntimeException");
+ context.createSharedDurableConsumer(invalidTopic, "InvalidDestinationRuntimeException");
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createSharedDurableConsumer(Topic, String, String) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createSharedDurableConsumer(Topic, String, String) -> expect InvalidDestinationRuntimeException");
+ context.createSharedDurableConsumer(invalidTopic, "InvalidDestinationRuntimeException",
+ "lastMessage = TRUE");
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.unsubscribe(String) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.unsubscribe(String) -> expect InvalidDestinationRuntimeException");
+ context.unsubscribe("InvalidSubscriptionName");
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createSharedConsumer(Topic, String) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createSharedConsumer(Topic, String) for InvalidDestinationRuntimeException");
+ context.createSharedConsumer(invalidTopic, "InvalidDestinationRuntimeException");
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createSharedConsumer(Topic, String, String) for InvalidDestinationRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createSharedConsumer(Topic, String, String) for InvalidDestinationRuntimeException");
+ context.createSharedConsumer(invalidTopic, "InvalidDestinationRuntimeException", "lastMessage = TRUE");
+ } catch (InvalidDestinationRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationRuntimeException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("invalidDestinationRuntimeExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("invalidDestinationRuntimeExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: invalidSelectorRuntimeExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:948; JMS:JAVADOC:952; JMS:JAVADOC:959;
+ * JMS:JAVADOC:1154; JMS:JAVADOC:1158; JMS:JAVADOC:959; JMS:JAVADOC:1162;
+ *
+ * @test_Strategy: Test InvalidSelectorRuntimeException conditions from various
+ * API methods.
+ *
+ * JMSContext.createConsumer(Destination, String)
+ * JMSContext.createConsumer(Destination, String, boolean)
+ * JMSContext.createDurableConsumer(Topic, String, String, boolean)
+ * JMSContext.createSharedConsumer(Topic, String, String)
+ * JMSContext.createSharedDurableConsumer(Topic, String, String)
+ *
+ */
+ @Test
+ public void invalidSelectorRuntimeExceptionTests() throws Exception {
+ boolean pass = true;
+ String invalidMessageSelector = "=TEST 'test'";
+ try {
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createConsumer(Destination, String) for InvalidSelectorRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createConsumer(Destination, String) -> expect InvalidSelectorRuntimeException");
+ context.createConsumer(topic, invalidMessageSelector);
+ } catch (InvalidSelectorRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidSelectorRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidSelectorRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createConsumer(Destination, String, boolean) for InvalidSelectorRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createConsumer(Destination, String, boolean) -> expect InvalidSelectorRuntimeException");
+ context.createConsumer(topic, invalidMessageSelector, false);
+ } catch (InvalidSelectorRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidSelectorRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidSelectorRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createDurableConsumer(Topic, String, String, boolean) for InvalidSelectorRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createDurableConsumer(Topic, String, String, boolean) -> expect InvalidSelectorRuntimeException");
+ context2.createDurableConsumer(topic, "InvalidSelectorRuntimeException", invalidMessageSelector, false);
+ } catch (InvalidSelectorRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidSelectorRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidSelectorRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createSharedDurableConsumer(Topic, String, String) for InvalidSelectorRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createSharedDurableConsumer(Topic, String, String) -> expect InvalidSelectorRuntimeException");
+ context.createSharedDurableConsumer(topic, "InvalidSelectorRuntimeException", invalidMessageSelector);
+ } catch (InvalidSelectorRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidSelectorRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidSelectorRuntimeException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing JMSContext.createSharedConsumer(Topic, String, String) for InvalidSelectorRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createSharedConsumer(Topic, String, String) for InvalidSelectorRuntimeException");
+ context.createSharedConsumer(topic, "InvalidSelectorRuntimeException", invalidMessageSelector);
+ } catch (InvalidSelectorRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidSelectorRuntimeException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidSelectorRuntimeException, received " + e);
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("invalidSelectorRuntimeExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("invalidSelectorRuntimeExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: jMSRuntimeExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:932; JMS:SPEC:264.2; JMS:JAVADOC:1274;
+ * JMS:JAVADOC:1260; JMS:JAVADOC:1384; JMS:JAVADOC:954; JMS:JAVADOC:1160;
+ * JMS:JAVADOC:957; JMS:JAVADOC:1152; JMS:JAVADOC:1156;
+ *
+ * @test_Strategy: Test JMSRuntimeException conditions from various API methods.
+ *
+ * JMSContext.createContext(int); JMSProducer.setPriority(int);
+ * JMSProducer.setDeliveryMode(long); JMSContext.createDurableConsumer(Topic,
+ * String) JMSContext.createDurableConsumer(Topic, String. String, boolean)
+ * JMSContext.createSharedConsumer(Topic, String)
+ * JMSContext.createSharedConsumer(Topic, String, String)
+ * JMSContext.createSharedDurableConsumer(Topic, String)
+ * JMSContext.createSharedDurableConsumer(Topic, String. String)
+ */
+ @Test
+ public void jMSRuntimeExceptionTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ if ((vehicle.equals("ejb") || vehicle.equals("jsp") || vehicle.equals("servlet"))) {
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling createContext must throw JMSRuntimeException for EJB/WEB container");
+ context.createContext(JMSContext.AUTO_ACKNOWLEDGE);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSRuntimeException");
+ pass = false;
+ } catch (JMSRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSRuntimeException, received " + e);
+ pass = false;
+ }
+ }
+
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+
+ try {
+ logger.log(Logger.Level.INFO, "Try and set an invalid priority of -1");
+ producer.setPriority(-1);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSRuntimeException");
+ pass = false;
+ } catch (JMSRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSRuntimeException, received " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and set an delivery mode to live of -1");
+ producer.setDeliveryMode(-1);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSRuntimeException");
+ pass = false;
+ } catch (JMSRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSRuntimeException, received " + e);
+ pass = false;
+ }
+
+ // Create shared consumer specifying topic and name
+ // Create second shared consumer with same name but specifying different
+ // topic,
+ // Verify JMSRuntimeException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create shared consumer");
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createSharedConsumer(Topic, String)");
+ consumer = context2.createSharedConsumer(topic, "dummySubSCJMSRuntime");
+ logger.log(Logger.Level.INFO, "Create second shared consumer with same name but different topic");
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createSharedConsumer(Topic, String)");
+ Topic mytopic = (Topic) tool.createNewTopic("MY_TOPIC2");
+ consumer2 = context2.createSharedConsumer(mytopic, "dummySubSCJMSRuntime");
+ logger.log(Logger.Level.INFO, "Verify that JMSRuntimeException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSRuntimeException");
+ } catch (JMSRuntimeException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected JMSRuntimeException from " + "JMSContext.createSharedConsumer(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ if (consumer2 != null)
+ consumer2.close();
+ } catch (Exception e) {
+ }
+ }
+
+ // Create shared consumer specifying topic and name and message selector
+ // Create second shared consumer with same name but specifying different
+ // topic and message selector
+ // Verify JMSRuntimeException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create shared consumer");
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createSharedConsumer(Topic, String, String)");
+ consumer = context2.createSharedConsumer(topic, "dummySubSCJMSRuntime", "TEST = 'test'");
+ logger.log(Logger.Level.INFO, "Create second shared consumer with same name but different topic");
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createSharedConsumer(Topic, String, String)");
+ Topic mytopic = (Topic) tool.createNewTopic("MY_TOPIC2");
+ consumer2 = context2.createSharedConsumer(mytopic, "dummySubSCJMSRuntime", "TEST = 'test'");
+ logger.log(Logger.Level.INFO, "Verify that JMSRuntimeException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSRuntimeException");
+ } catch (JMSRuntimeException ex) {
+ logger.log(Logger.Level.INFO, "Got expected JMSRuntimeException from "
+ + "JMSContext.createSharedConsumer(Topic, String, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ if (consumer2 != null)
+ consumer2.close();
+ } catch (Exception e) {
+ }
+ }
+
+ // Create shared durable subscription specifying topic, name. selector.
+ // Create second
+ // shared durable subscription with same name but specifying different
+ // topic, selector.
+ // Verify JMSRuntimeException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create shared durable subscription");
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createSharedDurableConsumer(Topic, String, String)");
+ consumer = context2.createSharedDurableConsumer(topic, "dummySubSJMSRuntime", "TEST = 'test'");
+ logger.log(Logger.Level.INFO,
+ "Create second shared durable subscription with same name but different other args");
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createSharedDurableConsumer(Topic, String, String)");
+ consumer2 = context2.createSharedDurableConsumer(topic, "dummySubSJMSRuntime", "TEST = 'test2'");
+ logger.log(Logger.Level.INFO, "Verify that JMSRuntimeException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSRuntimeException");
+ } catch (JMSRuntimeException ex) {
+ logger.log(Logger.Level.INFO, "Got expected JMSRuntimeException from "
+ + "JMSContext.createSharedDurableConsumer(Topic, String, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer2 != null)
+ consumer2.close();
+ cleanupSubscription(consumer, context2, "dummySubSJMSRuntime");
+ } catch (Exception e) {
+ }
+ }
+
+ // Create durable subscription specifying topic and name
+ // Create second durable subscription with same name but specifying
+ // different topic,
+ // Verify JMSRuntimeException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create durable subscription");
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createDurableConsumer(Topic, String)");
+ consumer = context2.createDurableConsumer(topic, "dummySubDJMSRuntime");
+ logger.log(Logger.Level.INFO, "Create second durable subscription with same name but different topic");
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createDurableConsumer(Topic, String)");
+ Topic mytopic = (Topic) tool.createNewTopic("MY_TOPIC2");
+ consumer2 = context2.createDurableConsumer(mytopic, "dummySubDJMSRuntime");
+ logger.log(Logger.Level.INFO, "Verify that JMSRuntimeException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSRuntimeException");
+ } catch (JMSRuntimeException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected JMSRuntimeException from " + "JMSContext.createDurableConsumer(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer2 != null)
+ consumer2.close();
+ cleanupSubscription(consumer, context2, "dummySubDJMSRuntime");
+ } catch (Exception e) {
+ }
+ }
+
+ // Create shared durable subscription specifying topic and name
+ // Create second shared durable subscription with same name but specifying
+ // different topic,
+ // Verify JMSRuntimeException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create shared durable subscription");
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createSharedDurableConsumer(Topic, String)");
+ consumer = context2.createSharedDurableConsumer(topic, "dummySubSDJMSRuntime");
+ logger.log(Logger.Level.INFO,
+ "Create second shared durable subscription with same name but different topic");
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createSharedDurableConsumer(Topic, String)");
+ Topic mytopic = (Topic) tool.createNewTopic("MY_TOPIC2");
+ consumer2 = context2.createSharedDurableConsumer(mytopic, "dummySubSDJMSRuntime");
+ logger.log(Logger.Level.INFO, "Verify that JMSRuntimeException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSRuntimeException");
+ } catch (JMSRuntimeException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected JMSRuntimeException from " + "JMSContext.createSharedDurableConsumer(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer2 != null)
+ consumer2.close();
+ cleanupSubscription(consumer, context2, "dummySubSDJMSRuntime");
+ } catch (Exception e) {
+ }
+ }
+
+ // Create durable subscription specifying topic, name. selector, and nolocal
+ // value.
+ // Create second durable subscription with same name but specifying
+ // different topic,
+ // selector, or nolocal value. Verify JMSRuntimeException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create durable subscription");
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createDurableConsumer(Topic, String, String, boolean)");
+ consumer = context2.createDurableConsumer(topic, "dummySubDJMSRuntime", "TEST = 'test'", true);
+ logger.log(Logger.Level.INFO, "Create second durable subscription with same name but different other args");
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createDurableConsumer(Topic, String, String, boolean)");
+ consumer2 = context2.createDurableConsumer(topic, "dummySubDJMSRuntime", "TEST = 'test2'", false);
+ logger.log(Logger.Level.INFO, "Verify that JMSRuntimeException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSRuntimeException");
+ } catch (JMSRuntimeException ex) {
+ logger.log(Logger.Level.INFO, "Got expected JMSRuntimeException from "
+ + "JMSContext.createDurableConsumer(Topic, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer2 != null)
+ consumer2.close();
+ cleanupSubscription(consumer, context2, "dummySubDJMSRuntime");
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("jMSRuntimeExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: illegalStateRuntimeExceptionTest
+ *
+ * @assertion_ids: JMS:JAVADOC:917; JMS:JAVADOC:994; JMS:JAVADOC:997;
+ * JMS:JAVADOC:1340; JMS:JAVADOC:1341; JMS:JAVADOC:1378;
+ *
+ * @test_Strategy: 1. Create a TextMessages and send to Topic 2. Then invoke
+ * JMSContext.commit() on a non-transacted session Verify that
+ * IllegalStateRuntimeException is thrown 3. Then test invoke
+ * JMSContext.rollback() on a non-transacted session Verify that
+ * IllegalStateRuntimeException is thrown 3. Then test invoke
+ * JMSContext.recover() on a transacted session Verify that
+ * IllegalStateRuntimeException is thrown 4. Create JMSContext with
+ * CLIENT_ACKNOWLEDGE then close JMSContext. Then test invoke
+ * JMSContext.acknowledge() on the JMSContext. Verify that
+ * IllegalStateRuntimeException is thrown 5. Verify that
+ * IllegalStateRuntimeException is thrown if nolocal=true and client id is unset
+ * for JMSContext.createSharedConsumer(...) and
+ * JMSContext.createSharedDurableConsumer(...) methods. 6. Verify that
+ * IllegalStateRuntimeException is thrown if client id is unset for
+ * JMSContext.createDurableConsumer(...) methods.
+ *
+ * JMSContext.commit(); JMSContext.rollback(); JMSContext.recover();
+ * JMSContext.acknowledge(); JMSContext.createDurableConsumer(Topic, String)
+ * JMSContext.createDurableConsumer(Topic, String. String, boolean)
+ */
+ @Test
+ public void illegalStateRuntimeExceptionTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+
+ try {
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateRuntimeExceptionTest");
+ // send the message to the Topic
+ logger.log(Logger.Level.TRACE, "Sending message to the Topic");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+
+ try {
+ logger.log(Logger.Level.TRACE,
+ "JMSContext.commit() on non-transacted session must throw IllegalStateRuntimeException");
+ context.commit();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: JMSContext.commit() didn't throw expected IllegalStateRuntimeException");
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateRuntimeException from JMSContext.commit()");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateRuntimeExceptionTest");
+ // send the message to the Topic
+ logger.log(Logger.Level.TRACE, "Sending message to the Topic");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+
+ try {
+ logger.log(Logger.Level.TRACE,
+ "JMSContext.rollback() on non-transacted session must throw IllegalStateRuntimeException");
+ context.rollback();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: JMSContext.rollback() didn't throw expected IllegalStateRuntimeException");
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateRuntimeException from JMSContext.rollback()");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateRuntimeExceptionTest");
+ // send the message to the Topic
+ logger.log(Logger.Level.TRACE, "Sending message to the Topic");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+
+ if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
+ // create JMSContext with SESSION_TRANSACTED then create producer
+ JMSContext contextTX = cf.createContext(user, password, JMSContext.SESSION_TRANSACTED);
+ JMSProducer producerTX = contextTX.createProducer();
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ expTextMessage = contextTX.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "illegalStateRuntimeExceptionTest");
+ // send the message to the Queue
+ logger.log(Logger.Level.INFO, "Sending message to the Queue");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producerTX.send(destination, expTextMessage);
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "JMSContext.recover() on a transacted session must throw IllegalStateRuntimeException");
+ contextTX.recover();
+ pass = false;
+ logger.log(Logger.Level.ERROR,
+ "Error: JMSContext.recover() didn't throw expected IllegalStateRuntimeException");
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateRuntimeException from JMSContext.recover()");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ contextTX.close();
+
+ try {
+ logger.log(Logger.Level.INFO, "Create JMSContext with CLIENT_ACKNOWLEDGE");
+ JMSContext msgcontext = cf.createContext(user, password, JMSContext.CLIENT_ACKNOWLEDGE);
+ logger.log(Logger.Level.INFO, "Close JMSContext");
+ msgcontext.close();
+ logger.log(Logger.Level.INFO, "Call JMSContext.acknowledge() on a closed session which is illegal");
+ msgcontext.acknowledge();
+ logger.log(Logger.Level.ERROR, "Didn't throw IllegalStateRuntimeException");
+ pass = false;
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateRuntimeException from JMSContext.acknowledge()");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught expected exception" + e);
+ pass = false;
+ }
+ }
+
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+
+ // Create durable consumer with client identifier unset
+ // Must throw IllegalStateRuntimeException
+ try {
+ consumer = null;
+ logger.log(Logger.Level.INFO, "Calling JMSContext.createDurableConsumer(Topic, String)");
+ logger.log(Logger.Level.INFO,
+ "Create Durable Consumer with client id unset (expect IllegalStateRuntimeException)");
+ consumer = context.createDurableConsumer(topic, "dummySubDIllegalState1");
+ logger.log(Logger.Level.ERROR, "No exception occurred - expected IllegalStateRuntimeException");
+ pass = false;
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer != null)
+ cleanupSubscription(consumer, context, "dummySubDIllegalState1");
+ } catch (Exception e) {
+ }
+ }
+
+ // Create durable consumer with client identifier unset (nolocal=false)
+ // Must throw IllegalStateRuntimeException
+ try {
+ consumer = null;
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createDurableConsumer(Topic, String, String, boolean)");
+ logger.log(Logger.Level.INFO,
+ "Create Durable Consumer with client id unset, nolocal=false (expect IllegalStateRuntimeException)");
+ consumer = context.createDurableConsumer(topic, "dummySubDIllegalState2", "lastMessage = TRUE", false);
+ logger.log(Logger.Level.ERROR, "No exception occurred - expected IllegalStateRuntimeException");
+ pass = false;
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception" + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer != null)
+ cleanupSubscription(consumer, context, "dummySubDIllegalState2");
+ } catch (Exception e) {
+ }
+ }
+
+ // Create durable consumer with client identifier unset (nolocal=true)
+ // Must throw IllegalStateRuntimeException
+ try {
+ consumer = null;
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.createDurableConsumer(Topic, String, String, boolean)");
+ logger.log(Logger.Level.INFO,
+ "Create Durable Consumer with client id unset, nolocal=true (expect IllegalStateRuntimeException)");
+ consumer = context.createDurableConsumer(topic, "dummySubDIllegalState2", "lastMessage = TRUE", true);
+ logger.log(Logger.Level.ERROR, "No exception occurred - expected IllegalStateRuntimeException");
+ pass = false;
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception" + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer != null)
+ cleanupSubscription(consumer, context, "dummySubDIllegalState2");
+ } catch (Exception e) {
+ }
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("illegalStateRuntimeExceptionTest");
+ }
+
+ if (!pass) {
+ throw new Exception("illegalStateRuntimeExceptionTest");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsproducerqueuetests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsproducerqueuetests/Client.java
deleted file mode 100644
index 4f8b33afb8..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsproducerqueuetests/Client.java
+++ /dev/null
@@ -1,5316 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.jmsproducerqueuetests;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.EOFException;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.Set;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.ConnectionMetaData;
-import jakarta.jms.DeliveryMode;
-import jakarta.jms.Destination;
-import jakarta.jms.JMSConsumer;
-import jakarta.jms.JMSContext;
-import jakarta.jms.JMSProducer;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.MessageFormatException;
-import jakarta.jms.MessageFormatRuntimeException;
-import jakarta.jms.MessageNotWriteableRuntimeException;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.Queue;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.jmsproducerqueuetests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null;
-
- // JMS objects
- private transient ConnectionFactory cf = null;
-
- private transient Queue queue = null;
-
- private transient Destination destination = null;
-
- private transient JMSContext context = null;
-
- private transient JMSProducer producer = null;
-
- private transient JMSConsumer consumer = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * helper method verifies that the ConnectionMetaData
- *
- * @param ConnectionMetaData returned from getJMSMessageID
- *
- * @return boolean true if ConnectionMetaData is as expected
- */
- private boolean verifyMetaData(ConnectionMetaData data) {
- boolean pass = true;
-
- try {
- String tmp = data.getJMSVersion();
- TestUtil.logTrace("JMSVersion=" + tmp);
-
- if (!tmp.equals("2.0")) {
- TestUtil.logErr("Error: incorrect JMSVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getJMSMajorVersion();
- TestUtil.logTrace("JMSMajorVersion=" + tmp);
-
- if (tmp != 2) {
- TestUtil.logErr("Error: incorrect JMSMajorVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSMajorVersion: ",
- e);
- pass = false;
- }
-
- try {
- int tmp = data.getJMSMinorVersion();
- TestUtil.logTrace("JMSMinorVersion=" + tmp);
-
- if (tmp != 0) {
- TestUtil.logErr("Error: incorrect JMSMajorVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSMinorVersion: ",
- e);
- pass = false;
- }
-
- try {
- String tmp = data.getJMSProviderName();
- TestUtil.logTrace("JMSProviderName=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSProviderName: ",
- e);
- pass = false;
- }
-
- try {
- String tmp = data.getProviderVersion();
- TestUtil.logTrace("JMSProviderVersion=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for ProviderVersion: ",
- e);
- pass = false;
- }
-
- try {
- int tmp = data.getProviderMajorVersion();
- TestUtil.logTrace("ProviderMajorVersion=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: incorrect type returned for ProviderMajorVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getProviderMinorVersion();
- TestUtil.logTrace("ProviderMinorVersion=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: incorrect type returned for ProviderMinorVersion: ", e);
- pass = false;
- }
- return pass;
- }
-
- /*
- * helper method verifies that the JMSMessageID starts with ID:
- *
- * @param String returned from getJMSMessageID
- *
- * @return boolean true if id correctly starts with ID:
- */
- private boolean chkMessageID(String id) {
- String status[] = { "Pass", "Fail" };
- boolean retcode = true;
-
- // message id must start with ID: - unless it is null
- int index = 0;
-
- if (id == null) {
- ;
- } else if (id.startsWith("ID:")) {
- ;
- } else {
- index = 1;
- retcode = false;
- }
- logTrace("Results: " + status[index]);
- return retcode;
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- queues = new ArrayList(3);
- connections = new ArrayList(5);
-
- // set up JmsTool for COMMON_Q setup
- TestUtil.logMsg("Setup JmsTool for COMMON_Q");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- cf = tool.getConnectionFactory();
- tool.getDefaultConnection().close();
- destination = tool.getDefaultDestination();
- queue = (Queue) destination;
-
- // create JMSContext with AUTO_ACKNOWLEDGE then create consumer/producer
- TestUtil.logMsg("Create JMSContext, JMSConsumer and JMSProducer");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- producer = context.createProducer();
- consumer = context.createConsumer(destination);
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Close JMSContext Objects");
- if (context != null) {
- context.close();
- context = null;
- }
- producer = null;
- TestUtil.logMsg("Flush any messages left on Queue");
- tool.flushDestination();
- TestUtil.logMsg("Close JMSConsumer objects");
- if (consumer != null) {
- consumer.close();
- consumer = null;
- }
- tool.closeAllResources();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * @testName: sendAndRecvTest1
- *
- * @assertion_ids: JMS:JAVADOC:1234;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * JMSProducer.send(Destination, Message) JMSConsumer.receive(long)
- *
- */
- public void sendAndRecvTest1() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvTest1");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Receive TextMessage via JMSconsumer.receive(long)");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvTest1", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTest1 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTest2
- *
- * @assertion_ids: JMS:JAVADOC:1239;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * JMSProducer.send(Destination, String) JMSConsumer.receiveBody(String, long)
- *
- */
- public void sendAndRecvTest2() throws Exception {
- boolean pass = true;
- String expTextMessage = "Where are you!";
- try {
- // send and receive TextMessage payload
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, String)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg(
- "Receive TextMessage via JMSConsumer.receiveBody(String, long)");
- String actTextMessage = consumer.receiveBody(String.class, timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.equals(expTextMessage)) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect expected " + expTextMessage
- + ", received " + actTextMessage);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvTest2", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTest2 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTest3
- *
- * @assertion_ids: JMS:JAVADOC:1251;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * JMSProducer.send(Destination, Serializable)
- * JMSConsumer.receiveBody(Serializable, long)
- *
- */
- public void sendAndRecvTest3() throws Exception {
- boolean pass = true;
- try {
- // send and receive ObjectMessage
- TestUtil.logMsg("Send ObjectMessage");
- TestUtil.logMsg("Set some values in ObjectMessage");
- ObjectMessage expObjectMessage = context.createObjectMessage();
- StringBuffer expSb = new StringBuffer("Where are you!");
- TestUtil.logMsg("Set object in ObjectMessage to a StringBuffer");
- expObjectMessage.setObject(expSb);
- expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvTest3");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Serializable)");
- producer.send(destination, expObjectMessage);
- TestUtil.logMsg(
- "Receive ObjectMessage via JMSConsumer.receiveBody(Serializable.class, long)");
- StringBuffer actSb = (StringBuffer) consumer
- .receiveBody(Serializable.class, timeout);
- if (actSb == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- TestUtil.logMsg("Check the value in ObjectMessage");
- if (actSb.toString().equals(expSb.toString())) {
- TestUtil.logMsg("ObjectMessage is correct");
- } else {
- TestUtil.logErr("ObjectMessage is incorrect expected "
- + expSb.toString() + ", received " + actSb.toString());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvTest3", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTest3 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTest4
- *
- * @assertion_ids: JMS:JAVADOC:1243;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * JMSProducer.send(Destination, Map)
- * JMSConsumer.receiveBody(Map, long))
- */
- public void sendAndRecvTest4() throws Exception {
- boolean pass = true;
- Map mapMsgSend = new HashMap();
- mapMsgSend.put("StringValue", "sendAndRecvTest4");
- mapMsgSend.put("BooleanValue", true);
- mapMsgSend.put("IntValue", (int) 10);
- try {
- // send and receive MapMessage payload
- TestUtil.logMsg(
- "Send MapMessage via JMSProducer.send(Destination, Map)");
- producer.send(destination, mapMsgSend);
- TestUtil.logMsg(
- "Receive MapMessage via JMSConsumer.receiveBody(Map.class, long)");
- Map mapMsgRecv = consumer.receiveBody(Map.class, timeout);
- if (mapMsgRecv == null) {
- throw new Exception("Did not receive MapMessage");
- }
- TestUtil.logMsg("Compare MapMsgSend and MapMsgRecv for equality");
- for (Entry entry : mapMsgSend.entrySet()) {
- String key = entry.getKey();
- TestUtil.logMsg(
- "key " + key + ": " + entry.getValue().equals(mapMsgRecv.get(key)));
- if (entry.getValue().equals(mapMsgRecv.get(key))) {
- continue;
- } else {
- pass = false;
- }
- }
- if (pass) {
- TestUtil.logMsg("MapMessage is correct");
- } else {
- TestUtil.logErr("MapMessage is incorrect expected " + mapMsgSend
- + ", received " + mapMsgRecv);
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvTest4", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTest4 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTest5
- *
- * @assertion_ids: JMS:JAVADOC:1247;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * JMSProducer.send(Destination, byte[]) JMSConsumer.receiveBody(byte[],
- * long))
- *
- */
- public void sendAndRecvTest5() throws Exception {
- boolean pass = true;
- String messageSend = "Where are you!";
- byte[] bytesMsgSend = messageSend.getBytes();
- try {
- // send and receive BytesMessage
- TestUtil.logMsg(
- "Send BytesMessage via JMSProducer.send(Destination, byte[])");
- producer.send(destination, bytesMsgSend);
- TestUtil.logMsg(
- "Receive BytesMessage via JMSConsumer.receiveBody(byte[].class, long)");
- byte[] bytesMsgRecv = consumer.receiveBody(byte[].class, timeout);
- if (bytesMsgRecv == null) {
- throw new Exception("Did not receive BytesMessage");
- }
- TestUtil.logMsg("Compare BytesMsgSend and BytesMsgRecv for equality");
- String messageRecv = new String(bytesMsgRecv);
- if (messageRecv.equals(messageSend)) {
- TestUtil.logMsg("BytesMessage is correct");
- } else {
- TestUtil.logErr("BytesMessage is incorrect expected " + messageRecv
- + ", received " + messageSend);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvTest5", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTest5 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvMsgsOfEachMsgTypeTest
- *
- * @assertion_ids: JMS:JAVADOC:925; JMS:JAVADOC:927; JMS:JAVADOC:929;
- * JMS:JAVADOC:934; JMS:JAVADOC:937; JMS:JAVADOC:940; JMS:JAVADOC:964;
- * JMS:JAVADOC:966; JMS:JAVADOC:942; JMS:JAVADOC:847; JMS:JAVADOC:1104;
- * JMS:JAVADOC:1234; JMS:JAVADOC:875; JMS:JAVADOC:936; JMS:JAVADOC:1177;
- *
- * @test_Strategy: Send and receive messages of each message type: Message,
- * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Gets
- * the delivery time of each send of the message. Tests the following API's
- *
- * ConnectionFactory.createContext(String, String, int)
- * JMSContext.createConsumer(Destination) JMSContext.createProducer()
- * JMSContext.createMessage() JMSContext.createBytesMessage()
- * JMSContext.createMapMessage() JMSContext.createObjectMessage()
- * JMSContext.createObjectMessage(Serializable object)
- * JMSContext.createStreamMessage() JMSContext.createTextMessage()
- * JMSContext.createTextMessage(String) JMSContext.createConsumer(Destination)
- * JMSProducer.send(Destination, Message) JMSConsumer.receive(long timeout)
- *
- */
- public void sendAndRecvMsgsOfEachMsgTypeTest() throws Exception {
- boolean pass = true;
- try {
- // send and receive Message
- TestUtil.logMsg("Send Message");
- Message msg = context.createMessage();
- TestUtil.logMsg("Set some values in Message");
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- msg.setBooleanProperty("booleanProperty", true);
- producer.send(destination, msg);
- long deliveryTime = msg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive Message");
- Message msgRecv = (Message) consumer.receive(timeout);
- if (msgRecv == null) {
- TestUtil.logErr("Did not receive Message");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in Message");
- if (msgRecv.getBooleanProperty("booleanProperty") == true) {
- TestUtil.logMsg("booleanproperty is correct");
- } else {
- TestUtil.logMsg("booleanproperty is incorrect");
- pass = false;
- }
- }
-
- // send and receive BytesMessage
- TestUtil.logMsg("Send BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- producer.send(destination, bMsg);
- deliveryTime = bMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive BytesMessage");
- BytesMessage bMsgRecv = (BytesMessage) consumer.receive(timeout);
- if (bMsgRecv == null) {
- TestUtil.logErr("Did not receive BytesMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in BytesMessage");
- if (bMsgRecv.readByte() == (byte) 1) {
- TestUtil.logMsg("bytevalue is correct");
- } else {
- TestUtil.logMsg("bytevalue is incorrect");
- pass = false;
- }
- if (bMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive MapMessage
- TestUtil.logMsg("Send MapMessage");
- MapMessage mMsg = context.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- producer.send(destination, mMsg);
- deliveryTime = mMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive MapMessage");
- MapMessage mMsgRecv = (MapMessage) consumer.receive(timeout);
- if (mMsgRecv == null) {
- TestUtil.logErr("Did not receive MapMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in MapMessage");
- Enumeration list = mMsgRecv.getMapNames();
- String name = null;
- while (list.hasMoreElements()) {
- name = (String) list.nextElement();
- if (name.equals("booleanvalue")) {
- if (mMsgRecv.getBoolean(name) == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logErr("booleanvalue is incorrect");
- pass = false;
- }
- } else if (name.equals("intvalue")) {
- if (mMsgRecv.getInt(name) == 10) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logErr("intvalue is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Unexpected name of [" + name + "] in MapMessage");
- pass = false;
- }
- }
- }
-
- // send and receive ObjectMessage
- TestUtil.logMsg("Send ObjectMessage");
- StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
- TestUtil.logMsg("Set some values in ObjectMessage");
- ObjectMessage oMsg = context.createObjectMessage();
- oMsg.setObject(sb1);
- oMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- producer.send(destination, oMsg);
- deliveryTime = oMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive ObjectMessage");
- ObjectMessage oMsgRecv = (ObjectMessage) consumer.receive(timeout);
- if (oMsgRecv == null) {
- TestUtil.logErr("Did not receive ObjectMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in ObjectMessage");
- StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
- if (sb2.toString().equals(sb1.toString())) {
- TestUtil.logMsg("objectvalue is correct");
- } else {
- TestUtil.logErr("objectvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive ObjectMessage passing object as param
- TestUtil.logMsg("Send ObjectMessage passing object as param");
- sb1 = new StringBuffer("This is a StringBuffer");
- TestUtil
- .logMsg("Set some values in ObjectMessage passing object as param");
- oMsg = context.createObjectMessage(sb1);
- oMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- producer.send(destination, oMsg);
- deliveryTime = oMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive ObjectMessage");
- oMsgRecv = (ObjectMessage) consumer.receive(timeout);
- if (oMsgRecv == null) {
- TestUtil.logErr("Did not receive ObjectMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in ObjectMessage");
- StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
- if (sb2.toString().equals(sb1.toString())) {
- TestUtil.logMsg("objectvalue is correct");
- } else {
- TestUtil.logErr("objectvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive StreamMessage
- TestUtil.logMsg("Send StreamMessage");
- StreamMessage sMsg = context.createStreamMessage();
- TestUtil.logMsg("Set some values in StreamMessage");
- sMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- sMsg.writeBoolean(true);
- sMsg.writeInt((int) 22);
- producer.send(destination, sMsg);
- deliveryTime = sMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive StreamMessage");
- StreamMessage sMsgRecv = (StreamMessage) consumer.receive(timeout);
- if (sMsgRecv == null) {
- TestUtil.logErr("Did not receive StreamMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in StreamMessage");
- if (sMsgRecv.readBoolean() == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logMsg("booleanvalue is incorrect");
- pass = false;
- }
- if (sMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive TextMessage
- TestUtil.logMsg("Send TextMessage");
- TextMessage tMsg = context.createTextMessage();
- TestUtil.logMsg("Set some values in TextMessage");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- tMsg.setText("Hello There!");
- producer.send(destination, tMsg);
- deliveryTime = tMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive TextMessage");
- TextMessage tMsgRecv = (TextMessage) consumer.receive(timeout);
- if (tMsgRecv == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (tMsgRecv.getText().equals("Hello There!")) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect");
- pass = false;
- }
- }
-
- // send and receive TextMessage passing string as param
- TestUtil.logMsg("Send TextMessage");
- tMsg = context.createTextMessage("Where are you!");
- TestUtil.logMsg("Set some values in TextMessage");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- producer.send(destination, tMsg);
- deliveryTime = tMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive TextMessage");
- tMsgRecv = (TextMessage) consumer.receive(timeout);
- if (tMsgRecv == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (tMsgRecv.getText().equals("Where are you!")) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvMsgsOfEachMsgTypeTest", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvMsgsOfEachMsgTypeTest failed");
- }
- }
-
- /*
- * @testName: setGetDeliveryModeTest
- *
- * @assertion_ids: JMS:JAVADOC:1192; JMS:JAVADOC:1259;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setDeliveryMode(int). JMSProducer.getDeliveryMode().
- */
- public void setGetDeliveryModeTest() throws Exception {
- boolean pass = true;
-
- // Test default case
- try {
- int expDeliveryMode = DeliveryMode.PERSISTENT;
- TestUtil.logMsg("Calling getDeliveryMode and expect " + expDeliveryMode
- + " to be returned");
- int actDeliveryMode = producer.getDeliveryMode();
- if (actDeliveryMode != expDeliveryMode) {
- TestUtil.logErr("getDeliveryMode() returned " + actDeliveryMode
- + ", expected " + expDeliveryMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDeliveryModeTest");
- }
-
- // Test non-default case
- try {
- int expDeliveryMode = DeliveryMode.NON_PERSISTENT;
- TestUtil.logMsg("Calling setDeliveryMode(" + expDeliveryMode + ")");
- producer.setDeliveryMode(expDeliveryMode);
- TestUtil.logMsg("Calling getDeliveryMode and expect " + expDeliveryMode
- + " to be returned");
- int actDeliveryMode = producer.getDeliveryMode();
- if (actDeliveryMode != expDeliveryMode) {
- TestUtil.logErr("getDeliveryMode() returned " + actDeliveryMode
- + ", expected " + expDeliveryMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDeliveryModeTest");
- }
-
- if (!pass) {
- throw new Exception("setGetDeliveryModeTest failed");
- }
- }
-
- /*
- * @testName: setGetDeliveryDelayTest
- *
- * @assertion_ids: JMS:JAVADOC:1190; JMS:JAVADOC:1257;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setDeliveryDelay(long). JMSProducer.getDeliveryDelay().
- */
- public void setGetDeliveryDelayTest() throws Exception {
- boolean pass = true;
-
- // Test default case
- try {
- long expDeliveryDelay = 0L;
- TestUtil.logMsg("Calling getDeliveryDelay and expect " + expDeliveryDelay
- + " to be returned");
- long actDeliveryDelay = producer.getDeliveryDelay();
- if (actDeliveryDelay != expDeliveryDelay) {
- TestUtil.logErr("getDeliveryDelay() returned " + actDeliveryDelay
- + ", expected " + expDeliveryDelay);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDeliveryDelayTest");
- }
-
- // Test non-default case
- try {
- long expDeliveryDelay = 1L;
- TestUtil.logMsg("Calling setDeliveryDelay(" + expDeliveryDelay + ")");
- producer.setDeliveryDelay(expDeliveryDelay);
- TestUtil.logMsg("Calling getDeliveryDelay and expect " + expDeliveryDelay
- + " to be returned");
- long actDeliveryDelay = producer.getDeliveryDelay();
- if (actDeliveryDelay != expDeliveryDelay) {
- TestUtil.logErr("getDeliveryDelay() returned " + actDeliveryDelay
- + ", expected " + expDeliveryDelay);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDeliveryDelayTest");
- }
-
- if (!pass) {
- throw new Exception("setGetDeliveryDelayTest failed");
- }
- }
-
- /*
- * @testName: setGetDisableMessageIDTest
- *
- * @assertion_ids: JMS:JAVADOC:1194; JMS:JAVADOC:1261;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setDisableMessageID(boolean).
- * JMSProducer.getDisableMessageID().
- */
- public void setGetDisableMessageIDTest() throws Exception {
- boolean pass = true;
- // Test default case
- try {
- boolean expDisableMessageID = true;
- TestUtil
- .logMsg("Calling setDisableMessageID(" + expDisableMessageID + ")");
- producer.setDisableMessageID(expDisableMessageID);
- TestUtil.logMsg("Calling getDisableMessageID and expect "
- + expDisableMessageID + " to be returned");
- boolean actDisableMessageID = producer.getDisableMessageID();
- if (actDisableMessageID != expDisableMessageID) {
- TestUtil.logErr("getDisableMessageID() returned " + actDisableMessageID
- + ", expected " + expDisableMessageID);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDisableMessageIDTest");
- }
-
- // Test non-default case
- try {
- boolean expDisableMessageID = false;
- TestUtil
- .logMsg("Calling setDisableMessageID(" + expDisableMessageID + ")");
- producer.setDisableMessageID(expDisableMessageID);
- TestUtil.logMsg("Calling getDisableMessageID and expect "
- + expDisableMessageID + " to be returned");
- boolean actDisableMessageID = producer.getDisableMessageID();
- if (actDisableMessageID != expDisableMessageID) {
- TestUtil.logErr("getDisableMessageID() returned " + actDisableMessageID
- + ", expected " + expDisableMessageID);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDisableMessageIDTest");
- }
-
- if (!pass) {
- throw new Exception("setGetDisableMessageIDTest failed");
- }
- }
-
- /*
- * @testName: setGetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:JAVADOC:1196; JMS:JAVADOC:1263;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setDisableMessageTimestamp(boolean).
- * JMSProducer.getDisableMessageTimestamp().
- */
- public void setGetDisableMessageTimestampTest() throws Exception {
- boolean pass = true;
- // Test default case
- try {
- boolean expDisableMessageTimestamp = true;
- TestUtil.logMsg("Calling setDisableMessageTimestamp("
- + expDisableMessageTimestamp + ")");
- producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
- TestUtil.logMsg("Calling getDisableMessageTimestamp and expect "
- + expDisableMessageTimestamp + " to be returned");
- boolean actDisableMessageTimestamp = producer
- .getDisableMessageTimestamp();
- if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
- TestUtil.logErr("getDisableMessageTimestamp() returned "
- + actDisableMessageTimestamp + ", expected "
- + expDisableMessageTimestamp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDisableMessageTimestampTest");
- }
-
- // Test non-default case
- try {
- boolean expDisableMessageTimestamp = false;
- TestUtil.logMsg("Calling setDisableMessageTimestamp("
- + expDisableMessageTimestamp + ")");
- producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
- TestUtil.logMsg("Calling getDisableMessageTimestamp and expect "
- + expDisableMessageTimestamp + " to be returned");
- boolean actDisableMessageTimestamp = producer
- .getDisableMessageTimestamp();
- if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
- TestUtil.logErr("getDisableMessageTimestamp() returned "
- + actDisableMessageTimestamp + ", expected "
- + expDisableMessageTimestamp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDisableMessageTimestampTest");
- }
-
- if (!pass) {
- throw new Exception("setGetDisableMessageTimestampTest failed");
- }
- }
-
- /*
- * @testName: setGetPriorityTest
- *
- * @assertion_ids: JMS:JAVADOC:1220; JMS:JAVADOC:1273;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setPriority(int). JMSProducer.getPriority().
- */
- public void setGetPriorityTest() throws Exception {
- boolean pass = true;
- try {
- // Test default
- int expPriority = Message.DEFAULT_PRIORITY;
- TestUtil.logMsg(
- "Calling getPriority and expect " + expPriority + " to be returned");
- int actPriority = producer.getPriority();
- if (actPriority != expPriority) {
- TestUtil.logErr("getPriority() returned " + actPriority + ", expected "
- + expPriority);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetPriorityTest");
- }
-
- // Test non-default
- int expPriority[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
-
- // Cycle through all priorties
- for (int i = 0; i < expPriority.length; i++) {
- try {
- TestUtil.logMsg("Calling setPriority(" + expPriority[i] + ")");
- producer.setPriority(expPriority[i]);
- TestUtil.logMsg("Calling getPriority and expect " + expPriority[i]
- + " to be returned");
- int actPriority = producer.getPriority();
- if (actPriority != expPriority[i]) {
- TestUtil.logErr("getPriority() returned " + actPriority
- + ", expected " + expPriority[i]);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetPriorityTest");
- }
- }
-
- if (!pass) {
- throw new Exception("setGetPriorityTest failed");
- }
- }
-
- /*
- * @testName: setGetTimeToLiveTest
- *
- * @assertion_ids: JMS:JAVADOC:1230; JMS:JAVADOC:1303;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setTimeToLive(long). JMSProducer.getTimeToLive().
- */
- public void setGetTimeToLiveTest() throws Exception {
- boolean pass = true;
-
- try {
- // Test default
- long expTimeToLive = 0;
- TestUtil.logMsg("Calling getTimeToLive and expect " + expTimeToLive
- + " to be returned");
- long actTimeToLive = producer.getTimeToLive();
- if (actTimeToLive != expTimeToLive) {
- TestUtil.logErr("getTimeToLive() returned " + actTimeToLive
- + ", expected " + expTimeToLive);
- pass = false;
- }
-
- // Test non-default
- expTimeToLive = 1000;
- TestUtil.logMsg("Calling setTimeToLive(" + expTimeToLive + ")");
- producer.setTimeToLive(expTimeToLive);
- TestUtil.logMsg("Calling getTimeToLive and expect " + expTimeToLive
- + " to be returned");
- actTimeToLive = producer.getTimeToLive();
- if (actTimeToLive != expTimeToLive) {
- TestUtil.logErr("getTimeToLive() returned " + actTimeToLive
- + ", expected " + expTimeToLive);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetTimeToLiveTest");
- }
-
- if (!pass) {
- throw new Exception("setGetTimeToLiveTest failed");
- }
- }
-
- /*
- * @testName: deliveryDelayTest
- *
- * @assertion_ids: JMS:SPEC:261; JMS:SPEC:256; JMS:JAVADOC:1257;
- *
- * @test_Strategy: Send message and verify that message is not delivered until
- * the DeliveryDelay of 20 seconds is reached. Test DeliveryMode.PERSISTENT
- * and DeliveryMode.NON_PERSISTENT.
- */
- public void deliveryDelayTest() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------------------------------------------------");
- TestUtil.logMsg("BEGIN TEST deliveryDelayTest with DeliveryDelay=20Secs");
- TestUtil.logMsg("------------------------------------------------------");
- producer.setDeliveryDelay(20000);
-
- // Send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage message = context.createTextMessage("This is a test!");
-
- TestUtil.logMsg("Set StringProperty COM_SUN_JMS_TESTNAME");
- message.setStringProperty("COM_SUN_JMS_TESTNAME", "deliveryDelayTest");
-
- TestUtil.logMsg(
- "Sending message with DeliveryMode.PERSISTENT and DeliveryDelay=20Secs");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- producer.setPriority(Message.DEFAULT_PRIORITY);
- producer.setTimeToLive(0L);
- producer.send(destination, message);
-
- TestUtil.logMsg("Waiting 10 seconds to receive message");
- message = (TextMessage) consumer.receive(10000);
- if (message != null) {
- TestUtil.logErr(
- "FAILED: Message received before delivery delay of 20 secs elapsed");
- pass = false;
- } else {
- TestUtil.logMsg("Didn't receive message after 10 seconds (CORRECT)");
- TestUtil.logMsg("Sleeping 5 more seconds before receiving message");
- Thread.sleep(5000);
- TestUtil.logMsg("Waiting 10 more seconds to receive message");
- message = (TextMessage) consumer.receive(10000);
- if (message == null) {
- TestUtil.logErr(
- "FAILED: Message was not received after delivery delay of 20 secs elapsed");
- pass = false;
- } else {
- TestUtil.logMsg("Received message after 20 secs elapsed (CORRECT)");
- }
- }
-
- TestUtil.logMsg(
- "Sending message with DeliveryMode.NON_PERSISTENT and DeliveryDelay=20Secs");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- producer.setPriority(Message.DEFAULT_PRIORITY);
- producer.setTimeToLive(0L);
- producer.send(destination, message);
-
- TestUtil.logMsg("Waiting 10 seconds to receive message");
- message = (TextMessage) consumer.receive(10000);
- if (message != null) {
- TestUtil.logErr(
- "FAILED: Message received before delivery delay of 20 secs elapsed");
- pass = false;
- } else {
- TestUtil.logMsg("Didn't receive message after 10 seconds (CORRECT)");
- TestUtil.logMsg("Sleeping 5 more seconds before receiving message");
- Thread.sleep(5000);
- TestUtil.logMsg("Waiting 10 more seconds to receive message");
- message = (TextMessage) consumer.receive(10000);
- if (message == null) {
- TestUtil.logErr(
- "FAILED: Message was not received after delivery delay of 20 secs elapsed");
- pass = false;
- } else {
- TestUtil.logMsg("Received message after 20 secs elapsed (CORRECT)");
- }
- }
- TestUtil.logMsg("----------------------------------------------------");
- TestUtil.logMsg("END TEST deliveryDelayTest with DeliveryDelay=20Secs");
- TestUtil.logMsg("----------------------------------------------------");
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("deliveryDelayTest", e);
- }
-
- if (!pass) {
- throw new Exception("deliveryDelayTest failed");
- }
- }
-
- /*
- * @testName: msgHdrMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343; JMS:JAVADOC:1261;
- * JMS:JAVADOC:1194;
- *
- * @test_Strategy: Send to a Queue and receive Text, Map, Bytes, Stream, and
- * Object message. Call getJMSMessageID and verify that it starts with ID:
- */
- public void msgHdrMessageIDTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- String id = null;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- producer.setDisableMessageID(false);
-
- // send and receive Object message to Queue
- TestUtil.logMsg("Send ObjectMessage to Queue.");
- messageSentO = context.createObjectMessage();
- messageSentO.setObject("msgHdrMessageIDTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrMessageIDTest");
- producer.send(destination, messageSentO);
- TestUtil.logMsg("Receive ObjectMessage from Queue.");
- messageReceivedO = (ObjectMessage) consumer.receive(timeout);
- if (messageReceivedO == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil
- .logMsg("getJMSMessageID=" + messageReceivedO.getJMSMessageID());
- id = messageReceivedO.getJMSMessageID();
- if (!chkMessageID(id)) {
- TestUtil.logErr(
- "ObjectMessage error: JMSMessageID does not start with ID:");
- pass = false;
- } else {
- TestUtil.logMsg("Objectessage JMSMessageID pass");
- }
- }
- // send and receive map message to Queue
- TestUtil.logMsg("Send MapMessage to Queue.");
- messageSentM = context.createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrMessageIDTest");
- messageSentM.setString("aString", "value");
- producer.send(destination, messageSentM);
- TestUtil.logMsg("Receive MapMessage from Queue.");
- messageReceivedM = (MapMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil
- .logMsg("getJMSMessageID=" + messageReceivedM.getJMSMessageID());
- id = messageReceivedM.getJMSMessageID();
- if (!chkMessageID(id)) {
- TestUtil
- .logErr("MapMessage error: JMSMessageID does not start with ID:");
- pass = false;
- } else {
- TestUtil.logMsg("MapMessage JMSMessageID pass");
- }
- }
-
- // send and receive bytes message to Queue
- TestUtil.logMsg("Send BytesMessage to Queue.");
- messageSentB = context.createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrMessageIDTest");
- messageSentB.writeByte(bValue);
- producer.send(destination, messageSentB);
- TestUtil.logMsg("Receive BytesMessage from Queue.");
- messageReceivedB = (BytesMessage) consumer.receive(timeout);
- if (messageReceivedB == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil
- .logMsg("getJMSMessageID=" + messageReceivedB.getJMSMessageID());
- id = messageReceivedB.getJMSMessageID();
- if (!chkMessageID(id)) {
- TestUtil.logErr(
- "BytesMessage error: JMSMessageID does not start with ID:");
- pass = false;
- } else {
- TestUtil.logMsg("BytesMessage JMSMessageID pass");
- }
- }
-
- // Send and receive a StreamMessage
- TestUtil.logMsg("Send StreamMessage to Queue");
- messageSentS = context.createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrMessageIDTest");
- messageSentS.writeString("Testing...");
- TestUtil.logMsg("Sending message");
- producer.send(destination, messageSentS);
- TestUtil.logMsg("Receive StreamMessage from Queue.");
- messageReceivedS = (StreamMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil
- .logMsg("getJMSMessageID=" + messageReceivedS.getJMSMessageID());
- id = messageReceivedS.getJMSMessageID();
- if (!chkMessageID(id)) {
- TestUtil.logErr(
- "StreamMessage error: JMSMessageID does not start with ID:");
- pass = false;
- } else {
- TestUtil.logMsg("StreamMessage JMSMessageID pass");
- }
- }
-
- // TextMessage
- TestUtil.logMsg("Send TextMessage to Queue");
- messageSent = context.createTextMessage();
- messageSent.setText("sending a TextMessage");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrMessageIDTest");
- producer.send(destination, messageSent);
- TestUtil.logMsg("Receive TextMessage from Queue.");
- messageReceived = (TextMessage) consumer.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("getJMSMessageID=" + messageReceived.getJMSMessageID());
- id = messageReceived.getJMSMessageID();
- if (!chkMessageID(id)) {
- TestUtil.logErr(
- "TextMessage error: JMSMessageID does not start with ID:");
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage JMSMessageID pass");
- }
- }
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSMessageID returned from JMSMessageID");
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrMessageIDTest");
- }
- }
-
- /*
- * @testName: msgHdrTimeStampTest
- *
- * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347; JMS:JAVADOC:1263;
- * JMS:JAVADOC:1196;
- *
- * @test_Strategy: Send to a Queue a single Text, map, bytes, stream, and
- * object message. Call getJMSTimestamp() and check time of send against time
- * send returns. JMSTimeStamp should be between these two
- */
- public void msgHdrTimeStampTest() throws Exception {
- boolean pass = true;
- long timeBeforeSend;
- long timeAfterSend;
- byte bValue = 127;
-
- try {
- TextMessage messageSent = null;
- StreamMessage messageSentS = null;
- BytesMessage messageSentB = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
-
- producer.setDisableMessageTimestamp(false);
-
- // send and receive Object message to Queue
- TestUtil.logMsg("Send ObjectMessage to Queue.");
- messageSentO = context.createObjectMessage();
- messageSentO.setObject("msgHdrTimeStampTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTest");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentO);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- TestUtil.logMsg("getJMSTimestamp=" + messageSentO.getJMSTimestamp());
- TestUtil.logMsg("Time at send is: " + timeBeforeSend);
- TestUtil.logMsg("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentO.getJMSTimestamp())
- && (timeAfterSend >= messageSentO.getJMSTimestamp())) {
- TestUtil.logMsg("ObjectMessage JMSTimeStamp pass");
- } else {
- TestUtil.logErr("ObjectMessage invalid JMSTimeStamp failed");
- pass = false;
- }
-
- // send map message to Queue
- TestUtil.logMsg("Send MapMessage to Queue.");
- messageSentM = context.createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTest");
- messageSentM.setString("aString", "value");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentM);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- TestUtil.logMsg("getJMSTimestamp=" + messageSentM.getJMSTimestamp());
- TestUtil.logMsg("Time at send is: " + timeBeforeSend);
- TestUtil.logMsg("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentM.getJMSTimestamp())
- && (timeAfterSend >= messageSentM.getJMSTimestamp())) {
- TestUtil.logMsg("MapMessage JMSTimeStamp pass");
- } else {
- TestUtil.logErr("MapMessage invalid JMSTimeStamp failed");
- pass = false;
- }
-
- // send and receive bytes message to Queue
- TestUtil.logMsg("Send BytesMessage to Queue.");
- messageSentB = context.createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTest");
- messageSentB.writeByte(bValue);
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentB);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- TestUtil.logMsg("getJMSTimestamp=" + messageSentB.getJMSTimestamp());
- TestUtil.logMsg("Time at send is: " + timeBeforeSend);
- TestUtil.logMsg("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentB.getJMSTimestamp())
- && (timeAfterSend >= messageSentB.getJMSTimestamp())) {
- TestUtil.logMsg("BytesMessage JMSTimeStamp pass");
- } else {
- TestUtil.logErr("BytesMessage invalid JMSTimeStamp failed");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- TestUtil.logMsg("Send StreamMessage to Queue");
- messageSentS = context.createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTest");
- messageSentS.writeString("Testing...");
- TestUtil.logMsg("Sending message");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentS);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- TestUtil.logMsg("getJMSTimestamp=" + messageSentS.getJMSTimestamp());
- TestUtil.logMsg("Time at send is: " + timeBeforeSend);
- TestUtil.logMsg("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentS.getJMSTimestamp())
- && (timeAfterSend >= messageSentS.getJMSTimestamp())) {
- TestUtil.logMsg("StreamMessage JMSTimeStamp pass");
- } else {
- TestUtil.logErr("StreamMessage invalid JMSTimeStamp failed");
- pass = false;
- }
-
- // TextMessage
- TestUtil.logMsg("Send TextMessage to Queue");
- messageSent = context.createTextMessage();
- messageSent.setText("sending a TextMessage to Queue");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTest");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSent);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- TestUtil.logMsg("getJMSTimestamp=" + messageSent.getJMSTimestamp());
- TestUtil.logMsg("Time at send is: " + timeBeforeSend);
- TestUtil.logMsg("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSent.getJMSTimestamp())
- && (timeAfterSend >= messageSent.getJMSTimestamp())) {
- TestUtil.logMsg("TextMessage JMSTimeStamp pass");
- } else {
- TestUtil.logErr("TextMessage invalid JMSTimeStamp failed");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrTimeStampTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSPriorityTest
- *
- * @assertion_ids: JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140; JMS:JAVADOC:1220;
- * JMS:JAVADOC:1273; JMS:JAVADOC:383;
- *
- * @test_Strategy: Send a message to a Queue with JMSPriority set to 2 test
- * with Text, map, object, byte, and stream messages Call getJMSPriorty() and
- * check that it matches the priority that was set on the JMSContext.
- */
- public void msgHdrJMSPriorityTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- int priority2 = 2;
- int priority4 = 4;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- TestUtil.logMsg("Setting priority to 2");
- producer.setPriority(priority2);
-
- messageSent = context.createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTest");
- TestUtil.logMsg("JMSPriority test - Send a TextMessage to Queue");
- producer.send(destination, messageSent);
- TestUtil.logMsg("JMSPriority test - Recv a TextMessage from Queue");
- messageReceived = (TextMessage) consumer.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("JMSPriority is " + messageReceived.getJMSPriority());
- if (messageReceived.getJMSPriority() == priority2) {
- TestUtil.logMsg("TextMessage JMSPriority passed");
- } else {
- TestUtil.logErr("TextMessage JMSPriority failed");
- pass = false;
- }
- }
-
- // send and receive Object message to Queue
- TestUtil.logMsg("JMSPriority test - Send ObjectMessage to Queue.");
- messageSentO = context.createObjectMessage();
- messageSentO.setObject("msgHdrJMSPriorityTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTest");
- producer.send(destination, messageSentO);
- TestUtil.logMsg("JMSPriority test - Recv a ObjectMessage from Queue");
- messageReceivedO = (ObjectMessage) consumer.receive(timeout);
- if (messageReceivedO == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("JMSPriority is " + messageReceivedO.getJMSPriority());
- if (messageReceivedO.getJMSPriority() == priority2) {
- TestUtil.logMsg("ObjectMessage JMSPriority passed");
- } else {
- TestUtil.logErr("ObjectMessage JMSPriority failed");
- pass = false;
- }
- }
-
- // send and receive map message to Queue
- TestUtil.logMsg("JMSPriority test - Send MapMessage to Queue.");
- messageSentM = context.createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTest");
- messageSentM.setString("aString", "value");
- producer.send(destination, messageSentM);
- TestUtil.logMsg("JMSPriority test - Recv a MapMessage from Queue");
- messageReceivedM = (MapMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("JMSPriority is " + messageReceivedM.getJMSPriority());
- if (messageReceivedM.getJMSPriority() == priority2) {
- TestUtil.logMsg("MapMessage JMSPriority passed");
- } else {
- TestUtil.logErr("MapMessage JMSPriority failed");
- pass = false;
- }
- }
-
- TestUtil.logMsg("Setting priority to 4");
- producer.setPriority(priority4);
-
- // send and receive bytes message to Queue
- TestUtil.logMsg("JMSPriority test - Send BytesMessage to Queue.");
- messageSentB = context.createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTest");
- messageSentB.writeByte(bValue);
- producer.send(destination, messageSentB);
- TestUtil.logMsg("JMSPriority test - Recv a BytesMessage from Queue");
- messageReceivedB = (BytesMessage) consumer.receive(timeout);
- if (messageReceivedB == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("JMSPriority is " + messageReceivedB.getJMSPriority());
- if (messageReceivedB.getJMSPriority() == priority4) {
- TestUtil.logMsg("BytesMessage JMSPriority passed");
- } else {
- TestUtil.logErr("BytesMessage JMSPriority failed");
- pass = false;
- }
- }
-
- // Send and receive a StreamMessage
- TestUtil.logMsg("JMSPriority test - Send a StreamMessage to Queue");
- messageSentS = context.createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTest");
- messageSentS.writeString("Testing...");
- producer.send(destination, messageSentS);
- TestUtil.logMsg("JMSPriority test - Recv a StreamMessage from Queue");
- messageReceivedS = (StreamMessage) consumer.receive(timeout);
- if (messageReceivedS == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("JMSPriority is " + messageReceivedS.getJMSPriority());
- if (messageReceivedS.getJMSPriority() == priority4) {
- TestUtil.logMsg("StreamMessage JMSPriority passed");
- } else {
- TestUtil.logErr("StreamMessage JMSPriority failed");
- pass = false;
- }
- }
- if (!pass) {
- throw new Exception("Error: invalid JMSPriority returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrJMSPriorityTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSExpirationTest
- *
- * @assertion_ids: JMS:SPEC:15.1; JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140;
- * JMS:JAVADOC:1303; JMS:JAVADOC:379;
- *
- * @test_Strategy: 1. Send a message to a Queue with time to live set to 0.
- * Verify on receive that JMSExpiration gets set to 0. Test with Text, Map,
- * Object, Bytes, and Stream messages. 2. Send a message to a Queue with time
- * to live set to non-0; Verify on receive that JMSExpiration gets set
- * correctly.
- */
- public void msgHdrJMSExpirationTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- long forever = 0L;
- long timeToLive = 5000L;
- String testName = "msgHdrJMSExpirationTest";
- long timeBeforeSend = 0L;
- long timeAfterSend = 0L;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- TestUtil.logMsg(
- "JMSExpiration test - Send a TextMessage (timeToLive is forever)");
- messageSent = context.createTextMessage();
- messageSent.setText("sending a TextMessage");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- producer.setTimeToLive(forever);
- producer.send(destination, messageSent);
-
- TestUtil.logMsg("JMSExpiration test - Recv a TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceived.getJMSExpiration() != forever) {
- TestUtil.logErr("TextMessage JMSExpiration failed");
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage JMSExpiration passed");
- }
- }
-
- TestUtil.logMsg(
- "JMSExpiration test - Send a TextMessage (timeToLive is 5000)");
- producer.setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSent);
- timeAfterSend = System.currentTimeMillis();
-
- long exp = messageSent.getJMSExpiration();
- TestUtil.logMsg("JMSExpiration is set to=" + exp);
- TestUtil.logMsg("Time before send=" + timeBeforeSend);
- TestUtil.logMsg("Time after send=" + timeAfterSend);
- TestUtil.logMsg("Time to Live =" + timeToLive);
-
- TestUtil.logMsg("JMSExpiration test - Recv a TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceived.getJMSExpiration() != exp) {
- TestUtil.logErr(
- "TextMessage failed: JMSExpiration didn't set correctly = "
- + messageReceived.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage JMSExpiration passed");
- }
- }
-
- // send and receive Object message to Queue
- TestUtil.logMsg(
- "JMSExpiration test - Send a ObjectMessage (timeToLive is forever)");
- messageSentO = context.createObjectMessage();
- messageSentO.setObject("msgHdrJMSExpirationTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- producer.setTimeToLive(forever);
- producer.send(destination, messageSentO);
- TestUtil.logMsg("JMSExpiration test - Recv a ObjectMessage");
- messageReceivedO = (ObjectMessage) consumer.receive(timeout);
- if (messageReceivedO == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedO.getJMSExpiration() != forever) {
- TestUtil.logMsg("ObjectMessage JMSExpiration failed");
- pass = false;
- } else {
- TestUtil.logMsg("ObjectMessage JMSExpiration passed");
- }
- }
-
- TestUtil.logMsg(
- "JMSExpiration test - Send a ObjectMessage (timeToLive is 5000)");
- producer.setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentO);
- timeAfterSend = System.currentTimeMillis();
-
- exp = messageSentO.getJMSExpiration();
- TestUtil.logMsg("JMSExpiration is set to=" + exp);
- TestUtil.logMsg("Time before send=" + timeBeforeSend);
- TestUtil.logMsg("Time after send=" + timeAfterSend);
- TestUtil.logMsg("Time to Live =" + timeToLive);
-
- TestUtil.logMsg("JMSExpiration test - Recv a ObjectMessage");
- messageReceivedO = (ObjectMessage) consumer.receive(timeout);
- if (messageReceivedO == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedO.getJMSExpiration() != exp) {
- TestUtil.logErr(
- "ObjectMessage failed: JMSExpiration didn't set correctly = "
- + messageReceivedO.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- } else {
- TestUtil.logMsg("ObjectMessage JMSExpiration passed");
- }
- }
-
- // send and receive map message to Queue
- TestUtil.logMsg(
- "JMSExpiration test - Send a MapMessage (timeToLive is forever)");
- messageSentM = context.createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentM.setString("aString", "value");
- producer.setTimeToLive(forever);
- producer.send(destination, messageSentM);
- TestUtil.logMsg("JMSExpiration test - Recv a MapMessage");
- messageReceivedM = (MapMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedM.getJMSExpiration() != forever) {
- TestUtil.logMsg("MapMessage JMSExpiration failed");
- pass = false;
- } else {
- TestUtil.logMsg("MapMessage JMSExpiration passed");
- }
- }
-
- TestUtil.logMsg(
- "JMSExpiration test - Send a MapMessage (timeToLive is 5000)");
- producer.setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentM);
- timeAfterSend = System.currentTimeMillis();
-
- exp = messageSentM.getJMSExpiration();
- TestUtil.logMsg("JMSExpiration is set to=" + exp);
- TestUtil.logMsg("Time before send=" + timeBeforeSend);
- TestUtil.logMsg("Time after send=" + timeAfterSend);
- TestUtil.logMsg("Time to Live =" + timeToLive);
-
- TestUtil.logMsg("JMSExpiration test - Recv a MapMessage");
- messageReceivedM = (MapMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedM.getJMSExpiration() != exp) {
- TestUtil
- .logErr("MapMessage failed: JMSExpiration didn't set correctly = "
- + messageReceivedM.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- } else {
- TestUtil.logMsg("MapMessage JMSExpiration passed");
- }
- }
-
- // send and receive bytes message to Queue
- TestUtil.logMsg(
- "JMSExpiration test - Send a Bytesessage (timeToLive is forever)");
- messageSentB = context.createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentB.writeByte(bValue);
- producer.setTimeToLive(forever);
- producer.send(destination, messageSentB);
- TestUtil.logMsg("JMSExpiration test - Recv a BytesMessage");
- messageReceivedB = (BytesMessage) consumer.receive(timeout);
- if (messageReceivedB == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedB.getJMSExpiration() != forever) {
- TestUtil.logMsg("BytesMessage JMSExpiration failed");
- pass = false;
- } else {
- TestUtil.logMsg("BytesMessage JMSExpiration passed");
- }
- }
-
- TestUtil.logMsg(
- "JMSExpiration test - Send a Bytesessage (timeToLive is 5000)");
- producer.setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentB);
- timeAfterSend = System.currentTimeMillis();
-
- exp = messageSentB.getJMSExpiration();
- TestUtil.logMsg("JMSExpiration is set to=" + exp);
- TestUtil.logMsg("Time before send=" + timeBeforeSend);
- TestUtil.logMsg("Time after send=" + timeAfterSend);
- TestUtil.logMsg("Time to Live =" + timeToLive);
-
- TestUtil.logMsg("JMSExpiration test - Recv a BytesMessage");
- messageReceivedB = (BytesMessage) consumer.receive(timeout);
- if (messageReceivedB == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedB.getJMSExpiration() != exp) {
- TestUtil.logErr(
- "BytesMessage failed: JMSExpiration didn't set correctly = "
- + messageReceivedB.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- } else {
- TestUtil.logMsg("BytesMessage JMSExpiration passed");
- }
- }
-
- // Send and receive a StreamMessage
- TestUtil.logMsg(
- "JMSExpiration test - Send a Streamessage (timeToLive is forever)");
- messageSentS = context.createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentS.writeString("Testing...");
- producer.setTimeToLive(forever);
- producer.send(destination, messageSentS);
- TestUtil.logMsg("JMSExpiration test - Recv a StreamMessage");
- messageReceivedS = (StreamMessage) consumer.receive(timeout);
- if (messageReceivedS == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedS.getJMSExpiration() != forever) {
- TestUtil.logMsg("StreamMessage JMSExpiration failed");
- pass = false;
- } else {
- TestUtil.logMsg("StreamMessage JMSExpiration passed");
- }
- }
-
- TestUtil.logMsg(
- "JMSExpiration test - Send a StreamMessage (timeToLive is 5000)");
- producer.setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentS);
- timeAfterSend = System.currentTimeMillis();
-
- exp = messageSentS.getJMSExpiration();
- TestUtil.logMsg("JMSExpiration is set to=" + exp);
- TestUtil.logMsg("Time before send=" + timeBeforeSend);
- TestUtil.logMsg("Time after send=" + timeAfterSend);
- TestUtil.logMsg("Time to Live =" + timeToLive);
-
- TestUtil.logMsg("JMSExpiration test - Recv a StreamMessage");
- messageReceivedS = (StreamMessage) consumer.receive(timeout);
- if (messageReceivedS == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedS.getJMSExpiration() != exp) {
- TestUtil.logErr(
- "StreamMessage failed: JMSExpiration didn't set correctly = "
- + messageReceivedS.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- } else {
- TestUtil.logMsg("StreamMessage JMSExpiration passed");
- }
- }
-
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSExpiration returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
- }
-
- /*
- * @testName: msgHdrJMSDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:3; JMS:SPEC:140; JMS:SPEC:246.2; JMS:JAVADOC:1192;
- * JMS:JAVADOC:1259; JMS:JAVADOC:367;
- *
- * @test_Strategy: 1. Create and send a message to the default Queue. Receive
- * the msg and verify that JMSDeliveryMode is set the default delivery mode of
- * persistent. 2. Create and test another message with a nonpersistent
- * delivery mode. Test with Text, map, object, byte, and stream messages 3.
- * Set JMSDeliveryMode to Message after receive. Verify that JMSDeliveryMode
- * is set correctly.
- */
- public void msgHdrJMSDeliveryModeTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- String testName = "msgHdrJMSDeliveryModeTest";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- // send and receive Text message to Queue
- TestUtil
- .logMsg("send TextMessage to Queue with DeliveryMode.PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- messageSent = context.createTextMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- producer.send(destination, messageSent);
- TestUtil.logMsg("receive TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- TestUtil.logErr("TextMessage is null (unexpected)");
- } else if (messageReceived
- .getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "TextMessage failed: JMSDeliveryMode should be set to persistent");
- } else {
- TestUtil.logMsg("TextMessage JMSDeliveryMode passed");
- }
-
- TestUtil.logMsg(
- "send TextMessage to Queue with DeliveryMode.NON_PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- messageSent = context.createTextMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- producer.send(destination, messageSent);
- TestUtil.logMsg("receive TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- TestUtil.logErr("TextMessage is null (unexpected)");
- } else if (messageReceived
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "TextMessage failed: JMSDeliveryMode should be set to non persistent");
- } else {
- TestUtil.logMsg("TextMessage JMSDeliveryMode passed");
- }
-
- // send and receive Object message to Queue
- TestUtil
- .logMsg("send ObjectMessage to Queue with DeliveryMode.PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- messageSentO = context.createObjectMessage();
- messageSentO.setObject("Test for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- producer.send(destination, messageSentO);
- TestUtil.logMsg("receive ObjectMessage");
- messageReceivedO = (ObjectMessage) consumer.receive(timeout);
- if (messageReceivedO == null) {
- pass = false;
- TestUtil.logErr("ObjectMessage is null (unexpected)");
- } else if (messageReceivedO
- .getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "ObjectMessage failed: JMSDeliveryMode should be set to persistent");
- } else {
- TestUtil.logMsg("ObjectMessage JMSDeliveryMode passed");
- }
-
- TestUtil.logMsg(
- "send ObjectMessage to Queue with DeliveryMode.NON_PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- messageSentO = context.createObjectMessage();
- messageSentO.setObject("Test for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- producer.send(destination, messageSentO);
- TestUtil.logMsg("receive ObjectMessage");
- messageReceivedO = (ObjectMessage) consumer.receive(timeout);
- if (messageReceivedO == null) {
- pass = false;
- TestUtil.logErr("ObjectMessage is null (unexpected)");
- } else if (messageReceivedO
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "ObjectMessage failed: JMSDeliveryMode should be set to non persistent");
- } else {
- TestUtil.logMsg("ObjectMessage JMSDeliveryMode passed");
- }
-
- // send and receive map message to Queue
- TestUtil.logMsg("send MapMessage to Queue with DeliveryMode.PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- messageSentM = context.createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentM.setString("aString", "value");
- producer.send(destination, messageSentM);
- TestUtil.logMsg("receive MapMessage");
- messageReceivedM = (MapMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- pass = false;
- TestUtil.logErr("MapMessage is null (unexpected)");
- } else if (messageReceivedM
- .getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "MapMessage failed: JMSDeliveryMode should be set to persistent");
- } else {
- TestUtil.logMsg("MapMessage JMSDeliveryMode passed");
- }
-
- TestUtil
- .logMsg("send MapMessage to Queue with DeliveryMode.NON_PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- messageSentM = context.createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentM.setString("aString", "value");
- producer.send(destination, messageSentM);
- TestUtil.logMsg("receive MapMessage");
- messageReceivedM = (MapMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- pass = false;
- TestUtil.logErr("MapMessage is null (unexpected)");
- } else if (messageReceivedM
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "MapMessage failed: JMSDeliveryMode should be set to non persistent");
- } else {
- TestUtil.logMsg("MapMessage JMSDeliveryMode passed");
- }
-
- // send and receive bytes message to Queue
- TestUtil
- .logMsg("send BytesMessage to Queue with DeliveryMode.PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- messageSentB = context.createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentB.writeByte(bValue);
- producer.send(destination, messageSentB);
- TestUtil.logMsg("receive BytesMessage");
- messageReceivedB = (BytesMessage) consumer.receive(timeout);
- if (messageReceivedB == null) {
- pass = false;
- TestUtil.logErr("BytesMessage is null (unexpected)");
- } else if (messageReceivedB
- .getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "BytesMessage failed: JMSDeliveryMode should be set to persistent");
- } else {
- TestUtil.logMsg("BytesMessage JMSDeliveryMode passed");
- }
-
- TestUtil.logMsg(
- "send BytesMessage to Queue with DeliveryMode.NON_PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- messageSentB = context.createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentB.writeByte(bValue);
- producer.send(destination, messageSentB);
- TestUtil.logMsg("receive BytesMessage");
- messageReceivedB = (BytesMessage) consumer.receive(timeout);
- if (messageReceivedB == null) {
- pass = false;
- TestUtil.logErr("BytesMessage is null (unexpected)");
- } else if (messageReceivedB
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "BytesMessage failed: JMSDeliveryMode should be set to non persistent");
- } else {
- TestUtil.logMsg("BytesMessage JMSDeliveryMode passed");
- }
-
- // send and receive a StreamMessage
- TestUtil
- .logMsg("send StreamMessage to Queue with DeliveryMode.PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- messageSentS = context.createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentS.writeString("Testing...");
- producer.send(destination, messageSentS);
- TestUtil.logMsg("receive StreamMessage");
- messageReceivedS = (StreamMessage) consumer.receive(timeout);
- if (messageReceivedS == null) {
- pass = false;
- TestUtil.logErr("StreamMessage is null (unexpected)");
- } else if (messageReceivedS
- .getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "StreamMessage failed: JMSDeliveryMode should be set to persistent");
- } else {
- TestUtil.logMsg("StreamMessage JMSDeliveryMode passed");
- }
-
- TestUtil.logMsg(
- "send StreamMessage to Queue with DeliveryMode.NON_PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- messageSentS = context.createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentS.writeString("Testing...");
- producer.send(destination, messageSentS);
- TestUtil.logMsg("receive StreamMessage");
- messageReceivedS = (StreamMessage) consumer.receive(timeout);
- if (messageReceivedS == null) {
- pass = false;
- TestUtil.logErr("StreamMessage is null (unexpected)");
- } else if (messageReceivedS
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "StreamMessage failed: JMSDeliveryMode should be set to non persistent");
- } else {
- TestUtil.logMsg("StreamMessage JMSDeliveryMode passed");
- }
-
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSDeliveryMode returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
- }
-
- /*
- * @testName: msgHdrJMSDeliveryTimeTest
- *
- * @assertion_ids: JMS:SPEC:246.11; JMS:SPEC:261; JMS:SPEC:256;
- * JMS:JAVADOC:1257; JMS:JAVADOC:875;
- *
- * @test_Strategy: Send message and verify that JMSDeliveryTime is correct
- * with the DeliveryDelay set to 20 seconds. Test with DeliveryMode.PERSISTENT
- * and DeliveryMode.NON_PERSISTENT.
- *
- * Retrieve and verify the JMSDeliveryTime
- */
- public void msgHdrJMSDeliveryTimeTest() throws Exception {
- boolean pass = true;
- try {
-
- long gmtTimebeforeSend = System.currentTimeMillis();
- TestUtil.logMsg(
- "---------------------------------------------------------------");
- TestUtil.logMsg(
- "BEGIN TEST msgHdrJMSDeliveryTimeTest with DeliveryDelay=20Secs");
- TestUtil.logMsg(
- "---------------------------------------------------------------");
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage messageSnd = context.createTextMessage("This is a test!");
-
- TestUtil.logMsg("Set StringProperty COM_SUN_JMS_TESTNAME");
- messageSnd.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDeliveryTimeTest");
-
- TestUtil.logMsg(
- "Sending message with DeliveryMode.PERSISTENT and DeliveryDelay=20Secs");
- producer.setDeliveryDelay(20000);
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- producer.setPriority(Message.DEFAULT_PRIORITY);
- producer.setTimeToLive(0L);
- producer.send(destination, messageSnd);
-
- // Get deliverytime and current GMT time after send
- TestUtil.logMsg("Get JMSDeliveryTime after sending message");
- long deliverydelay = producer.getDeliveryDelay();
- long gmtTimeAfterSend = System.currentTimeMillis();
- long JMSDeliveryTimeAfterSend = messageSnd.getJMSDeliveryTime();
-
- TestUtil.logMsg("Receive message with timeout value of 21Secs");
- TextMessage messageRcv = (TextMessage) consumer.receive(21000);
- if (messageRcv == null) {
- TestUtil.logErr(
- "FAILED: Message was not received after delivery delay of 20 secs elapsed");
- pass = false;
- } else {
- // Get JMSDeliverytime after receive
- TestUtil.logMsg("Get JMSDeliveryTime after receiving message");
- long gmtTimeAfterRecv = System.currentTimeMillis();
- long JMSDeliveryTimeAfterRecv = messageRcv.getJMSDeliveryTime();
-
- TestUtil.logMsg("Check JMSDeliverytime");
- TestUtil
- .logMsg("JMSDeliveryTime after send = " + JMSDeliveryTimeAfterSend);
- TestUtil.logMsg(
- "JMSDeliveryTime after receive = " + JMSDeliveryTimeAfterRecv);
- if (JMSDeliveryTimeAfterSend == JMSDeliveryTimeAfterRecv) {
- TestUtil.logMsg(
- "JMSDeliveryTimeAfterSend = JMSDeliveryTimeAfterRecv (PASS)");
- } else {
- TestUtil.logErr(
- "JMSDeliveryTimeAfterSend != JMSDeliveryTimeAfterRecv (FAIL)");
- pass = false;
- }
- TestUtil.logMsg("gmtTimeAfterSend after send = " + gmtTimeAfterSend);
- TestUtil.logMsg("gmtTimeAfterRecv after receive = " + gmtTimeAfterRecv);
- if (gmtTimeAfterRecv >= (gmtTimebeforeSend + deliverydelay)) {
- TestUtil.logMsg(
- "gmtTimeAfterRecv >= (gmtTimeAfterSend + deliverydelay) (PASS)");
- } else {
- TestUtil.logErr(
- "gmtTimeAfterRecv < (gmtTimeAfterSend + deliverydelay) (FAIL)");
- pass = false;
- }
- }
-
- TestUtil.logMsg(
- "Sending message with DeliveryMode.NON_PERSISTENT and DeliveryDelay=20Secs");
- producer.setDeliveryDelay(20000);
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- producer.setPriority(Message.DEFAULT_PRIORITY);
- producer.setTimeToLive(0L);
- producer.send(destination, messageSnd);
-
- // Get deliverytime and current GMT time after send
- TestUtil.logMsg("Get JMSDeliveryTime after sending message");
- gmtTimeAfterSend = System.currentTimeMillis();
- JMSDeliveryTimeAfterSend = messageSnd.getJMSDeliveryTime();
-
- TestUtil.logMsg("Receive message with timeout value of 21Secs");
- messageRcv = (TextMessage) consumer.receive(21000);
- if (messageRcv == null) {
- TestUtil.logErr(
- "FAILED: Message was not received after delivery delay of 20 secs elapsed");
- pass = false;
- } else {
- // Get JMSDeliverytime after receive
- TestUtil.logMsg("Get JMSDeliveryTime after receiving message");
- long gmtTimeAfterRecv = System.currentTimeMillis();
- long JMSDeliveryTimeAfterRecv = messageRcv.getJMSDeliveryTime();
-
- TestUtil.logMsg("Check JMSDeliverytime");
- TestUtil
- .logMsg("JMSDeliveryTime after send = " + JMSDeliveryTimeAfterSend);
- TestUtil.logMsg(
- "JMSDeliveryTime after receive = " + JMSDeliveryTimeAfterRecv);
- if (JMSDeliveryTimeAfterSend == JMSDeliveryTimeAfterRecv) {
- TestUtil.logMsg(
- "JMSDeliveryTimeAfterSend = JMSDeliveryTimeAfterRecv (PASS)");
- } else {
- TestUtil.logErr(
- "JMSDeliveryTimeAfterSend != JMSDeliveryTimeAfterRecv (FAIL)");
- pass = false;
- }
- TestUtil.logMsg("gmtTimeAfterSend after send = " + gmtTimeAfterSend);
- TestUtil.logMsg("gmtTimeAfterRecv after receive = " + gmtTimeAfterRecv);
- if (gmtTimeAfterRecv >= (gmtTimebeforeSend + deliverydelay)) {
- TestUtil.logMsg(
- "gmtTimeAfterRecv >= (gmtTimeAfterSend + deliverydelay) (PASS)");
- } else {
- TestUtil.logErr(
- "gmtTimeAfterRecv < (gmtTimeAfterSend + deliverydelay) (FAIL)");
- pass = false;
- }
- }
- TestUtil.logMsg(
- "-------------------------------------------------------------");
- TestUtil.logMsg(
- "END TEST msgHdrJMSDeliveryTimeTest with DeliveryDelay=20Secs");
- TestUtil.logMsg(
- "-------------------------------------------------------------");
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrJMSDeliveryTimeTest", e);
- }
-
- if (!pass) {
- throw new Exception("msgHdrJMSDeliveryTimeTest failed");
- }
- }
-
- /*
- * @testName: setGetAllPropertyTypesTest
- *
- * @assertion_ids: JMS:JAVADOC:1180; JMS:JAVADOC:1184; JMS:JAVADOC:1187;
- * JMS:JAVADOC:1198; JMS:JAVADOC:1201; JMS:JAVADOC:1204; JMS:JAVADOC:1215;
- * JMS:JAVADOC:1218; JMS:JAVADOC:1222; JMS:JAVADOC:1224; JMS:JAVADOC:1227;
- * JMS:JAVADOC:1232; JMS:JAVADOC:1275; JMS:JAVADOC:1278; JMS:JAVADOC:1281;
- * JMS:JAVADOC:1284; JMS:JAVADOC:1287; JMS:JAVADOC:1290; JMS:JAVADOC:1293;
- * JMS:JAVADOC:1296; JMS:JAVADOC:1299;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setProperty(String, boolean) JMSProducer.setProperty(String,
- * byte) JMSProducer.setProperty(String, double)
- * JMSProducer.setProperty(String, float) JMSProducer.setProperty(String, int)
- * JMSProducer.setProperty(String, long) JMSProducer.setProperty(String,
- * Object) JMSProducer.setProperty(String, short)
- * JMSProducer.setProperty(String, String)
- * JMSProducer.getBooleanProperty(String) JMSProducer.getByteProperty(String)
- * JMSProducer.getDoubleProperty(String) JMSProducer.getFloatProperty(String)
- * JMSProducer.getIntProperty(String) JMSProducer.getLongProperty(String)
- * JMSProducer.getObjectProperty(String) JMSProducer.getShortProperty(String)
- * JMSProducer.getStringProperty(String) JMSProducer.clearProperties(String)
- * JMSProducer.getPropertyNames() JMSProducer.propertyExists()
- */
- public void setGetAllPropertyTypesTest() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- int numPropertyNames = 16;
-
- try {
- // Create JMSProducer from JMSContext
- logMsg("Create a JMSProducer from JMSContext");
-
- producer = context.createProducer();
-
- logMsg("Set all JMSProducer properties");
- producer.setProperty("TESTBOOLEAN", bool);
- producer.setProperty("TESTBYTE", bValue);
- producer.setProperty("TESTDOUBLE", nDouble);
- producer.setProperty("TESTFLOAT", nFloat);
- producer.setProperty("TESTINT", nInt);
- producer.setProperty("TESTLONG", nLong);
- producer.setProperty("TESTSHORT", nShort);
- producer.setProperty("TESTSTRING", "test");
- producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
- producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
- producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
- producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
- producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
- producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
- producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
- producer.setProperty("OBJTESTSTRING", "test");
-
- logMsg("Get all JMSProducer properties");
- if (producer.getBooleanProperty("TESTBOOLEAN") == bool) {
- logMsg("Pass: getBooleanProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getBooleanProperty");
- pass = false;
- }
- if (producer.getByteProperty("TESTBYTE") == bValue) {
- logMsg("Pass: getByteProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getByteProperty");
- pass = false;
- }
- if (producer.getLongProperty("TESTLONG") == nLong) {
- logMsg("Pass: getLongProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getLongProperty");
- pass = false;
- }
- if (producer.getStringProperty("TESTSTRING").equals(testString)) {
- logMsg("Pass: getStringProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getStringProperty");
- pass = false;
- }
- if (producer.getDoubleProperty("TESTDOUBLE") == nDouble) {
- logMsg("Pass: getDoubleProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getDoubleProperty");
- pass = false;
- }
- if (producer.getFloatProperty("TESTFLOAT") == nFloat) {
- logMsg("Pass: getFloatProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getFloatProperty");
- pass = false;
- }
- if (producer.getIntProperty("TESTINT") == nInt) {
- logMsg("Pass: getIntProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getIntProperty");
- pass = false;
- }
- if (producer.getShortProperty("TESTSHORT") == nShort) {
- logMsg("Pass: getShortProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getShortProperty");
- pass = false;
- }
- if (((Boolean) producer.getObjectProperty("OBJTESTBOOLEAN"))
- .booleanValue() == bool) {
- logMsg("Pass: getObjectProperty returned correct Boolean value");
- } else {
- logMsg("Fail: incorrect Boolean value returned from getObjectProperty");
- pass = false;
- }
- if (((Byte) producer.getObjectProperty("OBJTESTBYTE"))
- .byteValue() == bValue) {
- logMsg("Pass: getObjectProperty returned correct Byte value");
- } else {
- logMsg("Fail: incorrect Byte value returned from getObjectProperty");
- pass = false;
- }
- if (((Long) producer.getObjectProperty("OBJTESTLONG"))
- .longValue() == nLong) {
- logMsg("Pass: getObjectProperty returned correct Long value");
- } else {
- logMsg("Fail: incorrect Long value returned from getObjectProperty");
- pass = false;
- }
- if (((String) producer.getObjectProperty("OBJTESTSTRING"))
- .equals(testString)) {
- logMsg("Pass: getObjectProperty returned correct String value");
- } else {
- logMsg("Fail: incorrect String value returned from getObjectProperty");
- pass = false;
- }
- if (((Double) producer.getObjectProperty("OBJTESTDOUBLE"))
- .doubleValue() == nDouble) {
- logMsg("Pass: getObjectProperty returned correct Double value");
- } else {
- logMsg("Fail: incorrect Double value returned from getObjectProperty");
- pass = false;
- }
- if (((Float) producer.getObjectProperty("OBJTESTFLOAT"))
- .floatValue() == nFloat) {
- logMsg("Pass: getObjectProperty returned correct Float value");
- } else {
- logMsg("Fail: incorrect Float value returned from getObjectProperty");
- pass = false;
- }
- if (((Integer) producer.getObjectProperty("OBJTESTINT"))
- .intValue() == nInt) {
- logMsg("Pass: getObjectProperty returned correct Integer value");
- } else {
- logMsg("Fail: incorrect Integer value returned from getObjectProperty");
- pass = false;
- }
- if (((Short) producer.getObjectProperty("OBJTESTSHORT"))
- .shortValue() == nShort) {
- logMsg("Pass: getObjectProperty returned correct Short value");
- } else {
- logMsg("Fail: incorrect Short value returned from getObjectProperty");
- pass = false;
- }
- logMsg(
- "Now check all property names returned by JMSProducer.getPropertyNames()");
- // iterate thru the property names
- int i = 0;
- Set propNames = producer.getPropertyNames();
- Iterator iterator = propNames.iterator();
- do {
- String tmp = iterator.next();
-
- if (!tmp.startsWith("JMS")) {
- i++;
- if (tmp.equals("TESTBOOLEAN") || tmp.equals("TESTBYTE")
- || tmp.equals("TESTINT") || tmp.equals("TESTSHORT")
- || tmp.equals("TESTFLOAT") || tmp.equals("TESTDOUBLE")
- || tmp.equals("TESTSTRING") || tmp.equals("TESTLONG")
- || tmp.equals("OBJTESTBOOLEAN") || tmp.equals("OBJTESTBYTE")
- || tmp.equals("OBJTESTINT") || tmp.equals("OBJTESTSHORT")
- || tmp.equals("OBJTESTFLOAT") || tmp.equals("OBJTESTDOUBLE")
- || tmp.equals("OBJTESTSTRING") || tmp.equals("OBJTESTLONG")) {
- logMsg("Producer Property set by client: " + tmp);
- } else {
- logErr("Producer Property not set by client: " + tmp);
- pass = false;
- }
- } else {
- logMsg("JMSProperty Name is: " + tmp);
- }
- } while (iterator.hasNext());
- if (i == numPropertyNames) {
- logMsg("Pass: # of properties is " + numPropertyNames + " as expected");
- } else {
- logMsg("Fail: expected " + numPropertyNames
- + " property names, but got " + i);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("setGetAllPropertyTypesTest");
- }
-
- if (!pass) {
- throw new Exception("setGetAllPropertyTypesTest failed");
- }
- }
-
- /*
- * @testName: setGetAllHeaderTypesTest
- *
- * @assertion_ids: JMS:JAVADOC:1265; JMS:JAVADOC:1267; JMS:JAVADOC:1269;
- * JMS:JAVADOC:1271; JMS:JAVADOC:1207; JMS:JAVADOC:1209; JMS:JAVADOC:1211;
- * JMS:JAVADOC:1213;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setJMSCorrelationID(String);
- * JMSProducer.setJMSCorrelationIDAsBytes(byte[]);
- * JMSProducer.setJMSReplyTo(Destination); JMSProducer.setJMSType(String);
- * JMSProducer.getJMSCorrelationID();
- * JMSProducer.getJMSCorrelationIDAsBytes(); JMSProducer.getJMSReplyTo();
- * JMSProducer.getJMSType();
- */
- public void setGetAllHeaderTypesTest() throws Exception {
- boolean pass = true;
-
- try {
- // Create JMSProducer from JMSContext
- logMsg("Create a JMSProducer from JMSContext");
-
- producer = context.createProducer();
-
- try {
- logMsg("Set JMSProducer message header JMSCorrelationID as bytes");
- byte[] cid = "TestCorrelationID".getBytes();
- producer.setJMSCorrelationIDAsBytes(cid);
-
- logMsg("Get JMSProducer message header JMSCorrelationID as bytes");
- cid = producer.getJMSCorrelationIDAsBytes();
- String cidString = new String(cid);
- if (cid == null) {
- logMsg("Fail: getJMSCorrelationID returned null");
- pass = false;
- } else if (cidString.equals("TestCorrelationID")) {
- logMsg("Pass: getJMSCorrelationID returned correct value");
- } else {
- logMsg("Fail: getJMSCorrelationID returned incorrect value, got: "
- + cidString + " expected: TestCorrelationID");
- pass = false;
- }
- } catch (java.lang.UnsupportedOperationException e) {
- logMsg("UnsupportedOperationException - no further testing.");
- }
-
- logMsg(
- "Set all JMSProducer message headers JMSCorrelationID, JMSType, JMSReplyTo");
- producer.setJMSCorrelationID("TestCorrelationID");
- producer.setJMSType("TestMessage");
- producer.setJMSReplyTo(destination);
-
- logMsg(
- "Get all JMSProducer message headers JMSCorrelationID, JMSType, JMSReplyTo");
- String temp = null;
- Destination tempdest = null;
- temp = producer.getJMSCorrelationID();
- if (temp == null) {
- logMsg("Fail: getJMSCorrelationID returned null");
- pass = false;
- } else if (temp.equals("TestCorrelationID")) {
- logMsg("Pass: getJMSCorrelationID returned correct value");
- } else {
- logMsg("Fail: getJMSCorrelationID returned incorrect value, got: "
- + temp + " expected: TestCorrelationID");
- pass = false;
- }
- temp = producer.getJMSType();
- if (temp == null) {
- logMsg("Fail: getJMSType returned null");
- pass = false;
- } else if (temp.equals("TestMessage")) {
- logMsg("Pass: getJMSType returned correct value");
- } else {
- logMsg("Fail: getJMSType returned incorrect value, got: " + temp
- + " expected: TestMessage");
- pass = false;
- }
- tempdest = producer.getJMSReplyTo();
- if (tempdest == null) {
- logMsg("Fail: getJMSReplyTo returned null");
- pass = false;
- } else if (tempdest.equals(destination)) {
- logMsg("Pass: getJMSReplyTo returned correct value");
- } else {
- logMsg("Fail: getJMSReplyTo returned incorrect value, got: " + tempdest
- + " expected: " + destination);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("setGetAllHeaderTypesTest");
- }
-
- if (!pass) {
- throw new Exception("setGetAllHeaderTypesTest failed");
- }
- }
-
- /*
- * @testName: msgPropertiesTest
- *
- * @assertion_ids: JMS:SPEC:20.1; JMS:SPEC:20.2; JMS:SPEC:20.3; JMS:SPEC:20.4;
- * JMS:SPEC:20.5; JMS:SPEC:20.6; JMS:SPEC:20.7; JMS:SPEC:20.8; JMS:SPEC:21;
- * JMS:SPEC:23; JMS:SPEC:25; JMS:SPEC:26; JMS:SPEC:10; JMS:SPEC:27;
- * JMS:SPEC:28; JMS:SPEC:29; JMS:SPEC:31; JMS:SPEC:32; JMS:SPEC:34;
- * JMS:SPEC:19; JMS:SPEC:70; JMS:SPEC:71; JMS:SPEC:24; JMS:JAVADOC:1180;
- * JMS:JAVADOC:1184; JMS:JAVADOC:1187; JMS:JAVADOC:1198; JMS:JAVADOC:1201;
- * JMS:JAVADOC:1204; JMS:JAVADOC:1215; JMS:JAVADOC:1218; JMS:JAVADOC:1222;
- * JMS:JAVADOC:1224; JMS:JAVADOC:1227; JMS:JAVADOC:1232; JMS:JAVADOC:1275;
- * JMS:JAVADOC:1278; JMS:JAVADOC:1281; JMS:JAVADOC:1284; JMS:JAVADOC:1287;
- * JMS:JAVADOC:1290; JMS:JAVADOC:1293; JMS:JAVADOC:1296; JMS:JAVADOC:1299;
- *
- * @test_Strategy: Set and read properties for boolean, byte, short, int,
- * long, float, double, and String. Verify expected results Set and read
- * properties for Boolean, Byte, Short, Int, Long, Float, Double, and String.
- * Verify expected results.
- *
- * Call property get methods (other than getStringProperty and
- * getObjectProperty) for non-existent properties and verify that a null
- * pointer exception is returned. Call getStringProperty and getObjectProperty
- * for non-existent properties and verify that a null is returned.
- *
- * Set object properties and verify the correct value is returned with the
- * getObjectProperty method.
- *
- * Call the clearProperties method on the JMSProducer and verify that the
- * message properties for that JMSProducer were deleted. Test that
- * getObjectProperty returns a null and the getShortProperty throws a null
- * pointer exception.
- *
- * Call getJMSXPropertyNames() and verify that the names of the required JMSX
- * properties for JMSXGroupID and JMSXGroupSeq are returned.
- */
- public void msgPropertiesTest() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- Enumeration propertyNames = null;
- Enumeration jmsxDefined = null;
- int numPropertyNames = 18;
- String testMessageBody = "Testing...";
- String message = "Where are you!";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // ------------------------------------------------------------------------------
- // Set JMSProducer message properties
- // Set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- logMsg("Set primitive property types on JMSProducer");
- producer.setProperty("TESTBOOLEAN", bool);
- producer.setProperty("TESTBYTE", bValue);
- producer.setProperty("TESTDOUBLE", nDouble);
- producer.setProperty("TESTFLOAT", nFloat);
- producer.setProperty("TESTINT", nInt);
- producer.setProperty("TESTLONG", nLong);
- producer.setProperty("TESTSHORT", nShort);
- producer.setProperty("TESTSTRING", "test");
-
- // ------------------------------------------------------------------------------
- // Set JMSProducer message properties
- // Set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
- // String.
- // ------------------------------------------------------------------------------
- logMsg("Set Object property types on JMSProducer");
- producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
- producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
- producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
- producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
- producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
- producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
- producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
- producer.setProperty("OBJTESTSTRING", "test");
-
- TestUtil.logMsg("Creating TextMessage");
- messageSent = context.createTextMessage(message);
- logMsg("messageSent=" + messageSent.getText());
- TestUtil.logMsg("Set some values in TextMessage");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesTest");
- producer.send(destination, messageSent);
- messageReceived = (TextMessage) consumer.receive(timeout);
- logMsg("messageReceived=" + messageReceived.getText());
-
- // Iterate thru the property names
- int i = 0;
- logMsg("Retrieve and verify correct # of properties set");
- propertyNames = messageReceived.getPropertyNames();
- do {
- String tmp = (String) propertyNames.nextElement();
- logMsg("Property Name is: " + tmp);
- if (tmp.indexOf("JMS") != 0)
- i++;
- else if (tmp.equals("JMSXDeliveryCount"))
- i++;
- } while (propertyNames.hasMoreElements());
-
- if (i == numPropertyNames) {
- logMsg("Pass: # of properties is " + numPropertyNames + " as expected");
- } else {
- logMsg("Fail: expected " + numPropertyNames
- + " property names, but got " + i);
- pass = false;
- }
-
- // -------------------------------------------------------------------------
- // Retrieve the JMSProducer properties and verify that they are correct
- // Get properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------
- logMsg(
- "Retrieve and verify that JMSProducer properties were set correctly");
- logMsg(
- "Get properties for boolean, byte, short, int, long, float, double, and String.");
- if (producer.getBooleanProperty("TESTBOOLEAN") == bool) {
- logMsg("Pass: getBooleanProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getBooleanProperty");
- pass = false;
- }
- if (producer.getByteProperty("TESTBYTE") == bValue) {
- logMsg("Pass: getByteProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getByteProperty");
- pass = false;
- }
- if (producer.getLongProperty("TESTLONG") == nLong) {
- logMsg("Pass: getLongProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getLongProperty");
- pass = false;
- }
- if (producer.getStringProperty("TESTSTRING").equals(testString)) {
- logMsg("Pass: getStringProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getStringProperty");
- pass = false;
- }
- if (producer.getDoubleProperty("TESTDOUBLE") == nDouble) {
- logMsg("Pass: getDoubleProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getDoubleProperty");
- pass = false;
- }
- if (producer.getFloatProperty("TESTFLOAT") == nFloat) {
- logMsg("Pass: getFloatProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getFloatProperty");
- pass = false;
- }
- if (producer.getIntProperty("TESTINT") == nInt) {
- logMsg("Pass: getIntProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getIntProperty");
- pass = false;
- }
- if (producer.getShortProperty("TESTSHORT") == nShort) {
- logMsg("Pass: getShortProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getShortProperty");
- pass = false;
- }
-
- // -----------------------------------------------------------------------------
- // Retrieve the JMSProducer properties and verify that they are correct
- // Get properties for Boolean, Byte, Short, Integer, Long, Float, Double,
- // String.
- // -----------------------------------------------------------------------------
- logMsg(
- "Get properties for Boolean, Byte, Short, Integer, Long, Float, Double, String.");
- if (((Boolean) producer.getObjectProperty("OBJTESTBOOLEAN"))
- .booleanValue() == bool) {
- logMsg("Pass: getObjectProperty returned correct Boolean value");
- } else {
- logMsg("Fail: incorrect Boolean value returned from getObjectProperty");
- pass = false;
- }
- if (((Byte) producer.getObjectProperty("OBJTESTBYTE"))
- .byteValue() == bValue) {
- logMsg("Pass: getObjectProperty returned correct Byte value");
- } else {
- logMsg("Fail: incorrect Byte value returned from getObjectProperty");
- pass = false;
- }
- if (((Long) producer.getObjectProperty("OBJTESTLONG"))
- .longValue() == nLong) {
- logMsg("Pass: getObjectProperty returned correct Long value");
- } else {
- logMsg("Fail: incorrect Long value returned from getObjectProperty");
- pass = false;
- }
- if (((String) producer.getObjectProperty("OBJTESTSTRING"))
- .equals(testString)) {
- logMsg("Pass: getObjectProperty returned correct String value");
- } else {
- logMsg("Fail: incorrect String value returned from getObjectProperty");
- pass = false;
- }
- if (((Double) producer.getObjectProperty("OBJTESTDOUBLE"))
- .doubleValue() == nDouble) {
- logMsg("Pass: getObjectProperty returned correct Double value");
- } else {
- logMsg("Fail: incorrect Double value returned from getObjectProperty");
- pass = false;
- }
- if (((Float) producer.getObjectProperty("OBJTESTFLOAT"))
- .floatValue() == nFloat) {
- logMsg("Pass: getObjectProperty returned correct Float value");
- } else {
- logMsg("Fail: incorrect Float value returned from getObjectProperty");
- pass = false;
- }
- if (((Integer) producer.getObjectProperty("OBJTESTINT"))
- .intValue() == nInt) {
- logMsg("Pass: getObjectProperty returned correct Integer value");
- } else {
- logMsg("Fail: incorrect Integer value returned from getObjectProperty");
- pass = false;
- }
- if (((Short) producer.getObjectProperty("OBJTESTSHORT"))
- .shortValue() == nShort) {
- logMsg("Pass: getObjectProperty returned correct Short value");
- } else {
- logMsg("Fail: incorrect Short value returned from getObjectProperty");
- pass = false;
- }
-
- // ---------------------------------------------------------------------------
- // Set JMSProducer message headers (Set JMSCorrelationID, JMSType,
- // JMSReplyTo)
- // ---------------------------------------------------------------------------
- logMsg(
- "Set message headers JMSCorrelationID, JMSType, JMSReplyTo on JMSProducer");
- producer.setJMSCorrelationID("TestCorrelationID");
- producer.setJMSType("TestMessage");
- producer.setJMSReplyTo(destination);
-
- // ---------------------------------------------------------------------------
- // Retrieve JMSProducer message headers and verify that they are set
- // correctly
- // ---------------------------------------------------------------------------
- String temp = null;
- Destination tempdest = null;
- temp = producer.getJMSCorrelationID();
- if (temp == null) {
- logMsg("Fail: getJMSCorrelationID returned null");
- pass = false;
- } else if (temp.equals("TestCorrelationID")) {
- logMsg("Pass: getJMSCorrelationID returned correct value");
- } else {
- logMsg("Fail: getJMSCorrelationID returned incorrect value, got: "
- + temp + " expected: TestCorrelationID");
- pass = false;
- }
- temp = producer.getJMSType();
- if (temp == null) {
- logMsg("Fail: getJMSType returned null");
- pass = false;
- } else if (temp.equals("TestMessage")) {
- logMsg("Pass: getJMSType returned correct value");
- } else {
- logMsg("Fail: getJMSType returned incorrect value, got: " + temp
- + " expected: TestMessage");
- pass = false;
- }
- tempdest = producer.getJMSReplyTo();
- if (tempdest == null) {
- logMsg("Fail: getJMSReplyTo returned null");
- pass = false;
- } else if (tempdest.equals(destination)) {
- logMsg("Pass: getJMSReplyTo returned correct value");
- } else {
- logMsg("Fail: getJMSReplyTo returned incorrect value, got: " + tempdest
- + " expected: " + destination);
- pass = false;
- }
-
- // --------------------------------------------------------------------------------------
- // Create a TextMessage, send it then receive it and verify that all the
- // JMSProducer
- // properties are set in the TextMessage
- // --------------------------------------------------------------------------------------
- logMsg("Create a TextMessage");
- messageSent = context.createTextMessage();
- messageSent.setText(testMessageBody);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesTest");
-
- logMsg("Send the TextMessage");
- producer.send(destination, messageSent);
- logMsg("messageSent=" + messageSent.getText());
-
- logMsg("Receive the TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
- logMsg("messageReceived=" + messageReceived.getText());
-
- // --------------------------------------------------------------------------------------
- // Retrieve the properties from the received TextMessage and verify that
- // they are correct
- // Get properties for boolean, byte, short, int, long, float, double, and
- // String.
- // -------------------------------------------------------------------------------------
- logMsg(
- "Retrieve and verify that TextMessage message properties were set correctly");
- if (messageReceived.getBooleanProperty("TESTBOOLEAN") == bool) {
- logMsg("Pass: getBooleanProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getBooleanProperty");
- pass = false;
- }
- if (messageReceived.getByteProperty("TESTBYTE") == bValue) {
- logMsg("Pass: getByteProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getByteProperty");
- pass = false;
- }
- if (messageReceived.getLongProperty("TESTLONG") == nLong) {
- logMsg("Pass: getLongProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getLongProperty");
- pass = false;
- }
- if (messageReceived.getStringProperty("TESTSTRING").equals(testString)) {
- logMsg("Pass: getStringProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getStringProperty");
- pass = false;
- }
- if (messageReceived.getDoubleProperty("TESTDOUBLE") == nDouble) {
- logMsg("Pass: getDoubleProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getDoubleProperty");
- pass = false;
- }
- if (messageReceived.getFloatProperty("TESTFLOAT") == nFloat) {
- logMsg("Pass: getFloatProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getFloatProperty");
- pass = false;
- }
- if (messageReceived.getIntProperty("TESTINT") == nInt) {
- logMsg("Pass: getIntProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getIntProperty");
- pass = false;
- }
- if (messageReceived.getShortProperty("TESTSHORT") == nShort) {
- logMsg("Pass: getShortProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getShortProperty");
- pass = false;
- }
- if (messageReceived.getIntProperty("JMSXDeliveryCount") >= 1) {
- logMsg(
- "Pass: getIntProperty(JMSXDeliveryCount) returned correct value");
- } else {
- logMsg(
- "Fail: incorrect value returned from getIntProperty(JMSXDeliveryCount)");
- pass = false;
- }
-
- // --------------------------------------------------------------------------------------
- // Retrieve the properties from the received TextMessage and verify that
- // they are correct
- // Get properties for Boolean, Byte, Short, Integer, Long, Float, Double,
- // and String.
- // --------------------------------------------------------------------------------------
- if (((Boolean) messageReceived.getObjectProperty("OBJTESTBOOLEAN"))
- .booleanValue() == bool) {
- logMsg("Pass: getObjectProperty returned correct Boolean value");
- } else {
- logMsg("Fail: incorrect Boolean value returned from getObjectProperty");
- pass = false;
- }
- if (((Byte) messageReceived.getObjectProperty("OBJTESTBYTE"))
- .byteValue() == bValue) {
- logMsg("Pass: getObjectProperty returned correct Byte value");
- } else {
- logMsg("Fail: incorrect Byte value returned from getObjectProperty");
- pass = false;
- }
- if (((Long) messageReceived.getObjectProperty("OBJTESTLONG"))
- .longValue() == nLong) {
- logMsg("Pass: getObjectProperty returned correct Long value");
- } else {
- logMsg("Fail: incorrect Long value returned from getObjectProperty");
- pass = false;
- }
- if (((String) messageReceived.getObjectProperty("OBJTESTSTRING"))
- .equals(testString)) {
- logMsg("Pass: getObjectProperty returned correct String value");
- } else {
- logMsg("Fail: incorrect String value returned from getObjectProperty");
- pass = false;
- }
- if (((Double) messageReceived.getObjectProperty("OBJTESTDOUBLE"))
- .doubleValue() == nDouble) {
- logMsg("Pass: getObjectProperty returned correct Double value");
- } else {
- logMsg("Fail: incorrect Double value returned from getObjectProperty");
- pass = false;
- }
- if (((Float) messageReceived.getObjectProperty("OBJTESTFLOAT"))
- .floatValue() == nFloat) {
- logMsg("Pass: getObjectProperty returned correct Float value");
- } else {
- logMsg("Fail: incorrect Float value returned from getObjectProperty");
- pass = false;
- }
- if (((Integer) messageReceived.getObjectProperty("OBJTESTINT"))
- .intValue() == nInt) {
- logMsg("Pass: getObjectProperty returned correct Integer value");
- } else {
- logMsg("Fail: incorrect Integer value returned from getObjectProperty");
- pass = false;
- }
- if (((Short) messageReceived.getObjectProperty("OBJTESTSHORT"))
- .shortValue() == nShort) {
- logMsg("Pass: getObjectProperty returned correct Short value");
- } else {
- logMsg("Fail: incorrect Short value returned from getObjectProperty");
- pass = false;
- }
-
- // ---------------------------------------------------------------------------------------
- // Retrieve message headers from the received TextMessage and verify that
- // they are correct
- // ---------------------------------------------------------------------------------------
- temp = messageReceived.getJMSCorrelationID();
- if (temp == null) {
- logMsg("Fail: getJMSCorrelationID returned null");
- pass = false;
- } else if (temp.equals("TestCorrelationID")) {
- logMsg("Pass: getJMSCorrelationID returned correct value");
- } else {
- logMsg("Fail: getJMSCorrelationID returned incorrect value, got: "
- + temp + " expected: TestCorrelationID");
- pass = false;
- }
- temp = messageReceived.getJMSType();
- if (temp == null) {
- logMsg("Fail: getJMSType returned null");
- pass = false;
- } else if (temp.equals("TestMessage")) {
- logMsg("Pass: getJMSType returned correct value");
- } else {
- logMsg("Fail: getJMSType returned incorrect value, got: " + temp
- + " expected: TestMessage");
- pass = false;
- }
- tempdest = messageReceived.getJMSReplyTo();
- if (tempdest == null) {
- logMsg("Fail: getJMSReplyTo returned null");
- pass = false;
- } else if (tempdest.equals(destination)) {
- logMsg("Pass: getJMSReplyTo returned correct value");
- } else {
- logMsg("Fail: getJMSReplyTo returned incorrect value, got: " + tempdest
- + " expected: " + destination);
- pass = false;
- }
-
- // ----------------------------------------------------------------------------------
- // The other property get methods (other than getStringProperty and
- // getObjectProperty)
- // must behave as if the property exists with a null value
- // ----------------------------------------------------------------------------------
- try {
- boolean b = producer.getBooleanProperty("TESTDUMMY");
- if (b != false) {
- logMsg("Fail: should have received false for getBooleanProperty");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- byte value = producer.getByteProperty("TESTDUMMY");
- logMsg(
- "Fail: NumberFormatException should have occurred for getByteProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logMsg("Pass: NumberFormatException as expected ");
- }
- try {
- short value = producer.getShortProperty("TESTDUMMY");
- logMsg(
- "Fail: NumberFormatException should have occurred for getShortProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logMsg("Pass: NumberFormatException as expected ");
- }
- try {
- int value = producer.getIntProperty("TESTDUMMY");
- logMsg(
- "Fail: NumberFormatException should have occurred for getIntProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logMsg("Pass: NumberFormatException as expected ");
- }
- try {
- long value = producer.getLongProperty("TESTDUMMY");
- logMsg(
- "Fail: NumberFormatException should have occurred for getLongProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logMsg("Pass: NumberFormatException as expected ");
- }
- try {
- float value = producer.getFloatProperty("TESTDUMMY");
- logMsg(
- "Fail: NullPointerException should have occurred for getFloatProperty");
- pass = false;
- } catch (java.lang.NullPointerException np) {
- logMsg("Pass: NullPointerException as expected ");
- }
- try {
- double value = producer.getDoubleProperty("TESTDUMMY");
- logMsg(
- "Fail: NullPointerException should have occurred for getDoubleProperty");
- pass = false;
- } catch (java.lang.NullPointerException np) {
- logMsg("Pass: NullPointerException as expected ");
- }
-
- // clear JMSProducer properties
- producer.clearProperties();
-
- // -------------------------------------------------------------------
- // All JMSProducer properties are deleted by the clearProperties method.
- // This leaves the message with an empty set of properties.
- // -------------------------------------------------------------------
- Long aLong = (Long) producer.getObjectProperty("OBJTESTLONG");
- if (aLong == null) {
- logMsg("Pass: property was cleared");
- } else {
- logMsg(
- "Fail: getObjectProperty should have returned null for cleared property");
- pass = false;
- }
- try {
- short aShort = producer.getShortProperty("TESTSHORT");
- logMsg(
- "Fail: NumberFormatException should have occurred for getShortProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logMsg("Pass: NumberFormatException as expected ");
- }
-
- // Check that we have no property names
- Set propNames = producer.getPropertyNames();
- Iterator iterator = propNames.iterator();
- boolean hasElements = iterator.hasNext();
- if (hasElements) {
- logMsg(
- "Fail: JMSProducer.getPropertyName() has properties (unexpected)");
- pass = false;
- } else {
- logMsg(
- "Pass: JMSProducer.getPropertyName() has no properties (expected)");
- }
- // -------------------------------------------------------------------
- // JMSContext.getJMSXPropertyNames() method returns the
- // names of the JMSX properties supported by a connection.
- // -------------------------------------------------------------------
- try {
- ConnectionMetaData data = context.getMetaData();
- Enumeration cmd = data.getJMSXPropertyNames();
- String propName;
-
- if (cmd == null) {
- logMsg("Fail: no JMSX property names were returned!");
- logMsg(
- "expected JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount at a miniumum");
- pass = false;
- } else {
- int iCount = 0;
- do {
- propName = (String) cmd.nextElement();
- logMsg(propName);
- if (propName.equals("JMSXGroupID")
- || propName.equals("JMSXGroupSeq")
- || propName.equals("JMSXDeliveryCount")) {
- iCount++;
- }
- } while (cmd.hasMoreElements());
- if (iCount > 1) {
- logMsg("Pass:");
- } else {
- logMsg("Fail: Expected property names not returned");
- pass = false;
- }
- }
- } catch (Exception ee) {
- logMsg("Fail: unexpected exception: " + ee);
- pass = false;
- }
- if (!pass) {
- throw new Exception("msgPropertiesTest failed");
- }
- } catch (Exception e) {
- logErr("Caught unexpected exception: " + e);
- e.printStackTrace();
- throw new Exception("msgPropertiesTest failed");
- }
- }
-
- /*
- * @testName: msgPropertiesConversionTests
- *
- * @assertion_ids: JMS:SPEC:22.1; JMS:SPEC:22.2; JMS:SPEC:22.3; JMS:SPEC:22.4;
- * JMS:SPEC:22.5; JMS:SPEC:22.6; JMS:SPEC:22.7; JMS:SPEC:22.8; JMS:SPEC:22.9;
- * JMS:SPEC:22.10; JMS:SPEC:22.11; JMS:SPEC:22.12; JMS:SPEC:22.13;
- * JMS:SPEC:22.14; JMS:SPEC:22.15; JMS:SPEC:22.16; JMS:JAVADOC:1180;
- * JMS:JAVADOC:1184; JMS:JAVADOC:1187; JMS:JAVADOC:1198; JMS:JAVADOC:1201;
- * JMS:JAVADOC:1204; JMS:JAVADOC:1215; JMS:JAVADOC:1218; JMS:JAVADOC:1222;
- * JMS:JAVADOC:1224; JMS:JAVADOC:1227; JMS:JAVADOC:1232; JMS:JAVADOC:1275;
- * JMS:JAVADOC:1278; JMS:JAVADOC:1281; JMS:JAVADOC:1284; JMS:JAVADOC:1287;
- * JMS:JAVADOC:1290; JMS:JAVADOC:1293; JMS:JAVADOC:1296; JMS:JAVADOC:1299;
- * JMS:JAVADOC:1186; JMS:JAVADOC:1189; JMS:JAVADOC:1200; JMS:JAVADOC:1203;
- * JMS:JAVADOC:1206; JMS:JAVADOC:1217; JMS:JAVADOC:1226; JMS:JAVADOC:1229;
- *
- * @test_Strategy: Create a JMSProducer, set properties for all of the
- * primitive types verify the conversion by getting the properties.
- */
- public void msgPropertiesConversionTests() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- String testMessageBody = "Testing...";
- int ntest = 0;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // ------------------------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- producer.setProperty("TESTBOOLEAN", bool);
- producer.setProperty("TESTBYTE", bValue);
- producer.setProperty("TESTSHORT", nShort);
- producer.setProperty("TESTINT", nInt);
- producer.setProperty("TESTFLOAT", nFloat);
- producer.setProperty("TESTDOUBLE", nDouble);
- producer.setProperty("TESTSTRING", "test");
- producer.setProperty("TESTLONG", nLong);
- producer.setProperty("TESTSTRINGTRUE", "true");
- producer.setProperty("TESTSTRINGFALSE", "false");
- producer.setProperty("TESTSTRING1", "1");
-
- // -------------------------------------------------------------------
- // test conversions for property values
- // -------------------------------------------------------------------
- // property set as boolean can be read only as string or boolean
- // -------------------------------------------------------------------
- // valid - boolean to string
- String myBool = producer.getStringProperty("TESTBOOLEAN");
-
- if (Boolean.valueOf(myBool).booleanValue() == bool) {
- logMsg("Pass: conversion from boolean to string - ok");
- } else {
- logMsg("Fail: conversion from boolean to string failed");
- pass = false;
- }
-
- // invalid - boolean to byte
- try {
- producer.getByteProperty("TESTBOOLEAN");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: boolean to byte ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- boolean to byte");
- pass = false;
- }
-
- // invalid - boolean to short
- try {
- producer.getShortProperty("TESTBOOLEAN");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: boolean to short ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- boolean to short");
- pass = false;
- }
-
- // invalid - boolean to int
- try {
- producer.getIntProperty("TESTBOOLEAN");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: boolean to int ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception --boolean to int ");
- pass = false;
- }
-
- // invalid - boolean to long
- try {
- producer.getLongProperty("TESTBOOLEAN");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: boolean to long ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- boolean to long");
- pass = false;
- }
-
- // invalid - boolean to float
- try {
- producer.getFloatProperty("TESTBOOLEAN");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: boolean to float ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- boolean to float");
- pass = false;
- }
-
- // invalid - boolean to double
- try {
- producer.getDoubleProperty("TESTBOOLEAN");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: boolean to double ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- boolean to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as byte can be read as a byte,short,int,long or string
- // valid - byte to string
- String myByte = producer.getStringProperty("TESTBYTE");
-
- if (Byte.valueOf(myByte).byteValue() == bValue) {
- logMsg("Pass: conversion from byte to string - ok");
- } else {
- logMsg("Fail: conversion from byte to string failed");
- pass = false;
- }
-
- // valid - byte to short
- if (producer.getShortProperty("TESTBYTE") == bValue) {
- logMsg("Pass: conversion from byte to short - ok");
- } else {
- logMsg("Fail: conversion from byte to short failed");
- pass = false;
- }
-
- // valid - byte to int
- if (producer.getIntProperty("TESTBYTE") == bValue) {
- logMsg("Pass: conversion from byte to int - ok");
- } else {
- logMsg("Fail: conversion from byte to int failed");
- pass = false;
- }
-
- // valid - byte to long
- if (producer.getLongProperty("TESTBYTE") == bValue) {
- logMsg("Pass: conversion from byte to long - ok");
- } else {
- logMsg("Fail: conversion from byte to long failed");
- pass = false;
- }
-
- // invalid - byte to boolean
- try {
- producer.getBooleanProperty("TESTBYTE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: byte to boolean ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- byte to boolean");
- pass = false;
- }
-
- // invalid - byte to float
- try {
- producer.getFloatProperty("TESTBYTE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: byte to float ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception --byte to float ");
- pass = false;
- }
-
- // invalid - byte to double
- try {
- producer.getDoubleProperty("TESTBYTE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: byte to double ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- byte to double");
- pass = false;
- }
-
- // -------------------------------------------------
- // property set as short can be read as short,int,long or string
- // valid - short to string
- String myshort = producer.getStringProperty("TESTSHORT");
-
- if (Short.valueOf(myshort).shortValue() == nShort) {
- logMsg("Pass: conversion from short to string - ok");
- } else {
- logMsg("Fail: conversion from short to string failed");
- pass = false;
- }
-
- // valid - short to int
- if (producer.getIntProperty("TESTSHORT") == nShort) {
- logMsg("Pass: conversion from short to int - ok");
- } else {
- logMsg("Fail: conversion from short to int failed");
- pass = false;
- }
-
- // valid - short to long
- if (producer.getLongProperty("TESTSHORT") == nShort) {
- logMsg("Pass: conversion from short to long - ok");
- } else {
- logMsg("Fail: conversion from short to long failed");
- pass = false;
- }
-
- // invalid - short to boolean
- try {
- producer.getBooleanProperty("TESTSHORT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: short to boolean ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- short to boolean");
- pass = false;
- }
-
- // invalid - short to byte
- try {
- producer.getByteProperty("TESTSHORT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: short to byte ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- short to byte");
- pass = false;
- }
-
- // invalid - short to float
- try {
- producer.getFloatProperty("TESTSHORT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: short to float ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- short to float");
- pass = false;
- }
-
- // invalid - short to double
- try {
- producer.getDoubleProperty("TESTSHORT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: short to double ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- short to double");
- pass = false;
- }
-
- // -------------------------------------------------
- // property set as int can be read only as int, long or string
- // valid - int to string
- if (Integer.valueOf(producer.getStringProperty("TESTINT"))
- .intValue() == nInt) {
- logMsg("Pass: conversion from int to string - ok");
- } else {
- logMsg("Fail: conversion from int to string failed");
- pass = false;
- }
-
- // valid - int to long
- if (producer.getLongProperty("TESTINT") == nInt) {
- logMsg("Pass: conversion from int to long - ok");
- } else {
- logMsg("Fail: conversion from int to long failed");
- pass = false;
- }
-
- // invalid - int to boolean
- try {
- producer.getBooleanProperty("TESTINT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: int to boolean ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- int to boolean");
- pass = false;
- }
-
- // invalid - int to byte
- try {
- producer.getByteProperty("TESTINT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: int to byte ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- int to byte");
- pass = false;
- }
-
- // invalid - int to short
- try {
- producer.getShortProperty("TESTINT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: int to short ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg(
- "Pass: MessageFormatRuntimeException as expected -- int to short ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception ");
- pass = false;
- }
-
- // invalid - int to float
- try {
- producer.getFloatProperty("TESTINT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: int to float ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- int to float");
- pass = false;
- }
-
- // invalid - int to double
- try {
- producer.getDoubleProperty("TESTINT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: int to double ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- int to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as long can be read only as long,or a string
- // valid - long to string
- if (Long.valueOf(producer.getStringProperty("TESTLONG"))
- .longValue() == nLong) {
- logMsg("Pass: conversion from long to string - ok");
- } else {
- logMsg("Fail: conversion from long to string failed");
- pass = false;
- }
-
- // invalid - long to boolean
- try {
- producer.getBooleanProperty("TESTLONG");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: long to boolean ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- long to boolean");
- pass = false;
- }
-
- // invalid - long to byte
- try {
- producer.getByteProperty("TESTLONG");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: long to byte ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- long to byte");
- pass = false;
- }
-
- // invalid - long to short
- try {
- producer.getShortProperty("TESTLONG");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: long to short ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- long to short ");
- pass = false;
- }
-
- // invalid - long to int
- try {
- producer.getIntProperty("TESTLONG");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: long to int ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- long to int");
- pass = false;
- }
-
- // invalid - long to float
- try {
- producer.getFloatProperty("TESTLONG");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: long to float ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- long to float");
- pass = false;
- }
-
- // invalid - long to double
- try {
- producer.getDoubleProperty("TESTLONG");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: long to double ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- long to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as float can be read only as float,double or a string
- // valid - float to string
- if (Float.valueOf(producer.getStringProperty("TESTFLOAT"))
- .floatValue() == nFloat) {
- logMsg("Pass: conversion from float to string - ok");
- } else {
- logMsg("Fail: conversion from float to string failed");
- pass = false;
- }
-
- // valid - float to double
- if (producer.getDoubleProperty("TESTFLOAT") == nFloat) {
- logMsg("Pass: conversion from long to double - ok");
- } else {
- logMsg("Fail: conversion from long to double failed");
- pass = false;
- }
-
- // invalid - float to boolean
- try {
- producer.getBooleanProperty("TESTFLOAT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: float to boolean ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- float to boolean ");
- pass = false;
- }
-
- // invalid - float to byte
- try {
- producer.getByteProperty("TESTFLOAT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: float to byte ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- float to byte");
- pass = false;
- }
-
- // invalid - float to short
- try {
- producer.getShortProperty("TESTFLOAT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: float to short ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception - float to short ");
- pass = false;
- }
-
- // invalid - float to int
- try {
- producer.getIntProperty("TESTFLOAT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: float to int ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception --- float to int");
- pass = false;
- }
-
- // invalid - float to long
- try {
- producer.getLongProperty("TESTFLOAT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: float to long ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- float to long");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as double can be read only as double or string
- // valid - double to string
- if (Double.valueOf(producer.getStringProperty("TESTDOUBLE"))
- .doubleValue() == nDouble) {
- logMsg("Pass: conversion from double to string - ok");
- } else {
- logMsg("Fail: conversion from double to string failed");
- pass = false;
- }
-
- // invalid - double to boolean
- try {
- producer.getBooleanProperty("TESTDOUBLE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: double to boolean ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- double to boolean ");
- pass = false;
- }
-
- // invalid - double to byte
- try {
- producer.getByteProperty("TESTDOUBLE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: double to byte ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- double to byte ");
- pass = false;
- }
-
- // invalid - double to short
- try {
- producer.getShortProperty("TESTDOUBLE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: double to short ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- double to short");
- pass = false;
- }
-
- // invalid - double to int
- try {
- producer.getIntProperty("TESTDOUBLE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: double to int ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception --- double to int ");
- pass = false;
- }
-
- // invalid - double to long
- try {
- producer.getLongProperty("TESTDOUBLE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: double to long ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- double to long");
- pass = false;
- }
-
- // invalid - double to float
- try {
- producer.getFloatProperty("TESTDOUBLE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: double to float ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- double to float");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as string can be read as boolean, byte, short,
- // int, long, float, double, and String.
- // valid - string to boolean
- if ((producer.getBooleanProperty("TESTSTRINGTRUE")) == true) {
- logMsg("Pass: conversion from string to boolean - expect true - ok");
- } else {
- logMsg(
- "Fail: conversion from string to boolean - expect true - failed");
- pass = false;
- }
- if ((producer.getBooleanProperty("TESTSTRINGFALSE")) == false) {
- logMsg("Pass: conversion from string to boolean expect false - ok");
- } else {
- logMsg("Fail: conversion from string to boolean expect false - failed");
- pass = false;
- }
-
- // valid - string to byte
- if (producer.getByteProperty("TESTSTRING1") == 1) {
- logMsg("Pass: conversion from string to byte - ok");
- } else {
- logMsg("Fail: conversion from string to byte failed");
- pass = false;
- }
-
- // valid - string to short
- if (producer.getShortProperty("TESTSTRING1") == 1) {
- logMsg("Pass: conversion from string to short - ok");
- } else {
- logMsg("Fail: conversion from string to short failed");
- pass = false;
- }
-
- // valid - string to int
- if (producer.getIntProperty("TESTSTRING1") == 1) {
- logMsg("Pass: conversion from string to int - ok");
- } else {
- logMsg("Fail: conversion from string to int failed");
- pass = false;
- }
-
- // valid - string to long
- if (producer.getLongProperty("TESTSTRING1") == 1) {
- logMsg("Pass: conversion from string to long - ok");
- } else {
- logMsg("Fail: conversion from string to long failed");
- pass = false;
- }
-
- // valid - string to float
- if (producer.getFloatProperty("TESTSTRING1") == 1) {
- logMsg("Pass: conversion from string to float - ok");
- } else {
- logMsg("Fail: conversion from string to float failed");
- pass = false;
- }
-
- // valid - string to double
- if (producer.getDoubleProperty("TESTSTRING1") == 1) {
- logMsg("Pass: conversion from string to double - ok");
- } else {
- logMsg("Fail: conversion from string to double failed");
- pass = false;
- }
- } catch (Exception e) {
- logMsg("Caught unexpected exception: " + e);
- throw new Exception("msgPropertiesConversionTests failed");
- }
-
- if (!pass) {
- throw new Exception("msgPropertiesConversionTests failed");
- }
- }
-
- /*
- * @testName: msgPropertyExistTest
- *
- * @assertion_ids: JMS:JAVADOC:1180; JMS:JAVADOC:1184; JMS:JAVADOC:1187;
- * JMS:JAVADOC:1198; JMS:JAVADOC:1201; JMS:JAVADOC:1204; JMS:JAVADOC:1215;
- * JMS:JAVADOC:1218; JMS:JAVADOC:1222; JMS:JAVADOC:1224; JMS:JAVADOC:1227;
- * JMS:JAVADOC:1232; JMS:JAVADOC:1275; JMS:JAVADOC:1278; JMS:JAVADOC:1281;
- * JMS:JAVADOC:1284; JMS:JAVADOC:1287; JMS:JAVADOC:1290; JMS:JAVADOC:1293;
- * JMS:JAVADOC:1296; JMS:JAVADOC:1299;
- *
- * @test_Strategy: Set and read properties for boolean, byte, short, int,
- * long, float, double, and String. Verify expected results.
- */
- public void msgPropertyExistTest() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- Enumeration propertyNames = null;
- String testMessageBody = "Testing msgPropertyExistTest";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // ------------------------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- producer.setProperty("TESTBOOLEAN", bool);
- producer.setProperty("TESTBYTE", bValue);
- producer.setProperty("TESTSHORT", nShort);
- producer.setProperty("TESTINT", nInt);
- producer.setProperty("TESTFLOAT", nFloat);
- producer.setProperty("TESTDOUBLE", nDouble);
- producer.setProperty("TESTSTRING", "test");
- producer.setProperty("TESTLONG", nLong);
- producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
-
- // --------------------------------------------------------------------------------------
- // Create a TextMessage, send it then receive it and verify that all the
- // JMSProducer
- // properties are set in the TextMessage
- // --------------------------------------------------------------------------------------
- logMsg("Create a TextMessage");
- messageSent = context.createTextMessage();
- messageSent.setText(testMessageBody);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesTest");
-
- logMsg("Send the TextMessage");
- producer.send(destination, messageSent);
-
- logMsg("Receive the TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
-
- if (messageReceived == null) {
- pass = false;
- TestUtil.logErr("messageReceived is null (unexpected)");
- } else {
-
- // iterate thru the property names
- int i = 0;
- propertyNames = messageReceived.getPropertyNames();
- do {
- String tmp = (String) propertyNames.nextElement();
-
- if (!tmp.startsWith("JMS")) {
- i++;
- if (tmp.equals("TESTBOOLEAN") || tmp.equals("TESTBYTE")
- || tmp.equals("TESTINT") || tmp.equals("TESTSHORT")
- || tmp.equals("TESTFLOAT") || tmp.equals("TESTDOUBLE")
- || tmp.equals("TESTSTRING") || tmp.equals("TESTLONG")
- || tmp.equals("OBJTESTBOOLEAN")
- || tmp.equals("COM_SUN_JMS_TESTNAME")) {
- logMsg("Application Property set by client is: " + tmp);
- if (!messageReceived.propertyExists(tmp)) {
- pass = messageReceived.propertyExists(tmp);
- logErr("Positive propertyExists test failed for " + tmp);
- } else if (messageReceived.propertyExists(tmp + "1")) {
- pass = false;
- logErr("Negative propertyExists test failed for " + tmp + "1");
- }
- } else {
- logErr("Appclication Property not set by client: " + tmp);
- pass = false;
- }
- } else {
- logMsg("JMSProperty Name is: " + tmp);
- }
- } while (propertyNames.hasMoreElements());
- }
-
- if (!pass) {
- throw new Exception("msgPropertyExistTest failed");
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- throw new Exception("msgPropertyExistTest failed");
- }
- }
-
- /*
- * @testName: msgJMSXPropertiesTest
- *
- * @assertion_ids: JMS:SPEC:34; JMS:SPEC:34.3; JMS:SPEC:34.4; JMS:SPEC:34.5;
- * JMS:SPEC:257;
- *
- * @test_Strategy: Set and read JMSX properties JMSXGroupID and JMSXGroupSeq.
- * Verify the value of the JMSX properties JMSXGroupID and JMSXGroupSeq are
- * the same as set by client. Verify that the JMS provider sets the mandatory
- * JMSXDeliveryCount.
- *
- * 1) Create JMSContext and JMSConsumer for Queue. 2) Create TextMessage and
- * set JMSXGroupID and JMSXGroupSeq message properties. 3) Send the
- * TextMessage to the Queue. 4) Receive the TextMessage from the Queue. 5)
- * Verify the TextMessage. Verify that the message properites JMSXGroupID,
- * JMSXGroupSeq, and JMSXDeliveryCount are correct.
- */
- public void msgJMSXPropertiesTest() throws Exception {
- boolean pass = true;
- String message = "Testing msgJMSXPropertiesTest";
- int seq = 123450;
- String id = "msgJMSXPropertiesTest";
- try {
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
-
- TestUtil.logMsg("Set StringProperty COM_SUN_JMS_TESTNAME");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgJMSXPropertiesTest");
-
- TestUtil.logMsg("Set JMSXGroupSeq and JMSXGroupSeq");
- expTextMessage.setStringProperty("JMSXGroupID", id);
- expTextMessage.setIntProperty("JMSXGroupSeq", seq);
-
- TestUtil.logMsg("Send the TextMessage");
- producer.send(destination, expTextMessage);
-
- TestUtil.logMsg("Receive the TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
-
- TestUtil.logMsg("Verify the value in TextMessage");
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
-
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
-
- TestUtil.logMsg(
- "Verify properties JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount in TextMessage");
- if (actTextMessage.propertyExists("JMSXGroupID")) {
- if (actTextMessage.getStringProperty("JMSXGroupID").equals(id)) {
- logMsg("Pass: getStringProperty(JMSXGroupID) returned correct value");
- } else {
- logErr(
- "Fail: incorrect value returned from getStringProperty(JMSXGroupID)");
- pass = false;
- }
- } else {
- logErr(
- "Fail: TextMessage does not contain expected JMSXGroupID property");
- pass = false;
- }
-
- if (actTextMessage.propertyExists("JMSXGroupSeq")) {
- if (actTextMessage.getIntProperty("JMSXGroupSeq") == seq) {
- logMsg("Pass: getIntProperty(JMSXGroupSeq) returned correct value");
- } else {
- logErr(
- "Fail: incorrect value returned from getIntProperty(JMSXGroupSeq)");
- pass = false;
- }
- } else {
- logErr(
- "Fail: TextMessage does not contain expected JMSXGroupSeq property");
- pass = false;
- }
-
- if (actTextMessage.propertyExists("JMSXDeliveryCount")) {
- if (actTextMessage.getIntProperty("JMSXDeliveryCount") == 1) {
- logMsg(
- "Pass: getIntProperty(JMSXDeliveryCount) returned correct value");
- } else {
- logErr(
- "Fail: incorrect value returned from getIntProperty(JMSXDeliveryCount)");
- pass = false;
- }
- } else {
- logErr(
- "Fail: TextMessage does not contain expected JMSXDeliveryCount property");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // ConnectionMetaData.getJMSXPropertyNames() method returns the
- // names of the JMSX properties supported by a connection.
- // -------------------------------------------------------------------
- TestUtil.logMsg("Verify the JMSXProperties in ConnectionMetaData");
- try {
- TestUtil.logMsg("Get ConnectionMetaData");
- ConnectionMetaData data = context.getMetaData();
- TestUtil.logMsg("Get JMSXPropertyNames");
- Enumeration cmd = data.getJMSXPropertyNames();
- TestUtil.logMsg(
- "Verify that we have JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount");
- if (cmd == null) {
- TestUtil.logErr("No JMSX property names were returned (Failed)");
- pass = false;
- } else {
- int iCount = 0;
- do {
- String propName = (String) cmd.nextElement();
- TestUtil.logTrace("Found JMSX property [" + propName + "]");
- if (propName.equals("JMSXGroupID"))
- iCount++;
- else if (propName.equals("JMSXGroupSeq"))
- iCount++;
- else if (propName.equals("JMSXDeliveryCount"))
- iCount++;
- } while (cmd.hasMoreElements());
-
- if (iCount > 2) {
- TestUtil
- .logMsg("Expected JMSX property names were returned (Passed)");
- } else {
- TestUtil
- .logErr("Expected JMSX property names not returned (Failed)");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("msgJMSXPropertiesTest", e);
- }
-
- if (!pass) {
- throw new Exception("msgJMSXPropertiesTest failed");
- }
- }
-
- /*
- * @testName: setPropertyExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1280; JMS:JAVADOC:1283; JMS:JAVADOC:1286;
- * JMS:JAVADOC:1289; JMS:JAVADOC:1292; JMS:JAVADOC:1295; JMS:JAVADOC:1298;
- * JMS:JAVADOC:1301; JMS:JAVADOC:1277; JMS:JAVADOC:1302;
- *
- * @test_Strategy: Tests IllegalArgumentException and
- * MessageFormatRuntimeException conditions from the following API's:
- *
- * JMSProducer.setProperty(String, boolean) throws IllegalArgumentException
- * JMSProducer.setProperty(String, byte)throws IllegalArgumentException
- * JMSProducer.setProperty(String, double)throws IllegalArgumentException
- * JMSProducer.setProperty(String, float)throws IllegalArgumentException
- * JMSProducer.setProperty(String, int)throws IllegalArgumentException
- * JMSProducer.setProperty(String, long)throws IllegalArgumentException
- * JMSProducer.setProperty(String, Object)throws IllegalArgumentException
- * JMSProducer.setProperty(String, short)throws IllegalArgumentException
- * JMSProducer.setProperty(String, String)throws IllegalArgumentException
- * JMSProducer.setProperty(String, Object)throws MessageFormatRuntimeException
- */
- public void setPropertyExceptionTests() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
-
- try {
- // Create JMSProducer from JMSContext
- logMsg("Create a JMSProducer from JMSContext");
- producer = context.createProducer();
-
- TestUtil.logMsg(
- "Test IllegalArgumentException from all JMSProducer setProperty() API's");
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", boolean)");
- producer.setProperty("", bool);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", byte)");
- producer.setProperty("", bValue);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", double)");
- producer.setProperty("", nDouble);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", float)");
- producer.setProperty("", nFloat);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil
- .logMsg("Test IllegalArgumentException for setProperty(\"\", int)");
- producer.setProperty("", nInt);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", long)");
- producer.setProperty("", nLong);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", short)");
- producer.setProperty("", nShort);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", String)");
- producer.setProperty("", "test");
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", Object)");
- producer.setProperty("", Long.valueOf(nLong));
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, boolean)");
- producer.setProperty(null, bool);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, byte)");
- producer.setProperty(null, bValue);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, double)");
- producer.setProperty(null, nDouble);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, float)");
- producer.setProperty(null, nFloat);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil
- .logMsg("Test IllegalArgumentException for setProperty(null, int)");
- producer.setProperty(null, nInt);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, long)");
- producer.setProperty(null, nLong);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, short)");
- producer.setProperty(null, nShort);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, String)");
- producer.setProperty(null, "test");
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, Object)");
- producer.setProperty(null, Long.valueOf(nLong));
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Test MessageFormatRuntimeException for setProperty(String, Object)");
- producer.setProperty("name1", new ArrayList(2));
- TestUtil.logErr(
- "Fail: Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Pass: Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setPropertyExceptionTests");
- }
-
- if (!pass) {
- throw new Exception("setPropertyExceptionTests failed");
- }
- }
-
- /*
- * @testName: sendExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1241; JMS:JAVADOC:1245; JMS:JAVADOC:1238;
- *
- * @test_Strategy: Tests MessageFormatRuntimeException and
- * MessageNotWriteableRuntimeException conditions from the following API's:
- *
- * JMSProducer.send(Destination, Message) throws
- * MessageNotWriteableRuntimeException JMSProducer.send(Destination, Message)
- * throws MessageFormatRuntimeException JMSProducer.send(Destination, Map)
- * throws MessageFormatRuntimeException
- *
- */
- public void sendExceptionTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- try {
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Message) for MessageFormatRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling send(Destination, Message) -> expect MessageFormatRuntimeException");
- producer.send(destination, (Message) null);
- TestUtil.logErr("MessageFormatRuntimeException was not thrown");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected MessageFormatRuntimeException, received " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Map) for MessageFormatRuntimeException");
- try {
- Map mp = new HashMap();
- mp.put("1", new ArrayList(2));
- mp.put("2", new Properties());
- mp.put("2", new Properties());
- mp.put("1", new ArrayList(2));
- TestUtil.logMsg(
- "Calling send(Destination, Map) -> expect MessageFormatRuntimeException");
- producer.send(destination, mp);
- TestUtil.logErr("MessageFormatRuntimeException was not thrown");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected MessageFormatRuntimeException, received " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Message) for MessageNotWriteableRuntimeException");
- try {
- // send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage sendTextMessage = context.createTextMessage(message);
- sendTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendExceptionTests");
- TestUtil.logMsg("Send TextMessage");
- producer.send(destination, sendTextMessage);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage recvTextMessage = (TextMessage) consumer.receive(timeout);
- if (recvTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (recvTextMessage.getText().equals(sendTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + sendTextMessage.getText()
- + ", received " + recvTextMessage.getText());
- pass = false;
- }
- }
- TestUtil.logMsg("Set a bunch of JMSProducer properties");
- producer.setProperty("TESTBOOLEAN", bool);
- producer.setProperty("TESTBYTE", bValue);
- producer.setProperty("TESTDOUBLE", nDouble);
- producer.setProperty("TESTFLOAT", nFloat);
- producer.setProperty("TESTINT", nInt);
- producer.setProperty("TESTLONG", nLong);
- producer.setProperty("TESTSHORT", nShort);
- producer.setProperty("TESTSTRING", testString);
- producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
- TestUtil.logMsg(
- "Using received TextMessage try and send it (expect MessageNotWriteableRuntimeException)");
- producer.send(destination, recvTextMessage);
- TestUtil.logErr("MessageNotWriteableRuntimeException was not thrown");
- pass = false;
- } catch (MessageNotWriteableRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageNotWriteableRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected MessageNotWriteableRuntimeException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("sendExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("sendExceptionTests failed");
- }
- }
-
- /*
- * @testName: getBodyTests
- *
- * @assertion_ids: JMS:JAVADOC:1357;
- *
- * @test_Strategy: Send and receive messages of the following types:
- * BytesMessage, MapMessage, ObjectMessage, TextMessage. Call
- * Message.getBody() to return the message as the specified Object type.
- *
- * Object message = Message.getBody(Class)
- *
- * Test the following:
- *
- * String message = Message.getBody(String.class) byte[] message =
- * Message.getBody(byte[].class); StringBuffer message =
- * Message.getBody(StringBuffer.class); Map message =
- * Message.getBody(Map.class);
- *
- */
- public void getBodyTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- StringBuffer expSbuffer = new StringBuffer("This is it!");
- try {
- // Send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
- TestUtil.logMsg("Send and receive the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Call TextMessage.getBody(String.class) to extract TextMessage as String");
- String actMessage = actTextMessage.getBody(String.class);
- TestUtil.logMsg("Check the value in String");
- if (actMessage.equals(message)) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect expected " + message
- + ", received " + actMessage);
- pass = false;
- }
-
- // Send and receive ObjectMessage
- TestUtil.logMsg("Create ObjectMessage");
- ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
- TestUtil.logMsg("Set some values in ObjectMessage");
- expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "getBodyTests");
- TestUtil.logMsg("Send and receive the ObjectMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expObjectMessage);
- TestUtil
- .logMsg("Call JMSConsumer.receive(long) to receive ObjectMessage");
- ObjectMessage actObjectMessage = (ObjectMessage) consumer
- .receive(timeout);
- if (actObjectMessage == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- TestUtil.logMsg(
- "Call ObjectMessage.getBody(StringBuffer.class) to extract ObjectMessage as StringBuffer");
- StringBuffer actSbuffer = actObjectMessage.getBody(StringBuffer.class);
- TestUtil.logMsg("Check the value in StringBuffer");
- if (actSbuffer.toString().equals(expSbuffer.toString())) {
- TestUtil.logMsg("ObjectMessage is correct");
- } else {
- TestUtil.logErr("ObjectMessage is incorrect expected " + expSbuffer
- + ", received " + actSbuffer);
- pass = false;
- }
-
- // Send and receive BytesMessage
- TestUtil.logMsg("Create BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- TestUtil.logMsg("Send and receive the BytesMessage");
- producer.send(destination, bMsg);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive BytesMessage");
- BytesMessage actBytesMessage = (BytesMessage) consumer.receive(timeout);
- if (actBytesMessage == null) {
- throw new Exception("Did not receive BytesMessage");
- }
- TestUtil.logMsg(
- "Call BytesMessage.getBody(StringBuffer.class) to extract BytesMessage as byte[] array");
- byte[] bytes = actBytesMessage.getBody(byte[].class);
- if (bytes == null) {
- TestUtil.logErr("Did not receive BytesMessage");
- pass = false;
- } else {
- try {
- DataInputStream di = new DataInputStream(
- new ByteArrayInputStream(bytes));
- TestUtil.logMsg("Check the values in BytesMessage");
- if (di.readByte() == (byte) 1) {
- TestUtil.logMsg("bytevalue is correct");
- } else {
- TestUtil.logMsg("bytevalue is incorrect");
- pass = false;
- }
- if (di.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- try {
- byte b = di.readByte();
- } catch (EOFException e) {
- TestUtil.logMsg("Caught expected EOFException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- }
- // Send and receive MapMessage
- TestUtil.logMsg("Send MapMessage");
- MapMessage mMsg = context.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- producer.send(destination, mMsg);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive MapMessage");
- MapMessage actMapMessage = (MapMessage) consumer.receive(timeout);
- if (actMapMessage == null) {
- throw new Exception("Did not receive MapMessage");
- }
- TestUtil.logMsg(
- "Call MapMessage.getBody(Map.class) to extract MapMessage as a Map object");
- Map map = actMapMessage.getBody(Map.class);
- if (map == null) {
- TestUtil.logErr("Did not receive MapMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in MapMessage");
- TestUtil.logMsg("map.size()=" + map.size());
- if (map.size() != 2) {
- TestUtil.logErr("Map size is " + map.size() + ", expected 2");
- pass = false;
- }
- Iterator it = map.keySet().iterator();
- String name = null;
- while (it.hasNext()) {
- name = (String) it.next();
- if (name.equals("booleanvalue")) {
- if ((boolean) map.get(name) == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logErr("booleanvalue is incorrect");
- pass = false;
- }
- } else if (name.equals("intvalue")) {
- if ((int) map.get(name) == 10) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logErr("intvalue is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Unexpected name of [" + name + "] in MapMessage");
- pass = false;
- }
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("getBodyTests", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("getBodyTests failed");
- }
- }
-
- /*
- * @testName: getBodyExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1359;
- *
- * @test_Strategy: Test exception case for Message.getBody(Class). Test
- * MessageFormatException.
- *
- * Object = Message.getBody(Class)
- *
- */
- public void getBodyExceptionTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- StringBuffer expSbuffer = new StringBuffer("This is it!");
- try {
- // Send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "getBodyExceptionTests");
- TestUtil.logMsg("Send and receive the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Call TextMessage.getBody(Boolean.class) to extract TextMessage "
- + "as Boolean (expect MessageFormatException)");
- try {
- Boolean myBool = actTextMessage.getBody(Boolean.class);
- TestUtil.logErr("Expected MessageFormatException to be thrown");
- pass = false;
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Caught correct MessageFormatException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive ObjectMessage
- TestUtil.logMsg("Create ObjectMessage of type StringBuffer");
- ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
- TestUtil.logMsg("Set some values in ObjectMessage");
- expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "getBodyExceptionTests");
- TestUtil.logMsg("Send and receive the ObjectMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expObjectMessage);
- TestUtil
- .logMsg("Call JMSConsumer.receive(long) to receive ObjectMessage");
- ObjectMessage actObjectMessage = (ObjectMessage) consumer
- .receive(timeout);
- if (actObjectMessage == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- TestUtil.logMsg(
- "Call ObjectMessage.getBody(HashMap.class) to extract ObjectMessage "
- + "as HashMap (expect MessageFormatException");
- try {
- HashMap hmap = actObjectMessage.getBody(HashMap.class);
- TestUtil.logErr("Expected MessageFormatException to be thrown");
- pass = false;
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Caught correct MessageFormatException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // send and receive StreamMessage
- TestUtil.logMsg("Create StreamMessage");
- StreamMessage expStreamMsg = context.createStreamMessage();
- TestUtil.logMsg("Set some values in StreamMessage");
- expStreamMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "getBodyExceptionTests");
- expStreamMsg.writeBoolean(true);
- expStreamMsg.writeInt((int) 22);
- TestUtil.logMsg("Send and receive the StreamMessage");
- producer.send(destination, expStreamMsg);
- StreamMessage actStreamMsg = (StreamMessage) consumer.receive(timeout);
- if (actStreamMsg == null) {
- throw new Exception("Did not receive StreamMessage");
- }
- TestUtil.logMsg(
- "Call StreamMessage.getBody(HashMap.class) to extract StreamMessage "
- + "as HashMap (expect MessageFormatException");
- try {
- HashMap hmap = actStreamMsg.getBody(HashMap.class);
- TestUtil.logErr("Expected MessageFormatException to be thrown");
- pass = false;
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Caught correct MessageFormatException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Create BytesMessage
- TestUtil.logMsg("Create BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyExceptionTests");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- TestUtil.logMsg("BytesMessage is in write-only mode");
- TestUtil
- .logMsg("Call BytesMessage.getBody(StringBuffer.class) to receive "
- + "BytesMessage as StringBuffer(expect MessageFormatException)");
- try {
- bMsg.getBody(StringBuffer.class);
- TestUtil.logErr("Expected MessageFormatException to be thrown");
- pass = false;
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Caught correct MessageFormatException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- TestUtil.logMsg("Send and receive the BytesMessage");
- producer.send(destination, bMsg);
- BytesMessage actBytesMsg = (BytesMessage) consumer.receive(timeout);
- try {
- actBytesMsg.getBody(StringBuffer.class);
- TestUtil.logErr("Expected MessageFormatException to be thrown");
- pass = false;
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Caught correct MessageFormatException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("getBodyExceptionTests", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("getBodyExceptionTests failed");
- }
- }
-
- /*
- * @testName: isBodyAssignableToTest
- *
- * @assertion_ids: JMS:JAVADOC:1361;
- *
- * @test_Strategy: Test Message.isBodyAssignableTo(Class) API.
- *
- * boolean = Message.isBodyAssignableTo(Class)
- *
- */
- public void isBodyAssignableToTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- StringBuffer expSbuffer = new StringBuffer("This is it!");
- try {
- // Send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "isBodyAssignableToTest");
- TestUtil.logMsg("Send and receive the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- try {
- TestUtil.logMsg(
- "Call TextMessage.isBodyAssignableTo(Boolean.class) (expect false)");
- boolean b = actTextMessage.isBodyAssignableTo(Boolean.class);
- if (b) {
- TestUtil.logErr("Expected false got true");
- pass = false;
- }
- TestUtil.logMsg(
- "Call TextMessage.isBodyAssignableTo(String.class) (expect true)");
- b = actTextMessage.isBodyAssignableTo(String.class);
- if (!b) {
- TestUtil.logErr("Expected true got false");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive ObjectMessage
- TestUtil.logMsg("Create ObjectMessage");
- ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
- TestUtil.logMsg("Set some values in ObjectMessage");
- expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "isBodyAssignableToTest");
- TestUtil.logMsg("Send and receive the ObjectMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expObjectMessage);
- TestUtil
- .logMsg("Call JMSConsumer.receive(long) to receive ObjectMessage");
- ObjectMessage actObjectMessage = (ObjectMessage) consumer
- .receive(timeout);
- if (actObjectMessage == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- try {
- TestUtil.logMsg(
- "Call ObjectMessage.isBodyAssignableTo(Boolean.class) (expect false)");
- boolean b = actObjectMessage.isBodyAssignableTo(Boolean.class);
- if (b) {
- TestUtil.logErr("Expected false got true");
- pass = false;
- }
- TestUtil.logMsg(
- "Call ObjectMessage.isBodyAssignableTo(StringBuffer.class) (expect true)");
- b = actObjectMessage.isBodyAssignableTo(StringBuffer.class);
- if (!b) {
- TestUtil.logErr("Expected true got false");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive BytesMessage
- TestUtil.logMsg("Create BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTest");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- TestUtil.logMsg("Send and receive the BytesMessage");
- producer.send(destination, bMsg);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive BytesMessage");
- BytesMessage actBytesMessage = (BytesMessage) consumer.receive(timeout);
- if (actBytesMessage == null) {
- throw new Exception("Did not receive BytesMessage");
- }
- try {
- TestUtil.logMsg(
- "Call BytesMessage.isBodyAssignableTo(String.class) (expect false)");
- boolean b = actBytesMessage.isBodyAssignableTo(String.class);
- if (b) {
- TestUtil.logErr("Expected false got true");
- pass = false;
- }
- TestUtil.logMsg(
- "Call BytesMessage.isBodyAssignableTo(byte[].class) (expect true)");
- b = actBytesMessage.isBodyAssignableTo(byte[].class);
- if (!b) {
- TestUtil.logErr("Expected true got false");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive MapMessage
- TestUtil.logMsg("Send MapMessage");
- MapMessage mMsg = context.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTest");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- producer.send(destination, mMsg);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive MapMessage");
- MapMessage actMapMessage = (MapMessage) consumer.receive(timeout);
- if (actMapMessage == null) {
- throw new Exception("Did not receive MapMessage");
- }
- try {
- TestUtil.logMsg(
- "Call MapMessage.isBodyAssignableTo(String.class) (expect false)");
- boolean b = actMapMessage.isBodyAssignableTo(String.class);
- if (b) {
- TestUtil.logErr("Expected false got true");
- pass = false;
- }
- TestUtil.logMsg(
- "Call MapMessage.isBodyAssignableTo(Map.class) (expect true)");
- b = actMapMessage.isBodyAssignableTo(Map.class);
- if (!b) {
- TestUtil.logErr("Expected true got false");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("isBodyAssignableToTest", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("isBodyAssignableToTest failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsproducerqueuetests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsproducerqueuetests/ClientIT.java
new file mode 100644
index 0000000000..96f965688c
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsproducerqueuetests/ClientIT.java
@@ -0,0 +1,5057 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.jmsproducerqueuetests;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.EOFException;
+import java.io.Serializable;
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.ConnectionMetaData;
+import jakarta.jms.DeliveryMode;
+import jakarta.jms.Destination;
+import jakarta.jms.JMSConsumer;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSProducer;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.MessageFormatException;
+import jakarta.jms.MessageFormatRuntimeException;
+import jakarta.jms.MessageNotWriteableRuntimeException;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.Queue;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.jmsproducerqueuetests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null;
+
+ // JMS objects
+ private transient ConnectionFactory cf = null;
+
+ private transient Queue queue = null;
+
+ private transient Destination destination = null;
+
+ private transient JMSContext context = null;
+
+ private transient JMSProducer producer = null;
+
+ private transient JMSConsumer consumer = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * helper method verifies that the ConnectionMetaData
+ *
+ * @param ConnectionMetaData returned from getJMSMessageID
+ *
+ * @return boolean true if ConnectionMetaData is as expected
+ */
+ private boolean verifyMetaData(ConnectionMetaData data) {
+ boolean pass = true;
+
+ try {
+ String tmp = data.getJMSVersion();
+ logger.log(Logger.Level.TRACE, "JMSVersion=" + tmp);
+
+ if (!tmp.equals("2.0")) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getJMSMajorVersion();
+ logger.log(Logger.Level.TRACE, "JMSMajorVersion=" + tmp);
+
+ if (tmp != 2) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSMajorVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSMajorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getJMSMinorVersion();
+ logger.log(Logger.Level.TRACE, "JMSMinorVersion=" + tmp);
+
+ if (tmp != 0) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSMajorVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSMinorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = data.getJMSProviderName();
+ logger.log(Logger.Level.TRACE, "JMSProviderName=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSProviderName: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = data.getProviderVersion();
+ logger.log(Logger.Level.TRACE, "JMSProviderVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getProviderMajorVersion();
+ logger.log(Logger.Level.TRACE, "ProviderMajorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderMajorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getProviderMinorVersion();
+ logger.log(Logger.Level.TRACE, "ProviderMinorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderMinorVersion: ", e);
+ pass = false;
+ }
+ return pass;
+ }
+
+ /*
+ * helper method verifies that the JMSMessageID starts with ID:
+ *
+ * @param String returned from getJMSMessageID
+ *
+ * @return boolean true if id correctly starts with ID:
+ */
+ private boolean chkMessageID(String id) {
+ String status[] = { "Pass", "Fail" };
+ boolean retcode = true;
+
+ // message id must start with ID: - unless it is null
+ int index = 0;
+
+ if (id == null) {
+ ;
+ } else if (id.startsWith("ID:")) {
+ ;
+ } else {
+ index = 1;
+ retcode = false;
+ }
+ logger.log(Logger.Level.TRACE, "Results: " + status[index]);
+ return retcode;
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ queues = new ArrayList(3);
+ connections = new ArrayList(5);
+
+ // set up JmsTool for COMMON_Q setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_Q");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ cf = tool.getConnectionFactory();
+ tool.getDefaultConnection().close();
+ destination = tool.getDefaultDestination();
+ queue = (Queue) destination;
+
+ // create JMSContext with AUTO_ACKNOWLEDGE then create consumer/producer
+ logger.log(Logger.Level.INFO, "Create JMSContext, JMSConsumer and JMSProducer");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ producer = context.createProducer();
+ consumer = context.createConsumer(destination);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Close JMSContext Objects");
+ if (context != null) {
+ context.close();
+ context = null;
+ }
+ producer = null;
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ tool.flushDestination();
+ logger.log(Logger.Level.INFO, "Close JMSConsumer objects");
+ if (consumer != null) {
+ consumer.close();
+ consumer = null;
+ }
+ tool.closeAllResources();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1234;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * JMSProducer.send(Destination, Message) JMSConsumer.receive(long)
+ *
+ */
+ @Test
+ public void sendAndRecvTest1() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvTest1");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage via JMSconsumer.receive(long)");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvTest1", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1239;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * JMSProducer.send(Destination, String) JMSConsumer.receiveBody(String, long)
+ *
+ */
+ @Test
+ public void sendAndRecvTest2() throws Exception {
+ boolean pass = true;
+ String expTextMessage = "Where are you!";
+ try {
+ // send and receive TextMessage payload
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, String)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage via JMSConsumer.receiveBody(String, long)");
+ String actTextMessage = consumer.receiveBody(String.class, timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.equals(expTextMessage)) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "TextMessage is incorrect expected " + expTextMessage + ", received " + actTextMessage);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvTest2", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:1251;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * JMSProducer.send(Destination, Serializable)
+ * JMSConsumer.receiveBody(Serializable, long)
+ *
+ */
+ @Test
+ public void sendAndRecvTest3() throws Exception {
+ boolean pass = true;
+ try {
+ // send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Send ObjectMessage");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ ObjectMessage expObjectMessage = context.createObjectMessage();
+ StringBuffer expSb = new StringBuffer("Where are you!");
+ logger.log(Logger.Level.INFO, "Set object in ObjectMessage to a StringBuffer");
+ expObjectMessage.setObject(expSb);
+ expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvTest3");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Serializable)");
+ producer.send(destination, expObjectMessage);
+ logger.log(Logger.Level.INFO,
+ "Receive ObjectMessage via JMSConsumer.receiveBody(Serializable.class, long)");
+ StringBuffer actSb = (StringBuffer) consumer.receiveBody(Serializable.class, timeout);
+ if (actSb == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in ObjectMessage");
+ if (actSb.toString().equals(expSb.toString())) {
+ logger.log(Logger.Level.INFO, "ObjectMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "ObjectMessage is incorrect expected " + expSb.toString() + ", received " + actSb.toString());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvTest3", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTest3 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTest4
+ *
+ * @assertion_ids: JMS:JAVADOC:1243;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * JMSProducer.send(Destination, Map)
+ * JMSConsumer.receiveBody(Map, long))
+ */
+ @Test
+ public void sendAndRecvTest4() throws Exception {
+ boolean pass = true;
+ Map mapMsgSend = new HashMap();
+ mapMsgSend.put("StringValue", "sendAndRecvTest4");
+ mapMsgSend.put("BooleanValue", true);
+ mapMsgSend.put("IntValue", (int) 10);
+ try {
+ // send and receive MapMessage payload
+ logger.log(Logger.Level.INFO, "Send MapMessage via JMSProducer.send(Destination, Map)");
+ producer.send(destination, mapMsgSend);
+ logger.log(Logger.Level.INFO, "Receive MapMessage via JMSConsumer.receiveBody(Map.class, long)");
+ Map mapMsgRecv = consumer.receiveBody(Map.class, timeout);
+ if (mapMsgRecv == null) {
+ throw new Exception("Did not receive MapMessage");
+ }
+ logger.log(Logger.Level.INFO, "Compare MapMsgSend and MapMsgRecv for equality");
+ for (Entry entry : mapMsgSend.entrySet()) {
+ String key = entry.getKey();
+ logger.log(Logger.Level.INFO, "key " + key + ": " + entry.getValue().equals(mapMsgRecv.get(key)));
+ if (entry.getValue().equals(mapMsgRecv.get(key))) {
+ continue;
+ } else {
+ pass = false;
+ }
+ }
+ if (pass) {
+ logger.log(Logger.Level.INFO, "MapMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "MapMessage is incorrect expected " + mapMsgSend + ", received " + mapMsgRecv);
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvTest4", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTest4 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTest5
+ *
+ * @assertion_ids: JMS:JAVADOC:1247;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * JMSProducer.send(Destination, byte[]) JMSConsumer.receiveBody(byte[], long))
+ *
+ */
+ @Test
+ public void sendAndRecvTest5() throws Exception {
+ boolean pass = true;
+ String messageSend = "Where are you!";
+ byte[] bytesMsgSend = messageSend.getBytes();
+ try {
+ // send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Send BytesMessage via JMSProducer.send(Destination, byte[])");
+ producer.send(destination, bytesMsgSend);
+ logger.log(Logger.Level.INFO, "Receive BytesMessage via JMSConsumer.receiveBody(byte[].class, long)");
+ byte[] bytesMsgRecv = consumer.receiveBody(byte[].class, timeout);
+ if (bytesMsgRecv == null) {
+ throw new Exception("Did not receive BytesMessage");
+ }
+ logger.log(Logger.Level.INFO, "Compare BytesMsgSend and BytesMsgRecv for equality");
+ String messageRecv = new String(bytesMsgRecv);
+ if (messageRecv.equals(messageSend)) {
+ logger.log(Logger.Level.INFO, "BytesMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "BytesMessage is incorrect expected " + messageRecv + ", received " + messageSend);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvTest5", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTest5 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvMsgsOfEachMsgTypeTest
+ *
+ * @assertion_ids: JMS:JAVADOC:925; JMS:JAVADOC:927; JMS:JAVADOC:929;
+ * JMS:JAVADOC:934; JMS:JAVADOC:937; JMS:JAVADOC:940; JMS:JAVADOC:964;
+ * JMS:JAVADOC:966; JMS:JAVADOC:942; JMS:JAVADOC:847; JMS:JAVADOC:1104;
+ * JMS:JAVADOC:1234; JMS:JAVADOC:875; JMS:JAVADOC:936; JMS:JAVADOC:1177;
+ *
+ * @test_Strategy: Send and receive messages of each message type: Message,
+ * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Gets the
+ * delivery time of each send of the message. Tests the following API's
+ *
+ * ConnectionFactory.createContext(String, String, int)
+ * JMSContext.createConsumer(Destination) JMSContext.createProducer()
+ * JMSContext.createMessage() JMSContext.createBytesMessage()
+ * JMSContext.createMapMessage() JMSContext.createObjectMessage()
+ * JMSContext.createObjectMessage(Serializable object)
+ * JMSContext.createStreamMessage() JMSContext.createTextMessage()
+ * JMSContext.createTextMessage(String) JMSContext.createConsumer(Destination)
+ * JMSProducer.send(Destination, Message) JMSConsumer.receive(long timeout)
+ *
+ */
+ @Test
+ public void sendAndRecvMsgsOfEachMsgTypeTest() throws Exception {
+ boolean pass = true;
+ try {
+ // send and receive Message
+ logger.log(Logger.Level.INFO, "Send Message");
+ Message msg = context.createMessage();
+ logger.log(Logger.Level.INFO, "Set some values in Message");
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ msg.setBooleanProperty("booleanProperty", true);
+ producer.send(destination, msg);
+ long deliveryTime = msg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive Message");
+ Message msgRecv = (Message) consumer.receive(timeout);
+ if (msgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive Message");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in Message");
+ if (msgRecv.getBooleanProperty("booleanProperty") == true) {
+ logger.log(Logger.Level.INFO, "booleanproperty is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanproperty is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Send BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ producer.send(destination, bMsg);
+ deliveryTime = bMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive BytesMessage");
+ BytesMessage bMsgRecv = (BytesMessage) consumer.receive(timeout);
+ if (bMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive BytesMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in BytesMessage");
+ if (bMsgRecv.readByte() == (byte) 1) {
+ logger.log(Logger.Level.INFO, "bytevalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "bytevalue is incorrect");
+ pass = false;
+ }
+ if (bMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send MapMessage");
+ MapMessage mMsg = context.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ producer.send(destination, mMsg);
+ deliveryTime = mMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive MapMessage");
+ MapMessage mMsgRecv = (MapMessage) consumer.receive(timeout);
+ if (mMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive MapMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in MapMessage");
+ Enumeration list = mMsgRecv.getMapNames();
+ String name = null;
+ while (list.hasMoreElements()) {
+ name = (String) list.nextElement();
+ if (name.equals("booleanvalue")) {
+ if (mMsgRecv.getBoolean(name) == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "booleanvalue is incorrect");
+ pass = false;
+ }
+ } else if (name.equals("intvalue")) {
+ if (mMsgRecv.getInt(name) == 10) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "intvalue is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected name of [" + name + "] in MapMessage");
+ pass = false;
+ }
+ }
+ }
+
+ // send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Send ObjectMessage");
+ StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ ObjectMessage oMsg = context.createObjectMessage();
+ oMsg.setObject(sb1);
+ oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ producer.send(destination, oMsg);
+ deliveryTime = oMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive ObjectMessage");
+ ObjectMessage oMsgRecv = (ObjectMessage) consumer.receive(timeout);
+ if (oMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive ObjectMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in ObjectMessage");
+ StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
+ if (sb2.toString().equals(sb1.toString())) {
+ logger.log(Logger.Level.INFO, "objectvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "objectvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive ObjectMessage passing object as param
+ logger.log(Logger.Level.INFO, "Send ObjectMessage passing object as param");
+ sb1 = new StringBuffer("This is a StringBuffer");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage passing object as param");
+ oMsg = context.createObjectMessage(sb1);
+ oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ producer.send(destination, oMsg);
+ deliveryTime = oMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive ObjectMessage");
+ oMsgRecv = (ObjectMessage) consumer.receive(timeout);
+ if (oMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive ObjectMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in ObjectMessage");
+ StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
+ if (sb2.toString().equals(sb1.toString())) {
+ logger.log(Logger.Level.INFO, "objectvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "objectvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive StreamMessage
+ logger.log(Logger.Level.INFO, "Send StreamMessage");
+ StreamMessage sMsg = context.createStreamMessage();
+ logger.log(Logger.Level.INFO, "Set some values in StreamMessage");
+ sMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ sMsg.writeBoolean(true);
+ sMsg.writeInt((int) 22);
+ producer.send(destination, sMsg);
+ deliveryTime = sMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive StreamMessage");
+ StreamMessage sMsgRecv = (StreamMessage) consumer.receive(timeout);
+ if (sMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive StreamMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in StreamMessage");
+ if (sMsgRecv.readBoolean() == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanvalue is incorrect");
+ pass = false;
+ }
+ if (sMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Send TextMessage");
+ TextMessage tMsg = context.createTextMessage();
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ tMsg.setText("Hello There!");
+ producer.send(destination, tMsg);
+ deliveryTime = tMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage tMsgRecv = (TextMessage) consumer.receive(timeout);
+ if (tMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (tMsgRecv.getText().equals("Hello There!")) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive TextMessage passing string as param
+ logger.log(Logger.Level.INFO, "Send TextMessage");
+ tMsg = context.createTextMessage("Where are you!");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ producer.send(destination, tMsg);
+ deliveryTime = tMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ tMsgRecv = (TextMessage) consumer.receive(timeout);
+ if (tMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (tMsgRecv.getText().equals("Where are you!")) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvMsgsOfEachMsgTypeTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvMsgsOfEachMsgTypeTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1192; JMS:JAVADOC:1259;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setDeliveryMode(int). JMSProducer.getDeliveryMode().
+ */
+ @Test
+ public void setGetDeliveryModeTest() throws Exception {
+ boolean pass = true;
+
+ // Test default case
+ try {
+ int expDeliveryMode = DeliveryMode.PERSISTENT;
+ logger.log(Logger.Level.INFO, "Calling getDeliveryMode and expect " + expDeliveryMode + " to be returned");
+ int actDeliveryMode = producer.getDeliveryMode();
+ if (actDeliveryMode != expDeliveryMode) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryMode() returned " + actDeliveryMode + ", expected " + expDeliveryMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDeliveryModeTest");
+ }
+
+ // Test non-default case
+ try {
+ int expDeliveryMode = DeliveryMode.NON_PERSISTENT;
+ logger.log(Logger.Level.INFO, "Calling setDeliveryMode(" + expDeliveryMode + ")");
+ producer.setDeliveryMode(expDeliveryMode);
+ logger.log(Logger.Level.INFO, "Calling getDeliveryMode and expect " + expDeliveryMode + " to be returned");
+ int actDeliveryMode = producer.getDeliveryMode();
+ if (actDeliveryMode != expDeliveryMode) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryMode() returned " + actDeliveryMode + ", expected " + expDeliveryMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDeliveryModeTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetDeliveryModeTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetDeliveryDelayTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1190; JMS:JAVADOC:1257;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setDeliveryDelay(long). JMSProducer.getDeliveryDelay().
+ */
+ @Test
+ public void setGetDeliveryDelayTest() throws Exception {
+ boolean pass = true;
+
+ // Test default case
+ try {
+ long expDeliveryDelay = 0L;
+ logger.log(Logger.Level.INFO,
+ "Calling getDeliveryDelay and expect " + expDeliveryDelay + " to be returned");
+ long actDeliveryDelay = producer.getDeliveryDelay();
+ if (actDeliveryDelay != expDeliveryDelay) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryDelay() returned " + actDeliveryDelay + ", expected " + expDeliveryDelay);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDeliveryDelayTest");
+ }
+
+ // Test non-default case
+ try {
+ long expDeliveryDelay = 1L;
+ logger.log(Logger.Level.INFO, "Calling setDeliveryDelay(" + expDeliveryDelay + ")");
+ producer.setDeliveryDelay(expDeliveryDelay);
+ logger.log(Logger.Level.INFO,
+ "Calling getDeliveryDelay and expect " + expDeliveryDelay + " to be returned");
+ long actDeliveryDelay = producer.getDeliveryDelay();
+ if (actDeliveryDelay != expDeliveryDelay) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryDelay() returned " + actDeliveryDelay + ", expected " + expDeliveryDelay);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDeliveryDelayTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetDeliveryDelayTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1194; JMS:JAVADOC:1261;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setDisableMessageID(boolean). JMSProducer.getDisableMessageID().
+ */
+ @Test
+ public void setGetDisableMessageIDTest() throws Exception {
+ boolean pass = true;
+ // Test default case
+ try {
+ boolean expDisableMessageID = true;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageID(" + expDisableMessageID + ")");
+ producer.setDisableMessageID(expDisableMessageID);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageID and expect " + expDisableMessageID + " to be returned");
+ boolean actDisableMessageID = producer.getDisableMessageID();
+ if (actDisableMessageID != expDisableMessageID) {
+ logger.log(Logger.Level.ERROR,
+ "getDisableMessageID() returned " + actDisableMessageID + ", expected " + expDisableMessageID);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDisableMessageIDTest");
+ }
+
+ // Test non-default case
+ try {
+ boolean expDisableMessageID = false;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageID(" + expDisableMessageID + ")");
+ producer.setDisableMessageID(expDisableMessageID);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageID and expect " + expDisableMessageID + " to be returned");
+ boolean actDisableMessageID = producer.getDisableMessageID();
+ if (actDisableMessageID != expDisableMessageID) {
+ logger.log(Logger.Level.ERROR,
+ "getDisableMessageID() returned " + actDisableMessageID + ", expected " + expDisableMessageID);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDisableMessageIDTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetDisableMessageIDTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1196; JMS:JAVADOC:1263;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setDisableMessageTimestamp(boolean).
+ * JMSProducer.getDisableMessageTimestamp().
+ */
+ @Test
+ public void setGetDisableMessageTimestampTest() throws Exception {
+ boolean pass = true;
+ // Test default case
+ try {
+ boolean expDisableMessageTimestamp = true;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageTimestamp(" + expDisableMessageTimestamp + ")");
+ producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageTimestamp and expect " + expDisableMessageTimestamp + " to be returned");
+ boolean actDisableMessageTimestamp = producer.getDisableMessageTimestamp();
+ if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
+ logger.log(Logger.Level.ERROR, "getDisableMessageTimestamp() returned " + actDisableMessageTimestamp
+ + ", expected " + expDisableMessageTimestamp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDisableMessageTimestampTest");
+ }
+
+ // Test non-default case
+ try {
+ boolean expDisableMessageTimestamp = false;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageTimestamp(" + expDisableMessageTimestamp + ")");
+ producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageTimestamp and expect " + expDisableMessageTimestamp + " to be returned");
+ boolean actDisableMessageTimestamp = producer.getDisableMessageTimestamp();
+ if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
+ logger.log(Logger.Level.ERROR, "getDisableMessageTimestamp() returned " + actDisableMessageTimestamp
+ + ", expected " + expDisableMessageTimestamp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDisableMessageTimestampTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetDisableMessageTimestampTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetPriorityTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1220; JMS:JAVADOC:1273;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setPriority(int). JMSProducer.getPriority().
+ */
+ @Test
+ public void setGetPriorityTest() throws Exception {
+ boolean pass = true;
+ try {
+ // Test default
+ int expPriority = Message.DEFAULT_PRIORITY;
+ logger.log(Logger.Level.INFO, "Calling getPriority and expect " + expPriority + " to be returned");
+ int actPriority = producer.getPriority();
+ if (actPriority != expPriority) {
+ logger.log(Logger.Level.ERROR, "getPriority() returned " + actPriority + ", expected " + expPriority);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetPriorityTest");
+ }
+
+ // Test non-default
+ int expPriority[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
+ // Cycle through all priorties
+ for (int i = 0; i < expPriority.length; i++) {
+ try {
+ logger.log(Logger.Level.INFO, "Calling setPriority(" + expPriority[i] + ")");
+ producer.setPriority(expPriority[i]);
+ logger.log(Logger.Level.INFO, "Calling getPriority and expect " + expPriority[i] + " to be returned");
+ int actPriority = producer.getPriority();
+ if (actPriority != expPriority[i]) {
+ logger.log(Logger.Level.ERROR,
+ "getPriority() returned " + actPriority + ", expected " + expPriority[i]);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetPriorityTest");
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("setGetPriorityTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1230; JMS:JAVADOC:1303;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setTimeToLive(long). JMSProducer.getTimeToLive().
+ */
+ @Test
+ public void setGetTimeToLiveTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ // Test default
+ long expTimeToLive = 0;
+ logger.log(Logger.Level.INFO, "Calling getTimeToLive and expect " + expTimeToLive + " to be returned");
+ long actTimeToLive = producer.getTimeToLive();
+ if (actTimeToLive != expTimeToLive) {
+ logger.log(Logger.Level.ERROR,
+ "getTimeToLive() returned " + actTimeToLive + ", expected " + expTimeToLive);
+ pass = false;
+ }
+
+ // Test non-default
+ expTimeToLive = 1000;
+ logger.log(Logger.Level.INFO, "Calling setTimeToLive(" + expTimeToLive + ")");
+ producer.setTimeToLive(expTimeToLive);
+ logger.log(Logger.Level.INFO, "Calling getTimeToLive and expect " + expTimeToLive + " to be returned");
+ actTimeToLive = producer.getTimeToLive();
+ if (actTimeToLive != expTimeToLive) {
+ logger.log(Logger.Level.ERROR,
+ "getTimeToLive() returned " + actTimeToLive + ", expected " + expTimeToLive);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetTimeToLiveTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetTimeToLiveTest failed");
+ }
+ }
+
+ /*
+ * @testName: deliveryDelayTest
+ *
+ * @assertion_ids: JMS:SPEC:261; JMS:SPEC:256; JMS:JAVADOC:1257;
+ *
+ * @test_Strategy: Send message and verify that message is not delivered until
+ * the DeliveryDelay of 20 seconds is reached. Test DeliveryMode.PERSISTENT and
+ * DeliveryMode.NON_PERSISTENT.
+ */
+ @Test
+ public void deliveryDelayTest() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------------------------------------------------");
+ logger.log(Logger.Level.INFO, "BEGIN TEST deliveryDelayTest with DeliveryDelay=20Secs");
+ logger.log(Logger.Level.INFO, "------------------------------------------------------");
+ producer.setDeliveryDelay(20000);
+
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage message = context.createTextMessage("This is a test!");
+
+ logger.log(Logger.Level.INFO, "Set StringProperty COM_SUN_JMS_TESTNAME");
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "deliveryDelayTest");
+
+ logger.log(Logger.Level.INFO, "Sending message with DeliveryMode.PERSISTENT and DeliveryDelay=20Secs");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ producer.setPriority(Message.DEFAULT_PRIORITY);
+ producer.setTimeToLive(0L);
+ producer.send(destination, message);
+
+ logger.log(Logger.Level.INFO, "Waiting 10 seconds to receive message");
+ message = (TextMessage) consumer.receive(10000);
+ if (message != null) {
+ logger.log(Logger.Level.ERROR, "FAILED: Message received before delivery delay of 20 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Didn't receive message after 10 seconds (CORRECT)");
+ logger.log(Logger.Level.INFO, "Sleeping 5 more seconds before receiving message");
+ Thread.sleep(5000);
+ logger.log(Logger.Level.INFO, "Waiting 10 more seconds to receive message");
+ message = (TextMessage) consumer.receive(10000);
+ if (message == null) {
+ logger.log(Logger.Level.ERROR,
+ "FAILED: Message was not received after delivery delay of 20 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message after 20 secs elapsed (CORRECT)");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Sending message with DeliveryMode.NON_PERSISTENT and DeliveryDelay=20Secs");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ producer.setPriority(Message.DEFAULT_PRIORITY);
+ producer.setTimeToLive(0L);
+ producer.send(destination, message);
+
+ logger.log(Logger.Level.INFO, "Waiting 10 seconds to receive message");
+ message = (TextMessage) consumer.receive(10000);
+ if (message != null) {
+ logger.log(Logger.Level.ERROR, "FAILED: Message received before delivery delay of 20 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Didn't receive message after 10 seconds (CORRECT)");
+ logger.log(Logger.Level.INFO, "Sleeping 5 more seconds before receiving message");
+ Thread.sleep(5000);
+ logger.log(Logger.Level.INFO, "Waiting 10 more seconds to receive message");
+ message = (TextMessage) consumer.receive(10000);
+ if (message == null) {
+ logger.log(Logger.Level.ERROR,
+ "FAILED: Message was not received after delivery delay of 20 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message after 20 secs elapsed (CORRECT)");
+ }
+ }
+ logger.log(Logger.Level.INFO, "----------------------------------------------------");
+ logger.log(Logger.Level.INFO, "END TEST deliveryDelayTest with DeliveryDelay=20Secs");
+ logger.log(Logger.Level.INFO, "----------------------------------------------------");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("deliveryDelayTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("deliveryDelayTest failed");
+ }
+ }
+
+ /*
+ * @testName: msgHdrMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343; JMS:JAVADOC:1261;
+ * JMS:JAVADOC:1194;
+ *
+ * @test_Strategy: Send to a Queue and receive Text, Map, Bytes, Stream, and
+ * Object message. Call getJMSMessageID and verify that it starts with ID:
+ */
+ @Test
+ public void msgHdrMessageIDTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ String id = null;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ producer.setDisableMessageID(false);
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.INFO, "Send ObjectMessage to Queue.");
+ messageSentO = context.createObjectMessage();
+ messageSentO.setObject("msgHdrMessageIDTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrMessageIDTest");
+ producer.send(destination, messageSentO);
+ logger.log(Logger.Level.INFO, "Receive ObjectMessage from Queue.");
+ messageReceivedO = (ObjectMessage) consumer.receive(timeout);
+ if (messageReceivedO == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "getJMSMessageID=" + messageReceivedO.getJMSMessageID());
+ id = messageReceivedO.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Objectessage JMSMessageID pass");
+ }
+ }
+ // send and receive map message to Queue
+ logger.log(Logger.Level.INFO, "Send MapMessage to Queue.");
+ messageSentM = context.createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrMessageIDTest");
+ messageSentM.setString("aString", "value");
+ producer.send(destination, messageSentM);
+ logger.log(Logger.Level.INFO, "Receive MapMessage from Queue.");
+ messageReceivedM = (MapMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "getJMSMessageID=" + messageReceivedM.getJMSMessageID());
+ id = messageReceivedM.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "MapMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSMessageID pass");
+ }
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.INFO, "Send BytesMessage to Queue.");
+ messageSentB = context.createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrMessageIDTest");
+ messageSentB.writeByte(bValue);
+ producer.send(destination, messageSentB);
+ logger.log(Logger.Level.INFO, "Receive BytesMessage from Queue.");
+ messageReceivedB = (BytesMessage) consumer.receive(timeout);
+ if (messageReceivedB == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "getJMSMessageID=" + messageReceivedB.getJMSMessageID());
+ id = messageReceivedB.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "BytesMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSMessageID pass");
+ }
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.INFO, "Send StreamMessage to Queue");
+ messageSentS = context.createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrMessageIDTest");
+ messageSentS.writeString("Testing...");
+ logger.log(Logger.Level.INFO, "Sending message");
+ producer.send(destination, messageSentS);
+ logger.log(Logger.Level.INFO, "Receive StreamMessage from Queue.");
+ messageReceivedS = (StreamMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "getJMSMessageID=" + messageReceivedS.getJMSMessageID());
+ id = messageReceivedS.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "StreamMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSMessageID pass");
+ }
+ }
+
+ // TextMessage
+ logger.log(Logger.Level.INFO, "Send TextMessage to Queue");
+ messageSent = context.createTextMessage();
+ messageSent.setText("sending a TextMessage");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrMessageIDTest");
+ producer.send(destination, messageSent);
+ logger.log(Logger.Level.INFO, "Receive TextMessage from Queue.");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "getJMSMessageID=" + messageReceived.getJMSMessageID());
+ id = messageReceived.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "TextMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage JMSMessageID pass");
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSMessageID returned from JMSMessageID");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrMessageIDTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrTimeStampTest
+ *
+ * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347; JMS:JAVADOC:1263;
+ * JMS:JAVADOC:1196;
+ *
+ * @test_Strategy: Send to a Queue a single Text, map, bytes, stream, and object
+ * message. Call getJMSTimestamp() and check time of send against time send
+ * returns. JMSTimeStamp should be between these two
+ */
+ @Test
+ public void msgHdrTimeStampTest() throws Exception {
+ boolean pass = true;
+ long timeBeforeSend;
+ long timeAfterSend;
+ byte bValue = 127;
+
+ try {
+ TextMessage messageSent = null;
+ StreamMessage messageSentS = null;
+ BytesMessage messageSentB = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+
+ producer.setDisableMessageTimestamp(false);
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.INFO, "Send ObjectMessage to Queue.");
+ messageSentO = context.createObjectMessage();
+ messageSentO.setObject("msgHdrTimeStampTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTest");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentO);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "getJMSTimestamp=" + messageSentO.getJMSTimestamp());
+ logger.log(Logger.Level.INFO, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentO.getJMSTimestamp())
+ && (timeAfterSend >= messageSentO.getJMSTimestamp())) {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSTimeStamp pass");
+ } else {
+ logger.log(Logger.Level.ERROR, "ObjectMessage invalid JMSTimeStamp failed");
+ pass = false;
+ }
+
+ // send map message to Queue
+ logger.log(Logger.Level.INFO, "Send MapMessage to Queue.");
+ messageSentM = context.createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTest");
+ messageSentM.setString("aString", "value");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentM);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "getJMSTimestamp=" + messageSentM.getJMSTimestamp());
+ logger.log(Logger.Level.INFO, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentM.getJMSTimestamp())
+ && (timeAfterSend >= messageSentM.getJMSTimestamp())) {
+ logger.log(Logger.Level.INFO, "MapMessage JMSTimeStamp pass");
+ } else {
+ logger.log(Logger.Level.ERROR, "MapMessage invalid JMSTimeStamp failed");
+ pass = false;
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.INFO, "Send BytesMessage to Queue.");
+ messageSentB = context.createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTest");
+ messageSentB.writeByte(bValue);
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentB);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "getJMSTimestamp=" + messageSentB.getJMSTimestamp());
+ logger.log(Logger.Level.INFO, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentB.getJMSTimestamp())
+ && (timeAfterSend >= messageSentB.getJMSTimestamp())) {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSTimeStamp pass");
+ } else {
+ logger.log(Logger.Level.ERROR, "BytesMessage invalid JMSTimeStamp failed");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.INFO, "Send StreamMessage to Queue");
+ messageSentS = context.createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTest");
+ messageSentS.writeString("Testing...");
+ logger.log(Logger.Level.INFO, "Sending message");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentS);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "getJMSTimestamp=" + messageSentS.getJMSTimestamp());
+ logger.log(Logger.Level.INFO, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentS.getJMSTimestamp())
+ && (timeAfterSend >= messageSentS.getJMSTimestamp())) {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSTimeStamp pass");
+ } else {
+ logger.log(Logger.Level.ERROR, "StreamMessage invalid JMSTimeStamp failed");
+ pass = false;
+ }
+
+ // TextMessage
+ logger.log(Logger.Level.INFO, "Send TextMessage to Queue");
+ messageSent = context.createTextMessage();
+ messageSent.setText("sending a TextMessage to Queue");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTest");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSent);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "getJMSTimestamp=" + messageSent.getJMSTimestamp());
+ logger.log(Logger.Level.INFO, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSent.getJMSTimestamp()) && (timeAfterSend >= messageSent.getJMSTimestamp())) {
+ logger.log(Logger.Level.INFO, "TextMessage JMSTimeStamp pass");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage invalid JMSTimeStamp failed");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrTimeStampTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140; JMS:JAVADOC:1220;
+ * JMS:JAVADOC:1273; JMS:JAVADOC:383;
+ *
+ * @test_Strategy: Send a message to a Queue with JMSPriority set to 2 test with
+ * Text, map, object, byte, and stream messages Call getJMSPriorty() and check
+ * that it matches the priority that was set on the JMSContext.
+ */
+ @Test
+ public void msgHdrJMSPriorityTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ int priority2 = 2;
+ int priority4 = 4;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ logger.log(Logger.Level.INFO, "Setting priority to 2");
+ producer.setPriority(priority2);
+
+ messageSent = context.createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTest");
+ logger.log(Logger.Level.INFO, "JMSPriority test - Send a TextMessage to Queue");
+ producer.send(destination, messageSent);
+ logger.log(Logger.Level.INFO, "JMSPriority test - Recv a TextMessage from Queue");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "JMSPriority is " + messageReceived.getJMSPriority());
+ if (messageReceived.getJMSPriority() == priority2) {
+ logger.log(Logger.Level.INFO, "TextMessage JMSPriority passed");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage JMSPriority failed");
+ pass = false;
+ }
+ }
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.INFO, "JMSPriority test - Send ObjectMessage to Queue.");
+ messageSentO = context.createObjectMessage();
+ messageSentO.setObject("msgHdrJMSPriorityTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTest");
+ producer.send(destination, messageSentO);
+ logger.log(Logger.Level.INFO, "JMSPriority test - Recv a ObjectMessage from Queue");
+ messageReceivedO = (ObjectMessage) consumer.receive(timeout);
+ if (messageReceivedO == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "JMSPriority is " + messageReceivedO.getJMSPriority());
+ if (messageReceivedO.getJMSPriority() == priority2) {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSPriority passed");
+ } else {
+ logger.log(Logger.Level.ERROR, "ObjectMessage JMSPriority failed");
+ pass = false;
+ }
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.INFO, "JMSPriority test - Send MapMessage to Queue.");
+ messageSentM = context.createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTest");
+ messageSentM.setString("aString", "value");
+ producer.send(destination, messageSentM);
+ logger.log(Logger.Level.INFO, "JMSPriority test - Recv a MapMessage from Queue");
+ messageReceivedM = (MapMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "JMSPriority is " + messageReceivedM.getJMSPriority());
+ if (messageReceivedM.getJMSPriority() == priority2) {
+ logger.log(Logger.Level.INFO, "MapMessage JMSPriority passed");
+ } else {
+ logger.log(Logger.Level.ERROR, "MapMessage JMSPriority failed");
+ pass = false;
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Setting priority to 4");
+ producer.setPriority(priority4);
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.INFO, "JMSPriority test - Send BytesMessage to Queue.");
+ messageSentB = context.createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTest");
+ messageSentB.writeByte(bValue);
+ producer.send(destination, messageSentB);
+ logger.log(Logger.Level.INFO, "JMSPriority test - Recv a BytesMessage from Queue");
+ messageReceivedB = (BytesMessage) consumer.receive(timeout);
+ if (messageReceivedB == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "JMSPriority is " + messageReceivedB.getJMSPriority());
+ if (messageReceivedB.getJMSPriority() == priority4) {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSPriority passed");
+ } else {
+ logger.log(Logger.Level.ERROR, "BytesMessage JMSPriority failed");
+ pass = false;
+ }
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.INFO, "JMSPriority test - Send a StreamMessage to Queue");
+ messageSentS = context.createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTest");
+ messageSentS.writeString("Testing...");
+ producer.send(destination, messageSentS);
+ logger.log(Logger.Level.INFO, "JMSPriority test - Recv a StreamMessage from Queue");
+ messageReceivedS = (StreamMessage) consumer.receive(timeout);
+ if (messageReceivedS == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "JMSPriority is " + messageReceivedS.getJMSPriority());
+ if (messageReceivedS.getJMSPriority() == priority4) {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSPriority passed");
+ } else {
+ logger.log(Logger.Level.ERROR, "StreamMessage JMSPriority failed");
+ pass = false;
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSPriority returned from JMS Header");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrJMSPriorityTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSExpirationTest
+ *
+ * @assertion_ids: JMS:SPEC:15.1; JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140;
+ * JMS:JAVADOC:1303; JMS:JAVADOC:379;
+ *
+ * @test_Strategy: 1. Send a message to a Queue with time to live set to 0.
+ * Verify on receive that JMSExpiration gets set to 0. Test with Text, Map,
+ * Object, Bytes, and Stream messages. 2. Send a message to a Queue with time to
+ * live set to non-0; Verify on receive that JMSExpiration gets set correctly.
+ */
+ @Test
+ public void msgHdrJMSExpirationTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ long forever = 0L;
+ long timeToLive = 5000L;
+ String testName = "msgHdrJMSExpirationTest";
+ long timeBeforeSend = 0L;
+ long timeAfterSend = 0L;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a TextMessage (timeToLive is forever)");
+ messageSent = context.createTextMessage();
+ messageSent.setText("sending a TextMessage");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ producer.setTimeToLive(forever);
+ producer.send(destination, messageSent);
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceived.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.ERROR, "TextMessage JMSExpiration failed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage JMSExpiration passed");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a TextMessage (timeToLive is 5000)");
+ producer.setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSent);
+ timeAfterSend = System.currentTimeMillis();
+
+ long exp = messageSent.getJMSExpiration();
+ logger.log(Logger.Level.INFO, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.INFO, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.INFO, "Time to Live =" + timeToLive);
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceived.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "TextMessage failed: JMSExpiration didn't set correctly = "
+ + messageReceived.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage JMSExpiration passed");
+ }
+ }
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a ObjectMessage (timeToLive is forever)");
+ messageSentO = context.createObjectMessage();
+ messageSentO.setObject("msgHdrJMSExpirationTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ producer.setTimeToLive(forever);
+ producer.send(destination, messageSentO);
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a ObjectMessage");
+ messageReceivedO = (ObjectMessage) consumer.receive(timeout);
+ if (messageReceivedO == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedO.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSExpiration failed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSExpiration passed");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a ObjectMessage (timeToLive is 5000)");
+ producer.setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentO);
+ timeAfterSend = System.currentTimeMillis();
+
+ exp = messageSentO.getJMSExpiration();
+ logger.log(Logger.Level.INFO, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.INFO, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.INFO, "Time to Live =" + timeToLive);
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a ObjectMessage");
+ messageReceivedO = (ObjectMessage) consumer.receive(timeout);
+ if (messageReceivedO == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedO.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage failed: JMSExpiration didn't set correctly = "
+ + messageReceivedO.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSExpiration passed");
+ }
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a MapMessage (timeToLive is forever)");
+ messageSentM = context.createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentM.setString("aString", "value");
+ producer.setTimeToLive(forever);
+ producer.send(destination, messageSentM);
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a MapMessage");
+ messageReceivedM = (MapMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedM.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.INFO, "MapMessage JMSExpiration failed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSExpiration passed");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a MapMessage (timeToLive is 5000)");
+ producer.setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentM);
+ timeAfterSend = System.currentTimeMillis();
+
+ exp = messageSentM.getJMSExpiration();
+ logger.log(Logger.Level.INFO, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.INFO, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.INFO, "Time to Live =" + timeToLive);
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a MapMessage");
+ messageReceivedM = (MapMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedM.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "MapMessage failed: JMSExpiration didn't set correctly = "
+ + messageReceivedM.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSExpiration passed");
+ }
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a Bytesessage (timeToLive is forever)");
+ messageSentB = context.createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentB.writeByte(bValue);
+ producer.setTimeToLive(forever);
+ producer.send(destination, messageSentB);
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a BytesMessage");
+ messageReceivedB = (BytesMessage) consumer.receive(timeout);
+ if (messageReceivedB == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedB.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSExpiration failed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSExpiration passed");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a Bytesessage (timeToLive is 5000)");
+ producer.setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentB);
+ timeAfterSend = System.currentTimeMillis();
+
+ exp = messageSentB.getJMSExpiration();
+ logger.log(Logger.Level.INFO, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.INFO, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.INFO, "Time to Live =" + timeToLive);
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a BytesMessage");
+ messageReceivedB = (BytesMessage) consumer.receive(timeout);
+ if (messageReceivedB == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedB.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "BytesMessage failed: JMSExpiration didn't set correctly = "
+ + messageReceivedB.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSExpiration passed");
+ }
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a Streamessage (timeToLive is forever)");
+ messageSentS = context.createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentS.writeString("Testing...");
+ producer.setTimeToLive(forever);
+ producer.send(destination, messageSentS);
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a StreamMessage");
+ messageReceivedS = (StreamMessage) consumer.receive(timeout);
+ if (messageReceivedS == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedS.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSExpiration failed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSExpiration passed");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a StreamMessage (timeToLive is 5000)");
+ producer.setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentS);
+ timeAfterSend = System.currentTimeMillis();
+
+ exp = messageSentS.getJMSExpiration();
+ logger.log(Logger.Level.INFO, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.INFO, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.INFO, "Time to Live =" + timeToLive);
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a StreamMessage");
+ messageReceivedS = (StreamMessage) consumer.receive(timeout);
+ if (messageReceivedS == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedS.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "StreamMessage failed: JMSExpiration didn't set correctly = "
+ + messageReceivedS.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSExpiration passed");
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("Error: invalid JMSExpiration returned from JMS Header");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:3; JMS:SPEC:140; JMS:SPEC:246.2; JMS:JAVADOC:1192;
+ * JMS:JAVADOC:1259; JMS:JAVADOC:367;
+ *
+ * @test_Strategy: 1. Create and send a message to the default Queue. Receive
+ * the msg and verify that JMSDeliveryMode is set the default delivery mode of
+ * persistent. 2. Create and test another message with a nonpersistent delivery
+ * mode. Test with Text, map, object, byte, and stream messages 3. Set
+ * JMSDeliveryMode to Message after receive. Verify that JMSDeliveryMode is set
+ * correctly.
+ */
+ @Test
+ public void msgHdrJMSDeliveryModeTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ String testName = "msgHdrJMSDeliveryModeTest";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ // send and receive Text message to Queue
+ logger.log(Logger.Level.INFO, "send TextMessage to Queue with DeliveryMode.PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ messageSent = context.createTextMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ producer.send(destination, messageSent);
+ logger.log(Logger.Level.INFO, "receive TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TextMessage is null (unexpected)");
+ } else if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TextMessage failed: JMSDeliveryMode should be set to persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage JMSDeliveryMode passed");
+ }
+
+ logger.log(Logger.Level.INFO, "send TextMessage to Queue with DeliveryMode.NON_PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ messageSent = context.createTextMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ producer.send(destination, messageSent);
+ logger.log(Logger.Level.INFO, "receive TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TextMessage is null (unexpected)");
+ } else if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TextMessage failed: JMSDeliveryMode should be set to non persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage JMSDeliveryMode passed");
+ }
+
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.INFO, "send ObjectMessage to Queue with DeliveryMode.PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ messageSentO = context.createObjectMessage();
+ messageSentO.setObject("Test for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ producer.send(destination, messageSentO);
+ logger.log(Logger.Level.INFO, "receive ObjectMessage");
+ messageReceivedO = (ObjectMessage) consumer.receive(timeout);
+ if (messageReceivedO == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "ObjectMessage is null (unexpected)");
+ } else if (messageReceivedO.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "ObjectMessage failed: JMSDeliveryMode should be set to persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSDeliveryMode passed");
+ }
+
+ logger.log(Logger.Level.INFO, "send ObjectMessage to Queue with DeliveryMode.NON_PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ messageSentO = context.createObjectMessage();
+ messageSentO.setObject("Test for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ producer.send(destination, messageSentO);
+ logger.log(Logger.Level.INFO, "receive ObjectMessage");
+ messageReceivedO = (ObjectMessage) consumer.receive(timeout);
+ if (messageReceivedO == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "ObjectMessage is null (unexpected)");
+ } else if (messageReceivedO.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "ObjectMessage failed: JMSDeliveryMode should be set to non persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSDeliveryMode passed");
+ }
+
+ // send and receive map message to Queue
+ logger.log(Logger.Level.INFO, "send MapMessage to Queue with DeliveryMode.PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ messageSentM = context.createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentM.setString("aString", "value");
+ producer.send(destination, messageSentM);
+ logger.log(Logger.Level.INFO, "receive MapMessage");
+ messageReceivedM = (MapMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "MapMessage is null (unexpected)");
+ } else if (messageReceivedM.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "MapMessage failed: JMSDeliveryMode should be set to persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSDeliveryMode passed");
+ }
+
+ logger.log(Logger.Level.INFO, "send MapMessage to Queue with DeliveryMode.NON_PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ messageSentM = context.createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentM.setString("aString", "value");
+ producer.send(destination, messageSentM);
+ logger.log(Logger.Level.INFO, "receive MapMessage");
+ messageReceivedM = (MapMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "MapMessage is null (unexpected)");
+ } else if (messageReceivedM.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "MapMessage failed: JMSDeliveryMode should be set to non persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSDeliveryMode passed");
+ }
+
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.INFO, "send BytesMessage to Queue with DeliveryMode.PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ messageSentB = context.createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentB.writeByte(bValue);
+ producer.send(destination, messageSentB);
+ logger.log(Logger.Level.INFO, "receive BytesMessage");
+ messageReceivedB = (BytesMessage) consumer.receive(timeout);
+ if (messageReceivedB == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "BytesMessage is null (unexpected)");
+ } else if (messageReceivedB.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "BytesMessage failed: JMSDeliveryMode should be set to persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSDeliveryMode passed");
+ }
+
+ logger.log(Logger.Level.INFO, "send BytesMessage to Queue with DeliveryMode.NON_PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ messageSentB = context.createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentB.writeByte(bValue);
+ producer.send(destination, messageSentB);
+ logger.log(Logger.Level.INFO, "receive BytesMessage");
+ messageReceivedB = (BytesMessage) consumer.receive(timeout);
+ if (messageReceivedB == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "BytesMessage is null (unexpected)");
+ } else if (messageReceivedB.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "BytesMessage failed: JMSDeliveryMode should be set to non persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSDeliveryMode passed");
+ }
+
+ // send and receive a StreamMessage
+ logger.log(Logger.Level.INFO, "send StreamMessage to Queue with DeliveryMode.PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ messageSentS = context.createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentS.writeString("Testing...");
+ producer.send(destination, messageSentS);
+ logger.log(Logger.Level.INFO, "receive StreamMessage");
+ messageReceivedS = (StreamMessage) consumer.receive(timeout);
+ if (messageReceivedS == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "StreamMessage is null (unexpected)");
+ } else if (messageReceivedS.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "StreamMessage failed: JMSDeliveryMode should be set to persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSDeliveryMode passed");
+ }
+
+ logger.log(Logger.Level.INFO, "send StreamMessage to Queue with DeliveryMode.NON_PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ messageSentS = context.createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentS.writeString("Testing...");
+ producer.send(destination, messageSentS);
+ logger.log(Logger.Level.INFO, "receive StreamMessage");
+ messageReceivedS = (StreamMessage) consumer.receive(timeout);
+ if (messageReceivedS == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "StreamMessage is null (unexpected)");
+ } else if (messageReceivedS.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "StreamMessage failed: JMSDeliveryMode should be set to non persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSDeliveryMode passed");
+ }
+
+ if (!pass) {
+ throw new Exception("Error: invalid JMSDeliveryMode returned from JMS Header");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSDeliveryTimeTest
+ *
+ * @assertion_ids: JMS:SPEC:246.11; JMS:SPEC:261; JMS:SPEC:256;
+ * JMS:JAVADOC:1257; JMS:JAVADOC:875;
+ *
+ * @test_Strategy: Send message and verify that JMSDeliveryTime is correct with
+ * the DeliveryDelay set to 20 seconds. Test with DeliveryMode.PERSISTENT and
+ * DeliveryMode.NON_PERSISTENT.
+ *
+ * Retrieve and verify the JMSDeliveryTime
+ */
+ @Test
+ public void msgHdrJMSDeliveryTimeTest() throws Exception {
+ boolean pass = true;
+ try {
+
+ long gmtTimebeforeSend = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "---------------------------------------------------------------");
+ logger.log(Logger.Level.INFO, "BEGIN TEST msgHdrJMSDeliveryTimeTest with DeliveryDelay=20Secs");
+ logger.log(Logger.Level.INFO, "---------------------------------------------------------------");
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage messageSnd = context.createTextMessage("This is a test!");
+
+ logger.log(Logger.Level.INFO, "Set StringProperty COM_SUN_JMS_TESTNAME");
+ messageSnd.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDeliveryTimeTest");
+
+ logger.log(Logger.Level.INFO, "Sending message with DeliveryMode.PERSISTENT and DeliveryDelay=20Secs");
+ producer.setDeliveryDelay(20000);
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ producer.setPriority(Message.DEFAULT_PRIORITY);
+ producer.setTimeToLive(0L);
+ producer.send(destination, messageSnd);
+
+ // Get deliverytime and current GMT time after send
+ logger.log(Logger.Level.INFO, "Get JMSDeliveryTime after sending message");
+ long deliverydelay = producer.getDeliveryDelay();
+ long gmtTimeAfterSend = System.currentTimeMillis();
+ long JMSDeliveryTimeAfterSend = messageSnd.getJMSDeliveryTime();
+
+ logger.log(Logger.Level.INFO, "Receive message with timeout value of 21Secs");
+ TextMessage messageRcv = (TextMessage) consumer.receive(21000);
+ if (messageRcv == null) {
+ logger.log(Logger.Level.ERROR,
+ "FAILED: Message was not received after delivery delay of 20 secs elapsed");
+ pass = false;
+ } else {
+ // Get JMSDeliverytime after receive
+ logger.log(Logger.Level.INFO, "Get JMSDeliveryTime after receiving message");
+ long gmtTimeAfterRecv = System.currentTimeMillis();
+ long JMSDeliveryTimeAfterRecv = messageRcv.getJMSDeliveryTime();
+
+ logger.log(Logger.Level.INFO, "Check JMSDeliverytime");
+ logger.log(Logger.Level.INFO, "JMSDeliveryTime after send = " + JMSDeliveryTimeAfterSend);
+ logger.log(Logger.Level.INFO, "JMSDeliveryTime after receive = " + JMSDeliveryTimeAfterRecv);
+ if (JMSDeliveryTimeAfterSend == JMSDeliveryTimeAfterRecv) {
+ logger.log(Logger.Level.INFO, "JMSDeliveryTimeAfterSend = JMSDeliveryTimeAfterRecv (PASS)");
+ } else {
+ logger.log(Logger.Level.ERROR, "JMSDeliveryTimeAfterSend != JMSDeliveryTimeAfterRecv (FAIL)");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "gmtTimeAfterSend after send = " + gmtTimeAfterSend);
+ logger.log(Logger.Level.INFO, "gmtTimeAfterRecv after receive = " + gmtTimeAfterRecv);
+ if (gmtTimeAfterRecv >= (gmtTimebeforeSend + deliverydelay)) {
+ logger.log(Logger.Level.INFO, "gmtTimeAfterRecv >= (gmtTimeAfterSend + deliverydelay) (PASS)");
+ } else {
+ logger.log(Logger.Level.ERROR, "gmtTimeAfterRecv < (gmtTimeAfterSend + deliverydelay) (FAIL)");
+ pass = false;
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Sending message with DeliveryMode.NON_PERSISTENT and DeliveryDelay=20Secs");
+ producer.setDeliveryDelay(20000);
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ producer.setPriority(Message.DEFAULT_PRIORITY);
+ producer.setTimeToLive(0L);
+ producer.send(destination, messageSnd);
+
+ // Get deliverytime and current GMT time after send
+ logger.log(Logger.Level.INFO, "Get JMSDeliveryTime after sending message");
+ gmtTimeAfterSend = System.currentTimeMillis();
+ JMSDeliveryTimeAfterSend = messageSnd.getJMSDeliveryTime();
+
+ logger.log(Logger.Level.INFO, "Receive message with timeout value of 21Secs");
+ messageRcv = (TextMessage) consumer.receive(21000);
+ if (messageRcv == null) {
+ logger.log(Logger.Level.ERROR,
+ "FAILED: Message was not received after delivery delay of 20 secs elapsed");
+ pass = false;
+ } else {
+ // Get JMSDeliverytime after receive
+ logger.log(Logger.Level.INFO, "Get JMSDeliveryTime after receiving message");
+ long gmtTimeAfterRecv = System.currentTimeMillis();
+ long JMSDeliveryTimeAfterRecv = messageRcv.getJMSDeliveryTime();
+
+ logger.log(Logger.Level.INFO, "Check JMSDeliverytime");
+ logger.log(Logger.Level.INFO, "JMSDeliveryTime after send = " + JMSDeliveryTimeAfterSend);
+ logger.log(Logger.Level.INFO, "JMSDeliveryTime after receive = " + JMSDeliveryTimeAfterRecv);
+ if (JMSDeliveryTimeAfterSend == JMSDeliveryTimeAfterRecv) {
+ logger.log(Logger.Level.INFO, "JMSDeliveryTimeAfterSend = JMSDeliveryTimeAfterRecv (PASS)");
+ } else {
+ logger.log(Logger.Level.ERROR, "JMSDeliveryTimeAfterSend != JMSDeliveryTimeAfterRecv (FAIL)");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "gmtTimeAfterSend after send = " + gmtTimeAfterSend);
+ logger.log(Logger.Level.INFO, "gmtTimeAfterRecv after receive = " + gmtTimeAfterRecv);
+ if (gmtTimeAfterRecv >= (gmtTimebeforeSend + deliverydelay)) {
+ logger.log(Logger.Level.INFO, "gmtTimeAfterRecv >= (gmtTimeAfterSend + deliverydelay) (PASS)");
+ } else {
+ logger.log(Logger.Level.ERROR, "gmtTimeAfterRecv < (gmtTimeAfterSend + deliverydelay) (FAIL)");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "-------------------------------------------------------------");
+ logger.log(Logger.Level.INFO, "END TEST msgHdrJMSDeliveryTimeTest with DeliveryDelay=20Secs");
+ logger.log(Logger.Level.INFO, "-------------------------------------------------------------");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrJMSDeliveryTimeTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("msgHdrJMSDeliveryTimeTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetAllPropertyTypesTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1180; JMS:JAVADOC:1184; JMS:JAVADOC:1187;
+ * JMS:JAVADOC:1198; JMS:JAVADOC:1201; JMS:JAVADOC:1204; JMS:JAVADOC:1215;
+ * JMS:JAVADOC:1218; JMS:JAVADOC:1222; JMS:JAVADOC:1224; JMS:JAVADOC:1227;
+ * JMS:JAVADOC:1232; JMS:JAVADOC:1275; JMS:JAVADOC:1278; JMS:JAVADOC:1281;
+ * JMS:JAVADOC:1284; JMS:JAVADOC:1287; JMS:JAVADOC:1290; JMS:JAVADOC:1293;
+ * JMS:JAVADOC:1296; JMS:JAVADOC:1299;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setProperty(String, boolean) JMSProducer.setProperty(String,
+ * byte) JMSProducer.setProperty(String, double) JMSProducer.setProperty(String,
+ * float) JMSProducer.setProperty(String, int) JMSProducer.setProperty(String,
+ * long) JMSProducer.setProperty(String, Object) JMSProducer.setProperty(String,
+ * short) JMSProducer.setProperty(String, String)
+ * JMSProducer.getBooleanProperty(String) JMSProducer.getByteProperty(String)
+ * JMSProducer.getDoubleProperty(String) JMSProducer.getFloatProperty(String)
+ * JMSProducer.getIntProperty(String) JMSProducer.getLongProperty(String)
+ * JMSProducer.getObjectProperty(String) JMSProducer.getShortProperty(String)
+ * JMSProducer.getStringProperty(String) JMSProducer.clearProperties(String)
+ * JMSProducer.getPropertyNames() JMSProducer.propertyExists()
+ */
+ @Test
+ public void setGetAllPropertyTypesTest() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ int numPropertyNames = 16;
+
+ try {
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create a JMSProducer from JMSContext");
+
+ producer = context.createProducer();
+
+ logger.log(Logger.Level.INFO, "Set all JMSProducer properties");
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTSTRING", "test");
+ producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
+ producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
+ producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
+ producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
+ producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
+ producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
+ producer.setProperty("OBJTESTSTRING", "test");
+
+ logger.log(Logger.Level.INFO, "Get all JMSProducer properties");
+ if (producer.getBooleanProperty("TESTBOOLEAN") == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getBooleanProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getBooleanProperty");
+ pass = false;
+ }
+ if (producer.getByteProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getByteProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getByteProperty");
+ pass = false;
+ }
+ if (producer.getLongProperty("TESTLONG") == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getLongProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getLongProperty");
+ pass = false;
+ }
+ if (producer.getStringProperty("TESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getStringProperty");
+ pass = false;
+ }
+ if (producer.getDoubleProperty("TESTDOUBLE") == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getDoubleProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getDoubleProperty");
+ pass = false;
+ }
+ if (producer.getFloatProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getFloatProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getFloatProperty");
+ pass = false;
+ }
+ if (producer.getIntProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getIntProperty");
+ pass = false;
+ }
+ if (producer.getShortProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getShortProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getShortProperty");
+ pass = false;
+ }
+ if (((Boolean) producer.getObjectProperty("OBJTESTBOOLEAN")).booleanValue() == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Boolean value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Byte) producer.getObjectProperty("OBJTESTBYTE")).byteValue() == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Byte value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Long) producer.getObjectProperty("OBJTESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Long value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Long value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((String) producer.getObjectProperty("OBJTESTSTRING")).equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct String value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect String value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Double) producer.getObjectProperty("OBJTESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Double value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Double value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Float) producer.getObjectProperty("OBJTESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Float value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Float value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Integer) producer.getObjectProperty("OBJTESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Integer value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Integer value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Short) producer.getObjectProperty("OBJTESTSHORT")).shortValue() == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Short value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Short value returned from getObjectProperty");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Now check all property names returned by JMSProducer.getPropertyNames()");
+ // iterate thru the property names
+ int i = 0;
+ Set propNames = producer.getPropertyNames();
+ Iterator iterator = propNames.iterator();
+ do {
+ String tmp = iterator.next();
+
+ if (!tmp.startsWith("JMS")) {
+ i++;
+ if (tmp.equals("TESTBOOLEAN") || tmp.equals("TESTBYTE") || tmp.equals("TESTINT")
+ || tmp.equals("TESTSHORT") || tmp.equals("TESTFLOAT") || tmp.equals("TESTDOUBLE")
+ || tmp.equals("TESTSTRING") || tmp.equals("TESTLONG") || tmp.equals("OBJTESTBOOLEAN")
+ || tmp.equals("OBJTESTBYTE") || tmp.equals("OBJTESTINT") || tmp.equals("OBJTESTSHORT")
+ || tmp.equals("OBJTESTFLOAT") || tmp.equals("OBJTESTDOUBLE") || tmp.equals("OBJTESTSTRING")
+ || tmp.equals("OBJTESTLONG")) {
+ logger.log(Logger.Level.INFO, "Producer Property set by client: " + tmp);
+ } else {
+ logger.log(Logger.Level.ERROR, "Producer Property not set by client: " + tmp);
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.INFO, "JMSProperty Name is: " + tmp);
+ }
+ } while (iterator.hasNext());
+ if (i == numPropertyNames) {
+ logger.log(Logger.Level.INFO, "Pass: # of properties is " + numPropertyNames + " as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: expected " + numPropertyNames + " property names, but got " + i);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("setGetAllPropertyTypesTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetAllPropertyTypesTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetAllHeaderTypesTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1265; JMS:JAVADOC:1267; JMS:JAVADOC:1269;
+ * JMS:JAVADOC:1271; JMS:JAVADOC:1207; JMS:JAVADOC:1209; JMS:JAVADOC:1211;
+ * JMS:JAVADOC:1213;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setJMSCorrelationID(String);
+ * JMSProducer.setJMSCorrelationIDAsBytes(byte[]);
+ * JMSProducer.setJMSReplyTo(Destination); JMSProducer.setJMSType(String);
+ * JMSProducer.getJMSCorrelationID(); JMSProducer.getJMSCorrelationIDAsBytes();
+ * JMSProducer.getJMSReplyTo(); JMSProducer.getJMSType();
+ */
+ @Test
+ public void setGetAllHeaderTypesTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create a JMSProducer from JMSContext");
+
+ producer = context.createProducer();
+
+ try {
+ logger.log(Logger.Level.INFO, "Set JMSProducer message header JMSCorrelationID as bytes");
+ byte[] cid = "TestCorrelationID".getBytes();
+ producer.setJMSCorrelationIDAsBytes(cid);
+
+ logger.log(Logger.Level.INFO, "Get JMSProducer message header JMSCorrelationID as bytes");
+ cid = producer.getJMSCorrelationIDAsBytes();
+ String cidString = new String(cid);
+ if (cid == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned null");
+ pass = false;
+ } else if (cidString.equals("TestCorrelationID")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSCorrelationID returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned incorrect value, got: "
+ + cidString + " expected: TestCorrelationID");
+ pass = false;
+ }
+ } catch (java.lang.UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "UnsupportedOperationException - no further testing.");
+ }
+
+ logger.log(Logger.Level.INFO, "Set all JMSProducer message headers JMSCorrelationID, JMSType, JMSReplyTo");
+ producer.setJMSCorrelationID("TestCorrelationID");
+ producer.setJMSType("TestMessage");
+ producer.setJMSReplyTo(destination);
+
+ logger.log(Logger.Level.INFO, "Get all JMSProducer message headers JMSCorrelationID, JMSType, JMSReplyTo");
+ String temp = null;
+ Destination tempdest = null;
+ temp = producer.getJMSCorrelationID();
+ if (temp == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned null");
+ pass = false;
+ } else if (temp.equals("TestCorrelationID")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSCorrelationID returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned incorrect value, got: " + temp
+ + " expected: TestCorrelationID");
+ pass = false;
+ }
+ temp = producer.getJMSType();
+ if (temp == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSType returned null");
+ pass = false;
+ } else if (temp.equals("TestMessage")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSType returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Fail: getJMSType returned incorrect value, got: " + temp + " expected: TestMessage");
+ pass = false;
+ }
+ tempdest = producer.getJMSReplyTo();
+ if (tempdest == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSReplyTo returned null");
+ pass = false;
+ } else if (tempdest.equals(destination)) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSReplyTo returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Fail: getJMSReplyTo returned incorrect value, got: " + tempdest + " expected: " + destination);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("setGetAllHeaderTypesTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetAllHeaderTypesTest failed");
+ }
+ }
+
+ /*
+ * @testName: msgPropertiesTest
+ *
+ * @assertion_ids: JMS:SPEC:20.1; JMS:SPEC:20.2; JMS:SPEC:20.3; JMS:SPEC:20.4;
+ * JMS:SPEC:20.5; JMS:SPEC:20.6; JMS:SPEC:20.7; JMS:SPEC:20.8; JMS:SPEC:21;
+ * JMS:SPEC:23; JMS:SPEC:25; JMS:SPEC:26; JMS:SPEC:10; JMS:SPEC:27; JMS:SPEC:28;
+ * JMS:SPEC:29; JMS:SPEC:31; JMS:SPEC:32; JMS:SPEC:34; JMS:SPEC:19; JMS:SPEC:70;
+ * JMS:SPEC:71; JMS:SPEC:24; JMS:JAVADOC:1180; JMS:JAVADOC:1184;
+ * JMS:JAVADOC:1187; JMS:JAVADOC:1198; JMS:JAVADOC:1201; JMS:JAVADOC:1204;
+ * JMS:JAVADOC:1215; JMS:JAVADOC:1218; JMS:JAVADOC:1222; JMS:JAVADOC:1224;
+ * JMS:JAVADOC:1227; JMS:JAVADOC:1232; JMS:JAVADOC:1275; JMS:JAVADOC:1278;
+ * JMS:JAVADOC:1281; JMS:JAVADOC:1284; JMS:JAVADOC:1287; JMS:JAVADOC:1290;
+ * JMS:JAVADOC:1293; JMS:JAVADOC:1296; JMS:JAVADOC:1299;
+ *
+ * @test_Strategy: Set and read properties for boolean, byte, short, int, long,
+ * float, double, and String. Verify expected results Set and read properties
+ * for Boolean, Byte, Short, Int, Long, Float, Double, and String. Verify
+ * expected results.
+ *
+ * Call property get methods (other than getStringProperty and
+ * getObjectProperty) for non-existent properties and verify that a null pointer
+ * exception is returned. Call getStringProperty and getObjectProperty for
+ * non-existent properties and verify that a null is returned.
+ *
+ * Set object properties and verify the correct value is returned with the
+ * getObjectProperty method.
+ *
+ * Call the clearProperties method on the JMSProducer and verify that the
+ * message properties for that JMSProducer were deleted. Test that
+ * getObjectProperty returns a null and the getShortProperty throws a null
+ * pointer exception.
+ *
+ * Call getJMSXPropertyNames() and verify that the names of the required JMSX
+ * properties for JMSXGroupID and JMSXGroupSeq are returned.
+ */
+ @Test
+ public void msgPropertiesTest() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ Enumeration propertyNames = null;
+ Enumeration jmsxDefined = null;
+ int numPropertyNames = 18;
+ String testMessageBody = "Testing...";
+ String message = "Where are you!";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // ------------------------------------------------------------------------------
+ // Set JMSProducer message properties
+ // Set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Set primitive property types on JMSProducer");
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTSTRING", "test");
+
+ // ------------------------------------------------------------------------------
+ // Set JMSProducer message properties
+ // Set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Set Object property types on JMSProducer");
+ producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
+ producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
+ producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
+ producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
+ producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
+ producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
+ producer.setProperty("OBJTESTSTRING", "test");
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ messageSent = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "messageSent=" + messageSent.getText());
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesTest");
+ producer.send(destination, messageSent);
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ logger.log(Logger.Level.INFO, "messageReceived=" + messageReceived.getText());
+
+ // Iterate thru the property names
+ int i = 0;
+ logger.log(Logger.Level.INFO, "Retrieve and verify correct # of properties set");
+ propertyNames = messageReceived.getPropertyNames();
+ do {
+ String tmp = (String) propertyNames.nextElement();
+ logger.log(Logger.Level.INFO, "Property Name is: " + tmp);
+ if (tmp.indexOf("JMS") != 0)
+ i++;
+ else if (tmp.equals("JMSXDeliveryCount"))
+ i++;
+ } while (propertyNames.hasMoreElements());
+
+ if (i == numPropertyNames) {
+ logger.log(Logger.Level.INFO, "Pass: # of properties is " + numPropertyNames + " as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: expected " + numPropertyNames + " property names, but got " + i);
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------------
+ // Retrieve the JMSProducer properties and verify that they are correct
+ // Get properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Retrieve and verify that JMSProducer properties were set correctly");
+ logger.log(Logger.Level.INFO,
+ "Get properties for boolean, byte, short, int, long, float, double, and String.");
+ if (producer.getBooleanProperty("TESTBOOLEAN") == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getBooleanProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getBooleanProperty");
+ pass = false;
+ }
+ if (producer.getByteProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getByteProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getByteProperty");
+ pass = false;
+ }
+ if (producer.getLongProperty("TESTLONG") == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getLongProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getLongProperty");
+ pass = false;
+ }
+ if (producer.getStringProperty("TESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getStringProperty");
+ pass = false;
+ }
+ if (producer.getDoubleProperty("TESTDOUBLE") == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getDoubleProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getDoubleProperty");
+ pass = false;
+ }
+ if (producer.getFloatProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getFloatProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getFloatProperty");
+ pass = false;
+ }
+ if (producer.getIntProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getIntProperty");
+ pass = false;
+ }
+ if (producer.getShortProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getShortProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getShortProperty");
+ pass = false;
+ }
+
+ // -----------------------------------------------------------------------------
+ // Retrieve the JMSProducer properties and verify that they are correct
+ // Get properties for Boolean, Byte, Short, Integer, Long, Float, Double,
+ // String.
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO,
+ "Get properties for Boolean, Byte, Short, Integer, Long, Float, Double, String.");
+ if (((Boolean) producer.getObjectProperty("OBJTESTBOOLEAN")).booleanValue() == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Boolean value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Byte) producer.getObjectProperty("OBJTESTBYTE")).byteValue() == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Byte value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Long) producer.getObjectProperty("OBJTESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Long value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Long value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((String) producer.getObjectProperty("OBJTESTSTRING")).equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct String value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect String value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Double) producer.getObjectProperty("OBJTESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Double value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Double value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Float) producer.getObjectProperty("OBJTESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Float value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Float value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Integer) producer.getObjectProperty("OBJTESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Integer value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Integer value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Short) producer.getObjectProperty("OBJTESTSHORT")).shortValue() == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Short value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Short value returned from getObjectProperty");
+ pass = false;
+ }
+
+ // ---------------------------------------------------------------------------
+ // Set JMSProducer message headers (Set JMSCorrelationID, JMSType,
+ // JMSReplyTo)
+ // ---------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Set message headers JMSCorrelationID, JMSType, JMSReplyTo on JMSProducer");
+ producer.setJMSCorrelationID("TestCorrelationID");
+ producer.setJMSType("TestMessage");
+ producer.setJMSReplyTo(destination);
+
+ // ---------------------------------------------------------------------------
+ // Retrieve JMSProducer message headers and verify that they are set
+ // correctly
+ // ---------------------------------------------------------------------------
+ String temp = null;
+ Destination tempdest = null;
+ temp = producer.getJMSCorrelationID();
+ if (temp == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned null");
+ pass = false;
+ } else if (temp.equals("TestCorrelationID")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSCorrelationID returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned incorrect value, got: " + temp
+ + " expected: TestCorrelationID");
+ pass = false;
+ }
+ temp = producer.getJMSType();
+ if (temp == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSType returned null");
+ pass = false;
+ } else if (temp.equals("TestMessage")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSType returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Fail: getJMSType returned incorrect value, got: " + temp + " expected: TestMessage");
+ pass = false;
+ }
+ tempdest = producer.getJMSReplyTo();
+ if (tempdest == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSReplyTo returned null");
+ pass = false;
+ } else if (tempdest.equals(destination)) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSReplyTo returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Fail: getJMSReplyTo returned incorrect value, got: " + tempdest + " expected: " + destination);
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------------
+ // Create a TextMessage, send it then receive it and verify that all the
+ // JMSProducer
+ // properties are set in the TextMessage
+ // --------------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Create a TextMessage");
+ messageSent = context.createTextMessage();
+ messageSent.setText(testMessageBody);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesTest");
+
+ logger.log(Logger.Level.INFO, "Send the TextMessage");
+ producer.send(destination, messageSent);
+ logger.log(Logger.Level.INFO, "messageSent=" + messageSent.getText());
+
+ logger.log(Logger.Level.INFO, "Receive the TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ logger.log(Logger.Level.INFO, "messageReceived=" + messageReceived.getText());
+
+ // --------------------------------------------------------------------------------------
+ // Retrieve the properties from the received TextMessage and verify that
+ // they are correct
+ // Get properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // -------------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Retrieve and verify that TextMessage message properties were set correctly");
+ if (messageReceived.getBooleanProperty("TESTBOOLEAN") == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getBooleanProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getBooleanProperty");
+ pass = false;
+ }
+ if (messageReceived.getByteProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getByteProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getByteProperty");
+ pass = false;
+ }
+ if (messageReceived.getLongProperty("TESTLONG") == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getLongProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getLongProperty");
+ pass = false;
+ }
+ if (messageReceived.getStringProperty("TESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getStringProperty");
+ pass = false;
+ }
+ if (messageReceived.getDoubleProperty("TESTDOUBLE") == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getDoubleProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getDoubleProperty");
+ pass = false;
+ }
+ if (messageReceived.getFloatProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getFloatProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getFloatProperty");
+ pass = false;
+ }
+ if (messageReceived.getIntProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getIntProperty");
+ pass = false;
+ }
+ if (messageReceived.getShortProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getShortProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getShortProperty");
+ pass = false;
+ }
+ if (messageReceived.getIntProperty("JMSXDeliveryCount") >= 1) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty(JMSXDeliveryCount) returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getIntProperty(JMSXDeliveryCount)");
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------------
+ // Retrieve the properties from the received TextMessage and verify that
+ // they are correct
+ // Get properties for Boolean, Byte, Short, Integer, Long, Float, Double,
+ // and String.
+ // --------------------------------------------------------------------------------------
+ if (((Boolean) messageReceived.getObjectProperty("OBJTESTBOOLEAN")).booleanValue() == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Boolean value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Byte) messageReceived.getObjectProperty("OBJTESTBYTE")).byteValue() == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Byte value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Long) messageReceived.getObjectProperty("OBJTESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Long value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Long value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((String) messageReceived.getObjectProperty("OBJTESTSTRING")).equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct String value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect String value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Double) messageReceived.getObjectProperty("OBJTESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Double value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Double value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Float) messageReceived.getObjectProperty("OBJTESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Float value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Float value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Integer) messageReceived.getObjectProperty("OBJTESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Integer value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Integer value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Short) messageReceived.getObjectProperty("OBJTESTSHORT")).shortValue() == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Short value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Short value returned from getObjectProperty");
+ pass = false;
+ }
+
+ // ---------------------------------------------------------------------------------------
+ // Retrieve message headers from the received TextMessage and verify that
+ // they are correct
+ // ---------------------------------------------------------------------------------------
+ temp = messageReceived.getJMSCorrelationID();
+ if (temp == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned null");
+ pass = false;
+ } else if (temp.equals("TestCorrelationID")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSCorrelationID returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned incorrect value, got: " + temp
+ + " expected: TestCorrelationID");
+ pass = false;
+ }
+ temp = messageReceived.getJMSType();
+ if (temp == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSType returned null");
+ pass = false;
+ } else if (temp.equals("TestMessage")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSType returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Fail: getJMSType returned incorrect value, got: " + temp + " expected: TestMessage");
+ pass = false;
+ }
+ tempdest = messageReceived.getJMSReplyTo();
+ if (tempdest == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSReplyTo returned null");
+ pass = false;
+ } else if (tempdest.equals(destination)) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSReplyTo returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Fail: getJMSReplyTo returned incorrect value, got: " + tempdest + " expected: " + destination);
+ pass = false;
+ }
+
+ // ----------------------------------------------------------------------------------
+ // The other property get methods (other than getStringProperty and
+ // getObjectProperty)
+ // must behave as if the property exists with a null value
+ // ----------------------------------------------------------------------------------
+ try {
+ boolean b = producer.getBooleanProperty("TESTDUMMY");
+ if (b != false) {
+ logger.log(Logger.Level.INFO, "Fail: should have received false for getBooleanProperty");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ byte value = producer.getByteProperty("TESTDUMMY");
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException should have occurred for getByteProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.INFO, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ short value = producer.getShortProperty("TESTDUMMY");
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException should have occurred for getShortProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.INFO, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ int value = producer.getIntProperty("TESTDUMMY");
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException should have occurred for getIntProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.INFO, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ long value = producer.getLongProperty("TESTDUMMY");
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException should have occurred for getLongProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.INFO, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ float value = producer.getFloatProperty("TESTDUMMY");
+ logger.log(Logger.Level.INFO, "Fail: NullPointerException should have occurred for getFloatProperty");
+ pass = false;
+ } catch (java.lang.NullPointerException np) {
+ logger.log(Logger.Level.INFO, "Pass: NullPointerException as expected ");
+ }
+ try {
+ double value = producer.getDoubleProperty("TESTDUMMY");
+ logger.log(Logger.Level.INFO, "Fail: NullPointerException should have occurred for getDoubleProperty");
+ pass = false;
+ } catch (java.lang.NullPointerException np) {
+ logger.log(Logger.Level.INFO, "Pass: NullPointerException as expected ");
+ }
+
+ // clear JMSProducer properties
+ producer.clearProperties();
+
+ // -------------------------------------------------------------------
+ // All JMSProducer properties are deleted by the clearProperties method.
+ // This leaves the message with an empty set of properties.
+ // -------------------------------------------------------------------
+ Long aLong = (Long) producer.getObjectProperty("OBJTESTLONG");
+ if (aLong == null) {
+ logger.log(Logger.Level.INFO, "Pass: property was cleared");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: getObjectProperty should have returned null for cleared property");
+ pass = false;
+ }
+ try {
+ short aShort = producer.getShortProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException should have occurred for getShortProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.INFO, "Pass: NumberFormatException as expected ");
+ }
+
+ // Check that we have no property names
+ Set propNames = producer.getPropertyNames();
+ Iterator iterator = propNames.iterator();
+ boolean hasElements = iterator.hasNext();
+ if (hasElements) {
+ logger.log(Logger.Level.INFO, "Fail: JMSProducer.getPropertyName() has properties (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Pass: JMSProducer.getPropertyName() has no properties (expected)");
+ }
+ // -------------------------------------------------------------------
+ // JMSContext.getJMSXPropertyNames() method returns the
+ // names of the JMSX properties supported by a connection.
+ // -------------------------------------------------------------------
+ try {
+ ConnectionMetaData data = context.getMetaData();
+ Enumeration cmd = data.getJMSXPropertyNames();
+ String propName;
+
+ if (cmd == null) {
+ logger.log(Logger.Level.INFO, "Fail: no JMSX property names were returned!");
+ logger.log(Logger.Level.INFO,
+ "expected JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount at a miniumum");
+ pass = false;
+ } else {
+ int iCount = 0;
+ do {
+ propName = (String) cmd.nextElement();
+ logger.log(Logger.Level.INFO, propName);
+ if (propName.equals("JMSXGroupID") || propName.equals("JMSXGroupSeq")
+ || propName.equals("JMSXDeliveryCount")) {
+ iCount++;
+ }
+ } while (cmd.hasMoreElements());
+ if (iCount > 1) {
+ logger.log(Logger.Level.INFO, "Pass:");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Expected property names not returned");
+ pass = false;
+ }
+ }
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: unexpected exception: " + ee);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("msgPropertiesTest failed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ e.printStackTrace();
+ throw new Exception("msgPropertiesTest failed");
+ }
+ }
+
+ /*
+ * @testName: msgPropertiesConversionTests
+ *
+ * @assertion_ids: JMS:SPEC:22.1; JMS:SPEC:22.2; JMS:SPEC:22.3; JMS:SPEC:22.4;
+ * JMS:SPEC:22.5; JMS:SPEC:22.6; JMS:SPEC:22.7; JMS:SPEC:22.8; JMS:SPEC:22.9;
+ * JMS:SPEC:22.10; JMS:SPEC:22.11; JMS:SPEC:22.12; JMS:SPEC:22.13;
+ * JMS:SPEC:22.14; JMS:SPEC:22.15; JMS:SPEC:22.16; JMS:JAVADOC:1180;
+ * JMS:JAVADOC:1184; JMS:JAVADOC:1187; JMS:JAVADOC:1198; JMS:JAVADOC:1201;
+ * JMS:JAVADOC:1204; JMS:JAVADOC:1215; JMS:JAVADOC:1218; JMS:JAVADOC:1222;
+ * JMS:JAVADOC:1224; JMS:JAVADOC:1227; JMS:JAVADOC:1232; JMS:JAVADOC:1275;
+ * JMS:JAVADOC:1278; JMS:JAVADOC:1281; JMS:JAVADOC:1284; JMS:JAVADOC:1287;
+ * JMS:JAVADOC:1290; JMS:JAVADOC:1293; JMS:JAVADOC:1296; JMS:JAVADOC:1299;
+ * JMS:JAVADOC:1186; JMS:JAVADOC:1189; JMS:JAVADOC:1200; JMS:JAVADOC:1203;
+ * JMS:JAVADOC:1206; JMS:JAVADOC:1217; JMS:JAVADOC:1226; JMS:JAVADOC:1229;
+ *
+ * @test_Strategy: Create a JMSProducer, set properties for all of the primitive
+ * types verify the conversion by getting the properties.
+ */
+ @Test
+ public void msgPropertiesConversionTests() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ String testMessageBody = "Testing...";
+ int ntest = 0;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // ------------------------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTSTRING", "test");
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("TESTSTRINGTRUE", "true");
+ producer.setProperty("TESTSTRINGFALSE", "false");
+ producer.setProperty("TESTSTRING1", "1");
+
+ // -------------------------------------------------------------------
+ // test conversions for property values
+ // -------------------------------------------------------------------
+ // property set as boolean can be read only as string or boolean
+ // -------------------------------------------------------------------
+ // valid - boolean to string
+ String myBool = producer.getStringProperty("TESTBOOLEAN");
+
+ if (Boolean.valueOf(myBool).booleanValue() == bool) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from boolean to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from boolean to string failed");
+ pass = false;
+ }
+
+ // invalid - boolean to byte
+ try {
+ producer.getByteProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: boolean to byte ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- boolean to byte");
+ pass = false;
+ }
+
+ // invalid - boolean to short
+ try {
+ producer.getShortProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: boolean to short ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- boolean to short");
+ pass = false;
+ }
+
+ // invalid - boolean to int
+ try {
+ producer.getIntProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: boolean to int ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception --boolean to int ");
+ pass = false;
+ }
+
+ // invalid - boolean to long
+ try {
+ producer.getLongProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: boolean to long ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- boolean to long");
+ pass = false;
+ }
+
+ // invalid - boolean to float
+ try {
+ producer.getFloatProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: boolean to float ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- boolean to float");
+ pass = false;
+ }
+
+ // invalid - boolean to double
+ try {
+ producer.getDoubleProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: boolean to double ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- boolean to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as byte can be read as a byte,short,int,long or string
+ // valid - byte to string
+ String myByte = producer.getStringProperty("TESTBYTE");
+
+ if (Byte.valueOf(myByte).byteValue() == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from byte to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from byte to string failed");
+ pass = false;
+ }
+
+ // valid - byte to short
+ if (producer.getShortProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from byte to short - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from byte to short failed");
+ pass = false;
+ }
+
+ // valid - byte to int
+ if (producer.getIntProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from byte to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from byte to int failed");
+ pass = false;
+ }
+
+ // valid - byte to long
+ if (producer.getLongProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from byte to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from byte to long failed");
+ pass = false;
+ }
+
+ // invalid - byte to boolean
+ try {
+ producer.getBooleanProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: byte to boolean ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- byte to boolean");
+ pass = false;
+ }
+
+ // invalid - byte to float
+ try {
+ producer.getFloatProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: byte to float ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception --byte to float ");
+ pass = false;
+ }
+
+ // invalid - byte to double
+ try {
+ producer.getDoubleProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: byte to double ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- byte to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------
+ // property set as short can be read as short,int,long or string
+ // valid - short to string
+ String myshort = producer.getStringProperty("TESTSHORT");
+
+ if (Short.valueOf(myshort).shortValue() == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from short to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from short to string failed");
+ pass = false;
+ }
+
+ // valid - short to int
+ if (producer.getIntProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from short to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from short to int failed");
+ pass = false;
+ }
+
+ // valid - short to long
+ if (producer.getLongProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from short to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from short to long failed");
+ pass = false;
+ }
+
+ // invalid - short to boolean
+ try {
+ producer.getBooleanProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: short to boolean ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- short to boolean");
+ pass = false;
+ }
+
+ // invalid - short to byte
+ try {
+ producer.getByteProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: short to byte ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- short to byte");
+ pass = false;
+ }
+
+ // invalid - short to float
+ try {
+ producer.getFloatProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: short to float ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- short to float");
+ pass = false;
+ }
+
+ // invalid - short to double
+ try {
+ producer.getDoubleProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: short to double ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- short to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------
+ // property set as int can be read only as int, long or string
+ // valid - int to string
+ if (Integer.valueOf(producer.getStringProperty("TESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from int to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from int to string failed");
+ pass = false;
+ }
+
+ // valid - int to long
+ if (producer.getLongProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from int to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from int to long failed");
+ pass = false;
+ }
+
+ // invalid - int to boolean
+ try {
+ producer.getBooleanProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: int to boolean ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- int to boolean");
+ pass = false;
+ }
+
+ // invalid - int to byte
+ try {
+ producer.getByteProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: int to byte ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- int to byte");
+ pass = false;
+ }
+
+ // invalid - int to short
+ try {
+ producer.getShortProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: int to short ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected -- int to short ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception ");
+ pass = false;
+ }
+
+ // invalid - int to float
+ try {
+ producer.getFloatProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: int to float ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- int to float");
+ pass = false;
+ }
+
+ // invalid - int to double
+ try {
+ producer.getDoubleProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: int to double ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- int to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as long can be read only as long,or a string
+ // valid - long to string
+ if (Long.valueOf(producer.getStringProperty("TESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from long to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from long to string failed");
+ pass = false;
+ }
+
+ // invalid - long to boolean
+ try {
+ producer.getBooleanProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: long to boolean ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- long to boolean");
+ pass = false;
+ }
+
+ // invalid - long to byte
+ try {
+ producer.getByteProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: long to byte ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- long to byte");
+ pass = false;
+ }
+
+ // invalid - long to short
+ try {
+ producer.getShortProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: long to short ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- long to short ");
+ pass = false;
+ }
+
+ // invalid - long to int
+ try {
+ producer.getIntProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: long to int ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- long to int");
+ pass = false;
+ }
+
+ // invalid - long to float
+ try {
+ producer.getFloatProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: long to float ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- long to float");
+ pass = false;
+ }
+
+ // invalid - long to double
+ try {
+ producer.getDoubleProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: long to double ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- long to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as float can be read only as float,double or a string
+ // valid - float to string
+ if (Float.valueOf(producer.getStringProperty("TESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from float to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from float to string failed");
+ pass = false;
+ }
+
+ // valid - float to double
+ if (producer.getDoubleProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from long to double - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from long to double failed");
+ pass = false;
+ }
+
+ // invalid - float to boolean
+ try {
+ producer.getBooleanProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: float to boolean ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- float to boolean ");
+ pass = false;
+ }
+
+ // invalid - float to byte
+ try {
+ producer.getByteProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: float to byte ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- float to byte");
+ pass = false;
+ }
+
+ // invalid - float to short
+ try {
+ producer.getShortProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: float to short ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception - float to short ");
+ pass = false;
+ }
+
+ // invalid - float to int
+ try {
+ producer.getIntProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: float to int ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception --- float to int");
+ pass = false;
+ }
+
+ // invalid - float to long
+ try {
+ producer.getLongProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: float to long ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- float to long");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as double can be read only as double or string
+ // valid - double to string
+ if (Double.valueOf(producer.getStringProperty("TESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from double to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from double to string failed");
+ pass = false;
+ }
+
+ // invalid - double to boolean
+ try {
+ producer.getBooleanProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: double to boolean ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- double to boolean ");
+ pass = false;
+ }
+
+ // invalid - double to byte
+ try {
+ producer.getByteProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: double to byte ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- double to byte ");
+ pass = false;
+ }
+
+ // invalid - double to short
+ try {
+ producer.getShortProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: double to short ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- double to short");
+ pass = false;
+ }
+
+ // invalid - double to int
+ try {
+ producer.getIntProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: double to int ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception --- double to int ");
+ pass = false;
+ }
+
+ // invalid - double to long
+ try {
+ producer.getLongProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: double to long ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- double to long");
+ pass = false;
+ }
+
+ // invalid - double to float
+ try {
+ producer.getFloatProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: double to float ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- double to float");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as string can be read as boolean, byte, short,
+ // int, long, float, double, and String.
+ // valid - string to boolean
+ if ((producer.getBooleanProperty("TESTSTRINGTRUE")) == true) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to boolean - expect true - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to boolean - expect true - failed");
+ pass = false;
+ }
+ if ((producer.getBooleanProperty("TESTSTRINGFALSE")) == false) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to boolean expect false - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to boolean expect false - failed");
+ pass = false;
+ }
+
+ // valid - string to byte
+ if (producer.getByteProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to byte - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to byte failed");
+ pass = false;
+ }
+
+ // valid - string to short
+ if (producer.getShortProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to short - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to short failed");
+ pass = false;
+ }
+
+ // valid - string to int
+ if (producer.getIntProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to int failed");
+ pass = false;
+ }
+
+ // valid - string to long
+ if (producer.getLongProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to long failed");
+ pass = false;
+ }
+
+ // valid - string to float
+ if (producer.getFloatProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to float - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to float failed");
+ pass = false;
+ }
+
+ // valid - string to double
+ if (producer.getDoubleProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to double - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to double failed");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("msgPropertiesConversionTests failed");
+ }
+
+ if (!pass) {
+ throw new Exception("msgPropertiesConversionTests failed");
+ }
+ }
+
+ /*
+ * @testName: msgPropertyExistTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1180; JMS:JAVADOC:1184; JMS:JAVADOC:1187;
+ * JMS:JAVADOC:1198; JMS:JAVADOC:1201; JMS:JAVADOC:1204; JMS:JAVADOC:1215;
+ * JMS:JAVADOC:1218; JMS:JAVADOC:1222; JMS:JAVADOC:1224; JMS:JAVADOC:1227;
+ * JMS:JAVADOC:1232; JMS:JAVADOC:1275; JMS:JAVADOC:1278; JMS:JAVADOC:1281;
+ * JMS:JAVADOC:1284; JMS:JAVADOC:1287; JMS:JAVADOC:1290; JMS:JAVADOC:1293;
+ * JMS:JAVADOC:1296; JMS:JAVADOC:1299;
+ *
+ * @test_Strategy: Set and read properties for boolean, byte, short, int, long,
+ * float, double, and String. Verify expected results.
+ */
+ @Test
+ public void msgPropertyExistTest() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ Enumeration propertyNames = null;
+ String testMessageBody = "Testing msgPropertyExistTest";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // ------------------------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTSTRING", "test");
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+
+ // --------------------------------------------------------------------------------------
+ // Create a TextMessage, send it then receive it and verify that all the
+ // JMSProducer
+ // properties are set in the TextMessage
+ // --------------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Create a TextMessage");
+ messageSent = context.createTextMessage();
+ messageSent.setText(testMessageBody);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesTest");
+
+ logger.log(Logger.Level.INFO, "Send the TextMessage");
+ producer.send(destination, messageSent);
+
+ logger.log(Logger.Level.INFO, "Receive the TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "messageReceived is null (unexpected)");
+ } else {
+
+ // iterate thru the property names
+ int i = 0;
+ propertyNames = messageReceived.getPropertyNames();
+ do {
+ String tmp = (String) propertyNames.nextElement();
+
+ if (!tmp.startsWith("JMS")) {
+ i++;
+ if (tmp.equals("TESTBOOLEAN") || tmp.equals("TESTBYTE") || tmp.equals("TESTINT")
+ || tmp.equals("TESTSHORT") || tmp.equals("TESTFLOAT") || tmp.equals("TESTDOUBLE")
+ || tmp.equals("TESTSTRING") || tmp.equals("TESTLONG") || tmp.equals("OBJTESTBOOLEAN")
+ || tmp.equals("COM_SUN_JMS_TESTNAME")) {
+ logger.log(Logger.Level.INFO, "Application Property set by client is: " + tmp);
+ if (!messageReceived.propertyExists(tmp)) {
+ pass = messageReceived.propertyExists(tmp);
+ logger.log(Logger.Level.ERROR, "Positive propertyExists test failed for " + tmp);
+ } else if (messageReceived.propertyExists(tmp + "1")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Negative propertyExists test failed for " + tmp + "1");
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Appclication Property not set by client: " + tmp);
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.INFO, "JMSProperty Name is: " + tmp);
+ }
+ } while (propertyNames.hasMoreElements());
+ }
+
+ if (!pass) {
+ throw new Exception("msgPropertyExistTest failed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("msgPropertyExistTest failed");
+ }
+ }
+
+ /*
+ * @testName: msgJMSXPropertiesTest
+ *
+ * @assertion_ids: JMS:SPEC:34; JMS:SPEC:34.3; JMS:SPEC:34.4; JMS:SPEC:34.5;
+ * JMS:SPEC:257;
+ *
+ * @test_Strategy: Set and read JMSX properties JMSXGroupID and JMSXGroupSeq.
+ * Verify the value of the JMSX properties JMSXGroupID and JMSXGroupSeq are the
+ * same as set by client. Verify that the JMS provider sets the mandatory
+ * JMSXDeliveryCount.
+ *
+ * 1) Create JMSContext and JMSConsumer for Queue. 2) Create TextMessage and set
+ * JMSXGroupID and JMSXGroupSeq message properties. 3) Send the TextMessage to
+ * the Queue. 4) Receive the TextMessage from the Queue. 5) Verify the
+ * TextMessage. Verify that the message properites JMSXGroupID, JMSXGroupSeq,
+ * and JMSXDeliveryCount are correct.
+ */
+ @Test
+ public void msgJMSXPropertiesTest() throws Exception {
+ boolean pass = true;
+ String message = "Testing msgJMSXPropertiesTest";
+ int seq = 123450;
+ String id = "msgJMSXPropertiesTest";
+ try {
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+
+ logger.log(Logger.Level.INFO, "Set StringProperty COM_SUN_JMS_TESTNAME");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgJMSXPropertiesTest");
+
+ logger.log(Logger.Level.INFO, "Set JMSXGroupSeq and JMSXGroupSeq");
+ expTextMessage.setStringProperty("JMSXGroupID", id);
+ expTextMessage.setIntProperty("JMSXGroupSeq", seq);
+
+ logger.log(Logger.Level.INFO, "Send the TextMessage");
+ producer.send(destination, expTextMessage);
+
+ logger.log(Logger.Level.INFO, "Receive the TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+
+ logger.log(Logger.Level.INFO, "Verify the value in TextMessage");
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Verify properties JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount in TextMessage");
+ if (actTextMessage.propertyExists("JMSXGroupID")) {
+ if (actTextMessage.getStringProperty("JMSXGroupID").equals(id)) {
+ logger.log(Logger.Level.INFO, "Pass: getStringProperty(JMSXGroupID) returned correct value");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Fail: incorrect value returned from getStringProperty(JMSXGroupID)");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: TextMessage does not contain expected JMSXGroupID property");
+ pass = false;
+ }
+
+ if (actTextMessage.propertyExists("JMSXGroupSeq")) {
+ if (actTextMessage.getIntProperty("JMSXGroupSeq") == seq) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty(JMSXGroupSeq) returned correct value");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: incorrect value returned from getIntProperty(JMSXGroupSeq)");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: TextMessage does not contain expected JMSXGroupSeq property");
+ pass = false;
+ }
+
+ if (actTextMessage.propertyExists("JMSXDeliveryCount")) {
+ if (actTextMessage.getIntProperty("JMSXDeliveryCount") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty(JMSXDeliveryCount) returned correct value");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Fail: incorrect value returned from getIntProperty(JMSXDeliveryCount)");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Fail: TextMessage does not contain expected JMSXDeliveryCount property");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // ConnectionMetaData.getJMSXPropertyNames() method returns the
+ // names of the JMSX properties supported by a connection.
+ // -------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Verify the JMSXProperties in ConnectionMetaData");
+ try {
+ logger.log(Logger.Level.INFO, "Get ConnectionMetaData");
+ ConnectionMetaData data = context.getMetaData();
+ logger.log(Logger.Level.INFO, "Get JMSXPropertyNames");
+ Enumeration cmd = data.getJMSXPropertyNames();
+ logger.log(Logger.Level.INFO, "Verify that we have JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount");
+ if (cmd == null) {
+ logger.log(Logger.Level.ERROR, "No JMSX property names were returned (Failed)");
+ pass = false;
+ } else {
+ int iCount = 0;
+ do {
+ String propName = (String) cmd.nextElement();
+ logger.log(Logger.Level.TRACE, "Found JMSX property [" + propName + "]");
+ if (propName.equals("JMSXGroupID"))
+ iCount++;
+ else if (propName.equals("JMSXGroupSeq"))
+ iCount++;
+ else if (propName.equals("JMSXDeliveryCount"))
+ iCount++;
+ } while (cmd.hasMoreElements());
+
+ if (iCount > 2) {
+ logger.log(Logger.Level.INFO, "Expected JMSX property names were returned (Passed)");
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected JMSX property names not returned (Failed)");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("msgJMSXPropertiesTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("msgJMSXPropertiesTest failed");
+ }
+ }
+
+ /*
+ * @testName: setPropertyExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1280; JMS:JAVADOC:1283; JMS:JAVADOC:1286;
+ * JMS:JAVADOC:1289; JMS:JAVADOC:1292; JMS:JAVADOC:1295; JMS:JAVADOC:1298;
+ * JMS:JAVADOC:1301; JMS:JAVADOC:1277; JMS:JAVADOC:1302;
+ *
+ * @test_Strategy: Tests IllegalArgumentException and
+ * MessageFormatRuntimeException conditions from the following API's:
+ *
+ * JMSProducer.setProperty(String, boolean) throws IllegalArgumentException
+ * JMSProducer.setProperty(String, byte)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, double)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, float)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, int)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, long)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, Object)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, short)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, String)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, Object)throws MessageFormatRuntimeException
+ */
+ @Test
+ public void setPropertyExceptionTests() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+
+ try {
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create a JMSProducer from JMSContext");
+ producer = context.createProducer();
+
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException from all JMSProducer setProperty() API's");
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", boolean)");
+ producer.setProperty("", bool);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", byte)");
+ producer.setProperty("", bValue);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", double)");
+ producer.setProperty("", nDouble);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", float)");
+ producer.setProperty("", nFloat);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", int)");
+ producer.setProperty("", nInt);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", long)");
+ producer.setProperty("", nLong);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", short)");
+ producer.setProperty("", nShort);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", String)");
+ producer.setProperty("", "test");
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", Object)");
+ producer.setProperty("", Long.valueOf(nLong));
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, boolean)");
+ producer.setProperty(null, bool);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, byte)");
+ producer.setProperty(null, bValue);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, double)");
+ producer.setProperty(null, nDouble);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, float)");
+ producer.setProperty(null, nFloat);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, int)");
+ producer.setProperty(null, nInt);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, long)");
+ producer.setProperty(null, nLong);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, short)");
+ producer.setProperty(null, nShort);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, String)");
+ producer.setProperty(null, "test");
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, Object)");
+ producer.setProperty(null, Long.valueOf(nLong));
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO, "Test MessageFormatRuntimeException for setProperty(String, Object)");
+ producer.setProperty("name1", new ArrayList(2));
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setPropertyExceptionTests");
+ }
+
+ if (!pass) {
+ throw new Exception("setPropertyExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: sendExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1241; JMS:JAVADOC:1245; JMS:JAVADOC:1238;
+ *
+ * @test_Strategy: Tests MessageFormatRuntimeException and
+ * MessageNotWriteableRuntimeException conditions from the following API's:
+ *
+ * JMSProducer.send(Destination, Message) throws
+ * MessageNotWriteableRuntimeException JMSProducer.send(Destination, Message)
+ * throws MessageFormatRuntimeException JMSProducer.send(Destination, Map)
+ * throws MessageFormatRuntimeException
+ *
+ */
+ @Test
+ public void sendExceptionTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ try {
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Message) for MessageFormatRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling send(Destination, Message) -> expect MessageFormatRuntimeException");
+ producer.send(destination, (Message) null);
+ logger.log(Logger.Level.ERROR, "MessageFormatRuntimeException was not thrown");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatRuntimeException, received " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Map) for MessageFormatRuntimeException");
+ try {
+ Map mp = new HashMap();
+ mp.put("1", new ArrayList(2));
+ mp.put("2", new Properties());
+ mp.put("2", new Properties());
+ mp.put("1", new ArrayList(2));
+ logger.log(Logger.Level.INFO, "Calling send(Destination, Map) -> expect MessageFormatRuntimeException");
+ producer.send(destination, mp);
+ logger.log(Logger.Level.ERROR, "MessageFormatRuntimeException was not thrown");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatRuntimeException, received " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Message) for MessageNotWriteableRuntimeException");
+ try {
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage sendTextMessage = context.createTextMessage(message);
+ sendTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendExceptionTests");
+ logger.log(Logger.Level.INFO, "Send TextMessage");
+ producer.send(destination, sendTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage recvTextMessage = (TextMessage) consumer.receive(timeout);
+ if (recvTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (recvTextMessage.getText().equals(sendTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + sendTextMessage.getText()
+ + ", received " + recvTextMessage.getText());
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Set a bunch of JMSProducer properties");
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTSTRING", testString);
+ producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
+ logger.log(Logger.Level.INFO,
+ "Using received TextMessage try and send it (expect MessageNotWriteableRuntimeException)");
+ producer.send(destination, recvTextMessage);
+ logger.log(Logger.Level.ERROR, "MessageNotWriteableRuntimeException was not thrown");
+ pass = false;
+ } catch (MessageNotWriteableRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageNotWriteableRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageNotWriteableRuntimeException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("sendExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: getBodyTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1357;
+ *
+ * @test_Strategy: Send and receive messages of the following types:
+ * BytesMessage, MapMessage, ObjectMessage, TextMessage. Call Message.getBody()
+ * to return the message as the specified Object type.
+ *
+ * Object message = Message.getBody(Class)
+ *
+ * Test the following:
+ *
+ * String message = Message.getBody(String.class) byte[] message =
+ * Message.getBody(byte[].class); StringBuffer message =
+ * Message.getBody(StringBuffer.class); Map message =
+ * Message.getBody(Map.class);
+ *
+ */
+ @Test
+ public void getBodyTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ StringBuffer expSbuffer = new StringBuffer("This is it!");
+ try {
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Call TextMessage.getBody(String.class) to extract TextMessage as String");
+ String actMessage = actTextMessage.getBody(String.class);
+ logger.log(Logger.Level.INFO, "Check the value in String");
+ if (actMessage.equals(message)) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "TextMessage is incorrect expected " + message + ", received " + actMessage);
+ pass = false;
+ }
+
+ // Send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Create ObjectMessage");
+ ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
+ logger.log(Logger.Level.INFO, "Send and receive the ObjectMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expObjectMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive ObjectMessage");
+ ObjectMessage actObjectMessage = (ObjectMessage) consumer.receive(timeout);
+ if (actObjectMessage == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ logger.log(Logger.Level.INFO,
+ "Call ObjectMessage.getBody(StringBuffer.class) to extract ObjectMessage as StringBuffer");
+ StringBuffer actSbuffer = actObjectMessage.getBody(StringBuffer.class);
+ logger.log(Logger.Level.INFO, "Check the value in StringBuffer");
+ if (actSbuffer.toString().equals(expSbuffer.toString())) {
+ logger.log(Logger.Level.INFO, "ObjectMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "ObjectMessage is incorrect expected " + expSbuffer + ", received " + actSbuffer);
+ pass = false;
+ }
+
+ // Send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Create BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ logger.log(Logger.Level.INFO, "Send and receive the BytesMessage");
+ producer.send(destination, bMsg);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive BytesMessage");
+ BytesMessage actBytesMessage = (BytesMessage) consumer.receive(timeout);
+ if (actBytesMessage == null) {
+ throw new Exception("Did not receive BytesMessage");
+ }
+ logger.log(Logger.Level.INFO,
+ "Call BytesMessage.getBody(StringBuffer.class) to extract BytesMessage as byte[] array");
+ byte[] bytes = actBytesMessage.getBody(byte[].class);
+ if (bytes == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive BytesMessage");
+ pass = false;
+ } else {
+ try {
+ DataInputStream di = new DataInputStream(new ByteArrayInputStream(bytes));
+ logger.log(Logger.Level.INFO, "Check the values in BytesMessage");
+ if (di.readByte() == (byte) 1) {
+ logger.log(Logger.Level.INFO, "bytevalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "bytevalue is incorrect");
+ pass = false;
+ }
+ if (di.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ try {
+ byte b = di.readByte();
+ } catch (EOFException e) {
+ logger.log(Logger.Level.INFO, "Caught expected EOFException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ }
+ // Send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send MapMessage");
+ MapMessage mMsg = context.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ producer.send(destination, mMsg);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive MapMessage");
+ MapMessage actMapMessage = (MapMessage) consumer.receive(timeout);
+ if (actMapMessage == null) {
+ throw new Exception("Did not receive MapMessage");
+ }
+ logger.log(Logger.Level.INFO, "Call MapMessage.getBody(Map.class) to extract MapMessage as a Map object");
+ Map map = actMapMessage.getBody(Map.class);
+ if (map == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive MapMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in MapMessage");
+ logger.log(Logger.Level.INFO, "map.size()=" + map.size());
+ if (map.size() != 2) {
+ logger.log(Logger.Level.ERROR, "Map size is " + map.size() + ", expected 2");
+ pass = false;
+ }
+ Iterator it = map.keySet().iterator();
+ String name = null;
+ while (it.hasNext()) {
+ name = (String) it.next();
+ if (name.equals("booleanvalue")) {
+ if ((boolean) map.get(name) == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "booleanvalue is incorrect");
+ pass = false;
+ }
+ } else if (name.equals("intvalue")) {
+ if ((int) map.get(name) == 10) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "intvalue is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected name of [" + name + "] in MapMessage");
+ pass = false;
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("getBodyTests", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("getBodyTests failed");
+ }
+ }
+
+ /*
+ * @testName: getBodyExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1359;
+ *
+ * @test_Strategy: Test exception case for Message.getBody(Class). Test
+ * MessageFormatException.
+ *
+ * Object = Message.getBody(Class)
+ *
+ */
+ @Test
+ public void getBodyExceptionTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ StringBuffer expSbuffer = new StringBuffer("This is it!");
+ try {
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyExceptionTests");
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Call TextMessage.getBody(Boolean.class) to extract TextMessage "
+ + "as Boolean (expect MessageFormatException)");
+ try {
+ Boolean myBool = actTextMessage.getBody(Boolean.class);
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException to be thrown");
+ pass = false;
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Caught correct MessageFormatException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Create ObjectMessage of type StringBuffer");
+ ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyExceptionTests");
+ logger.log(Logger.Level.INFO, "Send and receive the ObjectMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expObjectMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive ObjectMessage");
+ ObjectMessage actObjectMessage = (ObjectMessage) consumer.receive(timeout);
+ if (actObjectMessage == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ logger.log(Logger.Level.INFO, "Call ObjectMessage.getBody(HashMap.class) to extract ObjectMessage "
+ + "as HashMap (expect MessageFormatException");
+ try {
+ HashMap hmap = actObjectMessage.getBody(HashMap.class);
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException to be thrown");
+ pass = false;
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Caught correct MessageFormatException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // send and receive StreamMessage
+ logger.log(Logger.Level.INFO, "Create StreamMessage");
+ StreamMessage expStreamMsg = context.createStreamMessage();
+ logger.log(Logger.Level.INFO, "Set some values in StreamMessage");
+ expStreamMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyExceptionTests");
+ expStreamMsg.writeBoolean(true);
+ expStreamMsg.writeInt((int) 22);
+ logger.log(Logger.Level.INFO, "Send and receive the StreamMessage");
+ producer.send(destination, expStreamMsg);
+ StreamMessage actStreamMsg = (StreamMessage) consumer.receive(timeout);
+ if (actStreamMsg == null) {
+ throw new Exception("Did not receive StreamMessage");
+ }
+ logger.log(Logger.Level.INFO, "Call StreamMessage.getBody(HashMap.class) to extract StreamMessage "
+ + "as HashMap (expect MessageFormatException");
+ try {
+ HashMap hmap = actStreamMsg.getBody(HashMap.class);
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException to be thrown");
+ pass = false;
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Caught correct MessageFormatException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Create BytesMessage
+ logger.log(Logger.Level.INFO, "Create BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyExceptionTests");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ logger.log(Logger.Level.INFO, "BytesMessage is in write-only mode");
+ logger.log(Logger.Level.INFO, "Call BytesMessage.getBody(StringBuffer.class) to receive "
+ + "BytesMessage as StringBuffer(expect MessageFormatException)");
+ try {
+ bMsg.getBody(StringBuffer.class);
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException to be thrown");
+ pass = false;
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Caught correct MessageFormatException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Send and receive the BytesMessage");
+ producer.send(destination, bMsg);
+ BytesMessage actBytesMsg = (BytesMessage) consumer.receive(timeout);
+ try {
+ actBytesMsg.getBody(StringBuffer.class);
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException to be thrown");
+ pass = false;
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Caught correct MessageFormatException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("getBodyExceptionTests", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("getBodyExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: isBodyAssignableToTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1361;
+ *
+ * @test_Strategy: Test Message.isBodyAssignableTo(Class) API.
+ *
+ * boolean = Message.isBodyAssignableTo(Class)
+ *
+ */
+ @Test
+ public void isBodyAssignableToTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ StringBuffer expSbuffer = new StringBuffer("This is it!");
+ try {
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "isBodyAssignableToTest");
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Call TextMessage.isBodyAssignableTo(Boolean.class) (expect false)");
+ boolean b = actTextMessage.isBodyAssignableTo(Boolean.class);
+ if (b) {
+ logger.log(Logger.Level.ERROR, "Expected false got true");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Call TextMessage.isBodyAssignableTo(String.class) (expect true)");
+ b = actTextMessage.isBodyAssignableTo(String.class);
+ if (!b) {
+ logger.log(Logger.Level.ERROR, "Expected true got false");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Create ObjectMessage");
+ ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "isBodyAssignableToTest");
+ logger.log(Logger.Level.INFO, "Send and receive the ObjectMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expObjectMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive ObjectMessage");
+ ObjectMessage actObjectMessage = (ObjectMessage) consumer.receive(timeout);
+ if (actObjectMessage == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Call ObjectMessage.isBodyAssignableTo(Boolean.class) (expect false)");
+ boolean b = actObjectMessage.isBodyAssignableTo(Boolean.class);
+ if (b) {
+ logger.log(Logger.Level.ERROR, "Expected false got true");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO,
+ "Call ObjectMessage.isBodyAssignableTo(StringBuffer.class) (expect true)");
+ b = actObjectMessage.isBodyAssignableTo(StringBuffer.class);
+ if (!b) {
+ logger.log(Logger.Level.ERROR, "Expected true got false");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Create BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTest");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ logger.log(Logger.Level.INFO, "Send and receive the BytesMessage");
+ producer.send(destination, bMsg);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive BytesMessage");
+ BytesMessage actBytesMessage = (BytesMessage) consumer.receive(timeout);
+ if (actBytesMessage == null) {
+ throw new Exception("Did not receive BytesMessage");
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Call BytesMessage.isBodyAssignableTo(String.class) (expect false)");
+ boolean b = actBytesMessage.isBodyAssignableTo(String.class);
+ if (b) {
+ logger.log(Logger.Level.ERROR, "Expected false got true");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Call BytesMessage.isBodyAssignableTo(byte[].class) (expect true)");
+ b = actBytesMessage.isBodyAssignableTo(byte[].class);
+ if (!b) {
+ logger.log(Logger.Level.ERROR, "Expected true got false");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send MapMessage");
+ MapMessage mMsg = context.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTest");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ producer.send(destination, mMsg);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive MapMessage");
+ MapMessage actMapMessage = (MapMessage) consumer.receive(timeout);
+ if (actMapMessage == null) {
+ throw new Exception("Did not receive MapMessage");
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Call MapMessage.isBodyAssignableTo(String.class) (expect false)");
+ boolean b = actMapMessage.isBodyAssignableTo(String.class);
+ if (b) {
+ logger.log(Logger.Level.ERROR, "Expected false got true");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Call MapMessage.isBodyAssignableTo(Map.class) (expect true)");
+ b = actMapMessage.isBodyAssignableTo(Map.class);
+ if (!b) {
+ logger.log(Logger.Level.ERROR, "Expected true got false");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("isBodyAssignableToTest", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("isBodyAssignableToTest failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsproducertopictests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsproducertopictests/Client.java
deleted file mode 100644
index 000d7ce439..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsproducertopictests/Client.java
+++ /dev/null
@@ -1,5364 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.jmsproducertopictests;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.EOFException;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Properties;
-import java.util.Set;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.ConnectionMetaData;
-import jakarta.jms.DeliveryMode;
-import jakarta.jms.Destination;
-import jakarta.jms.JMSConsumer;
-import jakarta.jms.JMSContext;
-import jakarta.jms.JMSProducer;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.MessageFormatException;
-import jakarta.jms.MessageFormatRuntimeException;
-import jakarta.jms.MessageNotWriteableRuntimeException;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.jmsproducertopictests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null, tool2 = null;
-
- // JMS objects
- private transient ConnectionFactory cf = null;
-
- private transient ConnectionFactory cf2 = null;
-
- private transient Topic topic = null;
-
- private transient Destination destination = null;
-
- private transient Topic topic2 = null;
-
- private transient Destination destination2 = null;
-
- private transient JMSContext context = null;
-
- private transient JMSContext context2 = null;
-
- private transient JMSProducer producer = null;
-
- private transient JMSProducer producer2 = null;
-
- private transient JMSConsumer consumer = null;
-
- private transient JMSConsumer consumer2 = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- ArrayList connections = null;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Utility methods for tests */
-
- /*
- * helper method verifies that the ConnectionMetaData
- *
- * @param ConnectionMetaData returned from getJMSMessageID
- *
- * @return boolean true if ConnectionMetaData is as expected
- */
- private boolean verifyMetaData(ConnectionMetaData data) {
- boolean pass = true;
-
- try {
- String tmp = data.getJMSVersion();
- TestUtil.logTrace("JMSVersion=" + tmp);
-
- if (!tmp.equals("2.0")) {
- TestUtil.logErr("Error: incorrect JMSVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getJMSMajorVersion();
- TestUtil.logTrace("JMSMajorVersion=" + tmp);
-
- if (tmp != 2) {
- TestUtil.logErr("Error: incorrect JMSMajorVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSMajorVersion: ",
- e);
- pass = false;
- }
-
- try {
- int tmp = data.getJMSMinorVersion();
- TestUtil.logTrace("JMSMinorVersion=" + tmp);
-
- if (tmp != 0) {
- TestUtil.logErr("Error: incorrect JMSMajorVersion=" + tmp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSMinorVersion: ",
- e);
- pass = false;
- }
-
- try {
- String tmp = data.getJMSProviderName();
- TestUtil.logTrace("JMSProviderName=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for JMSProviderName: ",
- e);
- pass = false;
- }
-
- try {
- String tmp = data.getProviderVersion();
- TestUtil.logTrace("JMSProviderVersion=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr("Error: incorrect type returned for ProviderVersion: ",
- e);
- pass = false;
- }
-
- try {
- int tmp = data.getProviderMajorVersion();
- TestUtil.logTrace("ProviderMajorVersion=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: incorrect type returned for ProviderMajorVersion: ", e);
- pass = false;
- }
-
- try {
- int tmp = data.getProviderMinorVersion();
- TestUtil.logTrace("ProviderMinorVersion=" + tmp);
- } catch (Exception e) {
- TestUtil.logErr(
- "Error: incorrect type returned for ProviderMinorVersion: ", e);
- pass = false;
- }
- return pass;
- }
-
- /*
- * helper method verifies that the JMSMessageID starts with ID:
- *
- * @param String returned from getJMSMessageID
- *
- * @return boolean true if id correctly starts with ID:
- */
- private boolean chkMessageID(String id) {
- String status[] = { "Pass", "Fail" };
- boolean retcode = true;
-
- // message id must start with ID: - unless it is null
- int index = 0;
-
- if (id == null) {
- ;
- } else if (id.startsWith("ID:")) {
- ;
- } else {
- index = 1;
- retcode = false;
- }
- logTrace("Results: " + status[index]);
- return retcode;
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- String lookupDurableTopicFactory = "DURABLE_SUB_CONNECTION_FACTORY";
- String lookupNormalTopicFactory = "MyTopicConnectionFactory";
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- connections = new ArrayList(5);
-
- // set up JmsTool for COMMON_T setup
- TestUtil.logMsg(
- "Setup JmsTool for COMMON_T and normal topic connection factory");
- tool = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupNormalTopicFactory, mode);
- cf = tool.getConnectionFactory();
- tool.getDefaultConnection().close(); // Close connection (Create
- // JMSContext to use instead)
- destination = tool.getDefaultDestination();
- topic = (Topic) destination;
-
- // create JMSContext with AUTO_ACKNOWLEDGE then create consumer/producer
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- producer = context.createProducer();
- consumer = context.createConsumer(topic);
-
- // set up JmsTool for COMMON_T setup
- TestUtil.logMsg(
- "Setup JmsTool for COMMON_T and durable topic connection factory");
- tool2 = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupDurableTopicFactory, mode);
- tool2.getDefaultConnection().close(); // Close connection (Create
- // JMSContext to use instead)
- cf2 = tool2.getConnectionFactory();
- destination2 = tool2.getDefaultDestination();
- topic2 = (Topic) destination2;
-
- // create second JMSContext with AUTO_ACKNOWLEDGE, then create producer
- context2 = cf2.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- producer2 = context2.createProducer();
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Close JMSContext Objects");
- if (context != null) {
- context.close();
- context = null;
- }
- if (context2 != null) {
- context2.close();
- context2 = null;
- }
- producer = producer2 = null;
- TestUtil.logMsg("Close JMSConsumer Objects");
- if (consumer != null) {
- consumer.close();
- consumer = null;
- }
- tool.closeAllResources();
- tool2.closeAllResources();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * Cleanup method for tests that use durable subscriptions
- */
- private void cleanupSubscription(JMSConsumer consumer, JMSContext context,
- String subName) {
- if (consumer != null) {
- try {
- TestUtil.logTrace("Closing durable consumer: " + consumer);
- consumer.close();
- } catch (Exception e) {
- TestUtil.logErr("Exception during JMSConsumer.close: ", e);
- }
- }
-
- if (context != null) {
- try {
- TestUtil.logTrace("Unsubscribing \"" + subName + "\"");
- context.unsubscribe(subName);
- } catch (Exception e) {
- TestUtil.logErr("Exception during JMSContext.unsubscribe: ", e);
- }
- }
- }
-
- /*
- * @testName: sendAndRecvTest1
- *
- * @assertion_ids: JMS:JAVADOC:1234;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * JMSProducer.send(Destination, Message) JMSConsumer.receive(long)
- *
- */
- public void sendAndRecvTest1() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvTest1");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Receive TextMessage via JMSconsumer.receive(long)");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvTest1", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTest1 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTest2
- *
- * @assertion_ids: JMS:JAVADOC:1239;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * JMSProducer.send(Destination, String) JMSConsumer.receiveBody(String, long)
- *
- */
- public void sendAndRecvTest2() throws Exception {
- boolean pass = true;
- String expTextMessage = "Where are you!";
- try {
- // send and receive TextMessage payload
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, String)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg(
- "Receive TextMessage via JMSConsumer.receiveBody(String, long)");
- String actTextMessage = consumer.receiveBody(String.class, timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.equals(expTextMessage)) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect expected " + expTextMessage
- + ", received " + actTextMessage);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvTest2", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTest2 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTest3
- *
- * @assertion_ids: JMS:JAVADOC:1251;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * JMSProducer.send(Destination, Serializable)
- * JMSConsumer.receiveBody(Serializable, long)
- */
- public void sendAndRecvTest3() throws Exception {
- boolean pass = true;
- try {
- // send and receive ObjectMessage
- TestUtil.logMsg("Send ObjectMessage");
- TestUtil.logMsg("Set some values in ObjectMessage");
- ObjectMessage expObjectMessage = context.createObjectMessage();
- StringBuffer expSb = new StringBuffer("Where are you!");
- TestUtil.logMsg("Set object in ObjectMessage to a StringBuffer");
- expObjectMessage.setObject(expSb);
- expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvTest3");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Serializable)");
- producer.send(destination, expObjectMessage);
- TestUtil.logMsg(
- "Receive ObjectMessage via JMSConsumer.receiveBody(Serializable, long)");
- StringBuffer actSb = (StringBuffer) consumer
- .receiveBody(Serializable.class, timeout);
- if (actSb == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- TestUtil.logMsg("Check the value in ObjectMessage");
- if (actSb.toString().equals(expSb.toString())) {
- TestUtil.logMsg("ObjectMessage is correct");
- } else {
- TestUtil.logErr("ObjectMessage is incorrect expected "
- + expSb.toString() + ", received " + actSb.toString());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvTest3", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTest3 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTest4
- *
- * @assertion_ids: JMS:JAVADOC:1243;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * JMSProducer.send(Destination, Map)
- * JMSConsumer.receiveBody(Map, long)
- */
- public void sendAndRecvTest4() throws Exception {
- boolean pass = true;
- Map mapMsgSend = new HashMap();
- mapMsgSend.put("StringValue", "sendAndRecvTest4");
- mapMsgSend.put("BooleanValue", true);
- mapMsgSend.put("IntValue", (int) 10);
- try {
- // send and receive MapMessage payload
- TestUtil.logMsg(
- "Send MapMessage via JMSProducer.send(Destination, Map)");
- producer.send(destination, mapMsgSend);
- TestUtil.logMsg(
- "Receive MapMessage via JMSConsumer.receiveBody(Map.class, long");
- Map mapMsgRecv = consumer.receiveBody(Map.class, timeout);
- if (mapMsgRecv == null) {
- throw new Exception("Did not receive MapMessage");
- }
- TestUtil.logMsg("Compare MapMsgSend and MapMsgRecv for equality");
- for (Entry entry : mapMsgSend.entrySet()) {
- String key = entry.getKey();
- TestUtil.logMsg(
- "key " + key + ": " + entry.getValue().equals(mapMsgRecv.get(key)));
- if (entry.getValue().equals(mapMsgRecv.get(key))) {
- continue;
- } else {
- pass = false;
- }
- }
- if (pass) {
- TestUtil.logMsg("MapMessage is correct");
- } else {
- TestUtil.logErr("MapMessage is incorrect expected " + mapMsgSend
- + ", received " + mapMsgRecv);
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvTest4", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTest4 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTest5
- *
- * @assertion_ids: JMS:JAVADOC:1247;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * JMSProducer.send(Destination, byte[]) JMSConsumer.receiveBody(byte[], long)
- *
- */
- public void sendAndRecvTest5() throws Exception {
- boolean pass = true;
- String messageSend = "Where are you!";
- byte[] bytesMsgSend = messageSend.getBytes();
- try {
- // send and receive BytesMessage
- TestUtil.logMsg(
- "Send BytesMessage via JMSProducer.send(Destination, byte[])");
- producer.send(destination, bytesMsgSend);
- TestUtil.logMsg(
- "Receive BytesMessage via JMSConsumer.receiveBody(byte[].class, long");
- byte[] bytesMsgRecv = consumer.receiveBody(byte[].class, timeout);
- if (bytesMsgRecv == null) {
- throw new Exception("Did not receive BytesMessage");
- }
- TestUtil.logMsg("Compare BytesMsgSend and BytesMsgRecv for equality");
- String messageRecv = new String(bytesMsgRecv);
- if (messageRecv.equals(messageSend)) {
- TestUtil.logMsg("BytesMessage is correct");
- } else {
- TestUtil.logErr("BytesMessage is incorrect expected " + messageRecv
- + ", received " + messageSend);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvTest5", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTest5 failed");
- }
- }
-
- /*
- * @testName: sendAndRecvMsgsOfEachMsgTypeTest
- *
- * @assertion_ids: JMS:JAVADOC:925; JMS:JAVADOC:927; JMS:JAVADOC:929;
- * JMS:JAVADOC:934; JMS:JAVADOC:937; JMS:JAVADOC:940; JMS:JAVADOC:964;
- * JMS:JAVADOC:966; JMS:JAVADOC:942; JMS:JAVADOC:847; JMS:JAVADOC:1104;
- * JMS:JAVADOC:1234; JMS:JAVADOC:875; JMS:JAVADOC:936; JMS:JAVADOC:1177;
- *
- * @test_Strategy: Send and receive messages of each message type: Message,
- * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Gets
- * the delivery time of each send of the message. Tests the following API's
- *
- * ConnectionFactory.createContext(String, String, int)
- * JMSContext.createConsumer(Destination) JMSContext.createProducer()
- * JMSContext.createMessage() JMSContext.createBytesMessage()
- * JMSContext.createMapMessage() JMSContext.createObjectMessage()
- * JMSContext.createObjectMessage(Serializable object)
- * JMSContext.createStreamMessage() JMSContext.createTextMessage()
- * JMSContext.createTextMessage(String) JMSContext.createConsumer(Destination)
- * JMSProducer.send(Destination, Message) JMSConsumer.receive(long timeout)
- *
- */
- public void sendAndRecvMsgsOfEachMsgTypeTest() throws Exception {
- boolean pass = true;
- try {
- // send and receive Message
- TestUtil.logMsg("Send Message");
- Message msg = context.createMessage();
- TestUtil.logMsg("Set some values in Message");
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- msg.setBooleanProperty("booleanProperty", true);
- producer.send(destination, msg);
- long deliveryTime = msg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive Message");
- Message msgRecv = (Message) consumer.receive(timeout);
- if (msgRecv == null) {
- TestUtil.logErr("Did not receive Message");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in Message");
- if (msgRecv.getBooleanProperty("booleanProperty") == true) {
- TestUtil.logMsg("booleanproperty is correct");
- } else {
- TestUtil.logMsg("booleanproperty is incorrect");
- pass = false;
- }
- }
-
- // send and receive BytesMessage
- TestUtil.logMsg("Send BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- producer.send(destination, bMsg);
- deliveryTime = bMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive BytesMessage");
- BytesMessage bMsgRecv = (BytesMessage) consumer.receive(timeout);
- if (bMsgRecv == null) {
- TestUtil.logErr("Did not receive BytesMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in BytesMessage");
- if (bMsgRecv.readByte() == (byte) 1) {
- TestUtil.logMsg("bytevalue is correct");
- } else {
- TestUtil.logMsg("bytevalue is incorrect");
- pass = false;
- }
- if (bMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive MapMessage
- TestUtil.logMsg("Send MapMessage");
- MapMessage mMsg = context.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- producer.send(destination, mMsg);
- deliveryTime = mMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive MapMessage");
- MapMessage mMsgRecv = (MapMessage) consumer.receive(timeout);
- if (mMsgRecv == null) {
- TestUtil.logErr("Did not receive MapMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in MapMessage");
- Enumeration list = mMsgRecv.getMapNames();
- String name = null;
- while (list.hasMoreElements()) {
- name = (String) list.nextElement();
- if (name.equals("booleanvalue")) {
- if (mMsgRecv.getBoolean(name) == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logErr("booleanvalue is incorrect");
- pass = false;
- }
- } else if (name.equals("intvalue")) {
- if (mMsgRecv.getInt(name) == 10) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logErr("intvalue is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Unexpected name of [" + name + "] in MapMessage");
- pass = false;
- }
- }
- }
-
- // send and receive ObjectMessage
- TestUtil.logMsg("Send ObjectMessage");
- StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
- TestUtil.logMsg("Set some values in ObjectMessage");
- ObjectMessage oMsg = context.createObjectMessage();
- oMsg.setObject(sb1);
- oMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- producer.send(destination, oMsg);
- deliveryTime = oMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive ObjectMessage");
- ObjectMessage oMsgRecv = (ObjectMessage) consumer.receive(timeout);
- if (oMsgRecv == null) {
- TestUtil.logErr("Did not receive ObjectMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in ObjectMessage");
- StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
- if (sb2.toString().equals(sb1.toString())) {
- TestUtil.logMsg("objectvalue is correct");
- } else {
- TestUtil.logErr("objectvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive ObjectMessage passing object as param
- TestUtil.logMsg("Send ObjectMessage passing object as param");
- sb1 = new StringBuffer("This is a StringBuffer");
- TestUtil
- .logMsg("Set some values in ObjectMessage passing object as param");
- oMsg = context.createObjectMessage(sb1);
- oMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- producer.send(destination, oMsg);
- deliveryTime = oMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive ObjectMessage");
- oMsgRecv = (ObjectMessage) consumer.receive(timeout);
- if (oMsgRecv == null) {
- TestUtil.logErr("Did not receive ObjectMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in ObjectMessage");
- StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
- if (sb2.toString().equals(sb1.toString())) {
- TestUtil.logMsg("objectvalue is correct");
- } else {
- TestUtil.logErr("objectvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive StreamMessage
- TestUtil.logMsg("Send StreamMessage");
- StreamMessage sMsg = context.createStreamMessage();
- TestUtil.logMsg("Set some values in StreamMessage");
- sMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- sMsg.writeBoolean(true);
- sMsg.writeInt((int) 22);
- producer.send(destination, sMsg);
- deliveryTime = sMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive StreamMessage");
- StreamMessage sMsgRecv = (StreamMessage) consumer.receive(timeout);
- if (sMsgRecv == null) {
- TestUtil.logErr("Did not receive StreamMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in StreamMessage");
- if (sMsgRecv.readBoolean() == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logMsg("booleanvalue is incorrect");
- pass = false;
- }
- if (sMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- }
-
- // send and receive TextMessage
- TestUtil.logMsg("Send TextMessage");
- TextMessage tMsg = context.createTextMessage();
- TestUtil.logMsg("Set some values in TextMessage");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- tMsg.setText("Hello There!");
- producer.send(destination, tMsg);
- deliveryTime = tMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive TextMessage");
- TextMessage tMsgRecv = (TextMessage) consumer.receive(timeout);
- if (tMsgRecv == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (tMsgRecv.getText().equals("Hello There!")) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect");
- pass = false;
- }
- }
-
- // send and receive TextMessage passing string as param
- TestUtil.logMsg("Send TextMessage");
- tMsg = context.createTextMessage("Where are you!");
- TestUtil.logMsg("Set some values in TextMessage");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeTest");
- producer.send(destination, tMsg);
- deliveryTime = tMsg.getJMSDeliveryTime();
- TestUtil.logMsg("Receive TextMessage");
- tMsgRecv = (TextMessage) consumer.receive(timeout);
- if (tMsgRecv == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (tMsgRecv.getText().equals("Where are you!")) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("sendAndRecvMsgsOfEachMsgTypeTest", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvMsgsOfEachMsgTypeTest failed");
- }
- }
-
- /*
- * @testName: setGetDeliveryModeTest
- *
- * @assertion_ids: JMS:JAVADOC:1192; JMS:JAVADOC:1259;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setDeliveryMode(int). JMSProducer.getDeliveryMode().
- */
- public void setGetDeliveryModeTest() throws Exception {
- boolean pass = true;
-
- // Test default case
- try {
- int expDeliveryMode = DeliveryMode.PERSISTENT;
- TestUtil.logMsg("Calling getDeliveryMode and expect " + expDeliveryMode
- + " to be returned");
- int actDeliveryMode = producer.getDeliveryMode();
- if (actDeliveryMode != expDeliveryMode) {
- TestUtil.logErr("getDeliveryMode() returned " + actDeliveryMode
- + ", expected " + expDeliveryMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDeliveryModeTest");
- }
-
- // Test non-default case
- try {
- int expDeliveryMode = DeliveryMode.NON_PERSISTENT;
- TestUtil.logMsg("Calling setDeliveryMode(" + expDeliveryMode + ")");
- producer.setDeliveryMode(expDeliveryMode);
- TestUtil.logMsg("Calling getDeliveryMode and expect " + expDeliveryMode
- + " to be returned");
- int actDeliveryMode = producer.getDeliveryMode();
- if (actDeliveryMode != expDeliveryMode) {
- TestUtil.logErr("getDeliveryMode() returned " + actDeliveryMode
- + ", expected " + expDeliveryMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDeliveryModeTest");
- }
-
- if (!pass) {
- throw new Exception("setGetDeliveryModeTest failed");
- }
- }
-
- /*
- * @testName: setGetDeliveryDelayTest
- *
- * @assertion_ids: JMS:JAVADOC:1190; JMS:JAVADOC:1257;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setDeliveryDelay(long). JMSProducer.getDeliveryDelay().
- */
- public void setGetDeliveryDelayTest() throws Exception {
- boolean pass = true;
-
- // Test default case
- try {
- long expDeliveryDelay = 0L;
- TestUtil.logMsg("Calling getDeliveryDelay and expect " + expDeliveryDelay
- + " to be returned");
- long actDeliveryDelay = producer.getDeliveryDelay();
- if (actDeliveryDelay != expDeliveryDelay) {
- TestUtil.logErr("getDeliveryDelay() returned " + actDeliveryDelay
- + ", expected " + expDeliveryDelay);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDeliveryDelayTest");
- }
-
- // Test non-default case
- try {
- long expDeliveryDelay = 1L;
- TestUtil.logMsg("Calling setDeliveryDelay(" + expDeliveryDelay + ")");
- producer.setDeliveryDelay(expDeliveryDelay);
- TestUtil.logMsg("Calling getDeliveryDelay and expect " + expDeliveryDelay
- + " to be returned");
- long actDeliveryDelay = producer.getDeliveryDelay();
- if (actDeliveryDelay != expDeliveryDelay) {
- TestUtil.logErr("getDeliveryDelay() returned " + actDeliveryDelay
- + ", expected " + expDeliveryDelay);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDeliveryDelayTest");
- }
-
- if (!pass) {
- throw new Exception("setGetDeliveryDelayTest failed");
- }
- }
-
- /*
- * @testName: setGetDisableMessageIDTest
- *
- * @assertion_ids: JMS:JAVADOC:1194; JMS:JAVADOC:1261;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setDisableMessageID(boolean).
- * JMSProducer.getDisableMessageID().
- */
- public void setGetDisableMessageIDTest() throws Exception {
- boolean pass = true;
- // Test default case
- try {
- boolean expDisableMessageID = true;
- TestUtil
- .logMsg("Calling setDisableMessageID(" + expDisableMessageID + ")");
- producer.setDisableMessageID(expDisableMessageID);
- TestUtil.logMsg("Calling getDisableMessageID and expect "
- + expDisableMessageID + " to be returned");
- boolean actDisableMessageID = producer.getDisableMessageID();
- if (actDisableMessageID != expDisableMessageID) {
- TestUtil.logErr("getDisableMessageID() returned " + actDisableMessageID
- + ", expected " + expDisableMessageID);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDisableMessageIDTest");
- }
-
- // Test non-default case
- try {
- boolean expDisableMessageID = false;
- TestUtil
- .logMsg("Calling setDisableMessageID(" + expDisableMessageID + ")");
- producer.setDisableMessageID(expDisableMessageID);
- TestUtil.logMsg("Calling getDisableMessageID and expect "
- + expDisableMessageID + " to be returned");
- boolean actDisableMessageID = producer.getDisableMessageID();
- if (actDisableMessageID != expDisableMessageID) {
- TestUtil.logErr("getDisableMessageID() returned " + actDisableMessageID
- + ", expected " + expDisableMessageID);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDisableMessageIDTest");
- }
-
- if (!pass) {
- throw new Exception("setGetDisableMessageIDTest failed");
- }
- }
-
- /*
- * @testName: setGetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:JAVADOC:1196; JMS:JAVADOC:1263;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setDisableMessageTimestamp(boolean).
- * JMSProducer.getDisableMessageTimestamp().
- */
- public void setGetDisableMessageTimestampTest() throws Exception {
- boolean pass = true;
- // Test default case
- try {
- boolean expDisableMessageTimestamp = true;
- TestUtil.logMsg("Calling setDisableMessageTimestamp("
- + expDisableMessageTimestamp + ")");
- producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
- TestUtil.logMsg("Calling getDisableMessageTimestamp and expect "
- + expDisableMessageTimestamp + " to be returned");
- boolean actDisableMessageTimestamp = producer
- .getDisableMessageTimestamp();
- if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
- TestUtil.logErr("getDisableMessageTimestamp() returned "
- + actDisableMessageTimestamp + ", expected "
- + expDisableMessageTimestamp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDisableMessageTimestampTest");
- }
-
- // Test non-default case
- try {
- boolean expDisableMessageTimestamp = false;
- TestUtil.logMsg("Calling setDisableMessageTimestamp("
- + expDisableMessageTimestamp + ")");
- producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
- TestUtil.logMsg("Calling getDisableMessageTimestamp and expect "
- + expDisableMessageTimestamp + " to be returned");
- boolean actDisableMessageTimestamp = producer
- .getDisableMessageTimestamp();
- if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
- TestUtil.logErr("getDisableMessageTimestamp() returned "
- + actDisableMessageTimestamp + ", expected "
- + expDisableMessageTimestamp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetDisableMessageTimestampTest");
- }
-
- if (!pass) {
- throw new Exception("setGetDisableMessageTimestampTest failed");
- }
- }
-
- /*
- * @testName: setGetPriorityTest
- *
- * @assertion_ids: JMS:JAVADOC:1220; JMS:JAVADOC:1273;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setPriority(int). JMSProducer.getPriority().
- */
- public void setGetPriorityTest() throws Exception {
- boolean pass = true;
- try {
- // Test default
- int expPriority = Message.DEFAULT_PRIORITY;
- TestUtil.logMsg(
- "Calling getPriority and expect " + expPriority + " to be returned");
- int actPriority = producer.getPriority();
- if (actPriority != expPriority) {
- TestUtil.logErr("getPriority() returned " + actPriority + ", expected "
- + expPriority);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetPriorityTest");
- }
-
- // Test non-default
- int expPriority[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
-
- // Cycle through all priorties
- for (int i = 0; i < expPriority.length; i++) {
- try {
- TestUtil.logMsg("Calling setPriority(" + expPriority[i] + ")");
- producer.setPriority(expPriority[i]);
- TestUtil.logMsg("Calling getPriority and expect " + expPriority[i]
- + " to be returned");
- int actPriority = producer.getPriority();
- if (actPriority != expPriority[i]) {
- TestUtil.logErr("getPriority() returned " + actPriority
- + ", expected " + expPriority[i]);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetPriorityTest");
- }
- }
-
- if (!pass) {
- throw new Exception("setGetPriorityTest failed");
- }
- }
-
- /*
- * @testName: setGetTimeToLiveTest
- *
- * @assertion_ids: JMS:JAVADOC:1230; JMS:JAVADOC:1303;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setTimeToLive(long). JMSProducer.getTimeToLive()
- */
- public void setGetTimeToLiveTest() throws Exception {
- boolean pass = true;
-
- try {
- // Test default
- long expTimeToLive = 0;
- TestUtil.logMsg("Calling getTimeToLive and expect " + expTimeToLive
- + " to be returned");
- long actTimeToLive = producer.getTimeToLive();
- if (actTimeToLive != expTimeToLive) {
- TestUtil.logErr("getTimeToLive() returned " + actTimeToLive
- + ", expected " + expTimeToLive);
- pass = false;
- }
-
- // Test non-default
- expTimeToLive = 1000;
- TestUtil.logMsg("Calling setTimeToLive(" + expTimeToLive + ")");
- producer.setTimeToLive(expTimeToLive);
- TestUtil.logMsg("Calling getTimeToLive and expect " + expTimeToLive
- + " to be returned");
- actTimeToLive = producer.getTimeToLive();
- if (actTimeToLive != expTimeToLive) {
- TestUtil.logErr("getTimeToLive() returned " + actTimeToLive
- + ", expected " + expTimeToLive);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setGetTimeToLiveTest");
- }
-
- if (!pass) {
- throw new Exception("setGetTimeToLiveTest failed");
- }
- }
-
- /*
- * @testName: deliveryDelayTest
- *
- * @assertion_ids: JMS:SPEC:261; JMS:SPEC:256; JMS:JAVADOC:1257;
- *
- * @test_Strategy: Send message and verify that message is not delivered until
- * the DeliveryDelay of 20 seconds is reached. Test DeliveryMode.PERSISTENT
- * and DeliveryMode.NON_PERSISTENT.
- */
- public void deliveryDelayTest() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------------------------------------------------");
- TestUtil.logMsg("BEGIN TEST deliveryDelayTest with DeliveryDelay=20Secs");
- TestUtil.logMsg("------------------------------------------------------");
- producer.setDeliveryDelay(20000);
-
- // Send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage message = context.createTextMessage("This is a test!");
-
- TestUtil.logMsg("Set StringProperty COM_SUN_JMS_TESTNAME");
- message.setStringProperty("COM_SUN_JMS_TESTNAME", "deliveryDelayTest");
-
- TestUtil.logMsg(
- "Sending message with DeliveryMode.PERSISTENT and DeliveryDelay=20Secs");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- producer.setPriority(Message.DEFAULT_PRIORITY);
- producer.setTimeToLive(0L);
- producer.send(destination, message);
-
- TestUtil.logMsg("Waiting 10 seconds to receive message");
- message = (TextMessage) consumer.receive(10000);
- if (message != null) {
- TestUtil.logErr(
- "FAILED: Message received before delivery delay of 20 secs elapsed");
- pass = false;
- } else {
- TestUtil.logMsg("Didn't receive message after 10 seconds (CORRECT)");
- TestUtil.logMsg("Sleeping 5 more seconds before receiving message");
- Thread.sleep(5000);
- TestUtil.logMsg("Waiting 10 more seconds to receive message");
- message = (TextMessage) consumer.receive(10000);
- if (message == null) {
- TestUtil.logErr(
- "FAILED: Message was not received after delivery delay of 20 secs elapsed");
- pass = false;
- } else {
- TestUtil.logMsg("Received message after 20 secs elapsed (CORRECT)");
- }
- }
-
- TestUtil.logMsg(
- "Sending message with DeliveryMode.NON_PERSISTENT and DeliveryDelay=20Secs");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- producer.setPriority(Message.DEFAULT_PRIORITY);
- producer.setTimeToLive(0L);
- producer.send(destination, message);
-
- TestUtil.logMsg("Waiting 10 seconds to receive message");
- message = (TextMessage) consumer.receive(10000);
- if (message != null) {
- TestUtil.logErr(
- "FAILED: Message received before delivery delay of 20 secs elapsed");
- pass = false;
- } else {
- TestUtil.logMsg("Didn't receive message after 10 seconds (CORRECT)");
- TestUtil.logMsg("Sleeping 5 more seconds before receiving message");
- Thread.sleep(5000);
- TestUtil.logMsg("Waiting 10 more seconds to receive message");
- message = (TextMessage) consumer.receive(10000);
- if (message == null) {
- TestUtil.logErr(
- "FAILED: Message was not received after delivery delay of 20 secs elapsed");
- pass = false;
- } else {
- TestUtil.logMsg("Received message after 20 secs elapsed (CORRECT)");
- }
- }
- TestUtil.logMsg("----------------------------------------------------");
- TestUtil.logMsg("END TEST deliveryDelayTest with DeliveryDelay=20Secs");
- TestUtil.logMsg("----------------------------------------------------");
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("deliveryDelayTest", e);
- }
-
- if (!pass) {
- throw new Exception("deliveryDelayTest failed");
- }
- }
-
- /*
- * @testName: msgHdrMessageIDTest
- *
- * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343; JMS:JAVADOC:1261;
- * JMS:JAVADOC:1194;
- *
- * @test_Strategy: Send to a Topic and receive Text, Map, Bytes, Stream, and
- * Object message. Call getJMSMessageID and verify that it starts with ID:
- */
- public void msgHdrMessageIDTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- String id = null;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- producer.setDisableMessageID(false);
-
- // send and receive Object message to Topic
- TestUtil.logMsg("Send ObjectMessage to Topic.");
- messageSentO = context.createObjectMessage();
- messageSentO.setObject("msgHdrMessageIDTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrMessageIDTest");
- producer.send(destination, messageSentO);
- TestUtil.logMsg("Receive ObjectMessage from Topic.");
- messageReceivedO = (ObjectMessage) consumer.receive(timeout);
- if (messageReceivedO == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil
- .logMsg("getJMSMessageID=" + messageReceivedO.getJMSMessageID());
- id = messageReceivedO.getJMSMessageID();
- if (!chkMessageID(id)) {
- TestUtil.logErr(
- "ObjectMessage error: JMSMessageID does not start with ID:");
- pass = false;
- } else {
- TestUtil.logMsg("Objectessage JMSMessageID pass");
- }
- }
- // send and receive map message to Topic
- TestUtil.logMsg("Send MapMessage to Topic.");
- messageSentM = context.createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrMessageIDTest");
- messageSentM.setString("aString", "value");
- producer.send(destination, messageSentM);
- TestUtil.logMsg("Receive MapMessage from Topic.");
- messageReceivedM = (MapMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil
- .logMsg("getJMSMessageID=" + messageReceivedM.getJMSMessageID());
- id = messageReceivedM.getJMSMessageID();
- if (!chkMessageID(id)) {
- TestUtil
- .logErr("MapMessage error: JMSMessageID does not start with ID:");
- pass = false;
- } else {
- TestUtil.logMsg("MapMessage JMSMessageID pass");
- }
- }
-
- // send and receive bytes message to Topic
- TestUtil.logMsg("Send BytesMessage to Topic.");
- messageSentB = context.createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrMessageIDTest");
- messageSentB.writeByte(bValue);
- producer.send(destination, messageSentB);
- TestUtil.logMsg("Receive BytesMessage from Topic.");
- messageReceivedB = (BytesMessage) consumer.receive(timeout);
- if (messageReceivedB == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil
- .logMsg("getJMSMessageID=" + messageReceivedB.getJMSMessageID());
- id = messageReceivedB.getJMSMessageID();
- if (!chkMessageID(id)) {
- TestUtil.logErr(
- "BytesMessage error: JMSMessageID does not start with ID:");
- pass = false;
- } else {
- TestUtil.logMsg("BytesMessage JMSMessageID pass");
- }
- }
-
- // Send and receive a StreamMessage
- TestUtil.logMsg("Send StreamMessage to Topic");
- messageSentS = context.createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrMessageIDTest");
- messageSentS.writeString("Testing...");
- TestUtil.logMsg("Sending message");
- producer.send(destination, messageSentS);
- TestUtil.logMsg("Receive StreamMessage from Topic.");
- messageReceivedS = (StreamMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil
- .logMsg("getJMSMessageID=" + messageReceivedS.getJMSMessageID());
- id = messageReceivedS.getJMSMessageID();
- if (!chkMessageID(id)) {
- TestUtil.logErr(
- "StreamMessage error: JMSMessageID does not start with ID:");
- pass = false;
- } else {
- TestUtil.logMsg("StreamMessage JMSMessageID pass");
- }
- }
-
- // TextMessage
- TestUtil.logMsg("Send TextMessage to Topic");
- messageSent = context.createTextMessage();
- messageSent.setText("sending a TextMessage");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrMessageIDTest");
- producer.send(destination, messageSent);
- TestUtil.logMsg("Receive TextMessage from Topic.");
- messageReceived = (TextMessage) consumer.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("getJMSMessageID=" + messageReceived.getJMSMessageID());
- id = messageReceived.getJMSMessageID();
- if (!chkMessageID(id)) {
- TestUtil.logErr(
- "TextMessage error: JMSMessageID does not start with ID:");
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage JMSMessageID pass");
- }
- }
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSMessageID returned from JMSMessageID");
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrMessageIDTest");
- }
- }
-
- /*
- * @testName: msgHdrTimeStampTest
- *
- * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347; JMS:JAVADOC:1263;
- * JMS:JAVADOC:1196;
- *
- * @test_Strategy: Send to a Topic a single Text, map, bytes, stream, and
- * object message. Call getJMSTimestamp() and check time of send against time
- * send returns. JMSTimeStamp should be between these two
- */
- public void msgHdrTimeStampTest() throws Exception {
- boolean pass = true;
- long timeBeforeSend;
- long timeAfterSend;
- byte bValue = 127;
-
- try {
- TextMessage messageSent = null;
- StreamMessage messageSentS = null;
- BytesMessage messageSentB = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
-
- producer.setDisableMessageTimestamp(false);
-
- // send and receive Object message to Topic
- TestUtil.logMsg("Send ObjectMessage to Topic.");
- messageSentO = context.createObjectMessage();
- messageSentO.setObject("msgHdrTimeStampTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTest");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentO);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- TestUtil.logMsg("getJMSTimestamp=" + messageSentO.getJMSTimestamp());
- TestUtil.logMsg("Time at send is: " + timeBeforeSend);
- TestUtil.logMsg("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentO.getJMSTimestamp())
- && (timeAfterSend >= messageSentO.getJMSTimestamp())) {
- TestUtil.logMsg("ObjectMessage JMSTimeStamp pass");
- } else {
- TestUtil.logErr("ObjectMessage invalid JMSTimeStamp failed");
- pass = false;
- }
-
- // send map message to Topic
- TestUtil.logMsg("Send MapMessage to Topic.");
- messageSentM = context.createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTest");
- messageSentM.setString("aString", "value");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentM);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- TestUtil.logMsg("getJMSTimestamp=" + messageSentM.getJMSTimestamp());
- TestUtil.logMsg("Time at send is: " + timeBeforeSend);
- TestUtil.logMsg("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentM.getJMSTimestamp())
- && (timeAfterSend >= messageSentM.getJMSTimestamp())) {
- TestUtil.logMsg("MapMessage JMSTimeStamp pass");
- } else {
- TestUtil.logErr("MapMessage invalid JMSTimeStamp failed");
- pass = false;
- }
-
- // send and receive bytes message to Topic
- TestUtil.logMsg("Send BytesMessage to Topic.");
- messageSentB = context.createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTest");
- messageSentB.writeByte(bValue);
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentB);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- TestUtil.logMsg("getJMSTimestamp=" + messageSentB.getJMSTimestamp());
- TestUtil.logMsg("Time at send is: " + timeBeforeSend);
- TestUtil.logMsg("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentB.getJMSTimestamp())
- && (timeAfterSend >= messageSentB.getJMSTimestamp())) {
- TestUtil.logMsg("BytesMessage JMSTimeStamp pass");
- } else {
- TestUtil.logErr("BytesMessage invalid JMSTimeStamp failed");
- pass = false;
- }
-
- // Send and receive a StreamMessage
- TestUtil.logMsg("Send StreamMessage to Topic");
- messageSentS = context.createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTest");
- messageSentS.writeString("Testing...");
- TestUtil.logMsg("Sending message");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentS);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- TestUtil.logMsg("getJMSTimestamp=" + messageSentS.getJMSTimestamp());
- TestUtil.logMsg("Time at send is: " + timeBeforeSend);
- TestUtil.logMsg("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentS.getJMSTimestamp())
- && (timeAfterSend >= messageSentS.getJMSTimestamp())) {
- TestUtil.logMsg("StreamMessage JMSTimeStamp pass");
- } else {
- TestUtil.logErr("StreamMessage invalid JMSTimeStamp failed");
- pass = false;
- }
-
- // TextMessage
- TestUtil.logMsg("Send TextMessage to Topic");
- messageSent = context.createTextMessage();
- messageSent.setText("sending a TextMessage to Topic");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrTimeStampTest");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSent);
-
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- TestUtil.logMsg("getJMSTimestamp=" + messageSent.getJMSTimestamp());
- TestUtil.logMsg("Time at send is: " + timeBeforeSend);
- TestUtil.logMsg("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSent.getJMSTimestamp())
- && (timeAfterSend >= messageSent.getJMSTimestamp())) {
- TestUtil.logMsg("TextMessage JMSTimeStamp pass");
- } else {
- TestUtil.logErr("TextMessage invalid JMSTimeStamp failed");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrTimeStampTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSPriorityTest
- *
- * @assertion_ids: JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140; JMS:JAVADOC:1220;
- * JMS:JAVADOC:1273; JMS:JAVADOC:383;
- *
- * @test_Strategy: Send a message to a Topic with JMSPriority set to 2 test
- * with Text, map, object, byte, and stream messages Call getJMSPriorty() and
- * check that it matches the priority that was set on the JMSContext.
- */
- public void msgHdrJMSPriorityTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- int priority2 = 2;
- int priority4 = 4;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- TestUtil.logMsg("Setting priority to 2");
- producer.setPriority(priority2);
-
- messageSent = context.createTextMessage();
- messageSent.setText("sending a message");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTest");
- TestUtil.logMsg("JMSPriority test - Send a TextMessage to Topic");
- producer.send(destination, messageSent);
- TestUtil.logMsg("JMSPriority test - Recv a TextMessage from Topic");
- messageReceived = (TextMessage) consumer.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("JMSPriority is " + messageReceived.getJMSPriority());
- if (messageReceived.getJMSPriority() == priority2) {
- TestUtil.logMsg("TextMessage JMSPriority passed");
- } else {
- TestUtil.logErr("TextMessage JMSPriority failed");
- pass = false;
- }
- }
-
- // send and receive Object message to Topic
- TestUtil.logMsg("JMSPriority test - Send ObjectMessage to Topic.");
- messageSentO = context.createObjectMessage();
- messageSentO.setObject("msgHdrJMSPriorityTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTest");
- producer.send(destination, messageSentO);
- TestUtil.logMsg("JMSPriority test - Recv a ObjectMessage from Topic");
- messageReceivedO = (ObjectMessage) consumer.receive(timeout);
- if (messageReceivedO == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("JMSPriority is " + messageReceivedO.getJMSPriority());
- if (messageReceivedO.getJMSPriority() == priority2) {
- TestUtil.logMsg("ObjectMessage JMSPriority passed");
- } else {
- TestUtil.logErr("ObjectMessage JMSPriority failed");
- pass = false;
- }
- }
-
- // send and receive map message to Topic
- TestUtil.logMsg("JMSPriority test - Send MapMessage to Topic.");
- messageSentM = context.createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTest");
- messageSentM.setString("aString", "value");
- producer.send(destination, messageSentM);
- TestUtil.logMsg("JMSPriority test - Recv a MapMessage from Topic");
- messageReceivedM = (MapMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("JMSPriority is " + messageReceivedM.getJMSPriority());
- if (messageReceivedM.getJMSPriority() == priority2) {
- TestUtil.logMsg("MapMessage JMSPriority passed");
- } else {
- TestUtil.logErr("MapMessage JMSPriority failed");
- pass = false;
- }
- }
-
- TestUtil.logMsg("Setting priority to 4");
- producer.setPriority(priority4);
-
- // send and receive bytes message to Topic
- TestUtil.logMsg("JMSPriority test - Send BytesMessage to Topic.");
- messageSentB = context.createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTest");
- messageSentB.writeByte(bValue);
- producer.send(destination, messageSentB);
- TestUtil.logMsg("JMSPriority test - Recv a BytesMessage from Topic");
- messageReceivedB = (BytesMessage) consumer.receive(timeout);
- if (messageReceivedB == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("JMSPriority is " + messageReceivedB.getJMSPriority());
- if (messageReceivedB.getJMSPriority() == priority4) {
- TestUtil.logMsg("BytesMessage JMSPriority passed");
- } else {
- TestUtil.logErr("BytesMessage JMSPriority failed");
- pass = false;
- }
- }
-
- // Send and receive a StreamMessage
- TestUtil.logMsg("JMSPriority test - Send a StreamMessage to Topic");
- messageSentS = context.createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSPriorityTest");
- messageSentS.writeString("Testing...");
- producer.send(destination, messageSentS);
- TestUtil.logMsg("JMSPriority test - Recv a StreamMessage from Topic");
- messageReceivedS = (StreamMessage) consumer.receive(timeout);
- if (messageReceivedS == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- TestUtil.logMsg("JMSPriority is " + messageReceivedS.getJMSPriority());
- if (messageReceivedS.getJMSPriority() == priority4) {
- TestUtil.logMsg("StreamMessage JMSPriority passed");
- } else {
- TestUtil.logErr("StreamMessage JMSPriority failed");
- pass = false;
- }
- }
- if (!pass) {
- throw new Exception("Error: invalid JMSPriority returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrJMSPriorityTest");
- }
- }
-
- /*
- * @testName: msgHdrJMSExpirationTest
- *
- * @assertion_ids: JMS:SPEC:15.1; JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140;
- * JMS:JAVADOC:1303; JMS:JAVADOC:379;
- *
- * @test_Strategy: 1. Send a message to a Topic with time to live set to 0.
- * Verify on receive that JMSExpiration gets set to 0. Test with Text, Map,
- * Object, Bytes, and Stream messages. 2. Send a message to a Topic with time
- * to live set to non-0; Verify on receive that JMSExpiration gets set
- * correctly.
- */
- public void msgHdrJMSExpirationTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- long forever = 0L;
- long timeToLive = 5000L;
- String testName = "msgHdrJMSExpirationTest";
- long timeBeforeSend = 0L;
- long timeAfterSend = 0L;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- TestUtil.logMsg(
- "JMSExpiration test - Send a TextMessage (timeToLive is forever)");
- messageSent = context.createTextMessage();
- messageSent.setText("sending a TextMessage");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- producer.setTimeToLive(forever);
- producer.send(destination, messageSent);
-
- TestUtil.logMsg("JMSExpiration test - Recv a TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceived.getJMSExpiration() != forever) {
- TestUtil.logErr("TextMessage JMSExpiration failed");
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage JMSExpiration passed");
- }
- }
-
- TestUtil.logMsg(
- "JMSExpiration test - Send a TextMessage (timeToLive is 5000)");
- producer.setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSent);
- timeAfterSend = System.currentTimeMillis();
-
- long exp = messageSent.getJMSExpiration();
- TestUtil.logMsg("JMSExpiration is set to=" + exp);
- TestUtil.logMsg("Time before send=" + timeBeforeSend);
- TestUtil.logMsg("Time after send=" + timeAfterSend);
- TestUtil.logMsg("Time to Live =" + timeToLive);
-
- TestUtil.logMsg("JMSExpiration test - Recv a TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
- if (messageReceived == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceived.getJMSExpiration() != exp) {
- TestUtil.logErr(
- "TextMessage failed: JMSExpiration didn't set correctly = "
- + messageReceived.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage JMSExpiration passed");
- }
- }
-
- // send and receive Object message to Topic
- TestUtil.logMsg(
- "JMSExpiration test - Send a ObjectMessage (timeToLive is forever)");
- messageSentO = context.createObjectMessage();
- messageSentO.setObject("msgHdrJMSExpirationTest for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- producer.setTimeToLive(forever);
- producer.send(destination, messageSentO);
- TestUtil.logMsg("JMSExpiration test - Recv a ObjectMessage");
- messageReceivedO = (ObjectMessage) consumer.receive(timeout);
- if (messageReceivedO == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedO.getJMSExpiration() != forever) {
- TestUtil.logMsg("ObjectMessage JMSExpiration failed");
- pass = false;
- } else {
- TestUtil.logMsg("ObjectMessage JMSExpiration passed");
- }
- }
-
- TestUtil.logMsg(
- "JMSExpiration test - Send a ObjectMessage (timeToLive is 5000)");
- producer.setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentO);
- timeAfterSend = System.currentTimeMillis();
-
- exp = messageSentO.getJMSExpiration();
- TestUtil.logMsg("JMSExpiration is set to=" + exp);
- TestUtil.logMsg("Time before send=" + timeBeforeSend);
- TestUtil.logMsg("Time after send=" + timeAfterSend);
- TestUtil.logMsg("Time to Live =" + timeToLive);
-
- TestUtil.logMsg("JMSExpiration test - Recv a ObjectMessage");
- messageReceivedO = (ObjectMessage) consumer.receive(timeout);
- if (messageReceivedO == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedO.getJMSExpiration() != exp) {
- TestUtil.logErr(
- "ObjectMessage failed: JMSExpiration didn't set correctly = "
- + messageReceivedO.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- } else {
- TestUtil.logMsg("ObjectMessage JMSExpiration passed");
- }
- }
-
- // send and receive map message to Topic
- TestUtil.logMsg(
- "JMSExpiration test - Send a MapMessage (timeToLive is forever)");
- messageSentM = context.createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentM.setString("aString", "value");
- producer.setTimeToLive(forever);
- producer.send(destination, messageSentM);
- TestUtil.logMsg("JMSExpiration test - Recv a MapMessage");
- messageReceivedM = (MapMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedM.getJMSExpiration() != forever) {
- TestUtil.logMsg("MapMessage JMSExpiration failed");
- pass = false;
- } else {
- TestUtil.logMsg("MapMessage JMSExpiration passed");
- }
- }
-
- TestUtil.logMsg(
- "JMSExpiration test - Send a MapMessage (timeToLive is 5000)");
- producer.setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentM);
- timeAfterSend = System.currentTimeMillis();
-
- exp = messageSentM.getJMSExpiration();
- TestUtil.logMsg("JMSExpiration is set to=" + exp);
- TestUtil.logMsg("Time before send=" + timeBeforeSend);
- TestUtil.logMsg("Time after send=" + timeAfterSend);
- TestUtil.logMsg("Time to Live =" + timeToLive);
-
- TestUtil.logMsg("JMSExpiration test - Recv a MapMessage");
- messageReceivedM = (MapMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedM.getJMSExpiration() != exp) {
- TestUtil
- .logErr("MapMessage failed: JMSExpiration didn't set correctly = "
- + messageReceivedM.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- } else {
- TestUtil.logMsg("MapMessage JMSExpiration passed");
- }
- }
-
- // send and receive bytes message to Topic
- TestUtil.logMsg(
- "JMSExpiration test - Send a Bytesessage (timeToLive is forever)");
- messageSentB = context.createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentB.writeByte(bValue);
- producer.setTimeToLive(forever);
- producer.send(destination, messageSentB);
- TestUtil.logMsg("JMSExpiration test - Recv a BytesMessage");
- messageReceivedB = (BytesMessage) consumer.receive(timeout);
- if (messageReceivedB == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedB.getJMSExpiration() != forever) {
- TestUtil.logMsg("BytesMessage JMSExpiration failed");
- pass = false;
- } else {
- TestUtil.logMsg("BytesMessage JMSExpiration passed");
- }
- }
-
- TestUtil.logMsg(
- "JMSExpiration test - Send a Bytesessage (timeToLive is 5000)");
- producer.setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentB);
- timeAfterSend = System.currentTimeMillis();
-
- exp = messageSentB.getJMSExpiration();
- TestUtil.logMsg("JMSExpiration is set to=" + exp);
- TestUtil.logMsg("Time before send=" + timeBeforeSend);
- TestUtil.logMsg("Time after send=" + timeAfterSend);
- TestUtil.logMsg("Time to Live =" + timeToLive);
-
- TestUtil.logMsg("JMSExpiration test - Recv a BytesMessage");
- messageReceivedB = (BytesMessage) consumer.receive(timeout);
- if (messageReceivedB == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedB.getJMSExpiration() != exp) {
- TestUtil.logErr(
- "BytesMessage failed: JMSExpiration didn't set correctly = "
- + messageReceivedB.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- } else {
- TestUtil.logMsg("BytesMessage JMSExpiration passed");
- }
- }
-
- // Send and receive a StreamMessage
- TestUtil.logMsg(
- "JMSExpiration test - Send a Streamessage (timeToLive is forever)");
- messageSentS = context.createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentS.writeString("Testing...");
- producer.setTimeToLive(forever);
- producer.send(destination, messageSentS);
- TestUtil.logMsg("JMSExpiration test - Recv a StreamMessage");
- messageReceivedS = (StreamMessage) consumer.receive(timeout);
- if (messageReceivedS == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedS.getJMSExpiration() != forever) {
- TestUtil.logMsg("StreamMessage JMSExpiration failed");
- pass = false;
- } else {
- TestUtil.logMsg("StreamMessage JMSExpiration passed");
- }
- }
-
- TestUtil.logMsg(
- "JMSExpiration test - Send a StreamMessage (timeToLive is 5000)");
- producer.setTimeToLive(timeToLive);
- timeBeforeSend = System.currentTimeMillis();
- producer.send(destination, messageSentS);
- timeAfterSend = System.currentTimeMillis();
-
- exp = messageSentS.getJMSExpiration();
- TestUtil.logMsg("JMSExpiration is set to=" + exp);
- TestUtil.logMsg("Time before send=" + timeBeforeSend);
- TestUtil.logMsg("Time after send=" + timeAfterSend);
- TestUtil.logMsg("Time to Live =" + timeToLive);
-
- TestUtil.logMsg("JMSExpiration test - Recv a StreamMessage");
- messageReceivedS = (StreamMessage) consumer.receive(timeout);
- if (messageReceivedS == null) {
- TestUtil.logErr("Received no message NULL (unexpected)");
- pass = false;
- } else {
- if (messageReceivedS.getJMSExpiration() != exp) {
- TestUtil.logErr(
- "StreamMessage failed: JMSExpiration didn't set correctly = "
- + messageReceivedS.getJMSExpiration());
- TestUtil.logErr("JMSExpiration was set to=" + exp);
- pass = false;
- } else {
- TestUtil.logMsg("StreamMessage JMSExpiration passed");
- }
- }
-
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSExpiration returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
- }
-
- /*
- * @testName: msgHdrJMSDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:3; JMS:SPEC:140; JMS:SPEC:246.2; JMS:JAVADOC:1192;
- * JMS:JAVADOC:1259; JMS:JAVADOC:367;
- *
- * @test_Strategy: 1. Create and send a message to the default Topic. Receive
- * the msg and verify that JMSDeliveryMode is set the default delivery mode of
- * persistent. 2. Create and test another message with a nonpersistent
- * delivery mode. Test with Text, map, object, byte, and stream messages 3.
- * Set JMSDeliveryMode to Message after receive. Verify that JMSDeliveryMode
- * is set correctly.
- */
- public void msgHdrJMSDeliveryModeTest() throws Exception {
- boolean pass = true;
- byte bValue = 127;
- String testName = "msgHdrJMSDeliveryModeTest";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- StreamMessage messageSentS = null;
- StreamMessage messageReceivedS = null;
- BytesMessage messageSentB = null;
- BytesMessage messageReceivedB = null;
- MapMessage messageReceivedM = null;
- MapMessage messageSentM = null;
- ObjectMessage messageSentO = null;
- ObjectMessage messageReceivedO = null;
-
- // send and receive Text message to Topic
- TestUtil
- .logMsg("send TextMessage to Topic with DeliveryMode.PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- messageSent = context.createTextMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- producer.send(destination, messageSent);
- TestUtil.logMsg("receive TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- TestUtil.logErr("TextMessage is null (unexpected)");
- } else if (messageReceived
- .getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "TextMessage failed: JMSDeliveryMode should be set to persistent");
- } else {
- TestUtil.logMsg("TextMessage JMSDeliveryMode passed");
- }
-
- TestUtil.logMsg(
- "send TextMessage to Topic with DeliveryMode.NON_PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- messageSent = context.createTextMessage();
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- producer.send(destination, messageSent);
- TestUtil.logMsg("receive TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
- if (messageReceived == null) {
- pass = false;
- TestUtil.logErr("TextMessage is null (unexpected)");
- } else if (messageReceived
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "TextMessage failed: JMSDeliveryMode should be set to non persistent");
- } else {
- TestUtil.logMsg("TextMessage JMSDeliveryMode passed");
- }
-
- // send and receive Object message to Topic
- TestUtil
- .logMsg("send ObjectMessage to Topic with DeliveryMode.PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- messageSentO = context.createObjectMessage();
- messageSentO.setObject("Test for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- producer.send(destination, messageSentO);
- TestUtil.logMsg("receive ObjectMessage");
- messageReceivedO = (ObjectMessage) consumer.receive(timeout);
- if (messageReceivedO == null) {
- pass = false;
- TestUtil.logErr("ObjectMessage is null (unexpected)");
- } else if (messageReceivedO
- .getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "ObjectMessage failed: JMSDeliveryMode should be set to persistent");
- } else {
- TestUtil.logMsg("ObjectMessage JMSDeliveryMode passed");
- }
-
- TestUtil.logMsg(
- "send ObjectMessage to Topic with DeliveryMode.NON_PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- messageSentO = context.createObjectMessage();
- messageSentO.setObject("Test for ObjectMessage");
- messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- producer.send(destination, messageSentO);
- TestUtil.logMsg("receive ObjectMessage");
- messageReceivedO = (ObjectMessage) consumer.receive(timeout);
- if (messageReceivedO == null) {
- pass = false;
- TestUtil.logErr("ObjectMessage is null (unexpected)");
- } else if (messageReceivedO
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "ObjectMessage failed: JMSDeliveryMode should be set to non persistent");
- } else {
- TestUtil.logMsg("ObjectMessage JMSDeliveryMode passed");
- }
-
- // send and receive map message to Topic
- TestUtil.logMsg("send MapMessage to Topic with DeliveryMode.PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- messageSentM = context.createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentM.setString("aString", "value");
- producer.send(destination, messageSentM);
- TestUtil.logMsg("receive MapMessage");
- messageReceivedM = (MapMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- pass = false;
- TestUtil.logErr("MapMessage is null (unexpected)");
- } else if (messageReceivedM
- .getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "MapMessage failed: JMSDeliveryMode should be set to persistent");
- } else {
- TestUtil.logMsg("MapMessage JMSDeliveryMode passed");
- }
-
- TestUtil
- .logMsg("send MapMessage to Topic with DeliveryMode.NON_PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- messageSentM = context.createMapMessage();
- messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentM.setString("aString", "value");
- producer.send(destination, messageSentM);
- TestUtil.logMsg("receive MapMessage");
- messageReceivedM = (MapMessage) consumer.receive(timeout);
- if (messageReceivedM == null) {
- pass = false;
- TestUtil.logErr("MapMessage is null (unexpected)");
- } else if (messageReceivedM
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "MapMessage failed: JMSDeliveryMode should be set to non persistent");
- } else {
- TestUtil.logMsg("MapMessage JMSDeliveryMode passed");
- }
-
- // send and receive bytes message to Topic
- TestUtil
- .logMsg("send BytesMessage to Topic with DeliveryMode.PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- messageSentB = context.createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentB.writeByte(bValue);
- producer.send(destination, messageSentB);
- TestUtil.logMsg("receive BytesMessage");
- messageReceivedB = (BytesMessage) consumer.receive(timeout);
- if (messageReceivedB == null) {
- pass = false;
- TestUtil.logErr("BytesMessage is null (unexpected)");
- } else if (messageReceivedB
- .getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "BytesMessage failed: JMSDeliveryMode should be set to persistent");
- } else {
- TestUtil.logMsg("BytesMessage JMSDeliveryMode passed");
- }
-
- TestUtil.logMsg(
- "send BytesMessage to Topic with DeliveryMode.NON_PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- messageSentB = context.createBytesMessage();
- messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentB.writeByte(bValue);
- producer.send(destination, messageSentB);
- TestUtil.logMsg("receive BytesMessage");
- messageReceivedB = (BytesMessage) consumer.receive(timeout);
- if (messageReceivedB == null) {
- pass = false;
- TestUtil.logErr("BytesMessage is null (unexpected)");
- } else if (messageReceivedB
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "BytesMessage failed: JMSDeliveryMode should be set to non persistent");
- } else {
- TestUtil.logMsg("BytesMessage JMSDeliveryMode passed");
- }
-
- // send and receive a StreamMessage
- TestUtil
- .logMsg("send StreamMessage to Topic with DeliveryMode.PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- messageSentS = context.createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentS.writeString("Testing...");
- producer.send(destination, messageSentS);
- TestUtil.logMsg("receive StreamMessage");
- messageReceivedS = (StreamMessage) consumer.receive(timeout);
- if (messageReceivedS == null) {
- pass = false;
- TestUtil.logErr("StreamMessage is null (unexpected)");
- } else if (messageReceivedS
- .getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "StreamMessage failed: JMSDeliveryMode should be set to persistent");
- } else {
- TestUtil.logMsg("StreamMessage JMSDeliveryMode passed");
- }
-
- TestUtil.logMsg(
- "send StreamMessage to Topic with DeliveryMode.NON_PERSISTENT.");
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- messageSentS = context.createStreamMessage();
- messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
- messageSentS.writeString("Testing...");
- producer.send(destination, messageSentS);
- TestUtil.logMsg("receive StreamMessage");
- messageReceivedS = (StreamMessage) consumer.receive(timeout);
- if (messageReceivedS == null) {
- pass = false;
- TestUtil.logErr("StreamMessage is null (unexpected)");
- } else if (messageReceivedS
- .getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- pass = false;
- TestUtil.logErr(
- "StreamMessage failed: JMSDeliveryMode should be set to non persistent");
- } else {
- TestUtil.logMsg("StreamMessage JMSDeliveryMode passed");
- }
-
- if (!pass) {
- throw new Exception(
- "Error: invalid JMSDeliveryMode returned from JMS Header");
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception(testName);
- }
- }
-
- /*
- * @testName: msgHdrJMSDeliveryTimeTest
- *
- * @assertion_ids: JMS:SPEC:246.11; JMS:SPEC:261; JMS:SPEC:256;
- * JMS:JAVADOC:1257; JMS:JAVADOC:875;
- *
- * @test_Strategy: Send message and verify that JMSDeliveryTime is correct
- * with the DeliveryDelay set to 20 seconds. Test with DeliveryMode.PERSISTENT
- * and DeliveryMode.NON_PERSISTENT.
- *
- * Retrieve and verify the JMSDeliveryTime
- */
- public void msgHdrJMSDeliveryTimeTest() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg(
- "---------------------------------------------------------------");
- TestUtil.logMsg(
- "BEGIN TEST msgHdrJMSDeliveryTimeTest with DeliveryDelay=20Secs");
- TestUtil.logMsg(
- "---------------------------------------------------------------");
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage messageSnd = context.createTextMessage("This is a test!");
-
- TestUtil.logMsg("Set StringProperty COM_SUN_JMS_TESTNAME");
- messageSnd.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgHdrJMSDeliveryTimeTest");
-
- TestUtil.logMsg(
- "Sending message with DeliveryMode.PERSISTENT and DeliveryDelay=20Secs");
- producer.setDeliveryDelay(20000);
- producer.setDeliveryMode(DeliveryMode.PERSISTENT);
- producer.setPriority(Message.DEFAULT_PRIORITY);
- producer.setTimeToLive(0L);
- producer.send(destination, messageSnd);
-
- // Get deliverytime and current GMT time after send
- TestUtil.logMsg("Get JMSDeliveryTime after sending message");
- long deliverydelay = producer.getDeliveryDelay();
- long gmtTimeAfterSend = System.currentTimeMillis();
- long JMSDeliveryTimeAfterSend = messageSnd.getJMSDeliveryTime();
-
- TestUtil.logMsg("Receive message with timeout value of 21Secs");
- TextMessage messageRcv = (TextMessage) consumer.receive(21000);
- if (messageRcv == null) {
- TestUtil.logErr(
- "FAILED: Message was not received after delivery delay of 30 secs elapsed");
- pass = false;
- } else {
- // Get JMSDeliverytime after receive
- TestUtil.logMsg("Get JMSDeliveryTime after receiving message");
- long gmtTimeAfterRecv = System.currentTimeMillis();
- long JMSDeliveryTimeAfterRecv = messageRcv.getJMSDeliveryTime();
-
- TestUtil.logMsg("Check JMSDeliverytime");
- TestUtil
- .logMsg("JMSDeliveryTime after send = " + JMSDeliveryTimeAfterSend);
- TestUtil.logMsg(
- "JMSDeliveryTime after receive = " + JMSDeliveryTimeAfterRecv);
- if (JMSDeliveryTimeAfterSend == JMSDeliveryTimeAfterRecv) {
- TestUtil.logMsg(
- "JMSDeliveryTimeAfterSend = JMSDeliveryTimeAfterRecv (PASS)");
- } else {
- TestUtil.logErr(
- "JMSDeliveryTimeAfterSend != JMSDeliveryTimeAfterRecv (FAIL)");
- pass = false;
- }
- TestUtil.logMsg("gmtTimeAfterSend after send = " + gmtTimeAfterSend);
- TestUtil.logMsg("gmtTimeAfterRecv after receive = " + gmtTimeAfterRecv);
- if (gmtTimeAfterRecv >= (gmtTimeAfterSend + deliverydelay - 250)) {
- TestUtil.logMsg(
- "gmtTimeAfterRecv >= (gmtTimeAfterSend + deliverydelay) (PASS)");
- } else {
- TestUtil.logErr(
- "gmtTimeAfterRecv < (gmtTimeAfterSend + deliverydelay) (FAIL)");
- pass = false;
- }
- }
-
- TestUtil.logMsg(
- "Sending message with DeliveryMode.NON_PERSISTENT and DeliveryDelay=20Secs");
- producer.setDeliveryDelay(20000);
- producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
- producer.setPriority(Message.DEFAULT_PRIORITY);
- producer.setTimeToLive(0L);
- producer.send(destination, messageSnd);
-
- // Get deliverytime and current GMT time after send
- TestUtil.logMsg("Get JMSDeliveryTime after sending message");
- gmtTimeAfterSend = System.currentTimeMillis();
- JMSDeliveryTimeAfterSend = messageSnd.getJMSDeliveryTime();
-
- TestUtil.logMsg("Receive message with timeout value of 21Secs");
- messageRcv = (TextMessage) consumer.receive(21000);
- if (messageRcv == null) {
- TestUtil.logErr(
- "FAILED: Message was not received after delivery delay of 20 secs elapsed");
- pass = false;
- } else {
- // Get JMSDeliverytime after receive
- TestUtil.logMsg("Get JMSDeliveryTime after receiving message");
- long gmtTimeAfterRecv = System.currentTimeMillis();
- long JMSDeliveryTimeAfterRecv = messageRcv.getJMSDeliveryTime();
-
- TestUtil.logMsg("Check JMSDeliverytime");
- TestUtil
- .logMsg("JMSDeliveryTime after send = " + JMSDeliveryTimeAfterSend);
- TestUtil.logMsg(
- "JMSDeliveryTime after receive = " + JMSDeliveryTimeAfterRecv);
- if (JMSDeliveryTimeAfterSend == JMSDeliveryTimeAfterRecv) {
- TestUtil.logMsg(
- "JMSDeliveryTimeAfterSend = JMSDeliveryTimeAfterRecv (PASS)");
- } else {
- TestUtil.logErr(
- "JMSDeliveryTimeAfterSend != JMSDeliveryTimeAfterRecv (FAIL)");
- pass = false;
- }
- TestUtil.logMsg("gmtTimeAfterSend after send = " + gmtTimeAfterSend);
- TestUtil.logMsg("gmtTimeAfterRecv after receive = " + gmtTimeAfterRecv);
- if (gmtTimeAfterRecv >= (gmtTimeAfterSend + deliverydelay - 250)) {
- TestUtil.logMsg(
- "gmtTimeAfterRecv >= (gmtTimeAfterSend + deliverydelay) (PASS)");
- } else {
- TestUtil.logErr(
- "gmtTimeAfterRecv < (gmtTimeAfterSend + deliverydelay) (FAIL)");
- pass = false;
- }
- }
- TestUtil.logMsg(
- "-------------------------------------------------------------");
- TestUtil.logMsg(
- "END TEST msgHdrJMSDeliveryTimeTest with DeliveryDelay=20Secs");
- TestUtil.logMsg(
- "-------------------------------------------------------------");
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("msgHdrJMSDeliveryTimeTest", e);
- }
-
- if (!pass) {
- throw new Exception("msgHdrJMSDeliveryTimeTest failed");
- }
- }
-
- /*
- * @testName: setGetAllPropertyTypesTest
- *
- * @assertion_ids: JMS:JAVADOC:1180; JMS:JAVADOC:1184; JMS:JAVADOC:1187;
- * JMS:JAVADOC:1198; JMS:JAVADOC:1201; JMS:JAVADOC:1204; JMS:JAVADOC:1215;
- * JMS:JAVADOC:1218; JMS:JAVADOC:1222; JMS:JAVADOC:1224; JMS:JAVADOC:1227;
- * JMS:JAVADOC:1232; JMS:JAVADOC:1275; JMS:JAVADOC:1278; JMS:JAVADOC:1281;
- * JMS:JAVADOC:1284; JMS:JAVADOC:1287; JMS:JAVADOC:1290; JMS:JAVADOC:1293;
- * JMS:JAVADOC:1296; JMS:JAVADOC:1299;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setProperty(String, boolean) JMSProducer.setProperty(String,
- * byte) JMSProducer.setProperty(String, double)
- * JMSProducer.setProperty(String, float) JMSProducer.setProperty(String, int)
- * JMSProducer.setProperty(String, long) JMSProducer.setProperty(String,
- * Object) JMSProducer.setProperty(String, short)
- * JMSProducer.setProperty(String, String)
- * JMSProducer.getBooleanProperty(String) JMSProducer.getByteProperty(String)
- * JMSProducer.getDoubleProperty(String) JMSProducer.getFloatProperty(String)
- * JMSProducer.getIntProperty(String) JMSProducer.getLongProperty(String)
- * JMSProducer.getObjectProperty(String) JMSProducer.getShortProperty(String)
- * JMSProducer.getStringProperty(String) JMSProducer.clearProperties(String)
- * JMSProducer.getPropertyNames() JMSProducer.propertyExists()
- */
- public void setGetAllPropertyTypesTest() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- int numPropertyNames = 16;
-
- try {
- logMsg("Set all JMSProducer properties");
- producer.setProperty("TESTBOOLEAN", bool);
- producer.setProperty("TESTBYTE", bValue);
- producer.setProperty("TESTDOUBLE", nDouble);
- producer.setProperty("TESTFLOAT", nFloat);
- producer.setProperty("TESTINT", nInt);
- producer.setProperty("TESTLONG", nLong);
- producer.setProperty("TESTSHORT", nShort);
- producer.setProperty("TESTSTRING", "test");
- producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
- producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
- producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
- producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
- producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
- producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
- producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
- producer.setProperty("OBJTESTSTRING", "test");
-
- logMsg("Get all JMSProducer properties");
- if (producer.getBooleanProperty("TESTBOOLEAN") == bool) {
- logMsg("Pass: getBooleanProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getBooleanProperty");
- pass = false;
- }
- if (producer.getByteProperty("TESTBYTE") == bValue) {
- logMsg("Pass: getByteProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getByteProperty");
- pass = false;
- }
- if (producer.getLongProperty("TESTLONG") == nLong) {
- logMsg("Pass: getLongProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getLongProperty");
- pass = false;
- }
- if (producer.getStringProperty("TESTSTRING").equals(testString)) {
- logMsg("Pass: getStringProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getStringProperty");
- pass = false;
- }
- if (producer.getDoubleProperty("TESTDOUBLE") == nDouble) {
- logMsg("Pass: getDoubleProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getDoubleProperty");
- pass = false;
- }
- if (producer.getFloatProperty("TESTFLOAT") == nFloat) {
- logMsg("Pass: getFloatProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getFloatProperty");
- pass = false;
- }
- if (producer.getIntProperty("TESTINT") == nInt) {
- logMsg("Pass: getIntProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getIntProperty");
- pass = false;
- }
- if (producer.getShortProperty("TESTSHORT") == nShort) {
- logMsg("Pass: getShortProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getShortProperty");
- pass = false;
- }
- if (((Boolean) producer.getObjectProperty("OBJTESTBOOLEAN"))
- .booleanValue() == bool) {
- logMsg("Pass: getObjectProperty returned correct Boolean value");
- } else {
- logMsg("Fail: incorrect Boolean value returned from getObjectProperty");
- pass = false;
- }
- if (((Byte) producer.getObjectProperty("OBJTESTBYTE"))
- .byteValue() == bValue) {
- logMsg("Pass: getObjectProperty returned correct Byte value");
- } else {
- logMsg("Fail: incorrect Byte value returned from getObjectProperty");
- pass = false;
- }
- if (((Long) producer.getObjectProperty("OBJTESTLONG"))
- .longValue() == nLong) {
- logMsg("Pass: getObjectProperty returned correct Long value");
- } else {
- logMsg("Fail: incorrect Long value returned from getObjectProperty");
- pass = false;
- }
- if (((String) producer.getObjectProperty("OBJTESTSTRING"))
- .equals(testString)) {
- logMsg("Pass: getObjectProperty returned correct String value");
- } else {
- logMsg("Fail: incorrect String value returned from getObjectProperty");
- pass = false;
- }
- if (((Double) producer.getObjectProperty("OBJTESTDOUBLE"))
- .doubleValue() == nDouble) {
- logMsg("Pass: getObjectProperty returned correct Double value");
- } else {
- logMsg("Fail: incorrect Double value returned from getObjectProperty");
- pass = false;
- }
- if (((Float) producer.getObjectProperty("OBJTESTFLOAT"))
- .floatValue() == nFloat) {
- logMsg("Pass: getObjectProperty returned correct Float value");
- } else {
- logMsg("Fail: incorrect Float value returned from getObjectProperty");
- pass = false;
- }
- if (((Integer) producer.getObjectProperty("OBJTESTINT"))
- .intValue() == nInt) {
- logMsg("Pass: getObjectProperty returned correct Integer value");
- } else {
- logMsg("Fail: incorrect Integer value returned from getObjectProperty");
- pass = false;
- }
- if (((Short) producer.getObjectProperty("OBJTESTSHORT"))
- .shortValue() == nShort) {
- logMsg("Pass: getObjectProperty returned correct Short value");
- } else {
- logMsg("Fail: incorrect Short value returned from getObjectProperty");
- pass = false;
- }
- logMsg(
- "Now check all property names returned by JMSProducer.getPropertyNames()");
- // iterate thru the property names
- int i = 0;
- Set propNames = producer.getPropertyNames();
- Iterator iterator = propNames.iterator();
- do {
- String tmp = iterator.next();
-
- if (!tmp.startsWith("JMS")) {
- i++;
- if (tmp.equals("TESTBOOLEAN") || tmp.equals("TESTBYTE")
- || tmp.equals("TESTINT") || tmp.equals("TESTSHORT")
- || tmp.equals("TESTFLOAT") || tmp.equals("TESTDOUBLE")
- || tmp.equals("TESTSTRING") || tmp.equals("TESTLONG")
- || tmp.equals("OBJTESTBOOLEAN") || tmp.equals("OBJTESTBYTE")
- || tmp.equals("OBJTESTINT") || tmp.equals("OBJTESTSHORT")
- || tmp.equals("OBJTESTFLOAT") || tmp.equals("OBJTESTDOUBLE")
- || tmp.equals("OBJTESTSTRING") || tmp.equals("OBJTESTLONG")) {
- logMsg("Producer Property set by client: " + tmp);
- } else {
- logErr("Producer Property not set by client: " + tmp);
- pass = false;
- }
- } else {
- logMsg("JMSProperty Name is: " + tmp);
- }
- } while (iterator.hasNext());
- if (i == numPropertyNames) {
- logMsg("Pass: # of properties is " + numPropertyNames + " as expected");
- } else {
- logMsg("Fail: expected " + numPropertyNames
- + " property names, but got " + i);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("setGetAllPropertyTypesTest");
- }
-
- if (!pass) {
- throw new Exception("setGetAllPropertyTypesTest failed");
- }
- }
-
- /*
- * @testName: setGetAllHeaderTypesTest
- *
- * @assertion_ids: JMS:JAVADOC:1265; JMS:JAVADOC:1267; JMS:JAVADOC:1269;
- * JMS:JAVADOC:1271; JMS:JAVADOC:1207; JMS:JAVADOC:1209; JMS:JAVADOC:1211;
- * JMS:JAVADOC:1213;
- *
- * @test_Strategy: Test the following APIs:
- *
- * JMSProducer.setJMSCorrelationID(String);
- * JMSProducer.setJMSCorrelationIDAsBytes(byte[]);
- * JMSProducer.setJMSReplyTo(Destination); JMSProducer.setJMSType(String);
- * JMSProducer.getJMSCorrelationID();
- * JMSProducer.getJMSCorrelationIDAsBytes(); JMSProducer.getJMSReplyTo();
- * JMSProducer.getJMSType();
- */
- public void setGetAllHeaderTypesTest() throws Exception {
- boolean pass = true;
-
- try {
-
- try {
- logMsg("Set JMSProducer message header JMSCorrelationID as bytes");
- byte[] cid = "TestCorrelationID".getBytes();
- producer.setJMSCorrelationIDAsBytes(cid);
-
- logMsg("Get JMSProducer message header JMSCorrelationID as bytes");
- cid = producer.getJMSCorrelationIDAsBytes();
- String cidString = new String(cid);
- if (cid == null) {
- logMsg("Fail: getJMSCorrelationID returned null");
- pass = false;
- } else if (cidString.equals("TestCorrelationID")) {
- logMsg("Pass: getJMSCorrelationID returned correct value");
- } else {
- logMsg("Fail: getJMSCorrelationID returned incorrect value, got: "
- + cidString + " expected: TestCorrelationID");
- pass = false;
- }
- } catch (java.lang.UnsupportedOperationException e) {
- logMsg("UnsupportedOperationException - no further testing.");
- }
-
- logMsg(
- "Set all JMSProducer message headers JMSCorrelationID, JMSType, JMSReplyTo");
- producer.setJMSCorrelationID("TestCorrelationID");
- producer.setJMSType("TestMessage");
- producer.setJMSReplyTo(topic);
-
- logMsg(
- "Get all JMSProducer message headers JMSCorrelationID, JMSType, JMSReplyTo");
- String temp = null;
- Destination tempdest = null;
- temp = producer.getJMSCorrelationID();
- if (temp == null) {
- logMsg("Fail: getJMSCorrelationID returned null");
- pass = false;
- } else if (temp.equals("TestCorrelationID")) {
- logMsg("Pass: getJMSCorrelationID returned correct value");
- } else {
- logMsg("Fail: getJMSCorrelationID returned incorrect value, got: "
- + temp + " expected: TestCorrelationID");
- pass = false;
- }
- temp = producer.getJMSType();
- if (temp == null) {
- logMsg("Fail: getJMSType returned null");
- pass = false;
- } else if (temp.equals("TestMessage")) {
- logMsg("Pass: getJMSType returned correct value");
- } else {
- logMsg("Fail: getJMSType returned incorrect value, got: " + temp
- + " expected: TestMessage");
- pass = false;
- }
- tempdest = producer.getJMSReplyTo();
- if (tempdest == null) {
- logMsg("Fail: getJMSReplyTo returned null");
- pass = false;
- } else if (tempdest.equals(topic)) {
- logMsg("Pass: getJMSReplyTo returned correct value");
- } else {
- logMsg("Fail: getJMSReplyTo returned incorrect value, got: " + tempdest
- + " expected: " + topic);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("setGetAllHeaderTypesTest");
- }
-
- if (!pass) {
- throw new Exception("setGetAllHeaderTypesTest failed");
- }
- }
-
- /*
- * @testName: msgPropertiesTest
- *
- * @assertion_ids: JMS:SPEC:20.1; JMS:SPEC:20.2; JMS:SPEC:20.3; JMS:SPEC:20.4;
- * JMS:SPEC:20.5; JMS:SPEC:20.6; JMS:SPEC:20.7; JMS:SPEC:20.8; JMS:SPEC:21;
- * JMS:SPEC:23; JMS:SPEC:25; JMS:SPEC:26; JMS:SPEC:10; JMS:SPEC:27;
- * JMS:SPEC:28; JMS:SPEC:29; JMS:SPEC:31; JMS:SPEC:32; JMS:SPEC:34;
- * JMS:SPEC:19; JMS:SPEC:70; JMS:SPEC:71; JMS:SPEC:24; JMS:JAVADOC:1180;
- * JMS:JAVADOC:1184; JMS:JAVADOC:1187; JMS:JAVADOC:1198; JMS:JAVADOC:1201;
- * JMS:JAVADOC:1204; JMS:JAVADOC:1215; JMS:JAVADOC:1218; JMS:JAVADOC:1222;
- * JMS:JAVADOC:1224; JMS:JAVADOC:1227; JMS:JAVADOC:1232; JMS:JAVADOC:1275;
- * JMS:JAVADOC:1278; JMS:JAVADOC:1281; JMS:JAVADOC:1284; JMS:JAVADOC:1287;
- * JMS:JAVADOC:1290; JMS:JAVADOC:1293; JMS:JAVADOC:1296; JMS:JAVADOC:1299;
- *
- * @test_Strategy: Set and read properties for boolean, byte, short, int,
- * long, float, double, and String. Verify expected results Set and read
- * properties for Boolean, Byte, Short, Int, Long, Float, Double, and String.
- * Verify expected results.
- *
- * Call property get methods (other than getStringProperty and
- * getObjectProperty) for non-existent properties and verify that a null
- * pointer exception is returned. Call getStringProperty and getObjectProperty
- * for non-existent properties and verify that a null is returned.
- *
- * Set object properties and verify the correct value is returned with the
- * getObjectProperty method.
- *
- * Call the clearProperties method on the JMSProducer and verify that the
- * message properties for that JMSProducer were deleted. Test that
- * getObjectProperty returns a null and the getShortProperty throws a null
- * pointer exception.
- *
- * Call getJMSXPropertyNames() and verify that the names of the required JMSX
- * properties for JMSXGroupID and JMSXGroupSeq are returned.
- */
- public void msgPropertiesTest() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- Enumeration propertyNames = null;
- Enumeration jmsxDefined = null;
- int numPropertyNames = 18;
- String testMessageBody = "Testing...";
- String message = "Where are you!";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // ------------------------------------------------------------------------------
- // Set JMSProducer message properties
- // Set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- logMsg("Set primitive property types on JMSProducer");
- producer.setProperty("TESTBOOLEAN", bool);
- producer.setProperty("TESTBYTE", bValue);
- producer.setProperty("TESTDOUBLE", nDouble);
- producer.setProperty("TESTFLOAT", nFloat);
- producer.setProperty("TESTINT", nInt);
- producer.setProperty("TESTLONG", nLong);
- producer.setProperty("TESTSHORT", nShort);
- producer.setProperty("TESTSTRING", "test");
-
- // ------------------------------------------------------------------------------
- // Set JMSProducer message properties
- // Set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
- // String.
- // ------------------------------------------------------------------------------
- logMsg("Set Object property types on JMSProducer");
- producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
- producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
- producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
- producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
- producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
- producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
- producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
- producer.setProperty("OBJTESTSTRING", "test");
-
- TestUtil.logMsg("Creating TextMessage");
- messageSent = context.createTextMessage(message);
- logMsg("messageSent=" + messageSent.getText());
- TestUtil.logMsg("Set some values in TextMessage");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesTest");
- producer.send(destination, messageSent);
- messageReceived = (TextMessage) consumer.receive(timeout);
- logMsg("messageReceived=" + messageReceived.getText());
-
- // Iterate thru the property names
- int i = 0;
- logMsg("Retrieve and verify correct # of properties set");
- propertyNames = messageReceived.getPropertyNames();
- do {
- String tmp = (String) propertyNames.nextElement();
- logMsg("Property Name is: " + tmp);
- if (tmp.indexOf("JMS") != 0)
- i++;
- else if (tmp.equals("JMSXDeliveryCount"))
- i++;
- } while (propertyNames.hasMoreElements());
-
- if (i == numPropertyNames) {
- logMsg("Pass: # of properties is " + numPropertyNames + " as expected");
- } else {
- logMsg("Fail: expected " + numPropertyNames
- + " property names, but got " + i);
- pass = false;
- }
-
- // -------------------------------------------------------------------------
- // Retrieve the JMSProducer properties and verify that they are correct
- // Get properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------
- logMsg(
- "Get properties for boolean, byte, short, int, long, float, double, and String.");
- logMsg(
- "Retrieve and verify that JMSProducer properties were set correctly");
- if (producer.getBooleanProperty("TESTBOOLEAN") == bool) {
- logMsg("Pass: getBooleanProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getBooleanProperty");
- pass = false;
- }
- if (producer.getByteProperty("TESTBYTE") == bValue) {
- logMsg("Pass: getByteProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getByteProperty");
- pass = false;
- }
- if (producer.getLongProperty("TESTLONG") == nLong) {
- logMsg("Pass: getLongProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getLongProperty");
- pass = false;
- }
- if (producer.getStringProperty("TESTSTRING").equals(testString)) {
- logMsg("Pass: getStringProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getStringProperty");
- pass = false;
- }
- if (producer.getDoubleProperty("TESTDOUBLE") == nDouble) {
- logMsg("Pass: getDoubleProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getDoubleProperty");
- pass = false;
- }
- if (producer.getFloatProperty("TESTFLOAT") == nFloat) {
- logMsg("Pass: getFloatProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getFloatProperty");
- pass = false;
- }
- if (producer.getIntProperty("TESTINT") == nInt) {
- logMsg("Pass: getIntProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getIntProperty");
- pass = false;
- }
- if (producer.getShortProperty("TESTSHORT") == nShort) {
- logMsg("Pass: getShortProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getShortProperty");
- pass = false;
- }
-
- // -----------------------------------------------------------------------------
- // Retrieve the JMSProducer properties and verify that they are correct
- // Get properties for Boolean, Byte, Short, Integer, Long, Float, Double,
- // String.
- // -----------------------------------------------------------------------------
- logMsg(
- "Get properties for Boolean, Byte, Short, Integer, Long, Float, Double, String.");
- if (((Boolean) producer.getObjectProperty("OBJTESTBOOLEAN"))
- .booleanValue() == bool) {
- logMsg("Pass: getObjectProperty returned correct Boolean value");
- } else {
- logMsg("Fail: incorrect Boolean value returned from getObjectProperty");
- pass = false;
- }
- if (((Byte) producer.getObjectProperty("OBJTESTBYTE"))
- .byteValue() == bValue) {
- logMsg("Pass: getObjectProperty returned correct Byte value");
- } else {
- logMsg("Fail: incorrect Byte value returned from getObjectProperty");
- pass = false;
- }
- if (((Long) producer.getObjectProperty("OBJTESTLONG"))
- .longValue() == nLong) {
- logMsg("Pass: getObjectProperty returned correct Long value");
- } else {
- logMsg("Fail: incorrect Long value returned from getObjectProperty");
- pass = false;
- }
- if (((String) producer.getObjectProperty("OBJTESTSTRING"))
- .equals(testString)) {
- logMsg("Pass: getObjectProperty returned correct String value");
- } else {
- logMsg("Fail: incorrect String value returned from getObjectProperty");
- pass = false;
- }
- if (((Double) producer.getObjectProperty("OBJTESTDOUBLE"))
- .doubleValue() == nDouble) {
- logMsg("Pass: getObjectProperty returned correct Double value");
- } else {
- logMsg("Fail: incorrect Double value returned from getObjectProperty");
- pass = false;
- }
- if (((Float) producer.getObjectProperty("OBJTESTFLOAT"))
- .floatValue() == nFloat) {
- logMsg("Pass: getObjectProperty returned correct Float value");
- } else {
- logMsg("Fail: incorrect Float value returned from getObjectProperty");
- pass = false;
- }
- if (((Integer) producer.getObjectProperty("OBJTESTINT"))
- .intValue() == nInt) {
- logMsg("Pass: getObjectProperty returned correct Integer value");
- } else {
- logMsg("Fail: incorrect Integer value returned from getObjectProperty");
- pass = false;
- }
- if (((Short) producer.getObjectProperty("OBJTESTSHORT"))
- .shortValue() == nShort) {
- logMsg("Pass: getObjectProperty returned correct Short value");
- } else {
- logMsg("Fail: incorrect Short value returned from getObjectProperty");
- pass = false;
- }
-
- // ---------------------------------------------------------------------------
- // Set JMSProducer message headers (Set JMSCorrelationID, JMSType,
- // JMSReplyTo)
- // ---------------------------------------------------------------------------
- logMsg(
- "Set message headers JMSCorrelationID, JMSType, JMSReplyTo on JMSProducer");
- producer.setJMSCorrelationID("TestCorrelationID");
- producer.setJMSType("TestMessage");
- producer.setJMSReplyTo(topic);
-
- // ---------------------------------------------------------------------------
- // Retrieve JMSProducer message headers and verify that they are set
- // correctly
- // ---------------------------------------------------------------------------
- String temp = null;
- Destination tempdest = null;
- temp = producer.getJMSCorrelationID();
- if (temp == null) {
- logMsg("Fail: getJMSCorrelationID returned null");
- pass = false;
- } else if (temp.equals("TestCorrelationID")) {
- logMsg("Pass: getJMSCorrelationID returned correct value");
- } else {
- logMsg("Fail: getJMSCorrelationID returned incorrect value, got: "
- + temp + " expected: TestCorrelationID");
- pass = false;
- }
- temp = producer.getJMSType();
- if (temp == null) {
- logMsg("Fail: getJMSType returned null");
- pass = false;
- } else if (temp.equals("TestMessage")) {
- logMsg("Pass: getJMSType returned correct value");
- } else {
- logMsg("Fail: getJMSType returned incorrect value, got: " + temp
- + " expected: TestMessage");
- pass = false;
- }
- tempdest = producer.getJMSReplyTo();
- if (tempdest == null) {
- logMsg("Fail: getJMSReplyTo returned null");
- pass = false;
- } else if (tempdest.equals(topic)) {
- logMsg("Pass: getJMSReplyTo returned correct value");
- } else {
- logMsg("Fail: getJMSReplyTo returned incorrect value, got: " + tempdest
- + " expected: " + topic);
- pass = false;
- }
-
- // --------------------------------------------------------------------------------------
- // Create a TextMessage, send it then receive it and verify that all the
- // JMSProducer
- // properties are set in the TextMessage
- // --------------------------------------------------------------------------------------
- logMsg("Create a TextMessage");
- messageSent = context.createTextMessage();
- messageSent.setText(testMessageBody);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesTest");
-
- logMsg("Send the TextMessage");
- producer.send(destination, messageSent);
- logMsg("messageSent=" + messageSent.getText());
-
- logMsg("Receive the TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
- logMsg("messageReceived=" + messageReceived.getText());
-
- // --------------------------------------------------------------------------------------
- // Retrieve the properties from the received TextMessage and verify that
- // they are correct
- // Get properties for boolean, byte, short, int, long, float, double, and
- // String.
- // -------------------------------------------------------------------------------------
- logMsg(
- "Retrieve and verify that TextMessage message properties were set correctly");
- if (messageReceived.getBooleanProperty("TESTBOOLEAN") == bool) {
- logMsg("Pass: getBooleanProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getBooleanProperty");
- pass = false;
- }
- if (messageReceived.getByteProperty("TESTBYTE") == bValue) {
- logMsg("Pass: getByteProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getByteProperty");
- pass = false;
- }
- if (messageReceived.getLongProperty("TESTLONG") == nLong) {
- logMsg("Pass: getLongProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getLongProperty");
- pass = false;
- }
- if (messageReceived.getStringProperty("TESTSTRING").equals(testString)) {
- logMsg("Pass: getStringProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getStringProperty");
- pass = false;
- }
- if (messageReceived.getDoubleProperty("TESTDOUBLE") == nDouble) {
- logMsg("Pass: getDoubleProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getDoubleProperty");
- pass = false;
- }
- if (messageReceived.getFloatProperty("TESTFLOAT") == nFloat) {
- logMsg("Pass: getFloatProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getFloatProperty");
- pass = false;
- }
- if (messageReceived.getIntProperty("TESTINT") == nInt) {
- logMsg("Pass: getIntProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getIntProperty");
- pass = false;
- }
- if (messageReceived.getShortProperty("TESTSHORT") == nShort) {
- logMsg("Pass: getShortProperty returned correct value");
- } else {
- logMsg("Fail: incorrect value returned from getShortProperty");
- pass = false;
- }
- if (messageReceived.getIntProperty("JMSXDeliveryCount") >= 1) {
- logMsg(
- "Pass: getIntProperty(JMSXDeliveryCount) returned correct value");
- } else {
- logMsg(
- "Fail: incorrect value returned from getIntProperty(JMSXDeliveryCount)");
- pass = false;
- }
-
- // --------------------------------------------------------------------------------------
- // Retrieve the properties from the received TextMessage and verify that
- // they are correct
- // Get properties for Boolean, Byte, Short, Integer, Long, Float, Double,
- // and String.
- // --------------------------------------------------------------------------------------
- if (((Boolean) messageReceived.getObjectProperty("OBJTESTBOOLEAN"))
- .booleanValue() == bool) {
- logMsg("Pass: getObjectProperty returned correct Boolean value");
- } else {
- logMsg("Fail: incorrect Boolean value returned from getObjectProperty");
- pass = false;
- }
- if (((Byte) messageReceived.getObjectProperty("OBJTESTBYTE"))
- .byteValue() == bValue) {
- logMsg("Pass: getObjectProperty returned correct Byte value");
- } else {
- logMsg("Fail: incorrect Byte value returned from getObjectProperty");
- pass = false;
- }
- if (((Long) messageReceived.getObjectProperty("OBJTESTLONG"))
- .longValue() == nLong) {
- logMsg("Pass: getObjectProperty returned correct Long value");
- } else {
- logMsg("Fail: incorrect Long value returned from getObjectProperty");
- pass = false;
- }
- if (((String) messageReceived.getObjectProperty("OBJTESTSTRING"))
- .equals(testString)) {
- logMsg("Pass: getObjectProperty returned correct String value");
- } else {
- logMsg("Fail: incorrect String value returned from getObjectProperty");
- pass = false;
- }
- if (((Double) messageReceived.getObjectProperty("OBJTESTDOUBLE"))
- .doubleValue() == nDouble) {
- logMsg("Pass: getObjectProperty returned correct Double value");
- } else {
- logMsg("Fail: incorrect Double value returned from getObjectProperty");
- pass = false;
- }
- if (((Float) messageReceived.getObjectProperty("OBJTESTFLOAT"))
- .floatValue() == nFloat) {
- logMsg("Pass: getObjectProperty returned correct Float value");
- } else {
- logMsg("Fail: incorrect Float value returned from getObjectProperty");
- pass = false;
- }
- if (((Integer) messageReceived.getObjectProperty("OBJTESTINT"))
- .intValue() == nInt) {
- logMsg("Pass: getObjectProperty returned correct Integer value");
- } else {
- logMsg("Fail: incorrect Integer value returned from getObjectProperty");
- pass = false;
- }
- if (((Short) messageReceived.getObjectProperty("OBJTESTSHORT"))
- .shortValue() == nShort) {
- logMsg("Pass: getObjectProperty returned correct Short value");
- } else {
- logMsg("Fail: incorrect Short value returned from getObjectProperty");
- pass = false;
- }
-
- // ---------------------------------------------------------------------------------------
- // Retrieve message headers from the received TextMessage and verify that
- // they are correct
- // ---------------------------------------------------------------------------------------
- temp = messageReceived.getJMSCorrelationID();
- if (temp == null) {
- logMsg("Fail: getJMSCorrelationID returned null");
- pass = false;
- } else if (temp.equals("TestCorrelationID")) {
- logMsg("Pass: getJMSCorrelationID returned correct value");
- } else {
- logMsg("Fail: getJMSCorrelationID returned incorrect value, got: "
- + temp + " expected: TestCorrelationID");
- pass = false;
- }
- temp = messageReceived.getJMSType();
- if (temp == null) {
- logMsg("Fail: getJMSType returned null");
- pass = false;
- } else if (temp.equals("TestMessage")) {
- logMsg("Pass: getJMSType returned correct value");
- } else {
- logMsg("Fail: getJMSType returned incorrect value, got: " + temp
- + " expected: TestMessage");
- pass = false;
- }
- tempdest = messageReceived.getJMSReplyTo();
- if (tempdest == null) {
- logMsg("Fail: getJMSReplyTo returned null");
- pass = false;
- } else if (tempdest.equals(topic)) {
- logMsg("Pass: getJMSReplyTo returned correct value");
- } else {
- logMsg("Fail: getJMSReplyTo returned incorrect value, got: " + tempdest
- + " expected: " + topic);
- pass = false;
- }
-
- // ----------------------------------------------------------------------------------
- // The other property get methods (other than getStringProperty and
- // getObjectProperty)
- // must behave as if the property exists with a null value
- // ----------------------------------------------------------------------------------
- try {
- boolean b = producer.getBooleanProperty("TESTDUMMY");
- if (b != false) {
- logMsg("Fail: should have received false for getBooleanProperty");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- byte value = producer.getByteProperty("TESTDUMMY");
- logMsg(
- "Fail: NumberFormatException should have occurred for getByteProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logMsg("Pass: NumberFormatException as expected ");
- }
- try {
- short value = producer.getShortProperty("TESTDUMMY");
- logMsg(
- "Fail: NumberFormatException should have occurred for getShortProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logMsg("Pass: NumberFormatException as expected ");
- }
- try {
- int value = producer.getIntProperty("TESTDUMMY");
- logMsg(
- "Fail: NumberFormatException should have occurred for getIntProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logMsg("Pass: NumberFormatException as expected ");
- }
- try {
- long value = producer.getLongProperty("TESTDUMMY");
- logMsg(
- "Fail: NumberFormatException should have occurred for getLongProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logMsg("Pass: NumberFormatException as expected ");
- }
- try {
- float value = producer.getFloatProperty("TESTDUMMY");
- logMsg(
- "Fail: NullPointerException should have occurred for getFloatProperty");
- pass = false;
- } catch (java.lang.NullPointerException np) {
- logMsg("Pass: NullPointerException as expected ");
- }
- try {
- double value = producer.getDoubleProperty("TESTDUMMY");
- logMsg(
- "Fail: NullPointerException should have occurred for getDoubleProperty");
- pass = false;
- } catch (java.lang.NullPointerException np) {
- logMsg("Pass: NullPointerException as expected ");
- }
-
- // clear JMSProducer properties
- producer.clearProperties();
-
- // -------------------------------------------------------------------
- // All JMSProducer properties are deleted by the clearProperties method.
- // This leaves the message with an empty set of properties.
- // -------------------------------------------------------------------
- Long aLong = (Long) producer.getObjectProperty("OBJTESTLONG");
- if (aLong == null) {
- logMsg("Pass: property was cleared");
- } else {
- logMsg(
- "Fail: getObjectProperty should have returned null for cleared property");
- pass = false;
- }
- try {
- short aShort = producer.getShortProperty("TESTSHORT");
- logMsg(
- "Fail: NumberFormatException should have occurred for getShortProperty");
- pass = false;
- } catch (java.lang.NumberFormatException np) {
- logMsg("Pass: NumberFormatException as expected ");
- }
-
- // Check that we have no property names
- Set propNames = producer.getPropertyNames();
- Iterator iterator = propNames.iterator();
- boolean hasElements = iterator.hasNext();
- if (hasElements) {
- logMsg(
- "Fail: JMSProducer.getPropertyName() has properties (unexpected)");
- pass = false;
- } else {
- logMsg(
- "Pass: JMSProducer.getPropertyName() has no properties (expected)");
- }
-
- // -------------------------------------------------------------------
- // JMSContext.getJMSXPropertyNames() method returns the
- // names of the JMSX properties supported by a connection.
- // -------------------------------------------------------------------
- try {
- ConnectionMetaData data = context.getMetaData();
- Enumeration cmd = data.getJMSXPropertyNames();
- String propName;
-
- if (cmd == null) {
- logMsg("Fail: no JMSX property names were returned!");
- logMsg(
- "expected JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount at a miniumum");
- pass = false;
- } else {
- int iCount = 0;
- do {
- propName = (String) cmd.nextElement();
- logMsg(propName);
- if (propName.equals("JMSXGroupID")
- || propName.equals("JMSXGroupSeq")
- || propName.equals("JMSXDeliveryCount")) {
- iCount++;
- }
- } while (cmd.hasMoreElements());
- if (iCount > 1) {
- logMsg("Pass:");
- } else {
- logMsg("Fail: Expected property names not returned");
- pass = false;
- }
- }
- } catch (Exception ee) {
- logMsg("Fail: unexpected exception: " + ee);
- pass = false;
- }
- if (!pass) {
- throw new Exception("msgPropertiesTest failed");
- }
- } catch (Exception e) {
- logErr("Caught unexpected exception: " + e);
- e.printStackTrace();
- throw new Exception("msgPropertiesTest failed");
- }
- }
-
- /*
- * @testName: msgPropertiesConversionTests
- *
- * @assertion_ids: JMS:SPEC:22.1; JMS:SPEC:22.2; JMS:SPEC:22.3; JMS:SPEC:22.4;
- * JMS:SPEC:22.5; JMS:SPEC:22.6; JMS:SPEC:22.7; JMS:SPEC:22.8; JMS:SPEC:22.9;
- * JMS:SPEC:22.10; JMS:SPEC:22.11; JMS:SPEC:22.12; JMS:SPEC:22.13;
- * JMS:SPEC:22.14; JMS:SPEC:22.15; JMS:SPEC:22.16; JMS:JAVADOC:1180;
- * JMS:JAVADOC:1184; JMS:JAVADOC:1187; JMS:JAVADOC:1198; JMS:JAVADOC:1201;
- * JMS:JAVADOC:1204; JMS:JAVADOC:1215; JMS:JAVADOC:1218; JMS:JAVADOC:1222;
- * JMS:JAVADOC:1224; JMS:JAVADOC:1227; JMS:JAVADOC:1232; JMS:JAVADOC:1275;
- * JMS:JAVADOC:1278; JMS:JAVADOC:1281; JMS:JAVADOC:1284; JMS:JAVADOC:1287;
- * JMS:JAVADOC:1290; JMS:JAVADOC:1293; JMS:JAVADOC:1296; JMS:JAVADOC:1299;
- * JMS:JAVADOC:1186; JMS:JAVADOC:1189; JMS:JAVADOC:1200; JMS:JAVADOC:1203;
- * JMS:JAVADOC:1206; JMS:JAVADOC:1217; JMS:JAVADOC:1226; JMS:JAVADOC:1229;
- *
- * @test_Strategy: Create a JMSProducer, set properties for all of the
- * primitive types verify the conversion by getting the properties.
- */
- public void msgPropertiesConversionTests() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- String testMessageBody = "Testing...";
- int ntest = 0;
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // ------------------------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- producer.setProperty("TESTBOOLEAN", bool);
- producer.setProperty("TESTBYTE", bValue);
- producer.setProperty("TESTSHORT", nShort);
- producer.setProperty("TESTINT", nInt);
- producer.setProperty("TESTFLOAT", nFloat);
- producer.setProperty("TESTDOUBLE", nDouble);
- producer.setProperty("TESTSTRING", "test");
- producer.setProperty("TESTLONG", nLong);
- producer.setProperty("TESTSTRINGTRUE", "true");
- producer.setProperty("TESTSTRINGFALSE", "false");
- producer.setProperty("TESTSTRING1", "1");
-
- // -------------------------------------------------------------------
- // test conversions for property values
- // -------------------------------------------------------------------
- // property set as boolean can be read only as string or boolean
- // -------------------------------------------------------------------
- // valid - boolean to string
- String myBool = producer.getStringProperty("TESTBOOLEAN");
-
- if (Boolean.valueOf(myBool).booleanValue() == bool) {
- logMsg("Pass: conversion from boolean to string - ok");
- } else {
- logMsg("Fail: conversion from boolean to string failed");
- pass = false;
- }
-
- // invalid - boolean to byte
- try {
- producer.getByteProperty("TESTBOOLEAN");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: boolean to byte ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- boolean to byte");
- pass = false;
- }
-
- // invalid - boolean to short
- try {
- producer.getShortProperty("TESTBOOLEAN");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: boolean to short ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- boolean to short");
- pass = false;
- }
-
- // invalid - boolean to int
- try {
- producer.getIntProperty("TESTBOOLEAN");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: boolean to int ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception --boolean to int ");
- pass = false;
- }
-
- // invalid - boolean to long
- try {
- producer.getLongProperty("TESTBOOLEAN");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: boolean to long ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- boolean to long");
- pass = false;
- }
-
- // invalid - boolean to float
- try {
- producer.getFloatProperty("TESTBOOLEAN");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: boolean to float ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- boolean to float");
- pass = false;
- }
-
- // invalid - boolean to double
- try {
- producer.getDoubleProperty("TESTBOOLEAN");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: boolean to double ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- boolean to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as byte can be read as a byte,short,int,long or string
- // valid - byte to string
- String myByte = producer.getStringProperty("TESTBYTE");
-
- if (Byte.valueOf(myByte).byteValue() == bValue) {
- logMsg("Pass: conversion from byte to string - ok");
- } else {
- logMsg("Fail: conversion from byte to string failed");
- pass = false;
- }
-
- // valid - byte to short
- if (producer.getShortProperty("TESTBYTE") == bValue) {
- logMsg("Pass: conversion from byte to short - ok");
- } else {
- logMsg("Fail: conversion from byte to short failed");
- pass = false;
- }
-
- // valid - byte to int
- if (producer.getIntProperty("TESTBYTE") == bValue) {
- logMsg("Pass: conversion from byte to int - ok");
- } else {
- logMsg("Fail: conversion from byte to int failed");
- pass = false;
- }
-
- // valid - byte to long
- if (producer.getLongProperty("TESTBYTE") == bValue) {
- logMsg("Pass: conversion from byte to long - ok");
- } else {
- logMsg("Fail: conversion from byte to long failed");
- pass = false;
- }
-
- // invalid - byte to boolean
- try {
- producer.getBooleanProperty("TESTBYTE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: byte to boolean ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- byte to boolean");
- pass = false;
- }
-
- // invalid - byte to float
- try {
- producer.getFloatProperty("TESTBYTE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: byte to float ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception --byte to float ");
- pass = false;
- }
-
- // invalid - byte to double
- try {
- producer.getDoubleProperty("TESTBYTE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: byte to double ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- byte to double");
- pass = false;
- }
-
- // -------------------------------------------------
- // property set as short can be read as short,int,long or string
- // valid - short to string
- String myshort = producer.getStringProperty("TESTSHORT");
-
- if (Short.valueOf(myshort).shortValue() == nShort) {
- logMsg("Pass: conversion from short to string - ok");
- } else {
- logMsg("Fail: conversion from short to string failed");
- pass = false;
- }
-
- // valid - short to int
- if (producer.getIntProperty("TESTSHORT") == nShort) {
- logMsg("Pass: conversion from short to int - ok");
- } else {
- logMsg("Fail: conversion from short to int failed");
- pass = false;
- }
-
- // valid - short to long
- if (producer.getLongProperty("TESTSHORT") == nShort) {
- logMsg("Pass: conversion from short to long - ok");
- } else {
- logMsg("Fail: conversion from short to long failed");
- pass = false;
- }
-
- // invalid - short to boolean
- try {
- producer.getBooleanProperty("TESTSHORT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: short to boolean ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- short to boolean");
- pass = false;
- }
-
- // invalid - short to byte
- try {
- producer.getByteProperty("TESTSHORT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: short to byte ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- short to byte");
- pass = false;
- }
-
- // invalid - short to float
- try {
- producer.getFloatProperty("TESTSHORT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: short to float ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- short to float");
- pass = false;
- }
-
- // invalid - short to double
- try {
- producer.getDoubleProperty("TESTSHORT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: short to double ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- short to double");
- pass = false;
- }
-
- // -------------------------------------------------
- // property set as int can be read only as int, long or string
- // valid - int to string
- if (Integer.valueOf(producer.getStringProperty("TESTINT"))
- .intValue() == nInt) {
- logMsg("Pass: conversion from int to string - ok");
- } else {
- logMsg("Fail: conversion from int to string failed");
- pass = false;
- }
-
- // valid - int to long
- if (producer.getLongProperty("TESTINT") == nInt) {
- logMsg("Pass: conversion from int to long - ok");
- } else {
- logMsg("Fail: conversion from int to long failed");
- pass = false;
- }
-
- // invalid - int to boolean
- try {
- producer.getBooleanProperty("TESTINT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: int to boolean ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- int to boolean");
- pass = false;
- }
-
- // invalid - int to byte
- try {
- producer.getByteProperty("TESTINT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: int to byte ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- int to byte");
- pass = false;
- }
-
- // invalid - int to short
- try {
- producer.getShortProperty("TESTINT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: int to short ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg(
- "Pass: MessageFormatRuntimeException as expected -- int to short ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception ");
- pass = false;
- }
-
- // invalid - int to float
- try {
- producer.getFloatProperty("TESTINT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: int to float ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- int to float");
- pass = false;
- }
-
- // invalid - int to double
- try {
- producer.getDoubleProperty("TESTINT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: int to double ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- int to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as long can be read only as long,or a string
- // valid - long to string
- if (Long.valueOf(producer.getStringProperty("TESTLONG"))
- .longValue() == nLong) {
- logMsg("Pass: conversion from long to string - ok");
- } else {
- logMsg("Fail: conversion from long to string failed");
- pass = false;
- }
-
- // invalid - long to boolean
- try {
- producer.getBooleanProperty("TESTLONG");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: long to boolean ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- long to boolean");
- pass = false;
- }
-
- // invalid - long to byte
- try {
- producer.getByteProperty("TESTLONG");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: long to byte ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- long to byte");
- pass = false;
- }
-
- // invalid - long to short
- try {
- producer.getShortProperty("TESTLONG");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: long to short ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- long to short ");
- pass = false;
- }
-
- // invalid - long to int
- try {
- producer.getIntProperty("TESTLONG");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: long to int ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- long to int");
- pass = false;
- }
-
- // invalid - long to float
- try {
- producer.getFloatProperty("TESTLONG");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: long to float ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- long to float");
- pass = false;
- }
-
- // invalid - long to double
- try {
- producer.getDoubleProperty("TESTLONG");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: long to double ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- long to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as float can be read only as float,double or a string
- // valid - float to string
- if (Float.valueOf(producer.getStringProperty("TESTFLOAT"))
- .floatValue() == nFloat) {
- logMsg("Pass: conversion from float to string - ok");
- } else {
- logMsg("Fail: conversion from float to string failed");
- pass = false;
- }
-
- // valid - float to double
- if (producer.getDoubleProperty("TESTFLOAT") == nFloat) {
- logMsg("Pass: conversion from long to double - ok");
- } else {
- logMsg("Fail: conversion from long to double failed");
- pass = false;
- }
-
- // invalid - float to boolean
- try {
- producer.getBooleanProperty("TESTFLOAT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: float to boolean ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- float to boolean ");
- pass = false;
- }
-
- // invalid - float to byte
- try {
- producer.getByteProperty("TESTFLOAT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: float to byte ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- float to byte");
- pass = false;
- }
-
- // invalid - float to short
- try {
- producer.getShortProperty("TESTFLOAT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: float to short ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception - float to short ");
- pass = false;
- }
-
- // invalid - float to int
- try {
- producer.getIntProperty("TESTFLOAT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: float to int ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception --- float to int");
- pass = false;
- }
-
- // invalid - float to long
- try {
- producer.getLongProperty("TESTFLOAT");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: float to long ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- float to long");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as double can be read only as double or string
- // valid - double to string
- if (Double.valueOf(producer.getStringProperty("TESTDOUBLE"))
- .doubleValue() == nDouble) {
- logMsg("Pass: conversion from double to string - ok");
- } else {
- logMsg("Fail: conversion from double to string failed");
- pass = false;
- }
-
- // invalid - double to boolean
- try {
- producer.getBooleanProperty("TESTDOUBLE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: double to boolean ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- double to boolean ");
- pass = false;
- }
-
- // invalid - double to byte
- try {
- producer.getByteProperty("TESTDOUBLE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: double to byte ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- double to byte ");
- pass = false;
- }
-
- // invalid - double to short
- try {
- producer.getShortProperty("TESTDOUBLE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: double to short ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- double to short");
- pass = false;
- }
-
- // invalid - double to int
- try {
- producer.getIntProperty("TESTDOUBLE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: double to int ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception --- double to int ");
- pass = false;
- }
-
- // invalid - double to long
- try {
- producer.getLongProperty("TESTDOUBLE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: double to long ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- double to long");
- pass = false;
- }
-
- // invalid - double to float
- try {
- producer.getFloatProperty("TESTDOUBLE");
- logMsg(
- "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
- logMsg("Fail: unsupported conversion: double to float ");
- pass = false;
- } catch (MessageFormatRuntimeException me) {
- logMsg("Pass: MessageFormatRuntimeException as expected ");
- } catch (Exception ee) {
- logMsg("Fail: Caught unexpected exception: " + ee);
- logMsg("Fail: did not catch expected Exception -- double to float");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as string can be read as boolean, byte, short,
- // int, long, float, double, and String.
- // valid - string to boolean
- if ((producer.getBooleanProperty("TESTSTRINGTRUE")) == true) {
- logMsg("Pass: conversion from string to boolean - expect true - ok");
- } else {
- logMsg(
- "Fail: conversion from string to boolean - expect true - failed");
- pass = false;
- }
- if ((producer.getBooleanProperty("TESTSTRINGFALSE")) == false) {
- logMsg("Pass: conversion from string to boolean expect false - ok");
- } else {
- logMsg("Fail: conversion from string to boolean expect false - failed");
- pass = false;
- }
-
- // valid - string to byte
- if (producer.getByteProperty("TESTSTRING1") == 1) {
- logMsg("Pass: conversion from string to byte - ok");
- } else {
- logMsg("Fail: conversion from string to byte failed");
- pass = false;
- }
-
- // valid - string to short
- if (producer.getShortProperty("TESTSTRING1") == 1) {
- logMsg("Pass: conversion from string to short - ok");
- } else {
- logMsg("Fail: conversion from string to short failed");
- pass = false;
- }
-
- // valid - string to int
- if (producer.getIntProperty("TESTSTRING1") == 1) {
- logMsg("Pass: conversion from string to int - ok");
- } else {
- logMsg("Fail: conversion from string to int failed");
- pass = false;
- }
-
- // valid - string to long
- if (producer.getLongProperty("TESTSTRING1") == 1) {
- logMsg("Pass: conversion from string to long - ok");
- } else {
- logMsg("Fail: conversion from string to long failed");
- pass = false;
- }
-
- // valid - string to float
- if (producer.getFloatProperty("TESTSTRING1") == 1) {
- logMsg("Pass: conversion from string to float - ok");
- } else {
- logMsg("Fail: conversion from string to float failed");
- pass = false;
- }
-
- // valid - string to double
- if (producer.getDoubleProperty("TESTSTRING1") == 1) {
- logMsg("Pass: conversion from string to double - ok");
- } else {
- logMsg("Fail: conversion from string to double failed");
- pass = false;
- }
- } catch (Exception e) {
- logMsg("Caught unexpected exception: " + e);
- throw new Exception("msgPropertiesConversionTests failed");
- }
-
- if (!pass) {
- throw new Exception("msgPropertiesConversionTests failed");
- }
- }
-
- /*
- * @testName: msgPropertyExistTest
- *
- * @assertion_ids: JMS:JAVADOC:1180; JMS:JAVADOC:1184; JMS:JAVADOC:1187;
- * JMS:JAVADOC:1198; JMS:JAVADOC:1201; JMS:JAVADOC:1204; JMS:JAVADOC:1215;
- * JMS:JAVADOC:1218; JMS:JAVADOC:1222; JMS:JAVADOC:1224; JMS:JAVADOC:1227;
- * JMS:JAVADOC:1232; JMS:JAVADOC:1275; JMS:JAVADOC:1278; JMS:JAVADOC:1281;
- * JMS:JAVADOC:1284; JMS:JAVADOC:1287; JMS:JAVADOC:1290; JMS:JAVADOC:1293;
- * JMS:JAVADOC:1296; JMS:JAVADOC:1299;
- *
- * @test_Strategy: Set and read properties for boolean, byte, short, int,
- * long, float, double, and String. Verify expected results.
- */
- public void msgPropertyExistTest() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- Enumeration propertyNames = null;
- String testMessageBody = "Testing msgPropertyExistTest";
-
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // ------------------------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- producer.setProperty("TESTBOOLEAN", bool);
- producer.setProperty("TESTBYTE", bValue);
- producer.setProperty("TESTSHORT", nShort);
- producer.setProperty("TESTINT", nInt);
- producer.setProperty("TESTFLOAT", nFloat);
- producer.setProperty("TESTDOUBLE", nDouble);
- producer.setProperty("TESTSTRING", "test");
- producer.setProperty("TESTLONG", nLong);
- producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
-
- // --------------------------------------------------------------------------------------
- // Create a TextMessage, send it then receive it and verify that all the
- // JMSProducer
- // properties are set in the TextMessage
- // --------------------------------------------------------------------------------------
- logMsg("Create a TextMessage");
- messageSent = context.createTextMessage();
- messageSent.setText(testMessageBody);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesTest");
-
- logMsg("Send the TextMessage");
- producer.send(destination, messageSent);
-
- logMsg("Receive the TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
-
- if (messageReceived == null) {
- pass = false;
- TestUtil.logErr("messageReceived is null (unexpected)");
- } else {
-
- // iterate thru the property names
- int i = 0;
- propertyNames = messageReceived.getPropertyNames();
- do {
- String tmp = (String) propertyNames.nextElement();
-
- if (!tmp.startsWith("JMS")) {
- i++;
- if (tmp.equals("TESTBOOLEAN") || tmp.equals("TESTBYTE")
- || tmp.equals("TESTINT") || tmp.equals("TESTSHORT")
- || tmp.equals("TESTFLOAT") || tmp.equals("TESTDOUBLE")
- || tmp.equals("TESTSTRING") || tmp.equals("TESTLONG")
- || tmp.equals("OBJTESTBOOLEAN")
- || tmp.equals("COM_SUN_JMS_TESTNAME")) {
- logMsg("Application Property set by client is: " + tmp);
- if (!messageReceived.propertyExists(tmp)) {
- pass = messageReceived.propertyExists(tmp);
- logErr("Positive propertyExists test failed for " + tmp);
- } else if (messageReceived.propertyExists(tmp + "1")) {
- pass = false;
- logErr("Negative propertyExists test failed for " + tmp + "1");
- }
- } else {
- logErr("Appclication Property not set by client: " + tmp);
- pass = false;
- }
- } else {
- logMsg("JMSProperty Name is: " + tmp);
- }
- } while (propertyNames.hasMoreElements());
- }
-
- if (!pass) {
- throw new Exception("msgPropertyExistTest failed");
- }
- } catch (Exception e) {
- TestUtil.logMsg("Caught unexpected exception: " + e);
- throw new Exception("msgPropertyExistTest failed");
- }
- }
-
- /*
- * @testName: msgJMSXPropertiesTest
- *
- * @assertion_ids: JMS:SPEC:34; JMS:SPEC:34.3; JMS:SPEC:34.4; JMS:SPEC:34.5;
- * JMS:SPEC:257;
- *
- * @test_Strategy: Set and read JMSX properties JMSXGroupID and JMSXGroupSeq.
- * Verify the value of the JMSX properties JMSXGroupID and JMSXGroupSeq are
- * the same as set by client. Verify that the JMS provider sets the mandatory
- * JMSXDeliveryCount.
- *
- * 1) Create JMSContext and JMSConsumer for Topic. 2) Create TextMessage and
- * set JMSXGroupID and JMSXGroupSeq message properties. 3) Send the
- * TextMessage to the Topic. 4) Receive the TextMessage from the Topic. 5)
- * Verify the TextMessage. Verify that the message properites JMSXGroupID,
- * JMSXGroupSeq, and JMSXDeliveryCount are correct.
- */
- public void msgJMSXPropertiesTest() throws Exception {
- boolean pass = true;
- String message = "Testing msgJMSXPropertiesTest";
- int seq = 123450;
- String id = "msgJMSXPropertiesTest";
- try {
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
-
- TestUtil.logMsg("Set StringProperty COM_SUN_JMS_TESTNAME");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgJMSXPropertiesTest");
-
- TestUtil.logMsg("Set JMSXGroupID and JMSXGroupSeq");
- expTextMessage.setStringProperty("JMSXGroupID", id);
- expTextMessage.setIntProperty("JMSXGroupSeq", seq);
-
- TestUtil.logMsg("Send the TextMessage");
- producer.send(destination, expTextMessage);
-
- TestUtil.logMsg("Receive the TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
-
- TestUtil.logMsg("Verify the value in TextMessage");
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
-
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
-
- TestUtil.logMsg(
- "Verify properties JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount in TextMessage");
- if (actTextMessage.propertyExists("JMSXGroupID")) {
- if (actTextMessage.getStringProperty("JMSXGroupID").equals(id)) {
- logMsg("Pass: getStringProperty(JMSXGroupID) returned correct value");
- } else {
- logErr(
- "Fail: incorrect value returned from getStringProperty(JMSXGroupID)");
- pass = false;
- }
- } else {
- logErr(
- "Fail: TextMessage does not contain expected JMSXGroupID property");
- pass = false;
- }
-
- if (actTextMessage.propertyExists("JMSXGroupSeq")) {
- if (actTextMessage.getIntProperty("JMSXGroupSeq") == seq) {
- logMsg("Pass: getIntProperty(JMSXGroupSeq) returned correct value");
- } else {
- logErr(
- "Fail: incorrect value returned from getIntProperty(JMSXGroupSeq)");
- pass = false;
- }
- } else {
- logErr(
- "Fail: TextMessage does not contain expected JMSXGroupSeq property");
- pass = false;
- }
-
- if (actTextMessage.propertyExists("JMSXDeliveryCount")) {
- if (actTextMessage.getIntProperty("JMSXDeliveryCount") == 1) {
- logMsg(
- "Pass: getIntProperty(JMSXDeliveryCount) returned correct value");
- } else {
- logErr(
- "Fail: incorrect value returned from getIntProperty(JMSXDeliveryCount)");
- pass = false;
- }
- } else {
- logErr(
- "Fail: TextMessage does not contain expected JMSXDeliveryCount property");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // ConnectionMetaData.getJMSXPropertyNames() method returns the
- // names of the JMSX properties supported by a connection.
- // -------------------------------------------------------------------
- TestUtil.logMsg("Verify the JMSXProperties in ConnectionData");
- try {
- TestUtil.logMsg("Get ConnectionMetaData");
- ConnectionMetaData data = context.getMetaData();
- TestUtil.logMsg("Get JMSXPropertyNames");
- Enumeration cmd = data.getJMSXPropertyNames();
- TestUtil.logMsg(
- "Verify that we have JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount");
- if (cmd == null) {
- TestUtil.logErr("No JMSX property names were returned (Failed)");
- pass = false;
- } else {
- int iCount = 0;
- do {
- String propName = (String) cmd.nextElement();
- TestUtil.logTrace("Found JMSX property [" + propName + "]");
- if (propName.equals("JMSXGroupID"))
- iCount++;
- else if (propName.equals("JMSXGroupSeq"))
- iCount++;
- else if (propName.equals("JMSXDeliveryCount"))
- iCount++;
- } while (cmd.hasMoreElements());
-
- if (iCount > 2) {
- TestUtil
- .logMsg("Expected JMSX property names were returned (Passed)");
- } else {
- TestUtil
- .logErr("Expected JMSX property names not returned (Failed)");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("msgJMSXPropertiesTest", e);
- }
-
- if (!pass) {
- throw new Exception("msgJMSXPropertiesTest failed");
- }
- }
-
- /*
- * @testName: setPropertyExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1280; JMS:JAVADOC:1283; JMS:JAVADOC:1286;
- * JMS:JAVADOC:1289; JMS:JAVADOC:1292; JMS:JAVADOC:1295; JMS:JAVADOC:1298;
- * JMS:JAVADOC:1301; JMS:JAVADOC:1277; JMS:JAVADOC:1302;
- *
- * @test_Strategy: Tests IllegalArgumentException and
- * MessageFormatRuntimeException conditions from the following API's:
- *
- * JMSProducer.setProperty(String, boolean) throws IllegalArgumentException
- * JMSProducer.setProperty(String, byte)throws IllegalArgumentException
- * JMSProducer.setProperty(String, double)throws IllegalArgumentException
- * JMSProducer.setProperty(String, float)throws IllegalArgumentException
- * JMSProducer.setProperty(String, int)throws IllegalArgumentException
- * JMSProducer.setProperty(String, long)throws IllegalArgumentException
- * JMSProducer.setProperty(String, Object)throws IllegalArgumentException
- * JMSProducer.setProperty(String, short)throws IllegalArgumentException
- * JMSProducer.setProperty(String, String)throws IllegalArgumentException
- * JMSProducer.setProperty(String, Object)throws MessageFormatRuntimeException
- */
- public void setPropertyExceptionTests() throws Exception {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
-
- try {
- // Create JMSProducer from JMSContext
- logMsg("Create a JMSProducer from JMSContext");
- producer = context.createProducer();
-
- TestUtil.logMsg(
- "Test IllegalArgumentException from all JMSProducer setProperty() API's");
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", boolean)");
- producer.setProperty("", bool);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", byte)");
- producer.setProperty("", bValue);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", double)");
- producer.setProperty("", nDouble);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", float)");
- producer.setProperty("", nFloat);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil
- .logMsg("Test IllegalArgumentException for setProperty(\"\", int)");
- producer.setProperty("", nInt);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", long)");
- producer.setProperty("", nLong);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", short)");
- producer.setProperty("", nShort);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", String)");
- producer.setProperty("", "test");
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(\"\", Object)");
- producer.setProperty("", Long.valueOf(nLong));
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, boolean)");
- producer.setProperty(null, bool);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, byte)");
- producer.setProperty(null, bValue);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, double)");
- producer.setProperty(null, nDouble);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, float)");
- producer.setProperty(null, nFloat);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil
- .logMsg("Test IllegalArgumentException for setProperty(null, int)");
- producer.setProperty(null, nInt);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, long)");
- producer.setProperty(null, nLong);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, short)");
- producer.setProperty(null, nShort);
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, String)");
- producer.setProperty(null, "test");
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Test IllegalArgumentException for setProperty(null, Object)");
- producer.setProperty(null, Long.valueOf(nLong));
- TestUtil
- .logErr("Fail: Did not throw expected IllegalArgumentException");
- pass = false;
- } catch (IllegalArgumentException e) {
- TestUtil.logMsg("Pass: Caught expected IllegalArgumentException");
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Test MessageFormatRuntimeException for setProperty(String, Object)");
- producer.setProperty("name1", new java.util.Date());
- TestUtil.logErr(
- "Fail: Did not throw expected MessageFormatRuntimeException");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg(
- "Pass: Caught expected MessageFormatRuntimeException: " + e);
- } catch (Exception e) {
- TestUtil.logErr("Fail: Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setPropertyExceptionTests");
- }
-
- if (!pass) {
- throw new Exception("setPropertyExceptionTests failed");
- }
- }
-
- /*
- * @testName: sendExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1241; JMS:JAVADOC:1245; JMS:JAVADOC:1238;
- *
- * @test_Strategy: Tests MessageFormatRuntimeException and
- * MessageNotWriteableRuntimeException conditions from the following API's:
- *
- * JMSProducer.send(Destination, Message) throws
- * MessageNotWriteableRuntimeException JMSProducer.send(Destination, Message)
- * throws MessageFormatRuntimeException JMSProducer.send(Destination, Map)
- * throws MessageFormatRuntimeException
- *
- */
- public void sendExceptionTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- try {
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Message) for MessageFormatRuntimeException");
- try {
- TestUtil.logMsg(
- "Calling send(Destination, Message) -> expect MessageFormatRuntimeException");
- producer.send(destination, (Message) null);
- TestUtil.logErr("MessageFormatRuntimeException was not thrown");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected MessageFormatRuntimeException, received " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Map) for MessageFormatRuntimeException");
- try {
- Map mp = new HashMap();
- mp.put("1", new ArrayList(2));
- mp.put("2", new Properties());
- mp.put("2", new Properties());
- mp.put("1", new ArrayList(2));
- TestUtil.logMsg(
- "Calling send(Destination, Map) -> expect MessageFormatRuntimeException");
- producer.send(destination, mp);
- TestUtil.logErr("MessageFormatRuntimeException was not thrown");
- pass = false;
- } catch (MessageFormatRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageFormatRuntimeException");
- } catch (Exception e) {
- TestUtil
- .logErr("Expected MessageFormatRuntimeException, received " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Testing JMSProducer.send(Destination, Message) for MessageNotWriteableRuntimeException");
- try {
- // send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage sendTextMessage = context.createTextMessage(message);
- sendTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendExceptionTests");
- TestUtil.logMsg("Send TextMessage");
- producer.send(destination, sendTextMessage);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage recvTextMessage = (TextMessage) consumer.receive(timeout);
- if (recvTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (recvTextMessage.getText().equals(sendTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + sendTextMessage.getText()
- + ", received " + recvTextMessage.getText());
- pass = false;
- }
- }
- TestUtil.logMsg("Set a bunch of JMSProducer properties");
- producer.setProperty("TESTBOOLEAN", bool);
- producer.setProperty("TESTBYTE", bValue);
- producer.setProperty("TESTDOUBLE", nDouble);
- producer.setProperty("TESTFLOAT", nFloat);
- producer.setProperty("TESTINT", nInt);
- producer.setProperty("TESTLONG", nLong);
- producer.setProperty("TESTSHORT", nShort);
- producer.setProperty("TESTSTRING", testString);
- producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
- TestUtil.logMsg(
- "Using received TextMessage try and send it (expect MessageNotWriteableRuntimeException)");
- producer.send(destination, recvTextMessage);
- TestUtil.logErr("MessageNotWriteableRuntimeException was not thrown");
- pass = false;
- } catch (MessageNotWriteableRuntimeException e) {
- TestUtil.logMsg("Caught expected MessageNotWriteableRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected MessageNotWriteableRuntimeException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("sendExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("sendExceptionTests failed");
- }
- }
-
- /*
- * @testName: getBodyTests
- *
- * @assertion_ids: JMS:JAVADOC:1357;
- *
- * @test_Strategy: Send and receive messages of the following types:
- * BytesMessage, MapMessage, ObjectMessage, TextMessage. Call
- * Message.getBody() to return the message as the specified Object type.
- *
- * Object = Message.getBody(Class)
- *
- * Test the following:
- *
- * String message = Message.getBody(String.class) byte[] message =
- * Message.getBody(byte[].class); StringBuffer message =
- * Message.getBody(StringBuffer.class); Map message =
- * Message.getBody(Map.class);
- *
- */
- public void getBodyTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- StringBuffer expSbuffer = new StringBuffer("This is it!");
- try {
- // Send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
- TestUtil.logMsg("Send and receive the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Call TextMessage.getBody(String.class) to extract TextMessage as String");
- String actMessage = actTextMessage.getBody(String.class);
- TestUtil.logMsg("Check the value in String");
- if (actMessage.equals(message)) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect expected " + message
- + ", received " + actMessage);
- pass = false;
- }
-
- // Send and receive ObjectMessage
- TestUtil.logMsg("Create ObjectMessage");
- ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
- TestUtil.logMsg("Set some values in ObjectMessage");
- expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "getBodyTests");
- TestUtil.logMsg("Send and receive the ObjectMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expObjectMessage);
- TestUtil
- .logMsg("Call JMSConsumer.receive(long) to receive ObjectMessage");
- ObjectMessage actObjectMessage = (ObjectMessage) consumer
- .receive(timeout);
- if (actObjectMessage == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- TestUtil.logMsg(
- "Call ObjectMessage.getBody(StringBuffer.class) to extract ObjectMessage as StringBuffer");
- StringBuffer actSbuffer = actObjectMessage.getBody(StringBuffer.class);
- TestUtil.logMsg("Check the value in StringBuffer");
- if (actSbuffer.toString().equals(expSbuffer.toString())) {
- TestUtil.logMsg("ObjectMessage is correct");
- } else {
- TestUtil.logErr("ObjectMessage is incorrect expected " + expSbuffer
- + ", received " + actSbuffer);
- pass = false;
- }
-
- // Send and receive BytesMessage
- TestUtil.logMsg("Create BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- TestUtil.logMsg("Send and receive the BytesMessage");
- producer.send(destination, bMsg);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive BytesMessage");
- BytesMessage actBytesMessage = (BytesMessage) consumer.receive(timeout);
- if (actBytesMessage == null) {
- throw new Exception("Did not receive BytesMessage");
- }
- TestUtil.logMsg(
- "Call BytesMessage.getBody(StringBuffer.class) to extract BytesMessage as byte[] array");
- byte[] bytes = actBytesMessage.getBody(byte[].class);
- if (bytes == null) {
- TestUtil.logErr("Did not receive BytesMessage");
- pass = false;
- } else {
- try {
- DataInputStream di = new DataInputStream(
- new ByteArrayInputStream(bytes));
- TestUtil.logMsg("Check the values in BytesMessage");
- if (di.readByte() == (byte) 1) {
- TestUtil.logMsg("bytevalue is correct");
- } else {
- TestUtil.logMsg("bytevalue is incorrect");
- pass = false;
- }
- if (di.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
- try {
- byte b = di.readByte();
- } catch (EOFException e) {
- TestUtil.logMsg("Caught expected EOFException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- }
- // Send and receive MapMessage
- TestUtil.logMsg("Send MapMessage");
- MapMessage mMsg = context.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- producer.send(destination, mMsg);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive MapMessage");
- MapMessage actMapMessage = (MapMessage) consumer.receive(timeout);
- if (actMapMessage == null) {
- throw new Exception("Did not receive MapMessage");
- }
- TestUtil.logMsg(
- "Call MapMessage.getBody(Map.class) to extract MapMessage as a Map object");
- Map map = actMapMessage.getBody(Map.class);
- if (map == null) {
- TestUtil.logErr("Did not receive MapMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the values in MapMessage");
- TestUtil.logMsg("map.size()=" + map.size());
- if (map.size() != 2) {
- TestUtil.logErr("Map size is " + map.size() + ", expected 2");
- pass = false;
- }
- Iterator it = map.keySet().iterator();
- String name = null;
- while (it.hasNext()) {
- name = (String) it.next();
- if (name.equals("booleanvalue")) {
- if ((boolean) map.get(name) == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logErr("booleanvalue is incorrect");
- pass = false;
- }
- } else if (name.equals("intvalue")) {
- if ((int) map.get(name) == 10) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logErr("intvalue is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Unexpected name of [" + name + "] in MapMessage");
- pass = false;
- }
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.printStackTrace(e);
- throw new Exception("getBodyTests", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("getBodyTests failed");
- }
- }
-
- /*
- * @testName: getBodyExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1359;
- *
- * @test_Strategy: Test exception case for Message.getBody(Class). Test
- * MessageFormatException.
- *
- * Object = Message.getBody(Class)
- *
- */
- public void getBodyExceptionTests() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- StringBuffer expSbuffer = new StringBuffer("This is it!");
- try {
- // Send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "getBodyExceptionTests");
- TestUtil.logMsg("Send and receive the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Call TextMessage.getBody(Boolean.class) to extract TextMessage "
- + "as Boolean (expect MessageFormatException)");
- try {
- Boolean myBool = actTextMessage.getBody(Boolean.class);
- TestUtil.logErr("Expected MessageFormatException to be thrown");
- pass = false;
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Caught correct MessageFormatException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive ObjectMessage
- TestUtil.logMsg("Create ObjectMessage of type StringBuffer");
- ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
- TestUtil.logMsg("Set some values in ObjectMessage");
- expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "getBodyExceptionTests");
- TestUtil.logMsg("Send and receive the ObjectMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expObjectMessage);
- TestUtil
- .logMsg("Call JMSConsumer.receive(long) to receive ObjectMessage");
- ObjectMessage actObjectMessage = (ObjectMessage) consumer
- .receive(timeout);
- if (actObjectMessage == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- TestUtil.logMsg(
- "Call ObjectMessage.getBody(HashMap.class) to extract ObjectMessage "
- + "as HashMap (expect MessageFormatException");
- try {
- HashMap hmap = actObjectMessage.getBody(HashMap.class);
- TestUtil.logErr("Expected MessageFormatException to be thrown");
- pass = false;
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Caught correct MessageFormatException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // send and receive StreamMessage
- TestUtil.logMsg("Create StreamMessage");
- StreamMessage expStreamMsg = context.createStreamMessage();
- TestUtil.logMsg("Set some values in StreamMessage");
- expStreamMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "getBodyExceptionTests");
- expStreamMsg.writeBoolean(true);
- expStreamMsg.writeInt((int) 22);
- TestUtil.logMsg("Send and receive the StreamMessage");
- producer.send(destination, expStreamMsg);
- StreamMessage actStreamMsg = (StreamMessage) consumer.receive(timeout);
- if (actStreamMsg == null) {
- throw new Exception("Did not receive StreamMessage");
- }
- TestUtil.logMsg(
- "Call StreamMessage.getBody(HashMap.class) to extract StreamMessage "
- + "as HashMap (expect MessageFormatException");
- try {
- HashMap hmap = actStreamMsg.getBody(HashMap.class);
- TestUtil.logErr("Expected MessageFormatException to be thrown");
- pass = false;
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Caught correct MessageFormatException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Create BytesMessage
- TestUtil.logMsg("Create BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyExceptionTests");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- TestUtil.logMsg("BytesMessage is in write-only mode");
- TestUtil
- .logMsg("Call BytesMessage.getBody(StringBuffer.class) to receive "
- + "BytesMessage as StringBuffer(expect MessageFormatException)");
- try {
- bMsg.getBody(StringBuffer.class);
- TestUtil.logErr("Expected MessageFormatException to be thrown");
- pass = false;
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Caught correct MessageFormatException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- TestUtil.logMsg("Send and receive the BytesMessage");
- producer.send(destination, bMsg);
- BytesMessage actBytesMsg = (BytesMessage) consumer.receive(timeout);
- try {
- actBytesMsg.getBody(StringBuffer.class);
- TestUtil.logErr("Expected MessageFormatException to be thrown");
- pass = false;
- } catch (MessageFormatException e) {
- TestUtil.logMsg("Caught correct MessageFormatException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("getBodyExceptionTests", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("getBodyExceptionTests failed");
- }
- }
-
- /*
- * @testName: isBodyAssignableToTest
- *
- * @assertion_ids: JMS:JAVADOC:1361;
- *
- * @test_Strategy: Test Message.isBodyAssignableTo(Class) API.
- *
- * boolean = Message.isBodyAssignableTo(Class)
- *
- */
- public void isBodyAssignableToTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- StringBuffer expSbuffer = new StringBuffer("This is it!");
- try {
- // Send and receive TextMessage
- TestUtil.logMsg("Create TextMessage");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "isBodyAssignableToTest");
- TestUtil.logMsg("Send and receive the TextMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- try {
- TestUtil.logMsg(
- "Call TextMessage.isBodyAssignableTo(Boolean.class) (expect false)");
- boolean b = actTextMessage.isBodyAssignableTo(Boolean.class);
- if (b) {
- TestUtil.logErr("Expected false got true");
- pass = false;
- }
- TestUtil.logMsg(
- "Call TextMessage.isBodyAssignableTo(String.class) (expect true)");
- b = actTextMessage.isBodyAssignableTo(String.class);
- if (!b) {
- TestUtil.logErr("Expected true got false");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive ObjectMessage
- TestUtil.logMsg("Create ObjectMessage");
- ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
- TestUtil.logMsg("Set some values in ObjectMessage");
- expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "isBodyAssignableToTest");
- TestUtil.logMsg("Send and receive the ObjectMessage");
- TestUtil.logMsg("Call JMSProducer.send(Destination, Message)");
- producer.send(destination, expObjectMessage);
- TestUtil
- .logMsg("Call JMSConsumer.receive(long) to receive ObjectMessage");
- ObjectMessage actObjectMessage = (ObjectMessage) consumer
- .receive(timeout);
- if (actObjectMessage == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- try {
- TestUtil.logMsg(
- "Call ObjectMessage.isBodyAssignableTo(Boolean.class) (expect false)");
- boolean b = actObjectMessage.isBodyAssignableTo(Boolean.class);
- if (b) {
- TestUtil.logErr("Expected false got true");
- pass = false;
- }
- TestUtil.logMsg(
- "Call ObjectMessage.isBodyAssignableTo(StringBuffer.class) (expect true)");
- b = actObjectMessage.isBodyAssignableTo(StringBuffer.class);
- if (!b) {
- TestUtil.logErr("Expected true got false");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive BytesMessage
- TestUtil.logMsg("Create BytesMessage");
- BytesMessage bMsg = context.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTest");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- TestUtil.logMsg("Send and receive the BytesMessage");
- producer.send(destination, bMsg);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive BytesMessage");
- BytesMessage actBytesMessage = (BytesMessage) consumer.receive(timeout);
- if (actBytesMessage == null) {
- throw new Exception("Did not receive BytesMessage");
- }
- try {
- TestUtil.logMsg(
- "Call BytesMessage.isBodyAssignableTo(String.class) (expect false)");
- boolean b = actBytesMessage.isBodyAssignableTo(String.class);
- if (b) {
- TestUtil.logErr("Expected false got true");
- pass = false;
- }
- TestUtil.logMsg(
- "Call BytesMessage.isBodyAssignableTo(byte[].class) (expect true)");
- b = actBytesMessage.isBodyAssignableTo(byte[].class);
- if (!b) {
- TestUtil.logErr("Expected true got false");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- // Send and receive MapMessage
- TestUtil.logMsg("Send MapMessage");
- MapMessage mMsg = context.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTest");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- producer.send(destination, mMsg);
- TestUtil.logMsg("Call JMSConsumer.receive(long) to receive MapMessage");
- MapMessage actMapMessage = (MapMessage) consumer.receive(timeout);
- if (actMapMessage == null) {
- throw new Exception("Did not receive MapMessage");
- }
- try {
- TestUtil.logMsg(
- "Call MapMessage.isBodyAssignableTo(String.class) (expect false)");
- boolean b = actMapMessage.isBodyAssignableTo(String.class);
- if (b) {
- TestUtil.logErr("Expected false got true");
- pass = false;
- }
- TestUtil.logMsg(
- "Call MapMessage.isBodyAssignableTo(Map.class) (expect true)");
- b = actMapMessage.isBodyAssignableTo(Map.class);
- if (!b) {
- TestUtil.logErr("Expected true got false");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("isBodyAssignableToTest", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("isBodyAssignableToTest failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsproducertopictests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsproducertopictests/ClientIT.java
new file mode 100644
index 0000000000..d9762fda15
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/jmsproducertopictests/ClientIT.java
@@ -0,0 +1,5099 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.jmsproducertopictests;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.EOFException;
+import java.io.Serializable;
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.ConnectionMetaData;
+import jakarta.jms.DeliveryMode;
+import jakarta.jms.Destination;
+import jakarta.jms.JMSConsumer;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSProducer;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.MessageFormatException;
+import jakarta.jms.MessageFormatRuntimeException;
+import jakarta.jms.MessageNotWriteableRuntimeException;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.jmsproducertopictests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null, tool2 = null;
+
+ // JMS objects
+ private transient ConnectionFactory cf = null;
+
+ private transient ConnectionFactory cf2 = null;
+
+ private transient Topic topic = null;
+
+ private transient Destination destination = null;
+
+ private transient Topic topic2 = null;
+
+ private transient Destination destination2 = null;
+
+ private transient JMSContext context = null;
+
+ private transient JMSContext context2 = null;
+
+ private transient JMSProducer producer = null;
+
+ private transient JMSProducer producer2 = null;
+
+ private transient JMSConsumer consumer = null;
+
+ private transient JMSConsumer consumer2 = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ ArrayList connections = null;
+
+ /* Utility methods for tests */
+
+ /*
+ * helper method verifies that the ConnectionMetaData
+ *
+ * @param ConnectionMetaData returned from getJMSMessageID
+ *
+ * @return boolean true if ConnectionMetaData is as expected
+ */
+ private boolean verifyMetaData(ConnectionMetaData data) {
+ boolean pass = true;
+
+ try {
+ String tmp = data.getJMSVersion();
+ logger.log(Logger.Level.TRACE, "JMSVersion=" + tmp);
+
+ if (!tmp.equals("2.0")) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getJMSMajorVersion();
+ logger.log(Logger.Level.TRACE, "JMSMajorVersion=" + tmp);
+
+ if (tmp != 2) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSMajorVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSMajorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getJMSMinorVersion();
+ logger.log(Logger.Level.TRACE, "JMSMinorVersion=" + tmp);
+
+ if (tmp != 0) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect JMSMajorVersion=" + tmp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSMinorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = data.getJMSProviderName();
+ logger.log(Logger.Level.TRACE, "JMSProviderName=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for JMSProviderName: ", e);
+ pass = false;
+ }
+
+ try {
+ String tmp = data.getProviderVersion();
+ logger.log(Logger.Level.TRACE, "JMSProviderVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getProviderMajorVersion();
+ logger.log(Logger.Level.TRACE, "ProviderMajorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderMajorVersion: ", e);
+ pass = false;
+ }
+
+ try {
+ int tmp = data.getProviderMinorVersion();
+ logger.log(Logger.Level.TRACE, "ProviderMinorVersion=" + tmp);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error: incorrect type returned for ProviderMinorVersion: ", e);
+ pass = false;
+ }
+ return pass;
+ }
+
+ /*
+ * helper method verifies that the JMSMessageID starts with ID:
+ *
+ * @param String returned from getJMSMessageID
+ *
+ * @return boolean true if id correctly starts with ID:
+ */
+ private boolean chkMessageID(String id) {
+ String status[] = { "Pass", "Fail" };
+ boolean retcode = true;
+
+ // message id must start with ID: - unless it is null
+ int index = 0;
+
+ if (id == null) {
+ ;
+ } else if (id.startsWith("ID:")) {
+ ;
+ } else {
+ index = 1;
+ retcode = false;
+ }
+ logger.log(Logger.Level.TRACE, "Results: " + status[index]);
+ return retcode;
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ String lookupDurableTopicFactory = "DURABLE_SUB_CONNECTION_FACTORY";
+ String lookupNormalTopicFactory = "MyTopicConnectionFactory";
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ connections = new ArrayList(5);
+
+ // set up JmsTool for COMMON_T setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_T and normal topic connection factory");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, lookupNormalTopicFactory, mode);
+ cf = tool.getConnectionFactory();
+ tool.getDefaultConnection().close(); // Close connection (Create
+ // JMSContext to use instead)
+ destination = tool.getDefaultDestination();
+ topic = (Topic) destination;
+
+ // create JMSContext with AUTO_ACKNOWLEDGE then create consumer/producer
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ producer = context.createProducer();
+ consumer = context.createConsumer(topic);
+
+ // set up JmsTool for COMMON_T setup
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON_T and durable topic connection factory");
+ tool2 = new JmsTool(JmsTool.COMMON_T, user, password, lookupDurableTopicFactory, mode);
+ tool2.getDefaultConnection().close(); // Close connection (Create
+ // JMSContext to use instead)
+ cf2 = tool2.getConnectionFactory();
+ destination2 = tool2.getDefaultDestination();
+ topic2 = (Topic) destination2;
+
+ // create second JMSContext with AUTO_ACKNOWLEDGE, then create producer
+ context2 = cf2.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ producer2 = context2.createProducer();
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Close JMSContext Objects");
+ if (context != null) {
+ context.close();
+ context = null;
+ }
+ if (context2 != null) {
+ context2.close();
+ context2 = null;
+ }
+ producer = producer2 = null;
+ logger.log(Logger.Level.INFO, "Close JMSConsumer Objects");
+ if (consumer != null) {
+ consumer.close();
+ consumer = null;
+ }
+ tool.closeAllResources();
+ tool2.closeAllResources();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * Cleanup method for tests that use durable subscriptions
+ */
+ private void cleanupSubscription(JMSConsumer consumer, JMSContext context, String subName) {
+ if (consumer != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Closing durable consumer: " + consumer);
+ consumer.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception during JMSConsumer.close: ", e);
+ }
+ }
+
+ if (context != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Unsubscribing \"" + subName + "\"");
+ context.unsubscribe(subName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception during JMSContext.unsubscribe: ", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1234;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * JMSProducer.send(Destination, Message) JMSConsumer.receive(long)
+ *
+ */
+ @Test
+ public void sendAndRecvTest1() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvTest1");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage via JMSconsumer.receive(long)");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvTest1", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1239;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * JMSProducer.send(Destination, String) JMSConsumer.receiveBody(String, long)
+ *
+ */
+ @Test
+ public void sendAndRecvTest2() throws Exception {
+ boolean pass = true;
+ String expTextMessage = "Where are you!";
+ try {
+ // send and receive TextMessage payload
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, String)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage via JMSConsumer.receiveBody(String, long)");
+ String actTextMessage = consumer.receiveBody(String.class, timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.equals(expTextMessage)) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "TextMessage is incorrect expected " + expTextMessage + ", received " + actTextMessage);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvTest2", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:1251;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * JMSProducer.send(Destination, Serializable)
+ * JMSConsumer.receiveBody(Serializable, long)
+ */
+ @Test
+ public void sendAndRecvTest3() throws Exception {
+ boolean pass = true;
+ try {
+ // send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Send ObjectMessage");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ ObjectMessage expObjectMessage = context.createObjectMessage();
+ StringBuffer expSb = new StringBuffer("Where are you!");
+ logger.log(Logger.Level.INFO, "Set object in ObjectMessage to a StringBuffer");
+ expObjectMessage.setObject(expSb);
+ expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvTest3");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Serializable)");
+ producer.send(destination, expObjectMessage);
+ logger.log(Logger.Level.INFO, "Receive ObjectMessage via JMSConsumer.receiveBody(Serializable, long)");
+ StringBuffer actSb = (StringBuffer) consumer.receiveBody(Serializable.class, timeout);
+ if (actSb == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in ObjectMessage");
+ if (actSb.toString().equals(expSb.toString())) {
+ logger.log(Logger.Level.INFO, "ObjectMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "ObjectMessage is incorrect expected " + expSb.toString() + ", received " + actSb.toString());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvTest3", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTest3 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTest4
+ *
+ * @assertion_ids: JMS:JAVADOC:1243;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * JMSProducer.send(Destination, Map)
+ * JMSConsumer.receiveBody(Map, long)
+ */
+ @Test
+ public void sendAndRecvTest4() throws Exception {
+ boolean pass = true;
+ Map mapMsgSend = new HashMap();
+ mapMsgSend.put("StringValue", "sendAndRecvTest4");
+ mapMsgSend.put("BooleanValue", true);
+ mapMsgSend.put("IntValue", (int) 10);
+ try {
+ // send and receive MapMessage payload
+ logger.log(Logger.Level.INFO, "Send MapMessage via JMSProducer.send(Destination, Map)");
+ producer.send(destination, mapMsgSend);
+ logger.log(Logger.Level.INFO, "Receive MapMessage via JMSConsumer.receiveBody(Map.class, long");
+ Map mapMsgRecv = consumer.receiveBody(Map.class, timeout);
+ if (mapMsgRecv == null) {
+ throw new Exception("Did not receive MapMessage");
+ }
+ logger.log(Logger.Level.INFO, "Compare MapMsgSend and MapMsgRecv for equality");
+ for (Entry entry : mapMsgSend.entrySet()) {
+ String key = entry.getKey();
+ logger.log(Logger.Level.INFO, "key " + key + ": " + entry.getValue().equals(mapMsgRecv.get(key)));
+ if (entry.getValue().equals(mapMsgRecv.get(key))) {
+ continue;
+ } else {
+ pass = false;
+ }
+ }
+ if (pass) {
+ logger.log(Logger.Level.INFO, "MapMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "MapMessage is incorrect expected " + mapMsgSend + ", received " + mapMsgRecv);
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvTest4", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTest4 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTest5
+ *
+ * @assertion_ids: JMS:JAVADOC:1247;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * JMSProducer.send(Destination, byte[]) JMSConsumer.receiveBody(byte[], long)
+ *
+ */
+ @Test
+ public void sendAndRecvTest5() throws Exception {
+ boolean pass = true;
+ String messageSend = "Where are you!";
+ byte[] bytesMsgSend = messageSend.getBytes();
+ try {
+ // send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Send BytesMessage via JMSProducer.send(Destination, byte[])");
+ producer.send(destination, bytesMsgSend);
+ logger.log(Logger.Level.INFO, "Receive BytesMessage via JMSConsumer.receiveBody(byte[].class, long");
+ byte[] bytesMsgRecv = consumer.receiveBody(byte[].class, timeout);
+ if (bytesMsgRecv == null) {
+ throw new Exception("Did not receive BytesMessage");
+ }
+ logger.log(Logger.Level.INFO, "Compare BytesMsgSend and BytesMsgRecv for equality");
+ String messageRecv = new String(bytesMsgRecv);
+ if (messageRecv.equals(messageSend)) {
+ logger.log(Logger.Level.INFO, "BytesMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "BytesMessage is incorrect expected " + messageRecv + ", received " + messageSend);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvTest5", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTest5 failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvMsgsOfEachMsgTypeTest
+ *
+ * @assertion_ids: JMS:JAVADOC:925; JMS:JAVADOC:927; JMS:JAVADOC:929;
+ * JMS:JAVADOC:934; JMS:JAVADOC:937; JMS:JAVADOC:940; JMS:JAVADOC:964;
+ * JMS:JAVADOC:966; JMS:JAVADOC:942; JMS:JAVADOC:847; JMS:JAVADOC:1104;
+ * JMS:JAVADOC:1234; JMS:JAVADOC:875; JMS:JAVADOC:936; JMS:JAVADOC:1177;
+ *
+ * @test_Strategy: Send and receive messages of each message type: Message,
+ * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Gets the
+ * delivery time of each send of the message. Tests the following API's
+ *
+ * ConnectionFactory.createContext(String, String, int)
+ * JMSContext.createConsumer(Destination) JMSContext.createProducer()
+ * JMSContext.createMessage() JMSContext.createBytesMessage()
+ * JMSContext.createMapMessage() JMSContext.createObjectMessage()
+ * JMSContext.createObjectMessage(Serializable object)
+ * JMSContext.createStreamMessage() JMSContext.createTextMessage()
+ * JMSContext.createTextMessage(String) JMSContext.createConsumer(Destination)
+ * JMSProducer.send(Destination, Message) JMSConsumer.receive(long timeout)
+ *
+ */
+ @Test
+ public void sendAndRecvMsgsOfEachMsgTypeTest() throws Exception {
+ boolean pass = true;
+ try {
+ // send and receive Message
+ logger.log(Logger.Level.INFO, "Send Message");
+ Message msg = context.createMessage();
+ logger.log(Logger.Level.INFO, "Set some values in Message");
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ msg.setBooleanProperty("booleanProperty", true);
+ producer.send(destination, msg);
+ long deliveryTime = msg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive Message");
+ Message msgRecv = (Message) consumer.receive(timeout);
+ if (msgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive Message");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in Message");
+ if (msgRecv.getBooleanProperty("booleanProperty") == true) {
+ logger.log(Logger.Level.INFO, "booleanproperty is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanproperty is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Send BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ producer.send(destination, bMsg);
+ deliveryTime = bMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive BytesMessage");
+ BytesMessage bMsgRecv = (BytesMessage) consumer.receive(timeout);
+ if (bMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive BytesMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in BytesMessage");
+ if (bMsgRecv.readByte() == (byte) 1) {
+ logger.log(Logger.Level.INFO, "bytevalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "bytevalue is incorrect");
+ pass = false;
+ }
+ if (bMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send MapMessage");
+ MapMessage mMsg = context.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ producer.send(destination, mMsg);
+ deliveryTime = mMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive MapMessage");
+ MapMessage mMsgRecv = (MapMessage) consumer.receive(timeout);
+ if (mMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive MapMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in MapMessage");
+ Enumeration list = mMsgRecv.getMapNames();
+ String name = null;
+ while (list.hasMoreElements()) {
+ name = (String) list.nextElement();
+ if (name.equals("booleanvalue")) {
+ if (mMsgRecv.getBoolean(name) == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "booleanvalue is incorrect");
+ pass = false;
+ }
+ } else if (name.equals("intvalue")) {
+ if (mMsgRecv.getInt(name) == 10) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "intvalue is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected name of [" + name + "] in MapMessage");
+ pass = false;
+ }
+ }
+ }
+
+ // send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Send ObjectMessage");
+ StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ ObjectMessage oMsg = context.createObjectMessage();
+ oMsg.setObject(sb1);
+ oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ producer.send(destination, oMsg);
+ deliveryTime = oMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive ObjectMessage");
+ ObjectMessage oMsgRecv = (ObjectMessage) consumer.receive(timeout);
+ if (oMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive ObjectMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in ObjectMessage");
+ StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
+ if (sb2.toString().equals(sb1.toString())) {
+ logger.log(Logger.Level.INFO, "objectvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "objectvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive ObjectMessage passing object as param
+ logger.log(Logger.Level.INFO, "Send ObjectMessage passing object as param");
+ sb1 = new StringBuffer("This is a StringBuffer");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage passing object as param");
+ oMsg = context.createObjectMessage(sb1);
+ oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ producer.send(destination, oMsg);
+ deliveryTime = oMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive ObjectMessage");
+ oMsgRecv = (ObjectMessage) consumer.receive(timeout);
+ if (oMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive ObjectMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in ObjectMessage");
+ StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
+ if (sb2.toString().equals(sb1.toString())) {
+ logger.log(Logger.Level.INFO, "objectvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "objectvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive StreamMessage
+ logger.log(Logger.Level.INFO, "Send StreamMessage");
+ StreamMessage sMsg = context.createStreamMessage();
+ logger.log(Logger.Level.INFO, "Set some values in StreamMessage");
+ sMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ sMsg.writeBoolean(true);
+ sMsg.writeInt((int) 22);
+ producer.send(destination, sMsg);
+ deliveryTime = sMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive StreamMessage");
+ StreamMessage sMsgRecv = (StreamMessage) consumer.receive(timeout);
+ if (sMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive StreamMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in StreamMessage");
+ if (sMsgRecv.readBoolean() == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanvalue is incorrect");
+ pass = false;
+ }
+ if (sMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Send TextMessage");
+ TextMessage tMsg = context.createTextMessage();
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ tMsg.setText("Hello There!");
+ producer.send(destination, tMsg);
+ deliveryTime = tMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage tMsgRecv = (TextMessage) consumer.receive(timeout);
+ if (tMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (tMsgRecv.getText().equals("Hello There!")) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect");
+ pass = false;
+ }
+ }
+
+ // send and receive TextMessage passing string as param
+ logger.log(Logger.Level.INFO, "Send TextMessage");
+ tMsg = context.createTextMessage("Where are you!");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeTest");
+ producer.send(destination, tMsg);
+ deliveryTime = tMsg.getJMSDeliveryTime();
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ tMsgRecv = (TextMessage) consumer.receive(timeout);
+ if (tMsgRecv == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (tMsgRecv.getText().equals("Where are you!")) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("sendAndRecvMsgsOfEachMsgTypeTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvMsgsOfEachMsgTypeTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1192; JMS:JAVADOC:1259;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setDeliveryMode(int). JMSProducer.getDeliveryMode().
+ */
+ @Test
+ public void setGetDeliveryModeTest() throws Exception {
+ boolean pass = true;
+
+ // Test default case
+ try {
+ int expDeliveryMode = DeliveryMode.PERSISTENT;
+ logger.log(Logger.Level.INFO, "Calling getDeliveryMode and expect " + expDeliveryMode + " to be returned");
+ int actDeliveryMode = producer.getDeliveryMode();
+ if (actDeliveryMode != expDeliveryMode) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryMode() returned " + actDeliveryMode + ", expected " + expDeliveryMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDeliveryModeTest");
+ }
+
+ // Test non-default case
+ try {
+ int expDeliveryMode = DeliveryMode.NON_PERSISTENT;
+ logger.log(Logger.Level.INFO, "Calling setDeliveryMode(" + expDeliveryMode + ")");
+ producer.setDeliveryMode(expDeliveryMode);
+ logger.log(Logger.Level.INFO, "Calling getDeliveryMode and expect " + expDeliveryMode + " to be returned");
+ int actDeliveryMode = producer.getDeliveryMode();
+ if (actDeliveryMode != expDeliveryMode) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryMode() returned " + actDeliveryMode + ", expected " + expDeliveryMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDeliveryModeTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetDeliveryModeTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetDeliveryDelayTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1190; JMS:JAVADOC:1257;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setDeliveryDelay(long). JMSProducer.getDeliveryDelay().
+ */
+ @Test
+ public void setGetDeliveryDelayTest() throws Exception {
+ boolean pass = true;
+
+ // Test default case
+ try {
+ long expDeliveryDelay = 0L;
+ logger.log(Logger.Level.INFO,
+ "Calling getDeliveryDelay and expect " + expDeliveryDelay + " to be returned");
+ long actDeliveryDelay = producer.getDeliveryDelay();
+ if (actDeliveryDelay != expDeliveryDelay) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryDelay() returned " + actDeliveryDelay + ", expected " + expDeliveryDelay);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDeliveryDelayTest");
+ }
+
+ // Test non-default case
+ try {
+ long expDeliveryDelay = 1L;
+ logger.log(Logger.Level.INFO, "Calling setDeliveryDelay(" + expDeliveryDelay + ")");
+ producer.setDeliveryDelay(expDeliveryDelay);
+ logger.log(Logger.Level.INFO,
+ "Calling getDeliveryDelay and expect " + expDeliveryDelay + " to be returned");
+ long actDeliveryDelay = producer.getDeliveryDelay();
+ if (actDeliveryDelay != expDeliveryDelay) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryDelay() returned " + actDeliveryDelay + ", expected " + expDeliveryDelay);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDeliveryDelayTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetDeliveryDelayTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1194; JMS:JAVADOC:1261;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setDisableMessageID(boolean). JMSProducer.getDisableMessageID().
+ */
+ @Test
+ public void setGetDisableMessageIDTest() throws Exception {
+ boolean pass = true;
+ // Test default case
+ try {
+ boolean expDisableMessageID = true;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageID(" + expDisableMessageID + ")");
+ producer.setDisableMessageID(expDisableMessageID);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageID and expect " + expDisableMessageID + " to be returned");
+ boolean actDisableMessageID = producer.getDisableMessageID();
+ if (actDisableMessageID != expDisableMessageID) {
+ logger.log(Logger.Level.ERROR,
+ "getDisableMessageID() returned " + actDisableMessageID + ", expected " + expDisableMessageID);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDisableMessageIDTest");
+ }
+
+ // Test non-default case
+ try {
+ boolean expDisableMessageID = false;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageID(" + expDisableMessageID + ")");
+ producer.setDisableMessageID(expDisableMessageID);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageID and expect " + expDisableMessageID + " to be returned");
+ boolean actDisableMessageID = producer.getDisableMessageID();
+ if (actDisableMessageID != expDisableMessageID) {
+ logger.log(Logger.Level.ERROR,
+ "getDisableMessageID() returned " + actDisableMessageID + ", expected " + expDisableMessageID);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDisableMessageIDTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetDisableMessageIDTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1196; JMS:JAVADOC:1263;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setDisableMessageTimestamp(boolean).
+ * JMSProducer.getDisableMessageTimestamp().
+ */
+ @Test
+ public void setGetDisableMessageTimestampTest() throws Exception {
+ boolean pass = true;
+ // Test default case
+ try {
+ boolean expDisableMessageTimestamp = true;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageTimestamp(" + expDisableMessageTimestamp + ")");
+ producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageTimestamp and expect " + expDisableMessageTimestamp + " to be returned");
+ boolean actDisableMessageTimestamp = producer.getDisableMessageTimestamp();
+ if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
+ logger.log(Logger.Level.ERROR, "getDisableMessageTimestamp() returned " + actDisableMessageTimestamp
+ + ", expected " + expDisableMessageTimestamp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDisableMessageTimestampTest");
+ }
+
+ // Test non-default case
+ try {
+ boolean expDisableMessageTimestamp = false;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageTimestamp(" + expDisableMessageTimestamp + ")");
+ producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageTimestamp and expect " + expDisableMessageTimestamp + " to be returned");
+ boolean actDisableMessageTimestamp = producer.getDisableMessageTimestamp();
+ if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
+ logger.log(Logger.Level.ERROR, "getDisableMessageTimestamp() returned " + actDisableMessageTimestamp
+ + ", expected " + expDisableMessageTimestamp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetDisableMessageTimestampTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetDisableMessageTimestampTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetPriorityTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1220; JMS:JAVADOC:1273;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setPriority(int). JMSProducer.getPriority().
+ */
+ @Test
+ public void setGetPriorityTest() throws Exception {
+ boolean pass = true;
+ try {
+ // Test default
+ int expPriority = Message.DEFAULT_PRIORITY;
+ logger.log(Logger.Level.INFO, "Calling getPriority and expect " + expPriority + " to be returned");
+ int actPriority = producer.getPriority();
+ if (actPriority != expPriority) {
+ logger.log(Logger.Level.ERROR, "getPriority() returned " + actPriority + ", expected " + expPriority);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetPriorityTest");
+ }
+
+ // Test non-default
+ int expPriority[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
+ // Cycle through all priorties
+ for (int i = 0; i < expPriority.length; i++) {
+ try {
+ logger.log(Logger.Level.INFO, "Calling setPriority(" + expPriority[i] + ")");
+ producer.setPriority(expPriority[i]);
+ logger.log(Logger.Level.INFO, "Calling getPriority and expect " + expPriority[i] + " to be returned");
+ int actPriority = producer.getPriority();
+ if (actPriority != expPriority[i]) {
+ logger.log(Logger.Level.ERROR,
+ "getPriority() returned " + actPriority + ", expected " + expPriority[i]);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetPriorityTest");
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("setGetPriorityTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1230; JMS:JAVADOC:1303;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setTimeToLive(long). JMSProducer.getTimeToLive()
+ */
+ @Test
+ public void setGetTimeToLiveTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ // Test default
+ long expTimeToLive = 0;
+ logger.log(Logger.Level.INFO, "Calling getTimeToLive and expect " + expTimeToLive + " to be returned");
+ long actTimeToLive = producer.getTimeToLive();
+ if (actTimeToLive != expTimeToLive) {
+ logger.log(Logger.Level.ERROR,
+ "getTimeToLive() returned " + actTimeToLive + ", expected " + expTimeToLive);
+ pass = false;
+ }
+
+ // Test non-default
+ expTimeToLive = 1000;
+ logger.log(Logger.Level.INFO, "Calling setTimeToLive(" + expTimeToLive + ")");
+ producer.setTimeToLive(expTimeToLive);
+ logger.log(Logger.Level.INFO, "Calling getTimeToLive and expect " + expTimeToLive + " to be returned");
+ actTimeToLive = producer.getTimeToLive();
+ if (actTimeToLive != expTimeToLive) {
+ logger.log(Logger.Level.ERROR,
+ "getTimeToLive() returned " + actTimeToLive + ", expected " + expTimeToLive);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setGetTimeToLiveTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetTimeToLiveTest failed");
+ }
+ }
+
+ /*
+ * @testName: deliveryDelayTest
+ *
+ * @assertion_ids: JMS:SPEC:261; JMS:SPEC:256; JMS:JAVADOC:1257;
+ *
+ * @test_Strategy: Send message and verify that message is not delivered until
+ * the DeliveryDelay of 20 seconds is reached. Test DeliveryMode.PERSISTENT and
+ * DeliveryMode.NON_PERSISTENT.
+ */
+ @Test
+ public void deliveryDelayTest() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------------------------------------------------");
+ logger.log(Logger.Level.INFO, "BEGIN TEST deliveryDelayTest with DeliveryDelay=20Secs");
+ logger.log(Logger.Level.INFO, "------------------------------------------------------");
+ producer.setDeliveryDelay(20000);
+
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage message = context.createTextMessage("This is a test!");
+
+ logger.log(Logger.Level.INFO, "Set StringProperty COM_SUN_JMS_TESTNAME");
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "deliveryDelayTest");
+
+ logger.log(Logger.Level.INFO, "Sending message with DeliveryMode.PERSISTENT and DeliveryDelay=20Secs");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ producer.setPriority(Message.DEFAULT_PRIORITY);
+ producer.setTimeToLive(0L);
+ producer.send(destination, message);
+
+ logger.log(Logger.Level.INFO, "Waiting 10 seconds to receive message");
+ message = (TextMessage) consumer.receive(10000);
+ if (message != null) {
+ logger.log(Logger.Level.ERROR, "FAILED: Message received before delivery delay of 20 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Didn't receive message after 10 seconds (CORRECT)");
+ logger.log(Logger.Level.INFO, "Sleeping 5 more seconds before receiving message");
+ Thread.sleep(5000);
+ logger.log(Logger.Level.INFO, "Waiting 10 more seconds to receive message");
+ message = (TextMessage) consumer.receive(10000);
+ if (message == null) {
+ logger.log(Logger.Level.ERROR,
+ "FAILED: Message was not received after delivery delay of 20 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message after 20 secs elapsed (CORRECT)");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Sending message with DeliveryMode.NON_PERSISTENT and DeliveryDelay=20Secs");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ producer.setPriority(Message.DEFAULT_PRIORITY);
+ producer.setTimeToLive(0L);
+ producer.send(destination, message);
+
+ logger.log(Logger.Level.INFO, "Waiting 10 seconds to receive message");
+ message = (TextMessage) consumer.receive(10000);
+ if (message != null) {
+ logger.log(Logger.Level.ERROR, "FAILED: Message received before delivery delay of 20 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Didn't receive message after 10 seconds (CORRECT)");
+ logger.log(Logger.Level.INFO, "Sleeping 5 more seconds before receiving message");
+ Thread.sleep(5000);
+ logger.log(Logger.Level.INFO, "Waiting 10 more seconds to receive message");
+ message = (TextMessage) consumer.receive(10000);
+ if (message == null) {
+ logger.log(Logger.Level.ERROR,
+ "FAILED: Message was not received after delivery delay of 20 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message after 20 secs elapsed (CORRECT)");
+ }
+ }
+ logger.log(Logger.Level.INFO, "----------------------------------------------------");
+ logger.log(Logger.Level.INFO, "END TEST deliveryDelayTest with DeliveryDelay=20Secs");
+ logger.log(Logger.Level.INFO, "----------------------------------------------------");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("deliveryDelayTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("deliveryDelayTest failed");
+ }
+ }
+
+ /*
+ * @testName: msgHdrMessageIDTest
+ *
+ * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343; JMS:JAVADOC:1261;
+ * JMS:JAVADOC:1194;
+ *
+ * @test_Strategy: Send to a Topic and receive Text, Map, Bytes, Stream, and
+ * Object message. Call getJMSMessageID and verify that it starts with ID:
+ */
+ @Test
+ public void msgHdrMessageIDTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ String id = null;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ producer.setDisableMessageID(false);
+
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.INFO, "Send ObjectMessage to Topic.");
+ messageSentO = context.createObjectMessage();
+ messageSentO.setObject("msgHdrMessageIDTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrMessageIDTest");
+ producer.send(destination, messageSentO);
+ logger.log(Logger.Level.INFO, "Receive ObjectMessage from Topic.");
+ messageReceivedO = (ObjectMessage) consumer.receive(timeout);
+ if (messageReceivedO == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "getJMSMessageID=" + messageReceivedO.getJMSMessageID());
+ id = messageReceivedO.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Objectessage JMSMessageID pass");
+ }
+ }
+ // send and receive map message to Topic
+ logger.log(Logger.Level.INFO, "Send MapMessage to Topic.");
+ messageSentM = context.createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrMessageIDTest");
+ messageSentM.setString("aString", "value");
+ producer.send(destination, messageSentM);
+ logger.log(Logger.Level.INFO, "Receive MapMessage from Topic.");
+ messageReceivedM = (MapMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "getJMSMessageID=" + messageReceivedM.getJMSMessageID());
+ id = messageReceivedM.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "MapMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSMessageID pass");
+ }
+ }
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.INFO, "Send BytesMessage to Topic.");
+ messageSentB = context.createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrMessageIDTest");
+ messageSentB.writeByte(bValue);
+ producer.send(destination, messageSentB);
+ logger.log(Logger.Level.INFO, "Receive BytesMessage from Topic.");
+ messageReceivedB = (BytesMessage) consumer.receive(timeout);
+ if (messageReceivedB == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "getJMSMessageID=" + messageReceivedB.getJMSMessageID());
+ id = messageReceivedB.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "BytesMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSMessageID pass");
+ }
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.INFO, "Send StreamMessage to Topic");
+ messageSentS = context.createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrMessageIDTest");
+ messageSentS.writeString("Testing...");
+ logger.log(Logger.Level.INFO, "Sending message");
+ producer.send(destination, messageSentS);
+ logger.log(Logger.Level.INFO, "Receive StreamMessage from Topic.");
+ messageReceivedS = (StreamMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "getJMSMessageID=" + messageReceivedS.getJMSMessageID());
+ id = messageReceivedS.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "StreamMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSMessageID pass");
+ }
+ }
+
+ // TextMessage
+ logger.log(Logger.Level.INFO, "Send TextMessage to Topic");
+ messageSent = context.createTextMessage();
+ messageSent.setText("sending a TextMessage");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrMessageIDTest");
+ producer.send(destination, messageSent);
+ logger.log(Logger.Level.INFO, "Receive TextMessage from Topic.");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "getJMSMessageID=" + messageReceived.getJMSMessageID());
+ id = messageReceived.getJMSMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "TextMessage error: JMSMessageID does not start with ID:");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage JMSMessageID pass");
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSMessageID returned from JMSMessageID");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrMessageIDTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrTimeStampTest
+ *
+ * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347; JMS:JAVADOC:1263;
+ * JMS:JAVADOC:1196;
+ *
+ * @test_Strategy: Send to a Topic a single Text, map, bytes, stream, and object
+ * message. Call getJMSTimestamp() and check time of send against time send
+ * returns. JMSTimeStamp should be between these two
+ */
+ @Test
+ public void msgHdrTimeStampTest() throws Exception {
+ boolean pass = true;
+ long timeBeforeSend;
+ long timeAfterSend;
+ byte bValue = 127;
+
+ try {
+ TextMessage messageSent = null;
+ StreamMessage messageSentS = null;
+ BytesMessage messageSentB = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+
+ producer.setDisableMessageTimestamp(false);
+
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.INFO, "Send ObjectMessage to Topic.");
+ messageSentO = context.createObjectMessage();
+ messageSentO.setObject("msgHdrTimeStampTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTest");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentO);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "getJMSTimestamp=" + messageSentO.getJMSTimestamp());
+ logger.log(Logger.Level.INFO, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentO.getJMSTimestamp())
+ && (timeAfterSend >= messageSentO.getJMSTimestamp())) {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSTimeStamp pass");
+ } else {
+ logger.log(Logger.Level.ERROR, "ObjectMessage invalid JMSTimeStamp failed");
+ pass = false;
+ }
+
+ // send map message to Topic
+ logger.log(Logger.Level.INFO, "Send MapMessage to Topic.");
+ messageSentM = context.createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTest");
+ messageSentM.setString("aString", "value");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentM);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "getJMSTimestamp=" + messageSentM.getJMSTimestamp());
+ logger.log(Logger.Level.INFO, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentM.getJMSTimestamp())
+ && (timeAfterSend >= messageSentM.getJMSTimestamp())) {
+ logger.log(Logger.Level.INFO, "MapMessage JMSTimeStamp pass");
+ } else {
+ logger.log(Logger.Level.ERROR, "MapMessage invalid JMSTimeStamp failed");
+ pass = false;
+ }
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.INFO, "Send BytesMessage to Topic.");
+ messageSentB = context.createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTest");
+ messageSentB.writeByte(bValue);
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentB);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "getJMSTimestamp=" + messageSentB.getJMSTimestamp());
+ logger.log(Logger.Level.INFO, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentB.getJMSTimestamp())
+ && (timeAfterSend >= messageSentB.getJMSTimestamp())) {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSTimeStamp pass");
+ } else {
+ logger.log(Logger.Level.ERROR, "BytesMessage invalid JMSTimeStamp failed");
+ pass = false;
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.INFO, "Send StreamMessage to Topic");
+ messageSentS = context.createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTest");
+ messageSentS.writeString("Testing...");
+ logger.log(Logger.Level.INFO, "Sending message");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentS);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "getJMSTimestamp=" + messageSentS.getJMSTimestamp());
+ logger.log(Logger.Level.INFO, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentS.getJMSTimestamp())
+ && (timeAfterSend >= messageSentS.getJMSTimestamp())) {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSTimeStamp pass");
+ } else {
+ logger.log(Logger.Level.ERROR, "StreamMessage invalid JMSTimeStamp failed");
+ pass = false;
+ }
+
+ // TextMessage
+ logger.log(Logger.Level.INFO, "Send TextMessage to Topic");
+ messageSent = context.createTextMessage();
+ messageSent.setText("sending a TextMessage to Topic");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrTimeStampTest");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSent);
+
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.INFO, "getJMSTimestamp=" + messageSent.getJMSTimestamp());
+ logger.log(Logger.Level.INFO, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSent.getJMSTimestamp()) && (timeAfterSend >= messageSent.getJMSTimestamp())) {
+ logger.log(Logger.Level.INFO, "TextMessage JMSTimeStamp pass");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage invalid JMSTimeStamp failed");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrTimeStampTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140; JMS:JAVADOC:1220;
+ * JMS:JAVADOC:1273; JMS:JAVADOC:383;
+ *
+ * @test_Strategy: Send a message to a Topic with JMSPriority set to 2 test with
+ * Text, map, object, byte, and stream messages Call getJMSPriorty() and check
+ * that it matches the priority that was set on the JMSContext.
+ */
+ @Test
+ public void msgHdrJMSPriorityTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ int priority2 = 2;
+ int priority4 = 4;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ logger.log(Logger.Level.INFO, "Setting priority to 2");
+ producer.setPriority(priority2);
+
+ messageSent = context.createTextMessage();
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTest");
+ logger.log(Logger.Level.INFO, "JMSPriority test - Send a TextMessage to Topic");
+ producer.send(destination, messageSent);
+ logger.log(Logger.Level.INFO, "JMSPriority test - Recv a TextMessage from Topic");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "JMSPriority is " + messageReceived.getJMSPriority());
+ if (messageReceived.getJMSPriority() == priority2) {
+ logger.log(Logger.Level.INFO, "TextMessage JMSPriority passed");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage JMSPriority failed");
+ pass = false;
+ }
+ }
+
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.INFO, "JMSPriority test - Send ObjectMessage to Topic.");
+ messageSentO = context.createObjectMessage();
+ messageSentO.setObject("msgHdrJMSPriorityTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTest");
+ producer.send(destination, messageSentO);
+ logger.log(Logger.Level.INFO, "JMSPriority test - Recv a ObjectMessage from Topic");
+ messageReceivedO = (ObjectMessage) consumer.receive(timeout);
+ if (messageReceivedO == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "JMSPriority is " + messageReceivedO.getJMSPriority());
+ if (messageReceivedO.getJMSPriority() == priority2) {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSPriority passed");
+ } else {
+ logger.log(Logger.Level.ERROR, "ObjectMessage JMSPriority failed");
+ pass = false;
+ }
+ }
+
+ // send and receive map message to Topic
+ logger.log(Logger.Level.INFO, "JMSPriority test - Send MapMessage to Topic.");
+ messageSentM = context.createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTest");
+ messageSentM.setString("aString", "value");
+ producer.send(destination, messageSentM);
+ logger.log(Logger.Level.INFO, "JMSPriority test - Recv a MapMessage from Topic");
+ messageReceivedM = (MapMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "JMSPriority is " + messageReceivedM.getJMSPriority());
+ if (messageReceivedM.getJMSPriority() == priority2) {
+ logger.log(Logger.Level.INFO, "MapMessage JMSPriority passed");
+ } else {
+ logger.log(Logger.Level.ERROR, "MapMessage JMSPriority failed");
+ pass = false;
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Setting priority to 4");
+ producer.setPriority(priority4);
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.INFO, "JMSPriority test - Send BytesMessage to Topic.");
+ messageSentB = context.createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTest");
+ messageSentB.writeByte(bValue);
+ producer.send(destination, messageSentB);
+ logger.log(Logger.Level.INFO, "JMSPriority test - Recv a BytesMessage from Topic");
+ messageReceivedB = (BytesMessage) consumer.receive(timeout);
+ if (messageReceivedB == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "JMSPriority is " + messageReceivedB.getJMSPriority());
+ if (messageReceivedB.getJMSPriority() == priority4) {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSPriority passed");
+ } else {
+ logger.log(Logger.Level.ERROR, "BytesMessage JMSPriority failed");
+ pass = false;
+ }
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.INFO, "JMSPriority test - Send a StreamMessage to Topic");
+ messageSentS = context.createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSPriorityTest");
+ messageSentS.writeString("Testing...");
+ producer.send(destination, messageSentS);
+ logger.log(Logger.Level.INFO, "JMSPriority test - Recv a StreamMessage from Topic");
+ messageReceivedS = (StreamMessage) consumer.receive(timeout);
+ if (messageReceivedS == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "JMSPriority is " + messageReceivedS.getJMSPriority());
+ if (messageReceivedS.getJMSPriority() == priority4) {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSPriority passed");
+ } else {
+ logger.log(Logger.Level.ERROR, "StreamMessage JMSPriority failed");
+ pass = false;
+ }
+ }
+ if (!pass) {
+ throw new Exception("Error: invalid JMSPriority returned from JMS Header");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrJMSPriorityTest");
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSExpirationTest
+ *
+ * @assertion_ids: JMS:SPEC:15.1; JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140;
+ * JMS:JAVADOC:1303; JMS:JAVADOC:379;
+ *
+ * @test_Strategy: 1. Send a message to a Topic with time to live set to 0.
+ * Verify on receive that JMSExpiration gets set to 0. Test with Text, Map,
+ * Object, Bytes, and Stream messages. 2. Send a message to a Topic with time to
+ * live set to non-0; Verify on receive that JMSExpiration gets set correctly.
+ */
+ @Test
+ public void msgHdrJMSExpirationTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ long forever = 0L;
+ long timeToLive = 5000L;
+ String testName = "msgHdrJMSExpirationTest";
+ long timeBeforeSend = 0L;
+ long timeAfterSend = 0L;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a TextMessage (timeToLive is forever)");
+ messageSent = context.createTextMessage();
+ messageSent.setText("sending a TextMessage");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ producer.setTimeToLive(forever);
+ producer.send(destination, messageSent);
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceived.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.ERROR, "TextMessage JMSExpiration failed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage JMSExpiration passed");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a TextMessage (timeToLive is 5000)");
+ producer.setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSent);
+ timeAfterSend = System.currentTimeMillis();
+
+ long exp = messageSent.getJMSExpiration();
+ logger.log(Logger.Level.INFO, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.INFO, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.INFO, "Time to Live =" + timeToLive);
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceived.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "TextMessage failed: JMSExpiration didn't set correctly = "
+ + messageReceived.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage JMSExpiration passed");
+ }
+ }
+
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a ObjectMessage (timeToLive is forever)");
+ messageSentO = context.createObjectMessage();
+ messageSentO.setObject("msgHdrJMSExpirationTest for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ producer.setTimeToLive(forever);
+ producer.send(destination, messageSentO);
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a ObjectMessage");
+ messageReceivedO = (ObjectMessage) consumer.receive(timeout);
+ if (messageReceivedO == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedO.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSExpiration failed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSExpiration passed");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a ObjectMessage (timeToLive is 5000)");
+ producer.setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentO);
+ timeAfterSend = System.currentTimeMillis();
+
+ exp = messageSentO.getJMSExpiration();
+ logger.log(Logger.Level.INFO, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.INFO, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.INFO, "Time to Live =" + timeToLive);
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a ObjectMessage");
+ messageReceivedO = (ObjectMessage) consumer.receive(timeout);
+ if (messageReceivedO == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedO.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage failed: JMSExpiration didn't set correctly = "
+ + messageReceivedO.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSExpiration passed");
+ }
+ }
+
+ // send and receive map message to Topic
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a MapMessage (timeToLive is forever)");
+ messageSentM = context.createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentM.setString("aString", "value");
+ producer.setTimeToLive(forever);
+ producer.send(destination, messageSentM);
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a MapMessage");
+ messageReceivedM = (MapMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedM.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.INFO, "MapMessage JMSExpiration failed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSExpiration passed");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a MapMessage (timeToLive is 5000)");
+ producer.setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentM);
+ timeAfterSend = System.currentTimeMillis();
+
+ exp = messageSentM.getJMSExpiration();
+ logger.log(Logger.Level.INFO, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.INFO, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.INFO, "Time to Live =" + timeToLive);
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a MapMessage");
+ messageReceivedM = (MapMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedM.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "MapMessage failed: JMSExpiration didn't set correctly = "
+ + messageReceivedM.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSExpiration passed");
+ }
+ }
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a Bytesessage (timeToLive is forever)");
+ messageSentB = context.createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentB.writeByte(bValue);
+ producer.setTimeToLive(forever);
+ producer.send(destination, messageSentB);
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a BytesMessage");
+ messageReceivedB = (BytesMessage) consumer.receive(timeout);
+ if (messageReceivedB == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedB.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSExpiration failed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSExpiration passed");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a Bytesessage (timeToLive is 5000)");
+ producer.setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentB);
+ timeAfterSend = System.currentTimeMillis();
+
+ exp = messageSentB.getJMSExpiration();
+ logger.log(Logger.Level.INFO, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.INFO, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.INFO, "Time to Live =" + timeToLive);
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a BytesMessage");
+ messageReceivedB = (BytesMessage) consumer.receive(timeout);
+ if (messageReceivedB == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedB.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "BytesMessage failed: JMSExpiration didn't set correctly = "
+ + messageReceivedB.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSExpiration passed");
+ }
+ }
+
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a Streamessage (timeToLive is forever)");
+ messageSentS = context.createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentS.writeString("Testing...");
+ producer.setTimeToLive(forever);
+ producer.send(destination, messageSentS);
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a StreamMessage");
+ messageReceivedS = (StreamMessage) consumer.receive(timeout);
+ if (messageReceivedS == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedS.getJMSExpiration() != forever) {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSExpiration failed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSExpiration passed");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Send a StreamMessage (timeToLive is 5000)");
+ producer.setTimeToLive(timeToLive);
+ timeBeforeSend = System.currentTimeMillis();
+ producer.send(destination, messageSentS);
+ timeAfterSend = System.currentTimeMillis();
+
+ exp = messageSentS.getJMSExpiration();
+ logger.log(Logger.Level.INFO, "JMSExpiration is set to=" + exp);
+ logger.log(Logger.Level.INFO, "Time before send=" + timeBeforeSend);
+ logger.log(Logger.Level.INFO, "Time after send=" + timeAfterSend);
+ logger.log(Logger.Level.INFO, "Time to Live =" + timeToLive);
+
+ logger.log(Logger.Level.INFO, "JMSExpiration test - Recv a StreamMessage");
+ messageReceivedS = (StreamMessage) consumer.receive(timeout);
+ if (messageReceivedS == null) {
+ logger.log(Logger.Level.ERROR, "Received no message NULL (unexpected)");
+ pass = false;
+ } else {
+ if (messageReceivedS.getJMSExpiration() != exp) {
+ logger.log(Logger.Level.ERROR, "StreamMessage failed: JMSExpiration didn't set correctly = "
+ + messageReceivedS.getJMSExpiration());
+ logger.log(Logger.Level.ERROR, "JMSExpiration was set to=" + exp);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSExpiration passed");
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("Error: invalid JMSExpiration returned from JMS Header");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:3; JMS:SPEC:140; JMS:SPEC:246.2; JMS:JAVADOC:1192;
+ * JMS:JAVADOC:1259; JMS:JAVADOC:367;
+ *
+ * @test_Strategy: 1. Create and send a message to the default Topic. Receive
+ * the msg and verify that JMSDeliveryMode is set the default delivery mode of
+ * persistent. 2. Create and test another message with a nonpersistent delivery
+ * mode. Test with Text, map, object, byte, and stream messages 3. Set
+ * JMSDeliveryMode to Message after receive. Verify that JMSDeliveryMode is set
+ * correctly.
+ */
+ @Test
+ public void msgHdrJMSDeliveryModeTest() throws Exception {
+ boolean pass = true;
+ byte bValue = 127;
+ String testName = "msgHdrJMSDeliveryModeTest";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ StreamMessage messageSentS = null;
+ StreamMessage messageReceivedS = null;
+ BytesMessage messageSentB = null;
+ BytesMessage messageReceivedB = null;
+ MapMessage messageReceivedM = null;
+ MapMessage messageSentM = null;
+ ObjectMessage messageSentO = null;
+ ObjectMessage messageReceivedO = null;
+
+ // send and receive Text message to Topic
+ logger.log(Logger.Level.INFO, "send TextMessage to Topic with DeliveryMode.PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ messageSent = context.createTextMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ producer.send(destination, messageSent);
+ logger.log(Logger.Level.INFO, "receive TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TextMessage is null (unexpected)");
+ } else if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TextMessage failed: JMSDeliveryMode should be set to persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage JMSDeliveryMode passed");
+ }
+
+ logger.log(Logger.Level.INFO, "send TextMessage to Topic with DeliveryMode.NON_PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ messageSent = context.createTextMessage();
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ producer.send(destination, messageSent);
+ logger.log(Logger.Level.INFO, "receive TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TextMessage is null (unexpected)");
+ } else if (messageReceived.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TextMessage failed: JMSDeliveryMode should be set to non persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage JMSDeliveryMode passed");
+ }
+
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.INFO, "send ObjectMessage to Topic with DeliveryMode.PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ messageSentO = context.createObjectMessage();
+ messageSentO.setObject("Test for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ producer.send(destination, messageSentO);
+ logger.log(Logger.Level.INFO, "receive ObjectMessage");
+ messageReceivedO = (ObjectMessage) consumer.receive(timeout);
+ if (messageReceivedO == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "ObjectMessage is null (unexpected)");
+ } else if (messageReceivedO.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "ObjectMessage failed: JMSDeliveryMode should be set to persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSDeliveryMode passed");
+ }
+
+ logger.log(Logger.Level.INFO, "send ObjectMessage to Topic with DeliveryMode.NON_PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ messageSentO = context.createObjectMessage();
+ messageSentO.setObject("Test for ObjectMessage");
+ messageSentO.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ producer.send(destination, messageSentO);
+ logger.log(Logger.Level.INFO, "receive ObjectMessage");
+ messageReceivedO = (ObjectMessage) consumer.receive(timeout);
+ if (messageReceivedO == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "ObjectMessage is null (unexpected)");
+ } else if (messageReceivedO.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "ObjectMessage failed: JMSDeliveryMode should be set to non persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "ObjectMessage JMSDeliveryMode passed");
+ }
+
+ // send and receive map message to Topic
+ logger.log(Logger.Level.INFO, "send MapMessage to Topic with DeliveryMode.PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ messageSentM = context.createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentM.setString("aString", "value");
+ producer.send(destination, messageSentM);
+ logger.log(Logger.Level.INFO, "receive MapMessage");
+ messageReceivedM = (MapMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "MapMessage is null (unexpected)");
+ } else if (messageReceivedM.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "MapMessage failed: JMSDeliveryMode should be set to persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSDeliveryMode passed");
+ }
+
+ logger.log(Logger.Level.INFO, "send MapMessage to Topic with DeliveryMode.NON_PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ messageSentM = context.createMapMessage();
+ messageSentM.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentM.setString("aString", "value");
+ producer.send(destination, messageSentM);
+ logger.log(Logger.Level.INFO, "receive MapMessage");
+ messageReceivedM = (MapMessage) consumer.receive(timeout);
+ if (messageReceivedM == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "MapMessage is null (unexpected)");
+ } else if (messageReceivedM.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "MapMessage failed: JMSDeliveryMode should be set to non persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "MapMessage JMSDeliveryMode passed");
+ }
+
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.INFO, "send BytesMessage to Topic with DeliveryMode.PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ messageSentB = context.createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentB.writeByte(bValue);
+ producer.send(destination, messageSentB);
+ logger.log(Logger.Level.INFO, "receive BytesMessage");
+ messageReceivedB = (BytesMessage) consumer.receive(timeout);
+ if (messageReceivedB == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "BytesMessage is null (unexpected)");
+ } else if (messageReceivedB.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "BytesMessage failed: JMSDeliveryMode should be set to persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSDeliveryMode passed");
+ }
+
+ logger.log(Logger.Level.INFO, "send BytesMessage to Topic with DeliveryMode.NON_PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ messageSentB = context.createBytesMessage();
+ messageSentB.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentB.writeByte(bValue);
+ producer.send(destination, messageSentB);
+ logger.log(Logger.Level.INFO, "receive BytesMessage");
+ messageReceivedB = (BytesMessage) consumer.receive(timeout);
+ if (messageReceivedB == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "BytesMessage is null (unexpected)");
+ } else if (messageReceivedB.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "BytesMessage failed: JMSDeliveryMode should be set to non persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "BytesMessage JMSDeliveryMode passed");
+ }
+
+ // send and receive a StreamMessage
+ logger.log(Logger.Level.INFO, "send StreamMessage to Topic with DeliveryMode.PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ messageSentS = context.createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentS.writeString("Testing...");
+ producer.send(destination, messageSentS);
+ logger.log(Logger.Level.INFO, "receive StreamMessage");
+ messageReceivedS = (StreamMessage) consumer.receive(timeout);
+ if (messageReceivedS == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "StreamMessage is null (unexpected)");
+ } else if (messageReceivedS.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "StreamMessage failed: JMSDeliveryMode should be set to persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSDeliveryMode passed");
+ }
+
+ logger.log(Logger.Level.INFO, "send StreamMessage to Topic with DeliveryMode.NON_PERSISTENT.");
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ messageSentS = context.createStreamMessage();
+ messageSentS.setStringProperty("COM_SUN_JMS_TESTNAME", testName);
+ messageSentS.writeString("Testing...");
+ producer.send(destination, messageSentS);
+ logger.log(Logger.Level.INFO, "receive StreamMessage");
+ messageReceivedS = (StreamMessage) consumer.receive(timeout);
+ if (messageReceivedS == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "StreamMessage is null (unexpected)");
+ } else if (messageReceivedS.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "StreamMessage failed: JMSDeliveryMode should be set to non persistent");
+ } else {
+ logger.log(Logger.Level.INFO, "StreamMessage JMSDeliveryMode passed");
+ }
+
+ if (!pass) {
+ throw new Exception("Error: invalid JMSDeliveryMode returned from JMS Header");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception(testName);
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSDeliveryTimeTest
+ *
+ * @assertion_ids: JMS:SPEC:246.11; JMS:SPEC:261; JMS:SPEC:256;
+ * JMS:JAVADOC:1257; JMS:JAVADOC:875;
+ *
+ * @test_Strategy: Send message and verify that JMSDeliveryTime is correct with
+ * the DeliveryDelay set to 20 seconds. Test with DeliveryMode.PERSISTENT and
+ * DeliveryMode.NON_PERSISTENT.
+ *
+ * Retrieve and verify the JMSDeliveryTime
+ */
+ @Test
+ public void msgHdrJMSDeliveryTimeTest() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "---------------------------------------------------------------");
+ logger.log(Logger.Level.INFO, "BEGIN TEST msgHdrJMSDeliveryTimeTest with DeliveryDelay=20Secs");
+ logger.log(Logger.Level.INFO, "---------------------------------------------------------------");
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage messageSnd = context.createTextMessage("This is a test!");
+
+ logger.log(Logger.Level.INFO, "Set StringProperty COM_SUN_JMS_TESTNAME");
+ messageSnd.setStringProperty("COM_SUN_JMS_TESTNAME", "msgHdrJMSDeliveryTimeTest");
+
+ logger.log(Logger.Level.INFO, "Sending message with DeliveryMode.PERSISTENT and DeliveryDelay=20Secs");
+ producer.setDeliveryDelay(20000);
+ producer.setDeliveryMode(DeliveryMode.PERSISTENT);
+ producer.setPriority(Message.DEFAULT_PRIORITY);
+ producer.setTimeToLive(0L);
+ producer.send(destination, messageSnd);
+
+ // Get deliverytime and current GMT time after send
+ logger.log(Logger.Level.INFO, "Get JMSDeliveryTime after sending message");
+ long deliverydelay = producer.getDeliveryDelay();
+ long gmtTimeAfterSend = System.currentTimeMillis();
+ long JMSDeliveryTimeAfterSend = messageSnd.getJMSDeliveryTime();
+
+ logger.log(Logger.Level.INFO, "Receive message with timeout value of 21Secs");
+ TextMessage messageRcv = (TextMessage) consumer.receive(21000);
+ if (messageRcv == null) {
+ logger.log(Logger.Level.ERROR,
+ "FAILED: Message was not received after delivery delay of 30 secs elapsed");
+ pass = false;
+ } else {
+ // Get JMSDeliverytime after receive
+ logger.log(Logger.Level.INFO, "Get JMSDeliveryTime after receiving message");
+ long gmtTimeAfterRecv = System.currentTimeMillis();
+ long JMSDeliveryTimeAfterRecv = messageRcv.getJMSDeliveryTime();
+
+ logger.log(Logger.Level.INFO, "Check JMSDeliverytime");
+ logger.log(Logger.Level.INFO, "JMSDeliveryTime after send = " + JMSDeliveryTimeAfterSend);
+ logger.log(Logger.Level.INFO, "JMSDeliveryTime after receive = " + JMSDeliveryTimeAfterRecv);
+ if (JMSDeliveryTimeAfterSend == JMSDeliveryTimeAfterRecv) {
+ logger.log(Logger.Level.INFO, "JMSDeliveryTimeAfterSend = JMSDeliveryTimeAfterRecv (PASS)");
+ } else {
+ logger.log(Logger.Level.ERROR, "JMSDeliveryTimeAfterSend != JMSDeliveryTimeAfterRecv (FAIL)");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "gmtTimeAfterSend after send = " + gmtTimeAfterSend);
+ logger.log(Logger.Level.INFO, "gmtTimeAfterRecv after receive = " + gmtTimeAfterRecv);
+ if (gmtTimeAfterRecv >= (gmtTimeAfterSend + deliverydelay - 250)) {
+ logger.log(Logger.Level.INFO, "gmtTimeAfterRecv >= (gmtTimeAfterSend + deliverydelay) (PASS)");
+ } else {
+ logger.log(Logger.Level.ERROR, "gmtTimeAfterRecv < (gmtTimeAfterSend + deliverydelay) (FAIL)");
+ pass = false;
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Sending message with DeliveryMode.NON_PERSISTENT and DeliveryDelay=20Secs");
+ producer.setDeliveryDelay(20000);
+ producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
+ producer.setPriority(Message.DEFAULT_PRIORITY);
+ producer.setTimeToLive(0L);
+ producer.send(destination, messageSnd);
+
+ // Get deliverytime and current GMT time after send
+ logger.log(Logger.Level.INFO, "Get JMSDeliveryTime after sending message");
+ gmtTimeAfterSend = System.currentTimeMillis();
+ JMSDeliveryTimeAfterSend = messageSnd.getJMSDeliveryTime();
+
+ logger.log(Logger.Level.INFO, "Receive message with timeout value of 21Secs");
+ messageRcv = (TextMessage) consumer.receive(21000);
+ if (messageRcv == null) {
+ logger.log(Logger.Level.ERROR,
+ "FAILED: Message was not received after delivery delay of 20 secs elapsed");
+ pass = false;
+ } else {
+ // Get JMSDeliverytime after receive
+ logger.log(Logger.Level.INFO, "Get JMSDeliveryTime after receiving message");
+ long gmtTimeAfterRecv = System.currentTimeMillis();
+ long JMSDeliveryTimeAfterRecv = messageRcv.getJMSDeliveryTime();
+
+ logger.log(Logger.Level.INFO, "Check JMSDeliverytime");
+ logger.log(Logger.Level.INFO, "JMSDeliveryTime after send = " + JMSDeliveryTimeAfterSend);
+ logger.log(Logger.Level.INFO, "JMSDeliveryTime after receive = " + JMSDeliveryTimeAfterRecv);
+ if (JMSDeliveryTimeAfterSend == JMSDeliveryTimeAfterRecv) {
+ logger.log(Logger.Level.INFO, "JMSDeliveryTimeAfterSend = JMSDeliveryTimeAfterRecv (PASS)");
+ } else {
+ logger.log(Logger.Level.ERROR, "JMSDeliveryTimeAfterSend != JMSDeliveryTimeAfterRecv (FAIL)");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "gmtTimeAfterSend after send = " + gmtTimeAfterSend);
+ logger.log(Logger.Level.INFO, "gmtTimeAfterRecv after receive = " + gmtTimeAfterRecv);
+ if (gmtTimeAfterRecv >= (gmtTimeAfterSend + deliverydelay - 250)) {
+ logger.log(Logger.Level.INFO, "gmtTimeAfterRecv >= (gmtTimeAfterSend + deliverydelay) (PASS)");
+ } else {
+ logger.log(Logger.Level.ERROR, "gmtTimeAfterRecv < (gmtTimeAfterSend + deliverydelay) (FAIL)");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "-------------------------------------------------------------");
+ logger.log(Logger.Level.INFO, "END TEST msgHdrJMSDeliveryTimeTest with DeliveryDelay=20Secs");
+ logger.log(Logger.Level.INFO, "-------------------------------------------------------------");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgHdrJMSDeliveryTimeTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("msgHdrJMSDeliveryTimeTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetAllPropertyTypesTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1180; JMS:JAVADOC:1184; JMS:JAVADOC:1187;
+ * JMS:JAVADOC:1198; JMS:JAVADOC:1201; JMS:JAVADOC:1204; JMS:JAVADOC:1215;
+ * JMS:JAVADOC:1218; JMS:JAVADOC:1222; JMS:JAVADOC:1224; JMS:JAVADOC:1227;
+ * JMS:JAVADOC:1232; JMS:JAVADOC:1275; JMS:JAVADOC:1278; JMS:JAVADOC:1281;
+ * JMS:JAVADOC:1284; JMS:JAVADOC:1287; JMS:JAVADOC:1290; JMS:JAVADOC:1293;
+ * JMS:JAVADOC:1296; JMS:JAVADOC:1299;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setProperty(String, boolean) JMSProducer.setProperty(String,
+ * byte) JMSProducer.setProperty(String, double) JMSProducer.setProperty(String,
+ * float) JMSProducer.setProperty(String, int) JMSProducer.setProperty(String,
+ * long) JMSProducer.setProperty(String, Object) JMSProducer.setProperty(String,
+ * short) JMSProducer.setProperty(String, String)
+ * JMSProducer.getBooleanProperty(String) JMSProducer.getByteProperty(String)
+ * JMSProducer.getDoubleProperty(String) JMSProducer.getFloatProperty(String)
+ * JMSProducer.getIntProperty(String) JMSProducer.getLongProperty(String)
+ * JMSProducer.getObjectProperty(String) JMSProducer.getShortProperty(String)
+ * JMSProducer.getStringProperty(String) JMSProducer.clearProperties(String)
+ * JMSProducer.getPropertyNames() JMSProducer.propertyExists()
+ */
+ @Test
+ public void setGetAllPropertyTypesTest() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ int numPropertyNames = 16;
+
+ try {
+ logger.log(Logger.Level.INFO, "Set all JMSProducer properties");
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTSTRING", "test");
+ producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
+ producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
+ producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
+ producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
+ producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
+ producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
+ producer.setProperty("OBJTESTSTRING", "test");
+
+ logger.log(Logger.Level.INFO, "Get all JMSProducer properties");
+ if (producer.getBooleanProperty("TESTBOOLEAN") == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getBooleanProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getBooleanProperty");
+ pass = false;
+ }
+ if (producer.getByteProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getByteProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getByteProperty");
+ pass = false;
+ }
+ if (producer.getLongProperty("TESTLONG") == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getLongProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getLongProperty");
+ pass = false;
+ }
+ if (producer.getStringProperty("TESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getStringProperty");
+ pass = false;
+ }
+ if (producer.getDoubleProperty("TESTDOUBLE") == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getDoubleProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getDoubleProperty");
+ pass = false;
+ }
+ if (producer.getFloatProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getFloatProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getFloatProperty");
+ pass = false;
+ }
+ if (producer.getIntProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getIntProperty");
+ pass = false;
+ }
+ if (producer.getShortProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getShortProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getShortProperty");
+ pass = false;
+ }
+ if (((Boolean) producer.getObjectProperty("OBJTESTBOOLEAN")).booleanValue() == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Boolean value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Byte) producer.getObjectProperty("OBJTESTBYTE")).byteValue() == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Byte value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Long) producer.getObjectProperty("OBJTESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Long value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Long value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((String) producer.getObjectProperty("OBJTESTSTRING")).equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct String value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect String value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Double) producer.getObjectProperty("OBJTESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Double value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Double value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Float) producer.getObjectProperty("OBJTESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Float value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Float value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Integer) producer.getObjectProperty("OBJTESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Integer value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Integer value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Short) producer.getObjectProperty("OBJTESTSHORT")).shortValue() == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Short value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Short value returned from getObjectProperty");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Now check all property names returned by JMSProducer.getPropertyNames()");
+ // iterate thru the property names
+ int i = 0;
+ Set propNames = producer.getPropertyNames();
+ Iterator iterator = propNames.iterator();
+ do {
+ String tmp = iterator.next();
+
+ if (!tmp.startsWith("JMS")) {
+ i++;
+ if (tmp.equals("TESTBOOLEAN") || tmp.equals("TESTBYTE") || tmp.equals("TESTINT")
+ || tmp.equals("TESTSHORT") || tmp.equals("TESTFLOAT") || tmp.equals("TESTDOUBLE")
+ || tmp.equals("TESTSTRING") || tmp.equals("TESTLONG") || tmp.equals("OBJTESTBOOLEAN")
+ || tmp.equals("OBJTESTBYTE") || tmp.equals("OBJTESTINT") || tmp.equals("OBJTESTSHORT")
+ || tmp.equals("OBJTESTFLOAT") || tmp.equals("OBJTESTDOUBLE") || tmp.equals("OBJTESTSTRING")
+ || tmp.equals("OBJTESTLONG")) {
+ logger.log(Logger.Level.INFO, "Producer Property set by client: " + tmp);
+ } else {
+ logger.log(Logger.Level.ERROR, "Producer Property not set by client: " + tmp);
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.INFO, "JMSProperty Name is: " + tmp);
+ }
+ } while (iterator.hasNext());
+ if (i == numPropertyNames) {
+ logger.log(Logger.Level.INFO, "Pass: # of properties is " + numPropertyNames + " as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: expected " + numPropertyNames + " property names, but got " + i);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("setGetAllPropertyTypesTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetAllPropertyTypesTest failed");
+ }
+ }
+
+ /*
+ * @testName: setGetAllHeaderTypesTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1265; JMS:JAVADOC:1267; JMS:JAVADOC:1269;
+ * JMS:JAVADOC:1271; JMS:JAVADOC:1207; JMS:JAVADOC:1209; JMS:JAVADOC:1211;
+ * JMS:JAVADOC:1213;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * JMSProducer.setJMSCorrelationID(String);
+ * JMSProducer.setJMSCorrelationIDAsBytes(byte[]);
+ * JMSProducer.setJMSReplyTo(Destination); JMSProducer.setJMSType(String);
+ * JMSProducer.getJMSCorrelationID(); JMSProducer.getJMSCorrelationIDAsBytes();
+ * JMSProducer.getJMSReplyTo(); JMSProducer.getJMSType();
+ */
+ @Test
+ public void setGetAllHeaderTypesTest() throws Exception {
+ boolean pass = true;
+
+ try {
+
+ try {
+ logger.log(Logger.Level.INFO, "Set JMSProducer message header JMSCorrelationID as bytes");
+ byte[] cid = "TestCorrelationID".getBytes();
+ producer.setJMSCorrelationIDAsBytes(cid);
+
+ logger.log(Logger.Level.INFO, "Get JMSProducer message header JMSCorrelationID as bytes");
+ cid = producer.getJMSCorrelationIDAsBytes();
+ String cidString = new String(cid);
+ if (cid == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned null");
+ pass = false;
+ } else if (cidString.equals("TestCorrelationID")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSCorrelationID returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned incorrect value, got: "
+ + cidString + " expected: TestCorrelationID");
+ pass = false;
+ }
+ } catch (java.lang.UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "UnsupportedOperationException - no further testing.");
+ }
+
+ logger.log(Logger.Level.INFO, "Set all JMSProducer message headers JMSCorrelationID, JMSType, JMSReplyTo");
+ producer.setJMSCorrelationID("TestCorrelationID");
+ producer.setJMSType("TestMessage");
+ producer.setJMSReplyTo(topic);
+
+ logger.log(Logger.Level.INFO, "Get all JMSProducer message headers JMSCorrelationID, JMSType, JMSReplyTo");
+ String temp = null;
+ Destination tempdest = null;
+ temp = producer.getJMSCorrelationID();
+ if (temp == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned null");
+ pass = false;
+ } else if (temp.equals("TestCorrelationID")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSCorrelationID returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned incorrect value, got: " + temp
+ + " expected: TestCorrelationID");
+ pass = false;
+ }
+ temp = producer.getJMSType();
+ if (temp == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSType returned null");
+ pass = false;
+ } else if (temp.equals("TestMessage")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSType returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Fail: getJMSType returned incorrect value, got: " + temp + " expected: TestMessage");
+ pass = false;
+ }
+ tempdest = producer.getJMSReplyTo();
+ if (tempdest == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSReplyTo returned null");
+ pass = false;
+ } else if (tempdest.equals(topic)) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSReplyTo returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Fail: getJMSReplyTo returned incorrect value, got: " + tempdest + " expected: " + topic);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("setGetAllHeaderTypesTest");
+ }
+
+ if (!pass) {
+ throw new Exception("setGetAllHeaderTypesTest failed");
+ }
+ }
+
+ /*
+ * @testName: msgPropertiesTest
+ *
+ * @assertion_ids: JMS:SPEC:20.1; JMS:SPEC:20.2; JMS:SPEC:20.3; JMS:SPEC:20.4;
+ * JMS:SPEC:20.5; JMS:SPEC:20.6; JMS:SPEC:20.7; JMS:SPEC:20.8; JMS:SPEC:21;
+ * JMS:SPEC:23; JMS:SPEC:25; JMS:SPEC:26; JMS:SPEC:10; JMS:SPEC:27; JMS:SPEC:28;
+ * JMS:SPEC:29; JMS:SPEC:31; JMS:SPEC:32; JMS:SPEC:34; JMS:SPEC:19; JMS:SPEC:70;
+ * JMS:SPEC:71; JMS:SPEC:24; JMS:JAVADOC:1180; JMS:JAVADOC:1184;
+ * JMS:JAVADOC:1187; JMS:JAVADOC:1198; JMS:JAVADOC:1201; JMS:JAVADOC:1204;
+ * JMS:JAVADOC:1215; JMS:JAVADOC:1218; JMS:JAVADOC:1222; JMS:JAVADOC:1224;
+ * JMS:JAVADOC:1227; JMS:JAVADOC:1232; JMS:JAVADOC:1275; JMS:JAVADOC:1278;
+ * JMS:JAVADOC:1281; JMS:JAVADOC:1284; JMS:JAVADOC:1287; JMS:JAVADOC:1290;
+ * JMS:JAVADOC:1293; JMS:JAVADOC:1296; JMS:JAVADOC:1299;
+ *
+ * @test_Strategy: Set and read properties for boolean, byte, short, int, long,
+ * float, double, and String. Verify expected results Set and read properties
+ * for Boolean, Byte, Short, Int, Long, Float, Double, and String. Verify
+ * expected results.
+ *
+ * Call property get methods (other than getStringProperty and
+ * getObjectProperty) for non-existent properties and verify that a null pointer
+ * exception is returned. Call getStringProperty and getObjectProperty for
+ * non-existent properties and verify that a null is returned.
+ *
+ * Set object properties and verify the correct value is returned with the
+ * getObjectProperty method.
+ *
+ * Call the clearProperties method on the JMSProducer and verify that the
+ * message properties for that JMSProducer were deleted. Test that
+ * getObjectProperty returns a null and the getShortProperty throws a null
+ * pointer exception.
+ *
+ * Call getJMSXPropertyNames() and verify that the names of the required JMSX
+ * properties for JMSXGroupID and JMSXGroupSeq are returned.
+ */
+ @Test
+ public void msgPropertiesTest() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ Enumeration propertyNames = null;
+ Enumeration jmsxDefined = null;
+ int numPropertyNames = 18;
+ String testMessageBody = "Testing...";
+ String message = "Where are you!";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // ------------------------------------------------------------------------------
+ // Set JMSProducer message properties
+ // Set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Set primitive property types on JMSProducer");
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTSTRING", "test");
+
+ // ------------------------------------------------------------------------------
+ // Set JMSProducer message properties
+ // Set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Set Object property types on JMSProducer");
+ producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ producer.setProperty("OBJTESTBYTE", Byte.valueOf(bValue));
+ producer.setProperty("OBJTESTDOUBLE", Double.valueOf(nDouble));
+ producer.setProperty("OBJTESTFLOAT", Float.valueOf(nFloat));
+ producer.setProperty("OBJTESTINT", Integer.valueOf(nInt));
+ producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
+ producer.setProperty("OBJTESTSHORT", Short.valueOf(nShort));
+ producer.setProperty("OBJTESTSTRING", "test");
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ messageSent = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "messageSent=" + messageSent.getText());
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesTest");
+ producer.send(destination, messageSent);
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ logger.log(Logger.Level.INFO, "messageReceived=" + messageReceived.getText());
+
+ // Iterate thru the property names
+ int i = 0;
+ logger.log(Logger.Level.INFO, "Retrieve and verify correct # of properties set");
+ propertyNames = messageReceived.getPropertyNames();
+ do {
+ String tmp = (String) propertyNames.nextElement();
+ logger.log(Logger.Level.INFO, "Property Name is: " + tmp);
+ if (tmp.indexOf("JMS") != 0)
+ i++;
+ else if (tmp.equals("JMSXDeliveryCount"))
+ i++;
+ } while (propertyNames.hasMoreElements());
+
+ if (i == numPropertyNames) {
+ logger.log(Logger.Level.INFO, "Pass: # of properties is " + numPropertyNames + " as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: expected " + numPropertyNames + " property names, but got " + i);
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------------
+ // Retrieve the JMSProducer properties and verify that they are correct
+ // Get properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO,
+ "Get properties for boolean, byte, short, int, long, float, double, and String.");
+ logger.log(Logger.Level.INFO, "Retrieve and verify that JMSProducer properties were set correctly");
+ if (producer.getBooleanProperty("TESTBOOLEAN") == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getBooleanProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getBooleanProperty");
+ pass = false;
+ }
+ if (producer.getByteProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getByteProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getByteProperty");
+ pass = false;
+ }
+ if (producer.getLongProperty("TESTLONG") == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getLongProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getLongProperty");
+ pass = false;
+ }
+ if (producer.getStringProperty("TESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getStringProperty");
+ pass = false;
+ }
+ if (producer.getDoubleProperty("TESTDOUBLE") == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getDoubleProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getDoubleProperty");
+ pass = false;
+ }
+ if (producer.getFloatProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getFloatProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getFloatProperty");
+ pass = false;
+ }
+ if (producer.getIntProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getIntProperty");
+ pass = false;
+ }
+ if (producer.getShortProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getShortProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getShortProperty");
+ pass = false;
+ }
+
+ // -----------------------------------------------------------------------------
+ // Retrieve the JMSProducer properties and verify that they are correct
+ // Get properties for Boolean, Byte, Short, Integer, Long, Float, Double,
+ // String.
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO,
+ "Get properties for Boolean, Byte, Short, Integer, Long, Float, Double, String.");
+ if (((Boolean) producer.getObjectProperty("OBJTESTBOOLEAN")).booleanValue() == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Boolean value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Byte) producer.getObjectProperty("OBJTESTBYTE")).byteValue() == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Byte value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Long) producer.getObjectProperty("OBJTESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Long value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Long value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((String) producer.getObjectProperty("OBJTESTSTRING")).equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct String value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect String value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Double) producer.getObjectProperty("OBJTESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Double value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Double value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Float) producer.getObjectProperty("OBJTESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Float value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Float value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Integer) producer.getObjectProperty("OBJTESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Integer value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Integer value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Short) producer.getObjectProperty("OBJTESTSHORT")).shortValue() == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Short value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Short value returned from getObjectProperty");
+ pass = false;
+ }
+
+ // ---------------------------------------------------------------------------
+ // Set JMSProducer message headers (Set JMSCorrelationID, JMSType,
+ // JMSReplyTo)
+ // ---------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Set message headers JMSCorrelationID, JMSType, JMSReplyTo on JMSProducer");
+ producer.setJMSCorrelationID("TestCorrelationID");
+ producer.setJMSType("TestMessage");
+ producer.setJMSReplyTo(topic);
+
+ // ---------------------------------------------------------------------------
+ // Retrieve JMSProducer message headers and verify that they are set
+ // correctly
+ // ---------------------------------------------------------------------------
+ String temp = null;
+ Destination tempdest = null;
+ temp = producer.getJMSCorrelationID();
+ if (temp == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned null");
+ pass = false;
+ } else if (temp.equals("TestCorrelationID")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSCorrelationID returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned incorrect value, got: " + temp
+ + " expected: TestCorrelationID");
+ pass = false;
+ }
+ temp = producer.getJMSType();
+ if (temp == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSType returned null");
+ pass = false;
+ } else if (temp.equals("TestMessage")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSType returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Fail: getJMSType returned incorrect value, got: " + temp + " expected: TestMessage");
+ pass = false;
+ }
+ tempdest = producer.getJMSReplyTo();
+ if (tempdest == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSReplyTo returned null");
+ pass = false;
+ } else if (tempdest.equals(topic)) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSReplyTo returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Fail: getJMSReplyTo returned incorrect value, got: " + tempdest + " expected: " + topic);
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------------
+ // Create a TextMessage, send it then receive it and verify that all the
+ // JMSProducer
+ // properties are set in the TextMessage
+ // --------------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Create a TextMessage");
+ messageSent = context.createTextMessage();
+ messageSent.setText(testMessageBody);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesTest");
+
+ logger.log(Logger.Level.INFO, "Send the TextMessage");
+ producer.send(destination, messageSent);
+ logger.log(Logger.Level.INFO, "messageSent=" + messageSent.getText());
+
+ logger.log(Logger.Level.INFO, "Receive the TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ logger.log(Logger.Level.INFO, "messageReceived=" + messageReceived.getText());
+
+ // --------------------------------------------------------------------------------------
+ // Retrieve the properties from the received TextMessage and verify that
+ // they are correct
+ // Get properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // -------------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Retrieve and verify that TextMessage message properties were set correctly");
+ if (messageReceived.getBooleanProperty("TESTBOOLEAN") == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getBooleanProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getBooleanProperty");
+ pass = false;
+ }
+ if (messageReceived.getByteProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getByteProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getByteProperty");
+ pass = false;
+ }
+ if (messageReceived.getLongProperty("TESTLONG") == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getLongProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getLongProperty");
+ pass = false;
+ }
+ if (messageReceived.getStringProperty("TESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getStringProperty");
+ pass = false;
+ }
+ if (messageReceived.getDoubleProperty("TESTDOUBLE") == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getDoubleProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getDoubleProperty");
+ pass = false;
+ }
+ if (messageReceived.getFloatProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getFloatProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getFloatProperty");
+ pass = false;
+ }
+ if (messageReceived.getIntProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getIntProperty");
+ pass = false;
+ }
+ if (messageReceived.getShortProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getShortProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getShortProperty");
+ pass = false;
+ }
+ if (messageReceived.getIntProperty("JMSXDeliveryCount") >= 1) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty(JMSXDeliveryCount) returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect value returned from getIntProperty(JMSXDeliveryCount)");
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------------
+ // Retrieve the properties from the received TextMessage and verify that
+ // they are correct
+ // Get properties for Boolean, Byte, Short, Integer, Long, Float, Double,
+ // and String.
+ // --------------------------------------------------------------------------------------
+ if (((Boolean) messageReceived.getObjectProperty("OBJTESTBOOLEAN")).booleanValue() == bool) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Boolean value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Boolean value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Byte) messageReceived.getObjectProperty("OBJTESTBYTE")).byteValue() == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Byte value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Long) messageReceived.getObjectProperty("OBJTESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Long value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Long value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((String) messageReceived.getObjectProperty("OBJTESTSTRING")).equals(testString)) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct String value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect String value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Double) messageReceived.getObjectProperty("OBJTESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Double value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Double value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Float) messageReceived.getObjectProperty("OBJTESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Float value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Float value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Integer) messageReceived.getObjectProperty("OBJTESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Integer value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Integer value returned from getObjectProperty");
+ pass = false;
+ }
+ if (((Short) messageReceived.getObjectProperty("OBJTESTSHORT")).shortValue() == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: getObjectProperty returned correct Short value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: incorrect Short value returned from getObjectProperty");
+ pass = false;
+ }
+
+ // ---------------------------------------------------------------------------------------
+ // Retrieve message headers from the received TextMessage and verify that
+ // they are correct
+ // ---------------------------------------------------------------------------------------
+ temp = messageReceived.getJMSCorrelationID();
+ if (temp == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned null");
+ pass = false;
+ } else if (temp.equals("TestCorrelationID")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSCorrelationID returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: getJMSCorrelationID returned incorrect value, got: " + temp
+ + " expected: TestCorrelationID");
+ pass = false;
+ }
+ temp = messageReceived.getJMSType();
+ if (temp == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSType returned null");
+ pass = false;
+ } else if (temp.equals("TestMessage")) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSType returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Fail: getJMSType returned incorrect value, got: " + temp + " expected: TestMessage");
+ pass = false;
+ }
+ tempdest = messageReceived.getJMSReplyTo();
+ if (tempdest == null) {
+ logger.log(Logger.Level.INFO, "Fail: getJMSReplyTo returned null");
+ pass = false;
+ } else if (tempdest.equals(topic)) {
+ logger.log(Logger.Level.INFO, "Pass: getJMSReplyTo returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Fail: getJMSReplyTo returned incorrect value, got: " + tempdest + " expected: " + topic);
+ pass = false;
+ }
+
+ // ----------------------------------------------------------------------------------
+ // The other property get methods (other than getStringProperty and
+ // getObjectProperty)
+ // must behave as if the property exists with a null value
+ // ----------------------------------------------------------------------------------
+ try {
+ boolean b = producer.getBooleanProperty("TESTDUMMY");
+ if (b != false) {
+ logger.log(Logger.Level.INFO, "Fail: should have received false for getBooleanProperty");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ byte value = producer.getByteProperty("TESTDUMMY");
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException should have occurred for getByteProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.INFO, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ short value = producer.getShortProperty("TESTDUMMY");
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException should have occurred for getShortProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.INFO, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ int value = producer.getIntProperty("TESTDUMMY");
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException should have occurred for getIntProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.INFO, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ long value = producer.getLongProperty("TESTDUMMY");
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException should have occurred for getLongProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.INFO, "Pass: NumberFormatException as expected ");
+ }
+ try {
+ float value = producer.getFloatProperty("TESTDUMMY");
+ logger.log(Logger.Level.INFO, "Fail: NullPointerException should have occurred for getFloatProperty");
+ pass = false;
+ } catch (java.lang.NullPointerException np) {
+ logger.log(Logger.Level.INFO, "Pass: NullPointerException as expected ");
+ }
+ try {
+ double value = producer.getDoubleProperty("TESTDUMMY");
+ logger.log(Logger.Level.INFO, "Fail: NullPointerException should have occurred for getDoubleProperty");
+ pass = false;
+ } catch (java.lang.NullPointerException np) {
+ logger.log(Logger.Level.INFO, "Pass: NullPointerException as expected ");
+ }
+
+ // clear JMSProducer properties
+ producer.clearProperties();
+
+ // -------------------------------------------------------------------
+ // All JMSProducer properties are deleted by the clearProperties method.
+ // This leaves the message with an empty set of properties.
+ // -------------------------------------------------------------------
+ Long aLong = (Long) producer.getObjectProperty("OBJTESTLONG");
+ if (aLong == null) {
+ logger.log(Logger.Level.INFO, "Pass: property was cleared");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: getObjectProperty should have returned null for cleared property");
+ pass = false;
+ }
+ try {
+ short aShort = producer.getShortProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO, "Fail: NumberFormatException should have occurred for getShortProperty");
+ pass = false;
+ } catch (java.lang.NumberFormatException np) {
+ logger.log(Logger.Level.INFO, "Pass: NumberFormatException as expected ");
+ }
+
+ // Check that we have no property names
+ Set propNames = producer.getPropertyNames();
+ Iterator iterator = propNames.iterator();
+ boolean hasElements = iterator.hasNext();
+ if (hasElements) {
+ logger.log(Logger.Level.INFO, "Fail: JMSProducer.getPropertyName() has properties (unexpected)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Pass: JMSProducer.getPropertyName() has no properties (expected)");
+ }
+
+ // -------------------------------------------------------------------
+ // JMSContext.getJMSXPropertyNames() method returns the
+ // names of the JMSX properties supported by a connection.
+ // -------------------------------------------------------------------
+ try {
+ ConnectionMetaData data = context.getMetaData();
+ Enumeration cmd = data.getJMSXPropertyNames();
+ String propName;
+
+ if (cmd == null) {
+ logger.log(Logger.Level.INFO, "Fail: no JMSX property names were returned!");
+ logger.log(Logger.Level.INFO,
+ "expected JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount at a miniumum");
+ pass = false;
+ } else {
+ int iCount = 0;
+ do {
+ propName = (String) cmd.nextElement();
+ logger.log(Logger.Level.INFO, propName);
+ if (propName.equals("JMSXGroupID") || propName.equals("JMSXGroupSeq")
+ || propName.equals("JMSXDeliveryCount")) {
+ iCount++;
+ }
+ } while (cmd.hasMoreElements());
+ if (iCount > 1) {
+ logger.log(Logger.Level.INFO, "Pass:");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: Expected property names not returned");
+ pass = false;
+ }
+ }
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: unexpected exception: " + ee);
+ pass = false;
+ }
+ if (!pass) {
+ throw new Exception("msgPropertiesTest failed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ e.printStackTrace();
+ throw new Exception("msgPropertiesTest failed");
+ }
+ }
+
+ /*
+ * @testName: msgPropertiesConversionTests
+ *
+ * @assertion_ids: JMS:SPEC:22.1; JMS:SPEC:22.2; JMS:SPEC:22.3; JMS:SPEC:22.4;
+ * JMS:SPEC:22.5; JMS:SPEC:22.6; JMS:SPEC:22.7; JMS:SPEC:22.8; JMS:SPEC:22.9;
+ * JMS:SPEC:22.10; JMS:SPEC:22.11; JMS:SPEC:22.12; JMS:SPEC:22.13;
+ * JMS:SPEC:22.14; JMS:SPEC:22.15; JMS:SPEC:22.16; JMS:JAVADOC:1180;
+ * JMS:JAVADOC:1184; JMS:JAVADOC:1187; JMS:JAVADOC:1198; JMS:JAVADOC:1201;
+ * JMS:JAVADOC:1204; JMS:JAVADOC:1215; JMS:JAVADOC:1218; JMS:JAVADOC:1222;
+ * JMS:JAVADOC:1224; JMS:JAVADOC:1227; JMS:JAVADOC:1232; JMS:JAVADOC:1275;
+ * JMS:JAVADOC:1278; JMS:JAVADOC:1281; JMS:JAVADOC:1284; JMS:JAVADOC:1287;
+ * JMS:JAVADOC:1290; JMS:JAVADOC:1293; JMS:JAVADOC:1296; JMS:JAVADOC:1299;
+ * JMS:JAVADOC:1186; JMS:JAVADOC:1189; JMS:JAVADOC:1200; JMS:JAVADOC:1203;
+ * JMS:JAVADOC:1206; JMS:JAVADOC:1217; JMS:JAVADOC:1226; JMS:JAVADOC:1229;
+ *
+ * @test_Strategy: Create a JMSProducer, set properties for all of the primitive
+ * types verify the conversion by getting the properties.
+ */
+ @Test
+ public void msgPropertiesConversionTests() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ String testMessageBody = "Testing...";
+ int ntest = 0;
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // ------------------------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTSTRING", "test");
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("TESTSTRINGTRUE", "true");
+ producer.setProperty("TESTSTRINGFALSE", "false");
+ producer.setProperty("TESTSTRING1", "1");
+
+ // -------------------------------------------------------------------
+ // test conversions for property values
+ // -------------------------------------------------------------------
+ // property set as boolean can be read only as string or boolean
+ // -------------------------------------------------------------------
+ // valid - boolean to string
+ String myBool = producer.getStringProperty("TESTBOOLEAN");
+
+ if (Boolean.valueOf(myBool).booleanValue() == bool) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from boolean to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from boolean to string failed");
+ pass = false;
+ }
+
+ // invalid - boolean to byte
+ try {
+ producer.getByteProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: boolean to byte ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- boolean to byte");
+ pass = false;
+ }
+
+ // invalid - boolean to short
+ try {
+ producer.getShortProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: boolean to short ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- boolean to short");
+ pass = false;
+ }
+
+ // invalid - boolean to int
+ try {
+ producer.getIntProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: boolean to int ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception --boolean to int ");
+ pass = false;
+ }
+
+ // invalid - boolean to long
+ try {
+ producer.getLongProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: boolean to long ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- boolean to long");
+ pass = false;
+ }
+
+ // invalid - boolean to float
+ try {
+ producer.getFloatProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: boolean to float ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- boolean to float");
+ pass = false;
+ }
+
+ // invalid - boolean to double
+ try {
+ producer.getDoubleProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: boolean to double ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- boolean to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as byte can be read as a byte,short,int,long or string
+ // valid - byte to string
+ String myByte = producer.getStringProperty("TESTBYTE");
+
+ if (Byte.valueOf(myByte).byteValue() == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from byte to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from byte to string failed");
+ pass = false;
+ }
+
+ // valid - byte to short
+ if (producer.getShortProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from byte to short - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from byte to short failed");
+ pass = false;
+ }
+
+ // valid - byte to int
+ if (producer.getIntProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from byte to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from byte to int failed");
+ pass = false;
+ }
+
+ // valid - byte to long
+ if (producer.getLongProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from byte to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from byte to long failed");
+ pass = false;
+ }
+
+ // invalid - byte to boolean
+ try {
+ producer.getBooleanProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: byte to boolean ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- byte to boolean");
+ pass = false;
+ }
+
+ // invalid - byte to float
+ try {
+ producer.getFloatProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: byte to float ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception --byte to float ");
+ pass = false;
+ }
+
+ // invalid - byte to double
+ try {
+ producer.getDoubleProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: byte to double ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- byte to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------
+ // property set as short can be read as short,int,long or string
+ // valid - short to string
+ String myshort = producer.getStringProperty("TESTSHORT");
+
+ if (Short.valueOf(myshort).shortValue() == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from short to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from short to string failed");
+ pass = false;
+ }
+
+ // valid - short to int
+ if (producer.getIntProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from short to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from short to int failed");
+ pass = false;
+ }
+
+ // valid - short to long
+ if (producer.getLongProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from short to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from short to long failed");
+ pass = false;
+ }
+
+ // invalid - short to boolean
+ try {
+ producer.getBooleanProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: short to boolean ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- short to boolean");
+ pass = false;
+ }
+
+ // invalid - short to byte
+ try {
+ producer.getByteProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: short to byte ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- short to byte");
+ pass = false;
+ }
+
+ // invalid - short to float
+ try {
+ producer.getFloatProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: short to float ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- short to float");
+ pass = false;
+ }
+
+ // invalid - short to double
+ try {
+ producer.getDoubleProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: short to double ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- short to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------
+ // property set as int can be read only as int, long or string
+ // valid - int to string
+ if (Integer.valueOf(producer.getStringProperty("TESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from int to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from int to string failed");
+ pass = false;
+ }
+
+ // valid - int to long
+ if (producer.getLongProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from int to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from int to long failed");
+ pass = false;
+ }
+
+ // invalid - int to boolean
+ try {
+ producer.getBooleanProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: int to boolean ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- int to boolean");
+ pass = false;
+ }
+
+ // invalid - int to byte
+ try {
+ producer.getByteProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: int to byte ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- int to byte");
+ pass = false;
+ }
+
+ // invalid - int to short
+ try {
+ producer.getShortProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: int to short ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected -- int to short ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception ");
+ pass = false;
+ }
+
+ // invalid - int to float
+ try {
+ producer.getFloatProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: int to float ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- int to float");
+ pass = false;
+ }
+
+ // invalid - int to double
+ try {
+ producer.getDoubleProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: int to double ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- int to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as long can be read only as long,or a string
+ // valid - long to string
+ if (Long.valueOf(producer.getStringProperty("TESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from long to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from long to string failed");
+ pass = false;
+ }
+
+ // invalid - long to boolean
+ try {
+ producer.getBooleanProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: long to boolean ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- long to boolean");
+ pass = false;
+ }
+
+ // invalid - long to byte
+ try {
+ producer.getByteProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: long to byte ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- long to byte");
+ pass = false;
+ }
+
+ // invalid - long to short
+ try {
+ producer.getShortProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: long to short ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- long to short ");
+ pass = false;
+ }
+
+ // invalid - long to int
+ try {
+ producer.getIntProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: long to int ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- long to int");
+ pass = false;
+ }
+
+ // invalid - long to float
+ try {
+ producer.getFloatProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: long to float ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- long to float");
+ pass = false;
+ }
+
+ // invalid - long to double
+ try {
+ producer.getDoubleProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: long to double ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- long to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as float can be read only as float,double or a string
+ // valid - float to string
+ if (Float.valueOf(producer.getStringProperty("TESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from float to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from float to string failed");
+ pass = false;
+ }
+
+ // valid - float to double
+ if (producer.getDoubleProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from long to double - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from long to double failed");
+ pass = false;
+ }
+
+ // invalid - float to boolean
+ try {
+ producer.getBooleanProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: float to boolean ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- float to boolean ");
+ pass = false;
+ }
+
+ // invalid - float to byte
+ try {
+ producer.getByteProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: float to byte ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- float to byte");
+ pass = false;
+ }
+
+ // invalid - float to short
+ try {
+ producer.getShortProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: float to short ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception - float to short ");
+ pass = false;
+ }
+
+ // invalid - float to int
+ try {
+ producer.getIntProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: float to int ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception --- float to int");
+ pass = false;
+ }
+
+ // invalid - float to long
+ try {
+ producer.getLongProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: float to long ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- float to long");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as double can be read only as double or string
+ // valid - double to string
+ if (Double.valueOf(producer.getStringProperty("TESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from double to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from double to string failed");
+ pass = false;
+ }
+
+ // invalid - double to boolean
+ try {
+ producer.getBooleanProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: double to boolean ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- double to boolean ");
+ pass = false;
+ }
+
+ // invalid - double to byte
+ try {
+ producer.getByteProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: double to byte ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- double to byte ");
+ pass = false;
+ }
+
+ // invalid - double to short
+ try {
+ producer.getShortProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: double to short ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- double to short");
+ pass = false;
+ }
+
+ // invalid - double to int
+ try {
+ producer.getIntProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: double to int ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception --- double to int ");
+ pass = false;
+ }
+
+ // invalid - double to long
+ try {
+ producer.getLongProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: double to long ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- double to long");
+ pass = false;
+ }
+
+ // invalid - double to float
+ try {
+ producer.getFloatProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Fail: MessageFormatRuntimeException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "Fail: unsupported conversion: double to float ");
+ pass = false;
+ } catch (MessageFormatRuntimeException me) {
+ logger.log(Logger.Level.INFO, "Pass: MessageFormatRuntimeException as expected ");
+ } catch (Exception ee) {
+ logger.log(Logger.Level.INFO, "Fail: Caught unexpected exception: " + ee);
+ logger.log(Logger.Level.INFO, "Fail: did not catch expected Exception -- double to float");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as string can be read as boolean, byte, short,
+ // int, long, float, double, and String.
+ // valid - string to boolean
+ if ((producer.getBooleanProperty("TESTSTRINGTRUE")) == true) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to boolean - expect true - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to boolean - expect true - failed");
+ pass = false;
+ }
+ if ((producer.getBooleanProperty("TESTSTRINGFALSE")) == false) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to boolean expect false - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to boolean expect false - failed");
+ pass = false;
+ }
+
+ // valid - string to byte
+ if (producer.getByteProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to byte - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to byte failed");
+ pass = false;
+ }
+
+ // valid - string to short
+ if (producer.getShortProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to short - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to short failed");
+ pass = false;
+ }
+
+ // valid - string to int
+ if (producer.getIntProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to int failed");
+ pass = false;
+ }
+
+ // valid - string to long
+ if (producer.getLongProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to long failed");
+ pass = false;
+ }
+
+ // valid - string to float
+ if (producer.getFloatProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to float - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to float failed");
+ pass = false;
+ }
+
+ // valid - string to double
+ if (producer.getDoubleProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: conversion from string to double - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Fail: conversion from string to double failed");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("msgPropertiesConversionTests failed");
+ }
+
+ if (!pass) {
+ throw new Exception("msgPropertiesConversionTests failed");
+ }
+ }
+
+ /*
+ * @testName: msgPropertyExistTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1180; JMS:JAVADOC:1184; JMS:JAVADOC:1187;
+ * JMS:JAVADOC:1198; JMS:JAVADOC:1201; JMS:JAVADOC:1204; JMS:JAVADOC:1215;
+ * JMS:JAVADOC:1218; JMS:JAVADOC:1222; JMS:JAVADOC:1224; JMS:JAVADOC:1227;
+ * JMS:JAVADOC:1232; JMS:JAVADOC:1275; JMS:JAVADOC:1278; JMS:JAVADOC:1281;
+ * JMS:JAVADOC:1284; JMS:JAVADOC:1287; JMS:JAVADOC:1290; JMS:JAVADOC:1293;
+ * JMS:JAVADOC:1296; JMS:JAVADOC:1299;
+ *
+ * @test_Strategy: Set and read properties for boolean, byte, short, int, long,
+ * float, double, and String. Verify expected results.
+ */
+ @Test
+ public void msgPropertyExistTest() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ Enumeration propertyNames = null;
+ String testMessageBody = "Testing msgPropertyExistTest";
+
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // ------------------------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTSTRING", "test");
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+
+ // --------------------------------------------------------------------------------------
+ // Create a TextMessage, send it then receive it and verify that all the
+ // JMSProducer
+ // properties are set in the TextMessage
+ // --------------------------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Create a TextMessage");
+ messageSent = context.createTextMessage();
+ messageSent.setText(testMessageBody);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesTest");
+
+ logger.log(Logger.Level.INFO, "Send the TextMessage");
+ producer.send(destination, messageSent);
+
+ logger.log(Logger.Level.INFO, "Receive the TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+
+ if (messageReceived == null) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "messageReceived is null (unexpected)");
+ } else {
+
+ // iterate thru the property names
+ int i = 0;
+ propertyNames = messageReceived.getPropertyNames();
+ do {
+ String tmp = (String) propertyNames.nextElement();
+
+ if (!tmp.startsWith("JMS")) {
+ i++;
+ if (tmp.equals("TESTBOOLEAN") || tmp.equals("TESTBYTE") || tmp.equals("TESTINT")
+ || tmp.equals("TESTSHORT") || tmp.equals("TESTFLOAT") || tmp.equals("TESTDOUBLE")
+ || tmp.equals("TESTSTRING") || tmp.equals("TESTLONG") || tmp.equals("OBJTESTBOOLEAN")
+ || tmp.equals("COM_SUN_JMS_TESTNAME")) {
+ logger.log(Logger.Level.INFO, "Application Property set by client is: " + tmp);
+ if (!messageReceived.propertyExists(tmp)) {
+ pass = messageReceived.propertyExists(tmp);
+ logger.log(Logger.Level.ERROR, "Positive propertyExists test failed for " + tmp);
+ } else if (messageReceived.propertyExists(tmp + "1")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Negative propertyExists test failed for " + tmp + "1");
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Appclication Property not set by client: " + tmp);
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.INFO, "JMSProperty Name is: " + tmp);
+ }
+ } while (propertyNames.hasMoreElements());
+ }
+
+ if (!pass) {
+ throw new Exception("msgPropertyExistTest failed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Caught unexpected exception: " + e);
+ throw new Exception("msgPropertyExistTest failed");
+ }
+ }
+
+ /*
+ * @testName: msgJMSXPropertiesTest
+ *
+ * @assertion_ids: JMS:SPEC:34; JMS:SPEC:34.3; JMS:SPEC:34.4; JMS:SPEC:34.5;
+ * JMS:SPEC:257;
+ *
+ * @test_Strategy: Set and read JMSX properties JMSXGroupID and JMSXGroupSeq.
+ * Verify the value of the JMSX properties JMSXGroupID and JMSXGroupSeq are the
+ * same as set by client. Verify that the JMS provider sets the mandatory
+ * JMSXDeliveryCount.
+ *
+ * 1) Create JMSContext and JMSConsumer for Topic. 2) Create TextMessage and set
+ * JMSXGroupID and JMSXGroupSeq message properties. 3) Send the TextMessage to
+ * the Topic. 4) Receive the TextMessage from the Topic. 5) Verify the
+ * TextMessage. Verify that the message properites JMSXGroupID, JMSXGroupSeq,
+ * and JMSXDeliveryCount are correct.
+ */
+ @Test
+ public void msgJMSXPropertiesTest() throws Exception {
+ boolean pass = true;
+ String message = "Testing msgJMSXPropertiesTest";
+ int seq = 123450;
+ String id = "msgJMSXPropertiesTest";
+ try {
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+
+ logger.log(Logger.Level.INFO, "Set StringProperty COM_SUN_JMS_TESTNAME");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgJMSXPropertiesTest");
+
+ logger.log(Logger.Level.INFO, "Set JMSXGroupID and JMSXGroupSeq");
+ expTextMessage.setStringProperty("JMSXGroupID", id);
+ expTextMessage.setIntProperty("JMSXGroupSeq", seq);
+
+ logger.log(Logger.Level.INFO, "Send the TextMessage");
+ producer.send(destination, expTextMessage);
+
+ logger.log(Logger.Level.INFO, "Receive the TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+
+ logger.log(Logger.Level.INFO, "Verify the value in TextMessage");
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Verify properties JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount in TextMessage");
+ if (actTextMessage.propertyExists("JMSXGroupID")) {
+ if (actTextMessage.getStringProperty("JMSXGroupID").equals(id)) {
+ logger.log(Logger.Level.INFO, "Pass: getStringProperty(JMSXGroupID) returned correct value");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Fail: incorrect value returned from getStringProperty(JMSXGroupID)");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: TextMessage does not contain expected JMSXGroupID property");
+ pass = false;
+ }
+
+ if (actTextMessage.propertyExists("JMSXGroupSeq")) {
+ if (actTextMessage.getIntProperty("JMSXGroupSeq") == seq) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty(JMSXGroupSeq) returned correct value");
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: incorrect value returned from getIntProperty(JMSXGroupSeq)");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: TextMessage does not contain expected JMSXGroupSeq property");
+ pass = false;
+ }
+
+ if (actTextMessage.propertyExists("JMSXDeliveryCount")) {
+ if (actTextMessage.getIntProperty("JMSXDeliveryCount") == 1) {
+ logger.log(Logger.Level.INFO, "Pass: getIntProperty(JMSXDeliveryCount) returned correct value");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Fail: incorrect value returned from getIntProperty(JMSXDeliveryCount)");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Fail: TextMessage does not contain expected JMSXDeliveryCount property");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // ConnectionMetaData.getJMSXPropertyNames() method returns the
+ // names of the JMSX properties supported by a connection.
+ // -------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Verify the JMSXProperties in ConnectionData");
+ try {
+ logger.log(Logger.Level.INFO, "Get ConnectionMetaData");
+ ConnectionMetaData data = context.getMetaData();
+ logger.log(Logger.Level.INFO, "Get JMSXPropertyNames");
+ Enumeration cmd = data.getJMSXPropertyNames();
+ logger.log(Logger.Level.INFO, "Verify that we have JMSXGroupID, JMSXGroupSeq, JMSXDeliveryCount");
+ if (cmd == null) {
+ logger.log(Logger.Level.ERROR, "No JMSX property names were returned (Failed)");
+ pass = false;
+ } else {
+ int iCount = 0;
+ do {
+ String propName = (String) cmd.nextElement();
+ logger.log(Logger.Level.TRACE, "Found JMSX property [" + propName + "]");
+ if (propName.equals("JMSXGroupID"))
+ iCount++;
+ else if (propName.equals("JMSXGroupSeq"))
+ iCount++;
+ else if (propName.equals("JMSXDeliveryCount"))
+ iCount++;
+ } while (cmd.hasMoreElements());
+
+ if (iCount > 2) {
+ logger.log(Logger.Level.INFO, "Expected JMSX property names were returned (Passed)");
+ } else {
+ logger.log(Logger.Level.ERROR, "Expected JMSX property names not returned (Failed)");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("msgJMSXPropertiesTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("msgJMSXPropertiesTest failed");
+ }
+ }
+
+ /*
+ * @testName: setPropertyExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1280; JMS:JAVADOC:1283; JMS:JAVADOC:1286;
+ * JMS:JAVADOC:1289; JMS:JAVADOC:1292; JMS:JAVADOC:1295; JMS:JAVADOC:1298;
+ * JMS:JAVADOC:1301; JMS:JAVADOC:1277; JMS:JAVADOC:1302;
+ *
+ * @test_Strategy: Tests IllegalArgumentException and
+ * MessageFormatRuntimeException conditions from the following API's:
+ *
+ * JMSProducer.setProperty(String, boolean) throws IllegalArgumentException
+ * JMSProducer.setProperty(String, byte)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, double)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, float)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, int)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, long)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, Object)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, short)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, String)throws IllegalArgumentException
+ * JMSProducer.setProperty(String, Object)throws MessageFormatRuntimeException
+ */
+ @Test
+ public void setPropertyExceptionTests() throws Exception {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+
+ try {
+ // Create JMSProducer from JMSContext
+ logger.log(Logger.Level.INFO, "Create a JMSProducer from JMSContext");
+ producer = context.createProducer();
+
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException from all JMSProducer setProperty() API's");
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", boolean)");
+ producer.setProperty("", bool);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", byte)");
+ producer.setProperty("", bValue);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", double)");
+ producer.setProperty("", nDouble);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", float)");
+ producer.setProperty("", nFloat);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", int)");
+ producer.setProperty("", nInt);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", long)");
+ producer.setProperty("", nLong);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", short)");
+ producer.setProperty("", nShort);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", String)");
+ producer.setProperty("", "test");
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(\"\", Object)");
+ producer.setProperty("", Long.valueOf(nLong));
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, boolean)");
+ producer.setProperty(null, bool);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, byte)");
+ producer.setProperty(null, bValue);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, double)");
+ producer.setProperty(null, nDouble);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, float)");
+ producer.setProperty(null, nFloat);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, int)");
+ producer.setProperty(null, nInt);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, long)");
+ producer.setProperty(null, nLong);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, short)");
+ producer.setProperty(null, nShort);
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, String)");
+ producer.setProperty(null, "test");
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Test IllegalArgumentException for setProperty(null, Object)");
+ producer.setProperty(null, Long.valueOf(nLong));
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected IllegalArgumentException");
+ pass = false;
+ } catch (IllegalArgumentException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected IllegalArgumentException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO, "Test MessageFormatRuntimeException for setProperty(String, Object)");
+ producer.setProperty("name1", new java.util.Date());
+ logger.log(Logger.Level.ERROR, "Fail: Did not throw expected MessageFormatRuntimeException");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Pass: Caught expected MessageFormatRuntimeException: " + e);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Fail: Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setPropertyExceptionTests");
+ }
+
+ if (!pass) {
+ throw new Exception("setPropertyExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: sendExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1241; JMS:JAVADOC:1245; JMS:JAVADOC:1238;
+ *
+ * @test_Strategy: Tests MessageFormatRuntimeException and
+ * MessageNotWriteableRuntimeException conditions from the following API's:
+ *
+ * JMSProducer.send(Destination, Message) throws
+ * MessageNotWriteableRuntimeException JMSProducer.send(Destination, Message)
+ * throws MessageFormatRuntimeException JMSProducer.send(Destination, Map)
+ * throws MessageFormatRuntimeException
+ *
+ */
+ @Test
+ public void sendExceptionTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ try {
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Message) for MessageFormatRuntimeException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling send(Destination, Message) -> expect MessageFormatRuntimeException");
+ producer.send(destination, (Message) null);
+ logger.log(Logger.Level.ERROR, "MessageFormatRuntimeException was not thrown");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatRuntimeException, received " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Map) for MessageFormatRuntimeException");
+ try {
+ Map mp = new HashMap();
+ mp.put("1", new ArrayList(2));
+ mp.put("2", new Properties());
+ mp.put("2", new Properties());
+ mp.put("1", new ArrayList(2));
+ logger.log(Logger.Level.INFO, "Calling send(Destination, Map) -> expect MessageFormatRuntimeException");
+ producer.send(destination, mp);
+ logger.log(Logger.Level.ERROR, "MessageFormatRuntimeException was not thrown");
+ pass = false;
+ } catch (MessageFormatRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageFormatRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatRuntimeException, received " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO,
+ "Testing JMSProducer.send(Destination, Message) for MessageNotWriteableRuntimeException");
+ try {
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage sendTextMessage = context.createTextMessage(message);
+ sendTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendExceptionTests");
+ logger.log(Logger.Level.INFO, "Send TextMessage");
+ producer.send(destination, sendTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage recvTextMessage = (TextMessage) consumer.receive(timeout);
+ if (recvTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (recvTextMessage.getText().equals(sendTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + sendTextMessage.getText()
+ + ", received " + recvTextMessage.getText());
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Set a bunch of JMSProducer properties");
+ producer.setProperty("TESTBOOLEAN", bool);
+ producer.setProperty("TESTBYTE", bValue);
+ producer.setProperty("TESTDOUBLE", nDouble);
+ producer.setProperty("TESTFLOAT", nFloat);
+ producer.setProperty("TESTINT", nInt);
+ producer.setProperty("TESTLONG", nLong);
+ producer.setProperty("TESTSHORT", nShort);
+ producer.setProperty("TESTSTRING", testString);
+ producer.setProperty("OBJTESTLONG", Long.valueOf(nLong));
+ logger.log(Logger.Level.INFO,
+ "Using received TextMessage try and send it (expect MessageNotWriteableRuntimeException)");
+ producer.send(destination, recvTextMessage);
+ logger.log(Logger.Level.ERROR, "MessageNotWriteableRuntimeException was not thrown");
+ pass = false;
+ } catch (MessageNotWriteableRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected MessageNotWriteableRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected MessageNotWriteableRuntimeException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("sendExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: getBodyTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1357;
+ *
+ * @test_Strategy: Send and receive messages of the following types:
+ * BytesMessage, MapMessage, ObjectMessage, TextMessage. Call Message.getBody()
+ * to return the message as the specified Object type.
+ *
+ * Object = Message.getBody(Class)
+ *
+ * Test the following:
+ *
+ * String message = Message.getBody(String.class) byte[] message =
+ * Message.getBody(byte[].class); StringBuffer message =
+ * Message.getBody(StringBuffer.class); Map message =
+ * Message.getBody(Map.class);
+ *
+ */
+ @Test
+ public void getBodyTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ StringBuffer expSbuffer = new StringBuffer("This is it!");
+ try {
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Call TextMessage.getBody(String.class) to extract TextMessage as String");
+ String actMessage = actTextMessage.getBody(String.class);
+ logger.log(Logger.Level.INFO, "Check the value in String");
+ if (actMessage.equals(message)) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "TextMessage is incorrect expected " + message + ", received " + actMessage);
+ pass = false;
+ }
+
+ // Send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Create ObjectMessage");
+ ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
+ logger.log(Logger.Level.INFO, "Send and receive the ObjectMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expObjectMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive ObjectMessage");
+ ObjectMessage actObjectMessage = (ObjectMessage) consumer.receive(timeout);
+ if (actObjectMessage == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ logger.log(Logger.Level.INFO,
+ "Call ObjectMessage.getBody(StringBuffer.class) to extract ObjectMessage as StringBuffer");
+ StringBuffer actSbuffer = actObjectMessage.getBody(StringBuffer.class);
+ logger.log(Logger.Level.INFO, "Check the value in StringBuffer");
+ if (actSbuffer.toString().equals(expSbuffer.toString())) {
+ logger.log(Logger.Level.INFO, "ObjectMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "ObjectMessage is incorrect expected " + expSbuffer + ", received " + actSbuffer);
+ pass = false;
+ }
+
+ // Send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Create BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ logger.log(Logger.Level.INFO, "Send and receive the BytesMessage");
+ producer.send(destination, bMsg);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive BytesMessage");
+ BytesMessage actBytesMessage = (BytesMessage) consumer.receive(timeout);
+ if (actBytesMessage == null) {
+ throw new Exception("Did not receive BytesMessage");
+ }
+ logger.log(Logger.Level.INFO,
+ "Call BytesMessage.getBody(StringBuffer.class) to extract BytesMessage as byte[] array");
+ byte[] bytes = actBytesMessage.getBody(byte[].class);
+ if (bytes == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive BytesMessage");
+ pass = false;
+ } else {
+ try {
+ DataInputStream di = new DataInputStream(new ByteArrayInputStream(bytes));
+ logger.log(Logger.Level.INFO, "Check the values in BytesMessage");
+ if (di.readByte() == (byte) 1) {
+ logger.log(Logger.Level.INFO, "bytevalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "bytevalue is incorrect");
+ pass = false;
+ }
+ if (di.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+ try {
+ byte b = di.readByte();
+ } catch (EOFException e) {
+ logger.log(Logger.Level.INFO, "Caught expected EOFException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ }
+ // Send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send MapMessage");
+ MapMessage mMsg = context.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTests");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ producer.send(destination, mMsg);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive MapMessage");
+ MapMessage actMapMessage = (MapMessage) consumer.receive(timeout);
+ if (actMapMessage == null) {
+ throw new Exception("Did not receive MapMessage");
+ }
+ logger.log(Logger.Level.INFO, "Call MapMessage.getBody(Map.class) to extract MapMessage as a Map object");
+ Map map = actMapMessage.getBody(Map.class);
+ if (map == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive MapMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the values in MapMessage");
+ logger.log(Logger.Level.INFO, "map.size()=" + map.size());
+ if (map.size() != 2) {
+ logger.log(Logger.Level.ERROR, "Map size is " + map.size() + ", expected 2");
+ pass = false;
+ }
+ Iterator it = map.keySet().iterator();
+ String name = null;
+ while (it.hasNext()) {
+ name = (String) it.next();
+ if (name.equals("booleanvalue")) {
+ if ((boolean) map.get(name) == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "booleanvalue is incorrect");
+ pass = false;
+ }
+ } else if (name.equals("intvalue")) {
+ if ((int) map.get(name) == 10) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "intvalue is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected name of [" + name + "] in MapMessage");
+ pass = false;
+ }
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ TestUtil.printStackTrace(e);
+ throw new Exception("getBodyTests", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("getBodyTests failed");
+ }
+ }
+
+ /*
+ * @testName: getBodyExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1359;
+ *
+ * @test_Strategy: Test exception case for Message.getBody(Class). Test
+ * MessageFormatException.
+ *
+ * Object = Message.getBody(Class)
+ *
+ */
+ @Test
+ public void getBodyExceptionTests() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ StringBuffer expSbuffer = new StringBuffer("This is it!");
+ try {
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyExceptionTests");
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Call TextMessage.getBody(Boolean.class) to extract TextMessage "
+ + "as Boolean (expect MessageFormatException)");
+ try {
+ Boolean myBool = actTextMessage.getBody(Boolean.class);
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException to be thrown");
+ pass = false;
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Caught correct MessageFormatException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Create ObjectMessage of type StringBuffer");
+ ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyExceptionTests");
+ logger.log(Logger.Level.INFO, "Send and receive the ObjectMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expObjectMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive ObjectMessage");
+ ObjectMessage actObjectMessage = (ObjectMessage) consumer.receive(timeout);
+ if (actObjectMessage == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ logger.log(Logger.Level.INFO, "Call ObjectMessage.getBody(HashMap.class) to extract ObjectMessage "
+ + "as HashMap (expect MessageFormatException");
+ try {
+ HashMap hmap = actObjectMessage.getBody(HashMap.class);
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException to be thrown");
+ pass = false;
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Caught correct MessageFormatException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // send and receive StreamMessage
+ logger.log(Logger.Level.INFO, "Create StreamMessage");
+ StreamMessage expStreamMsg = context.createStreamMessage();
+ logger.log(Logger.Level.INFO, "Set some values in StreamMessage");
+ expStreamMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyExceptionTests");
+ expStreamMsg.writeBoolean(true);
+ expStreamMsg.writeInt((int) 22);
+ logger.log(Logger.Level.INFO, "Send and receive the StreamMessage");
+ producer.send(destination, expStreamMsg);
+ StreamMessage actStreamMsg = (StreamMessage) consumer.receive(timeout);
+ if (actStreamMsg == null) {
+ throw new Exception("Did not receive StreamMessage");
+ }
+ logger.log(Logger.Level.INFO, "Call StreamMessage.getBody(HashMap.class) to extract StreamMessage "
+ + "as HashMap (expect MessageFormatException");
+ try {
+ HashMap hmap = actStreamMsg.getBody(HashMap.class);
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException to be thrown");
+ pass = false;
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Caught correct MessageFormatException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Create BytesMessage
+ logger.log(Logger.Level.INFO, "Create BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyExceptionTests");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ logger.log(Logger.Level.INFO, "BytesMessage is in write-only mode");
+ logger.log(Logger.Level.INFO, "Call BytesMessage.getBody(StringBuffer.class) to receive "
+ + "BytesMessage as StringBuffer(expect MessageFormatException)");
+ try {
+ bMsg.getBody(StringBuffer.class);
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException to be thrown");
+ pass = false;
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Caught correct MessageFormatException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Send and receive the BytesMessage");
+ producer.send(destination, bMsg);
+ BytesMessage actBytesMsg = (BytesMessage) consumer.receive(timeout);
+ try {
+ actBytesMsg.getBody(StringBuffer.class);
+ logger.log(Logger.Level.ERROR, "Expected MessageFormatException to be thrown");
+ pass = false;
+ } catch (MessageFormatException e) {
+ logger.log(Logger.Level.INFO, "Caught correct MessageFormatException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("getBodyExceptionTests", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("getBodyExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: isBodyAssignableToTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1361;
+ *
+ * @test_Strategy: Test Message.isBodyAssignableTo(Class) API.
+ *
+ * boolean = Message.isBodyAssignableTo(Class)
+ *
+ */
+ @Test
+ public void isBodyAssignableToTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ StringBuffer expSbuffer = new StringBuffer("This is it!");
+ try {
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "isBodyAssignableToTest");
+ logger.log(Logger.Level.INFO, "Send and receive the TextMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Call TextMessage.isBodyAssignableTo(Boolean.class) (expect false)");
+ boolean b = actTextMessage.isBodyAssignableTo(Boolean.class);
+ if (b) {
+ logger.log(Logger.Level.ERROR, "Expected false got true");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Call TextMessage.isBodyAssignableTo(String.class) (expect true)");
+ b = actTextMessage.isBodyAssignableTo(String.class);
+ if (!b) {
+ logger.log(Logger.Level.ERROR, "Expected true got false");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Create ObjectMessage");
+ ObjectMessage expObjectMessage = context.createObjectMessage(expSbuffer);
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ expObjectMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "isBodyAssignableToTest");
+ logger.log(Logger.Level.INFO, "Send and receive the ObjectMessage");
+ logger.log(Logger.Level.INFO, "Call JMSProducer.send(Destination, Message)");
+ producer.send(destination, expObjectMessage);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive ObjectMessage");
+ ObjectMessage actObjectMessage = (ObjectMessage) consumer.receive(timeout);
+ if (actObjectMessage == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Call ObjectMessage.isBodyAssignableTo(Boolean.class) (expect false)");
+ boolean b = actObjectMessage.isBodyAssignableTo(Boolean.class);
+ if (b) {
+ logger.log(Logger.Level.ERROR, "Expected false got true");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO,
+ "Call ObjectMessage.isBodyAssignableTo(StringBuffer.class) (expect true)");
+ b = actObjectMessage.isBodyAssignableTo(StringBuffer.class);
+ if (!b) {
+ logger.log(Logger.Level.ERROR, "Expected true got false");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Create BytesMessage");
+ BytesMessage bMsg = context.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTest");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ logger.log(Logger.Level.INFO, "Send and receive the BytesMessage");
+ producer.send(destination, bMsg);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive BytesMessage");
+ BytesMessage actBytesMessage = (BytesMessage) consumer.receive(timeout);
+ if (actBytesMessage == null) {
+ throw new Exception("Did not receive BytesMessage");
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Call BytesMessage.isBodyAssignableTo(String.class) (expect false)");
+ boolean b = actBytesMessage.isBodyAssignableTo(String.class);
+ if (b) {
+ logger.log(Logger.Level.ERROR, "Expected false got true");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Call BytesMessage.isBodyAssignableTo(byte[].class) (expect true)");
+ b = actBytesMessage.isBodyAssignableTo(byte[].class);
+ if (!b) {
+ logger.log(Logger.Level.ERROR, "Expected true got false");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ // Send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send MapMessage");
+ MapMessage mMsg = context.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "getBodyTest");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ producer.send(destination, mMsg);
+ logger.log(Logger.Level.INFO, "Call JMSConsumer.receive(long) to receive MapMessage");
+ MapMessage actMapMessage = (MapMessage) consumer.receive(timeout);
+ if (actMapMessage == null) {
+ throw new Exception("Did not receive MapMessage");
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Call MapMessage.isBodyAssignableTo(String.class) (expect false)");
+ boolean b = actMapMessage.isBodyAssignableTo(String.class);
+ if (b) {
+ logger.log(Logger.Level.ERROR, "Expected false got true");
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Call MapMessage.isBodyAssignableTo(Map.class) (expect true)");
+ b = actMapMessage.isBodyAssignableTo(Map.class);
+ if (!b) {
+ logger.log(Logger.Level.ERROR, "Expected true got false");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("isBodyAssignableToTest", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("isBodyAssignableToTest failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/messageproducertests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/messageproducertests/Client.java
deleted file mode 100644
index 77edd0eb56..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/messageproducertests/Client.java
+++ /dev/null
@@ -1,2339 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.messageproducertests;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.CompletionListener;
-import jakarta.jms.Connection;
-import jakarta.jms.DeliveryMode;
-import jakarta.jms.Destination;
-import jakarta.jms.InvalidDestinationException;
-import jakarta.jms.JMSException;
-import jakarta.jms.Message;
-import jakarta.jms.MessageConsumer;
-import jakarta.jms.MessageProducer;
-import jakarta.jms.Queue;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.messageproducertests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool tool = null;
-
- // JMS objects
- transient MessageProducer producer = null;
-
- transient MessageConsumer consumer = null;
-
- transient Connection connection = null;
-
- transient Session session = null;
-
- transient Destination destination = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- // used for tests
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- boolean queueTest = false;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Closing default Connection");
- tool.getDefaultConnection().close();
- if (queueTest) {
- TestUtil.logMsg("Flush any messages left on Queue");
- tool.flushDestination();
- }
- tool.closeAllResources();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * @testName: queueSendAndRecvTest1
- *
- * @assertion_ids: JMS:JAVADOC:321; JMS:JAVADOC:334;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Destination, Message) MessageConsumer.receive(timeout)
- */
- public void queueSendAndRecvTest1() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueSendAndRecvTest1");
- TestUtil.logMsg("Sending TextMessage");
- TestUtil.logMsg("Calling MessageProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- e.printStackTrace();
- throw new Exception("queueSendAndRecvTest1", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueSendAndRecvTest1 failed");
- }
- }
-
- /*
- * @testName: queueSendAndRecvTest2
- *
- * @assertion_ids: JMS:JAVADOC:323; JMS:JAVADOC:334;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Destination, Message, int, int, long)
- * MessageConsumer.receive(timeout)
- */
- public void queueSendAndRecvTest2() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueSendAndRecvTest2");
- TestUtil.logMsg("Sending TextMessage");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, int, int, long)");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY - 1, 0L);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Check the values in TextMessage, deliverymode, priority, time to live");
- if (!actTextMessage.getText().equals(expTextMessage.getText())
- || actTextMessage.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
- || actTextMessage.getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)
- || actTextMessage.getJMSExpiration() != 0L) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- TestUtil.logErr("DeliveryMode=" + actTextMessage.getJMSDeliveryMode()
- + ", expected " + expTextMessage.getJMSDeliveryMode());
- TestUtil.logErr("Priority=" + actTextMessage.getJMSPriority()
- + ", expected " + expTextMessage.getJMSPriority());
- TestUtil.logErr("TimeToLive=" + actTextMessage.getJMSExpiration()
- + ", expected " + expTextMessage.getJMSExpiration());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- e.printStackTrace();
- throw new Exception("queueSendAndRecvTest2", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueSendAndRecvTest2 failed");
- }
- }
-
- /*
- * @testName: queueSendAndRecvTest3
- *
- * @assertion_ids: JMS:JAVADOC:317; JMS:JAVADOC:334;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Message) MessageConsumer.receive(timeout)
- */
- public void queueSendAndRecvTest3() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueSendAndRecvTest3");
- TestUtil.logMsg("Sending TextMessage");
- TestUtil.logMsg("Calling MessageProducer.send(Message)");
- producer.send(expTextMessage);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- e.printStackTrace();
- throw new Exception("queueSendAndRecvTest3", e);
- }
-
- if (!pass) {
- throw new Exception("queueSendAndRecvTest3 failed");
- }
- }
-
- /*
- * @testName: queueSendAndRecvTest4
- *
- * @assertion_ids: JMS:JAVADOC:319; JMS:JAVADOC:334;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Message, int, int, long)
- * MessageConsumer.receive(timeout)
- */
- public void queueSendAndRecvTest4() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueSendAndRecvTest4");
- TestUtil.logMsg("Sending TextMessage");
- TestUtil.logMsg("Calling MessageProducer.send(Message, int, int, long)");
- producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY - 1, 0L);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Check the values in TextMessage, deliverymode, priority, time to live");
- if (!actTextMessage.getText().equals(expTextMessage.getText())
- || actTextMessage.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
- || actTextMessage.getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)
- || actTextMessage.getJMSExpiration() != 0L) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- TestUtil.logErr("DeliveryMode=" + actTextMessage.getJMSDeliveryMode()
- + ", expected " + expTextMessage.getJMSDeliveryMode());
- TestUtil.logErr("Priority=" + actTextMessage.getJMSPriority()
- + ", expected " + expTextMessage.getJMSPriority());
- TestUtil.logErr("TimeToLive=" + actTextMessage.getJMSExpiration()
- + ", expected " + expTextMessage.getJMSExpiration());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- e.printStackTrace();
- throw new Exception("queueSendAndRecvTest4", e);
- }
-
- if (!pass) {
- throw new Exception("queueSendAndRecvTest4 failed");
- }
- }
-
- /*
- * @testName: queueSetGetDeliveryModeTest
- *
- * @assertion_ids: JMS:JAVADOC:301; JMS:JAVADOC:303;
- *
- * @test_Strategy: Test the following APIs:
- *
- * MessageProducer.setDeliveryMode(int). MessageProducer.getDeliveryMode().
- */
- public void queueSetGetDeliveryModeTest() throws Exception {
- boolean pass = true;
-
- // Test default case
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- queueTest = true;
-
- long expDeliveryMode = DeliveryMode.PERSISTENT;
- TestUtil.logMsg("Calling getDeliveryMode and expect " + expDeliveryMode
- + " to be returned");
- long actDeliveryMode = producer.getDeliveryMode();
- if (actDeliveryMode != expDeliveryMode) {
- TestUtil.logErr("getDeliveryMode() returned " + actDeliveryMode
- + ", expected " + expDeliveryMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueSetGetDeliveryModeTest");
- }
-
- // Test non-default case
- try {
- int expDeliveryMode = DeliveryMode.NON_PERSISTENT;
- TestUtil.logMsg("Calling setDeliveryMode(" + expDeliveryMode + ")");
- producer.setDeliveryMode(expDeliveryMode);
- TestUtil.logMsg("Calling getDeliveryMode and expect " + expDeliveryMode
- + " to be returned");
- int actDeliveryMode = producer.getDeliveryMode();
- if (actDeliveryMode != expDeliveryMode) {
- TestUtil.logErr("getDeliveryMode() returned " + actDeliveryMode
- + ", expected " + expDeliveryMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueSetGetDeliveryModeTest");
- }
-
- if (!pass) {
- throw new Exception("queueSetGetDeliveryModeTest failed");
- }
- }
-
- /*
- * @testName: queueSetGetDeliveryDelayTest
- *
- * @assertion_ids: JMS:JAVADOC:907; JMS:JAVADOC:886; JMS:SPEC:261;
- *
- * @test_Strategy: Test the following APIs:
- *
- * MessageProducer.setDeliveryDelay(long). MessageProducer.getDeliveryDelay().
- */
- public void queueSetGetDeliveryDelayTest() throws Exception {
- boolean pass = true;
-
- // Test default case
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- queueTest = true;
-
- long expDeliveryDelay = 0L;
- TestUtil.logMsg("Calling getDeliveryDelay and expect " + expDeliveryDelay
- + " to be returned");
- long actDeliveryDelay = producer.getDeliveryDelay();
- if (actDeliveryDelay != expDeliveryDelay) {
- TestUtil.logErr("getDeliveryDelay() returned " + actDeliveryDelay
- + ", expected " + expDeliveryDelay);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueSetGetDeliveryDelayTest");
- }
-
- // Test non-default case
- try {
- long expDeliveryDelay = 1L;
- TestUtil.logMsg("Calling setDeliveryDelay(" + expDeliveryDelay + ")");
- producer.setDeliveryDelay(expDeliveryDelay);
- TestUtil.logMsg("Calling getDeliveryDelay and expect " + expDeliveryDelay
- + " to be returned");
- long actDeliveryDelay = producer.getDeliveryDelay();
- if (actDeliveryDelay != expDeliveryDelay) {
- TestUtil.logErr("getDeliveryDelay() returned " + actDeliveryDelay
- + ", expected " + expDeliveryDelay);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueSetGetDeliveryDelayTest");
- }
-
- if (!pass) {
- throw new Exception("queueSetGetDeliveryDelayTest failed");
- }
- }
-
- /*
- * @testName: queueSetGetDisableMessageIDTest
- *
- * @assertion_ids: JMS:JAVADOC:293; JMS:JAVADOC:295;
- *
- * @test_Strategy: Test the following APIs:
- *
- * MessageProducer.setDisableMessageID(int).
- * MessageProducer.getDisableMessageID().
- */
- public void queueSetGetDisableMessageIDTest() throws Exception {
- boolean pass = true;
- // Test true case
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- queueTest = true;
-
- boolean expDisableMessageID = true;
- TestUtil
- .logMsg("Calling setDisableMessageID(" + expDisableMessageID + ")");
- producer.setDisableMessageID(expDisableMessageID);
- TestUtil.logMsg("Calling getDisableMessageID and expect "
- + expDisableMessageID + " to be returned");
- boolean actDisableMessageID = producer.getDisableMessageID();
- if (actDisableMessageID != expDisableMessageID) {
- TestUtil.logErr("getDisableMessageID() returned " + actDisableMessageID
- + ", expected " + expDisableMessageID);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueSetGetDisableMessageIDTest");
- }
-
- // Test false case
- try {
- boolean expDisableMessageID = false;
- TestUtil
- .logMsg("Calling setDisableMessageID(" + expDisableMessageID + ")");
- producer.setDisableMessageID(expDisableMessageID);
- TestUtil.logMsg("Calling getDisableMessageID and expect "
- + expDisableMessageID + " to be returned");
- boolean actDisableMessageID = producer.getDisableMessageID();
- if (actDisableMessageID != expDisableMessageID) {
- TestUtil.logErr("getDisableMessageID() returned " + actDisableMessageID
- + ", expected " + expDisableMessageID);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueSetGetDisableMessageIDTest");
- }
-
- if (!pass) {
- throw new Exception("queueSetGetDisableMessageIDTest failed");
- }
- }
-
- /*
- * @testName: queueSetGetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:JAVADOC:297; JMS:JAVADOC:299;
- *
- * @test_Strategy: Test the following APIs:
- *
- * MessageProducer.setDisableMessageTimestamp(int).
- * MessageProducer.getDisableMessageTimestamp().
- */
- public void queueSetGetDisableMessageTimestampTest() throws Exception {
- boolean pass = true;
- // Test true case
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- queueTest = true;
-
- boolean expDisableMessageTimestamp = true;
- TestUtil.logMsg("Calling setDisableMessageTimestamp("
- + expDisableMessageTimestamp + ")");
- producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
- TestUtil.logMsg("Calling getDisableMessageTimestamp and expect "
- + expDisableMessageTimestamp + " to be returned");
- boolean actDisableMessageTimestamp = producer
- .getDisableMessageTimestamp();
- if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
- TestUtil.logErr("getDisableMessageTimestamp() returned "
- + actDisableMessageTimestamp + ", expected "
- + expDisableMessageTimestamp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueSetGetDisableMessageTimestampTest");
- }
-
- // Test false case
- try {
- boolean expDisableMessageTimestamp = false;
- TestUtil.logMsg("Calling setDisableMessageTimestamp("
- + expDisableMessageTimestamp + ")");
- producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
- TestUtil.logMsg("Calling getDisableMessageTimestamp and expect "
- + expDisableMessageTimestamp + " to be returned");
- boolean actDisableMessageTimestamp = producer
- .getDisableMessageTimestamp();
- if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
- TestUtil.logErr("getDisableMessageTimestamp() returned "
- + actDisableMessageTimestamp + ", expected "
- + expDisableMessageTimestamp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueSetGetDisableMessageTimestampTest");
- }
-
- if (!pass) {
- throw new Exception("queueSetGetDisableMessageTimestampTest failed");
- }
- }
-
- /*
- * @testName: queueSetGetPriorityTest
- *
- * @assertion_ids: JMS:JAVADOC:305; JMS:JAVADOC:307;
- *
- * @test_Strategy: Test the following APIs:
- *
- * MessageProducer.setPriority(int). MessageProducer.getPriority().
- */
- public void queueSetGetPriorityTest() throws Exception {
- boolean pass = true;
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- queueTest = true;
-
- // Test default
- int expPriority = 4;
- TestUtil.logMsg(
- "Calling getPriority and expect " + expPriority + " to be returned");
- int actPriority = producer.getPriority();
- if (actPriority != expPriority) {
- TestUtil.logErr("getPriority() returned " + actPriority + ", expected "
- + expPriority);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueSetGetPriorityTest");
- }
-
- // Test non-default
- int expPriority[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
-
- // Cycle through all priorties
- for (int i = 0; i < expPriority.length; i++) {
- try {
- TestUtil.logMsg("Calling setPriority(" + expPriority[i] + ")");
- producer.setPriority(expPriority[i]);
- TestUtil.logMsg("Calling getPriority and expect " + expPriority[i]
- + " to be returned");
- int actPriority = producer.getPriority();
- if (actPriority != expPriority[i]) {
- TestUtil.logErr("getPriority() returned " + actPriority
- + ", expected " + expPriority[i]);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueSetGetPriorityTest");
- }
- }
-
- if (!pass) {
- throw new Exception("queueSetGetPriorityTest failed");
- }
- }
-
- /*
- * @testName: queueSetGetTimeToLiveTest
- *
- * @assertion_ids: JMS:JAVADOC:309; JMS:JAVADOC:311;
- *
- * @test_Strategy: Test the following APIs:
- *
- * MessageProducer.setTimeToLive(long). MessageProducer.getTimeToLive()
- */
- public void queueSetGetTimeToLiveTest() throws Exception {
- boolean pass = true;
-
- try {
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- queueTest = true;
-
- // Test default
- long expTimeToLive = 0;
- TestUtil.logMsg("Calling getTimeToLive and expect " + expTimeToLive
- + " to be returned");
- long actTimeToLive = producer.getTimeToLive();
- if (actTimeToLive != expTimeToLive) {
- TestUtil.logErr("getTimeToLive() returned " + actTimeToLive
- + ", expected " + expTimeToLive);
- pass = false;
- }
-
- // Test non-default
- expTimeToLive = 1000;
- TestUtil.logMsg("Calling setTimeToLive(" + expTimeToLive + ")");
- producer.setTimeToLive(expTimeToLive);
- TestUtil.logMsg("Calling getTimeToLive and expect " + expTimeToLive
- + " to be returned");
- actTimeToLive = producer.getTimeToLive();
- if (actTimeToLive != expTimeToLive) {
- TestUtil.logErr("getTimeToLive() returned " + actTimeToLive
- + ", expected " + expTimeToLive);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueSetGetTimeToLiveTest");
- }
-
- if (!pass) {
- throw new Exception("queueSetGetTimeToLiveTest failed");
- }
- }
-
- /*
- * @testName: queueInvalidDestinationExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:598; JMS:JAVADOC:601; JMS:JAVADOC:604;
- * JMS:JAVADOC:607;
- *
- * @test_Strategy: Test for InvalidDestinationException from MessageProducer
- * API's.
- *
- * MessageProducer.send(Destination, Message)
- * MessageProducer.send(Destination, Message, init, int, int)
- */
- public void queueInvalidDestinationExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- TestUtil.logMsg("Setup JmsTool for COMMON QUEUE");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = null;
- connection.start();
- queueTest = true;
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueInvalidDestinationExceptionTests");
-
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(destination, expTextMessage);
- TestUtil.logErr("Didn't throw InvalidDestinationException");
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Caught expected InvalidDestinationException");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L);
- TestUtil.logErr("Didn't throw InvalidDestinationException");
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Caught expected InvalidDestinationException");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationException, received " + e.getMessage());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueInvalidDestinationExceptionTests", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueInvalidDestinationExceptionTests failed");
- }
- }
-
- /*
- * @testName: queueUnsupportedOperationExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:599; JMS:JAVADOC:602; JMS:JAVADOC:605;
- * JMS:JAVADOC:1318;
- *
- * @test_Strategy: Test for UnsupportedOperationException from MessageProducer
- * API's.
- *
- * MessageProducer.send(Destination, Message)
- * MessageProducer.send(Destination, Message, init, int, int)
- * MessageProducer.send(Message) MessageProducer.send(Message, init, int, int)
- */
- public void queueUnsupportedOperationExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- TestUtil.logMsg("Setup JmsTool for COMMON QUEUE");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueUnsupportedOperationExceptionTests");
-
- try {
- TestUtil
- .logMsg("Send message with destination specified at creation time");
- producer.send(destination, expTextMessage);
- TestUtil.logErr("Didn't throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil.logErr("Expected UnsupportedOperationException, received "
- + e.getMessage());
- pass = false;
- }
- try {
- TestUtil
- .logMsg("Send message with destination specified at creation time");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L);
- TestUtil.logErr("Didn't throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil.logErr("Expected UnsupportedOperationException, received "
- + e.getMessage());
- pass = false;
- }
-
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
-
- try {
- TestUtil.logMsg(
- "Send message with destination not specified at creation time");
- producer.send(expTextMessage);
- TestUtil.logErr("Didn't throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil.logErr("Expected UnsupportedOperationException, received "
- + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Send message with destination not specified at creation time");
- producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L);
- TestUtil.logErr("Didn't throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil.logErr("Expected UnsupportedOperationException, received "
- + e.getMessage());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueUnsupportedOperationExceptionTests", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("queueUnsupportedOperationExceptionTests failed");
- }
- }
-
- /*
- * @testName: queueDeliveryDelayTest
- *
- * @assertion_ids: JMS:SPEC:261; JMS:JAVADOC:907;
- *
- * @test_Strategy: Send message and verify that message is not delivered until
- * the DeliveryDelay of 30 seconds is reached. Test DeliveryMode.PERSISTENT
- * and DeliveryMode.NON_PERSISTENT.
- *
- * MessageProducer.setDeliveryDelay(30000) MessageProducer.send(Destination,
- * Message, int, int, long)
- */
- public void queueDeliveryDelayTest() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg(
- "-----------------------------------------------------------");
- TestUtil.logMsg(
- "BEGIN TEST queueDeliveryDelayTest with DeliveryDelay=30Secs");
- TestUtil.logMsg(
- "-----------------------------------------------------------");
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- producer.setDeliveryDelay(30000);
-
- // Send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage message = session.createTextMessage("This is a test!");
-
- TestUtil.logMsg("Set StringProperty COM_SUN_JMS_TESTNAME");
- message.setStringProperty("COM_SUN_JMS_TESTNAME",
- "queueDeliveryDelayTest");
-
- TestUtil.logMsg(
- "Sending message with DeliveryMode.PERSISTENT and DeliveryDelay=30Secs");
- producer.send(destination, message, DeliveryMode.PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L);
-
- TestUtil.logMsg("Waiting 15 seconds to receive message");
- message = (TextMessage) consumer.receive(15000);
- if (message != null) {
- TestUtil.logErr(
- "FAILED: Message received before delivery delay of 30 secs elapsed");
- pass = false;
- } else {
- TestUtil.logMsg("Message not available after 15 seconds (CORRECT)");
- TestUtil.logMsg("Sleeping 15 more seconds before receiving message");
- Thread.sleep(15000);
- TestUtil.logMsg("Waiting 15 seconds to receive message");
- message = (TextMessage) consumer.receive(15000);
- if (message == null) {
- TestUtil.logErr(
- "FAILED: Message was not received after delivery delay of 30 secs elapsed");
- pass = false;
- } else {
- TestUtil
- .logMsg("Message received after 30 seconds expired (CORRECT)");
- }
- }
-
- TestUtil.logMsg(
- "Sending message with DeliveryMode.NON_PERSISTENT and DeliveryDelay=30Secs");
- producer.send(destination, message, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L);
-
- TestUtil.logMsg("Waiting 15 seconds to receive message");
- message = (TextMessage) consumer.receive(15000);
- if (message != null) {
- TestUtil.logErr(
- "FAILED: Message received before delivery delay of 30 secs elapsed");
- pass = false;
- } else {
- TestUtil.logMsg("Message not available after 15 seconds (CORRECT)");
- TestUtil.logMsg("Sleeping 15 more seconds before receiving message");
- Thread.sleep(15000);
- TestUtil.logMsg("Waiting 15 seconds to receive message");
- message = (TextMessage) consumer.receive(15000);
- if (message == null) {
- TestUtil.logErr(
- "FAILED: Message was not received after delivery delay of 30 secs elapsed");
- pass = false;
- } else {
- TestUtil
- .logMsg("Message received after 30 seconds expired (CORRECT)");
- }
- }
- TestUtil
- .logMsg("---------------------------------------------------------");
- TestUtil
- .logMsg("END TEST queueDeliveryDelayTest with DeliveryDelay=30Secs");
- TestUtil
- .logMsg("---------------------------------------------------------");
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- e.printStackTrace();
- throw new Exception("queueDeliveryDelayTest", e);
- }
-
- if (!pass) {
- throw new Exception("queueDeliveryDelayTest failed");
- }
- }
-
- /*
- * @testName: topicSendAndRecvTest1
- *
- * @assertion_ids: JMS:JAVADOC:321; JMS:JAVADOC:334;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Destination, Message) MessageConsumer.receive(timeout)
- */ public void topicSendAndRecvTest1() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Topic) null);
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicSendAndRecvTest1");
- TestUtil.logMsg("Sending TextMessage");
- TestUtil.logMsg("Calling MessageProducer.send(Destination, Message)");
- producer.send(destination, expTextMessage);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- consumer.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- e.printStackTrace();
- throw new Exception("topicSendAndRecvTest1", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicSendAndRecvTest1 failed");
- }
- }
-
- /*
- * @testName: topicSendAndRecvTest2
- *
- * @assertion_ids: JMS:JAVADOC:323; JMS:JAVADOC:334;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Destination, Message, int, int, long)
- * MessageConsumer.receive(timeout)
- */
- public void topicSendAndRecvTest2() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Topic) null);
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicSendAndRecvTest2");
- TestUtil.logMsg("Sending TextMessage");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, int, int, long)");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY - 1, 0L);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Check the values in TextMessage, deliverymode, priority, time to live");
- if (!actTextMessage.getText().equals(expTextMessage.getText())
- || actTextMessage.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
- || actTextMessage.getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)
- || actTextMessage.getJMSExpiration() != 0L) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- TestUtil.logErr("DeliveryMode=" + actTextMessage.getJMSDeliveryMode()
- + ", expected " + expTextMessage.getJMSDeliveryMode());
- TestUtil.logErr("Priority=" + actTextMessage.getJMSPriority()
- + ", expected " + expTextMessage.getJMSPriority());
- TestUtil.logErr("TimeToLive=" + actTextMessage.getJMSExpiration()
- + ", expected " + expTextMessage.getJMSExpiration());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- e.printStackTrace();
- throw new Exception("topicSendAndRecvTest2", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicSendAndRecvTest2 failed");
- }
- }
-
- /*
- * @testName: topicSendAndRecvTest3
- *
- * @assertion_ids: JMS:JAVADOC:317; JMS:JAVADOC:334;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Message) MessageConsumer.receive(timeout)
- */
- public void topicSendAndRecvTest3() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicSendAndRecvTest3");
- TestUtil.logMsg("Sending TextMessage");
- TestUtil.logMsg("Calling MessageProducer.send(Message)");
- producer.send(expTextMessage);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- e.printStackTrace();
- throw new Exception("topicSendAndRecvTest3", e);
- }
-
- if (!pass) {
- throw new Exception("topicSendAndRecvTest3 failed");
- }
- }
-
- /*
- * @testName: topicSendAndRecvTest4
- *
- * @assertion_ids: JMS:JAVADOC:319; JMS:JAVADOC:334;
- *
- * @test_Strategy: Send a message using the following API method and verify
- * the send and recv of data:
- *
- * MessageProducer.send(Message, int, int, long)
- * MessageConsumer.receive(timeout)
- */
- public void topicSendAndRecvTest4() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- // send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicSendAndRecvTest4");
- TestUtil.logMsg("Sending TextMessage");
- TestUtil.logMsg("Calling MessageProducer.send(Message, int, int, long)");
- producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY - 1, 0L);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg(
- "Check the values in TextMessage, deliverymode, priority, time to live");
- if (!actTextMessage.getText().equals(expTextMessage.getText())
- || actTextMessage.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
- || actTextMessage.getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)
- || actTextMessage.getJMSExpiration() != 0L) {
- TestUtil.logErr("Didn't get the right message.");
- TestUtil.logErr("text=" + actTextMessage.getText() + ", expected "
- + expTextMessage.getText());
- TestUtil.logErr("DeliveryMode=" + actTextMessage.getJMSDeliveryMode()
- + ", expected " + expTextMessage.getJMSDeliveryMode());
- TestUtil.logErr("Priority=" + actTextMessage.getJMSPriority()
- + ", expected " + expTextMessage.getJMSPriority());
- TestUtil.logErr("TimeToLive=" + actTextMessage.getJMSExpiration()
- + ", expected " + expTextMessage.getJMSExpiration());
- pass = false;
- } else {
- TestUtil.logMsg("TextMessage is correct");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- e.printStackTrace();
- throw new Exception("topicSendAndRecvTest4", e);
- }
-
- if (!pass) {
- throw new Exception("topicSendAndRecvTest4 failed");
- }
- }
-
- /*
- * @testName: topicSetGetDeliveryModeTest
- *
- * @assertion_ids: JMS:JAVADOC:301; JMS:JAVADOC:303;
- *
- * @test_Strategy: Test the following APIs:
- *
- * MessageProducer.setDeliveryMode(int). MessageProducer.getDeliveryMode().
- */
- public void topicSetGetDeliveryModeTest() throws Exception {
- boolean pass = true;
-
- // Test default case
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- queueTest = false;
-
- int expDeliveryMode = DeliveryMode.PERSISTENT;
- TestUtil.logMsg("Calling getDeliveryMode and expect " + expDeliveryMode
- + " to be returned");
- int actDeliveryMode = producer.getDeliveryMode();
- if (actDeliveryMode != expDeliveryMode) {
- TestUtil.logErr("getDeliveryMode() returned " + actDeliveryMode
- + ", expected " + expDeliveryMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("topicSetGetDeliveryModeTest");
- }
-
- // Test non-default case
- try {
- int expDeliveryMode = DeliveryMode.NON_PERSISTENT;
- TestUtil.logMsg("Calling setDeliveryMode(" + expDeliveryMode + ")");
- producer.setDeliveryMode(expDeliveryMode);
- TestUtil.logMsg("Calling getDeliveryMode and expect " + expDeliveryMode
- + " to be returned");
- int actDeliveryMode = producer.getDeliveryMode();
- if (actDeliveryMode != expDeliveryMode) {
- TestUtil.logErr("getDeliveryMode() returned " + actDeliveryMode
- + ", expected " + expDeliveryMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("topicSetGetDeliveryModeTest");
- }
-
- if (!pass) {
- throw new Exception("topicSetGetDeliveryModeTest failed");
- }
- }
-
- /*
- * @testName: topicSetGetDeliveryDelayTest
- *
- * @assertion_ids: JMS:JAVADOC:907; JMS:JAVADOC:886; JMS:SPEC:261;
- *
- * @test_Strategy: Test the following APIs:
- *
- * MessageProducer.setDeliveryDelay(long). MessageProducer.getDeliveryDelay().
- */
- public void topicSetGetDeliveryDelayTest() throws Exception {
- boolean pass = true;
-
- // Test default case
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- queueTest = false;
-
- long expDeliveryDelay = 0L;
- TestUtil.logMsg("Calling getDeliveryDelay and expect " + expDeliveryDelay
- + " to be returned");
- long actDeliveryDelay = producer.getDeliveryDelay();
- if (actDeliveryDelay != expDeliveryDelay) {
- TestUtil.logErr("getDeliveryDelay() returned " + actDeliveryDelay
- + ", expected " + expDeliveryDelay);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("topicSetGetDeliveryDelayTest");
- }
-
- // Test non-default case
- try {
- long expDeliveryDelay = 1L;
- TestUtil.logMsg("Calling setDeliveryDelay(" + expDeliveryDelay + ")");
- producer.setDeliveryDelay(expDeliveryDelay);
- TestUtil.logMsg("Calling getDeliveryDelay and expect " + expDeliveryDelay
- + " to be returned");
- long actDeliveryDelay = producer.getDeliveryDelay();
- if (actDeliveryDelay != expDeliveryDelay) {
- TestUtil.logErr("getDeliveryDelay() returned " + actDeliveryDelay
- + ", expected " + expDeliveryDelay);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("topicSetGetDeliveryDelayTest");
- }
-
- if (!pass) {
- throw new Exception("topicSetGetDeliveryDelayTest failed");
- }
- }
-
- /*
- * @testName: topicSetGetDisableMessageIDTest
- *
- * @assertion_ids: JMS:JAVADOC:293; JMS:JAVADOC:295;
- *
- * @test_Strategy: Test the following APIs:
- *
- * MessageProducer.setDisableMessageID(int).
- * MessageProducer.getDisableMessageID().
- */
- public void topicSetGetDisableMessageIDTest() throws Exception {
- boolean pass = true;
- // Test true case
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- queueTest = false;
-
- boolean expDisableMessageID = true;
- TestUtil
- .logMsg("Calling setDisableMessageID(" + expDisableMessageID + ")");
- producer.setDisableMessageID(expDisableMessageID);
- TestUtil.logMsg("Calling getDisableMessageID and expect "
- + expDisableMessageID + " to be returned");
- boolean actDisableMessageID = producer.getDisableMessageID();
- if (actDisableMessageID != expDisableMessageID) {
- TestUtil.logErr("getDisableMessageID() returned " + actDisableMessageID
- + ", expected " + expDisableMessageID);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("topicSetGetDisableMessageIDTest");
- }
-
- // Test false case
- try {
- boolean expDisableMessageID = false;
- TestUtil
- .logMsg("Calling setDisableMessageID(" + expDisableMessageID + ")");
- producer.setDisableMessageID(expDisableMessageID);
- TestUtil.logMsg("Calling getDisableMessageID and expect "
- + expDisableMessageID + " to be returned");
- boolean actDisableMessageID = producer.getDisableMessageID();
- if (actDisableMessageID != expDisableMessageID) {
- TestUtil.logErr("getDisableMessageID() returned " + actDisableMessageID
- + ", expected " + expDisableMessageID);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("topicSetGetDisableMessageIDTest");
- }
-
- if (!pass) {
- throw new Exception("topicSetGetDisableMessageIDTest failed");
- }
- }
-
- /*
- * @testName: topicSetGetDisableMessageTimestampTest
- *
- * @assertion_ids: JMS:JAVADOC:297; JMS:JAVADOC:299;
- *
- * @test_Strategy: Test the following APIs:
- *
- * MessageProducer.setDisableMessageTimestamp(int).
- * MessageProducer.getDisableMessageTimestamp().
- */
- public void topicSetGetDisableMessageTimestampTest() throws Exception {
- boolean pass = true;
- // Test true case
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- queueTest = false;
-
- boolean expDisableMessageTimestamp = true;
- TestUtil.logMsg("Calling setDisableMessageTimestamp("
- + expDisableMessageTimestamp + ")");
- producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
- TestUtil.logMsg("Calling getDisableMessageTimestamp and expect "
- + expDisableMessageTimestamp + " to be returned");
- boolean actDisableMessageTimestamp = producer
- .getDisableMessageTimestamp();
- if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
- TestUtil.logErr("getDisableMessageTimestamp() returned "
- + actDisableMessageTimestamp + ", expected "
- + expDisableMessageTimestamp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("topicSetGetDisableMessageTimestampTest");
- }
-
- // Test false case
- try {
- boolean expDisableMessageTimestamp = false;
- TestUtil.logMsg("Calling setDisableMessageTimestamp("
- + expDisableMessageTimestamp + ")");
- producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
- TestUtil.logMsg("Calling getDisableMessageTimestamp and expect "
- + expDisableMessageTimestamp + " to be returned");
- boolean actDisableMessageTimestamp = producer
- .getDisableMessageTimestamp();
- if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
- TestUtil.logErr("getDisableMessageTimestamp() returned "
- + actDisableMessageTimestamp + ", expected "
- + expDisableMessageTimestamp);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("topicSetGetDisableMessageTimestampTest");
- }
-
- if (!pass) {
- throw new Exception("topicSetGetDisableMessageTimestampTest failed");
- }
- }
-
- /*
- * @testName: topicSetGetPriorityTest
- *
- * @assertion_ids: JMS:JAVADOC:305; JMS:JAVADOC:307;
- *
- * @test_Strategy: Test the following APIs:
- *
- * MessageProducer.setPriority(int). MessageProducer.getPriority().
- */
- public void topicSetGetPriorityTest() throws Exception {
- boolean pass = true;
- try {
- // set up test tool for Topic
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- queueTest = false;
-
- // Test default
- int expPriority = 4;
- TestUtil.logMsg(
- "Calling getPriority and expect " + expPriority + " to be returned");
- int actPriority = producer.getPriority();
- if (actPriority != expPriority) {
- TestUtil.logErr("getPriority() returned " + actPriority + ", expected "
- + expPriority);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("topicSetGetPriorityTest");
- }
-
- // Test non-default
- int expPriority[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
-
- // Cycle through all priorties
- for (int i = 0; i < expPriority.length; i++) {
- try {
- TestUtil.logMsg("Calling setPriority(" + expPriority[i] + ")");
- producer.setPriority(expPriority[i]);
- TestUtil.logMsg("Calling getPriority and expect " + expPriority[i]
- + " to be returned");
- int actPriority = producer.getPriority();
- if (actPriority != expPriority[i]) {
- TestUtil.logErr("getPriority() returned " + actPriority
- + ", expected " + expPriority[i]);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("topicSetGetPriorityTest");
- }
- }
-
- if (!pass) {
- throw new Exception("topicSetGetPriorityTest failed");
- }
- }
-
- /*
- * @testName: topicSetGetTimeToLiveTest
- *
- * @assertion_ids: JMS:JAVADOC:309; JMS:JAVADOC:311;
- *
- * @test_Strategy: Test the following APIs:
- *
- * MessageProducer.setTimeToLive(long). MessageProducer.getTimeToLive()
- *
- * public void topicSetGetTimeToLiveTest() throws Exception { boolean pass = true;
- *
- * try { // set up test tool for Topic tool = new JmsTool(JmsTool.COMMON_T,
- * user, password, mode); producer = tool.getDefaultProducer(); connection =
- * tool.getDefaultConnection(); session = tool.getDefaultSession();
- * destination = tool.getDefaultDestination(); queueTest = false;
- *
- * // Test default long expTimeToLive = 0;
- * TestUtil.logMsg("Calling getTimeToLive and expect " + expTimeToLive +
- * " to be returned"); long actTimeToLive = producer.getTimeToLive();
- * if(actTimeToLive != expTimeToLive) {
- * TestUtil.logErr("getTimeToLive() returned "+ actTimeToLive + ", expected "
- * + expTimeToLive); pass = false; }
- *
- * // Test non-default long expTimeToLive = 1000;
- * TestUtil.logMsg("Calling setTimeToLive("+expTimeToLive+")");
- * producer.setTimeToLive(expTimeToLive);
- * TestUtil.logMsg("Calling getTimeToLive and expect " + expTimeToLive +
- * " to be returned"); long actTimeToLive = producer.getTimeToLive();
- * if(actTimeToLive != expTimeToLive) {
- * TestUtil.logErr("getTimeToLive() returned "+ actTimeToLive + ", expected "
- * + expTimeToLive); pass = false; } } catch (Exception e) {
- * TestUtil.logErr("Caught exception: " + e.getMessage()); throw new
- * Fault("topicSetGetTimeToLiveTest"); }
- *
- * if (!pass) { throw new Exception("topicSetGetTimeToLiveTest failed"); } }
- *
- * /*
- *
- * @testName: topicInvalidDestinationExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:598; JMS:JAVADOC:601; JMS:JAVADOC:604;
- * JMS:JAVADOC:607;
- *
- * @test_Strategy: Test for InvalidDestinationException from MessageProducer
- * API's.
- *
- * MessageProducer.send(Destination, Message)
- * MessageProducer.send(Destination, Message, init, int, int)
- */
- public void topicInvalidDestinationExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- TestUtil.logMsg("Setup JmsTool for COMMON TOPIC");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = null;
- connection.start();
- queueTest = false;
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicInvalidDestinationExceptionTests");
-
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(destination, expTextMessage);
- TestUtil.logErr("Didn't throw InvalidDestinationException");
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Caught expected InvalidDestinationException");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Send message with invalid destination");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L);
- TestUtil.logErr("Didn't throw InvalidDestinationException");
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Caught expected InvalidDestinationException");
- } catch (Exception e) {
- TestUtil.logErr(
- "Expected InvalidDestinationException, received " + e.getMessage());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("queueInvalidDestinationExceptionTests", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicInvalidDestinationExceptionTests failed");
- }
- }
-
- /*
- * @testName: topicUnsupportedOperationExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:599; JMS:JAVADOC:602; JMS:JAVADOC:605;
- * JMS:JAVADOC:1318;
- *
- * @test_Strategy: Test for UnsupportedOperationException from MessageProducer
- * API's.
- *
- * MessageProducer.send(Destination, Message)
- * MessageProducer.send(Destination, Message, init, int, int)
- * MessageProducer.send(Message) MessageProducer.send(Message, init, int, int)
- *
- */
- public void topicUnsupportedOperationExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Topic
- TestUtil.logMsg("Setup JmsTool for COMMON TOPIC");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicUnsupportedOperationExceptionTests");
-
- try {
- TestUtil
- .logMsg("Send message with destination specified at creation time");
- producer.send(destination, expTextMessage);
- TestUtil.logErr("Didn't throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil.logErr("Expected UnsupportedOperationException, received "
- + e.getMessage());
- pass = false;
- }
- try {
- TestUtil
- .logMsg("Send message with destination specified at creation time");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L);
- TestUtil.logErr("Didn't throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil.logErr("Expected UnsupportedOperationException, received "
- + e.getMessage());
- pass = false;
- }
-
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
-
- try {
- TestUtil.logMsg(
- "Send message with destination not specified at creation time");
- producer.send(expTextMessage);
- TestUtil.logErr("Didn't throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil.logErr("Expected UnsupportedOperationException, received "
- + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg(
- "Send message with destination not specified at creation time");
- producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L);
- TestUtil.logErr("Didn't throw UnsupportedOperationException");
- } catch (UnsupportedOperationException e) {
- TestUtil.logMsg("Caught expected UnsupportedOperationException");
- } catch (Exception e) {
- TestUtil.logErr("Expected UnsupportedOperationException, received "
- + e.getMessage());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("topicUnsupportedOperationExceptionTests", e);
- } finally {
- try {
- producer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("topicUnsupportedOperationExceptionTests failed");
- }
- }
-
- /*
- * @testName: topicDeliveryDelayTest
- *
- * @assertion_ids: JMS:SPEC:261; JMS:JAVADOC:907;
- *
- * @test_Strategy: Send message and verify that message is not delivered until
- * the DeliveryDelay of 30 seconds is reached. Test DeliveryMode.PERSISTENT
- * and DeliveryMode.NON_PERSISTENT.
- *
- * MessageProducer.setDeliveryDelay(30000) MessageProducer.send(Destination,
- * Message, int, int, long)
- */
- public void topicDeliveryDelayTest() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg(
- "-----------------------------------------------------------");
- TestUtil.logMsg(
- "BEGIN TEST topicDeliveryDelayTest with DeliveryDelay=30Secs");
- TestUtil.logMsg(
- "-----------------------------------------------------------");
- // set up test tool for Queue
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- producer.setDeliveryDelay(30000);
-
- // Send and receive TextMessage
- TestUtil.logMsg("Creating TextMessage");
- TextMessage message = session.createTextMessage("This is a test!");
-
- TestUtil.logMsg("Set StringProperty COM_SUN_JMS_TESTNAME");
- message.setStringProperty("COM_SUN_JMS_TESTNAME",
- "topicDeliveryDelayTest");
-
- TestUtil.logMsg(
- "Sending message with DeliveryMode.PERSISTENT and DeliveryDelay=30Secs");
- producer.send(destination, message, DeliveryMode.PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L);
-
- TestUtil.logMsg("Waiting 15 seconds to receive message");
- message = (TextMessage) consumer.receive(15000);
- if (message != null) {
- TestUtil.logErr(
- "FAILED: Message received before delivery delay of 30 secs elapsed");
- pass = false;
- } else {
- TestUtil.logMsg("Message not available after 15 seconds (CORRECT)");
- TestUtil.logMsg("Sleeping 15 more seconds before receiving message");
- Thread.sleep(15000);
- TestUtil.logMsg("Waiting 15 seconds to receive message");
- message = (TextMessage) consumer.receive(15000);
- if (message == null) {
- TestUtil.logErr(
- "FAILED: Message was not received after delivery delay of 30 secs elapsed");
- pass = false;
- } else {
- TestUtil
- .logMsg("Message received after 30 seconds expired (CORRECT)");
- }
- }
-
- TestUtil.logMsg(
- "Sending message with DeliveryMode.NON_PERSISTENT and DeliveryDelay=30Secs");
- producer.send(destination, message, DeliveryMode.NON_PERSISTENT,
- Message.DEFAULT_PRIORITY, 0L);
-
- TestUtil.logMsg("Waiting 15 seconds to receive message");
- message = (TextMessage) consumer.receive(15000);
- if (message != null) {
- TestUtil.logErr(
- "FAILED: Message received before delivery delay of 30 secs elapsed");
- pass = false;
- } else {
- TestUtil.logMsg("Message not available after 15 seconds (CORRECT)");
- TestUtil.logMsg("Sleeping 15 more seconds before receiving message");
- Thread.sleep(15000);
- TestUtil.logMsg("Waiting 15 seconds to receive message");
- message = (TextMessage) consumer.receive(15000);
- if (message == null) {
- TestUtil.logErr(
- "FAILED: Message was not received after delivery delay of 30 secs elapsed");
- pass = false;
- } else {
- TestUtil
- .logMsg("Message received after 30 seconds expired (CORRECT)");
- }
- }
- TestUtil
- .logMsg("---------------------------------------------------------");
- TestUtil
- .logMsg("END TEST topicDeliveryDelayTest with DeliveryDelay=30Secs");
- TestUtil
- .logMsg("---------------------------------------------------------");
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- e.printStackTrace();
- throw new Exception("topicDeliveryDelayTest", e);
- }
-
- if (!pass) {
- throw new Exception("topicDeliveryDelayTest failed");
- }
- }
-
- /*
- * @testName: JMSExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:302; JMS:JAVADOC:306; JMS:JAVADOC:908;
- * JMS:JAVADOC:310; JMS:JAVADOC:320;
- *
- * @test_Strategy: Test for JMSException from MessageProducer API's.
- *
- * MessageProducer.setPriority(int) MessageProducer.setDeliveryMode(int)
- * MessageProducer.send(Message, int, int, long) MessageProducer.send(Message,
- * int, int, long, CompletionListener) MessageProducer.send(Destination,
- * Message, int, int, long) MessageProducer.send(Destination, Message, int,
- * int, long, CompletionListener)
- */
- public void JMSExceptionTests() throws Exception {
- boolean pass = true;
- TextMessage tempMsg = null;
- String message = "Where are you!";
- try {
- // set up test tool for Queue
- TestUtil.logMsg("Setup JmsTool for COMMON QUEUE");
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- producer = tool.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = true;
-
- TestUtil.logMsg("Creating TextMessage");
- TextMessage expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "JMSExceptionTests");
-
- try {
- TestUtil.logMsg("Try and set an invalid priority of -1");
- TestUtil.logMsg("Calling MessageProducer.setPriorty(-1)");
- producer.setPriority(-1);
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and set an invalid delivery mode of -1");
- TestUtil.logMsg("Calling MessageProducer.setDeliveryMode(-1)");
- producer.setDeliveryMode(-1);
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with delivery mode of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Message, -1, Message.DEFAULT_PRIORITY, 0L)");
- producer.send(expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L);
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with priority of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Message, DeliveryMode.NON_PERSISTENT, -1, 0L)");
- producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L);
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with delivery mode of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Message, -1, Message.DEFAULT_PRIORITY, 0L, CompletionListener");
- producer.send(expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L,
- new MyCompletionListener());
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with priority of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Message, DeliveryMode.NON_PERSISTENT, -1, 0L, CompletionListener");
- producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L,
- new MyCompletionListener());
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
-
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Queue) null);
-
- try {
- TestUtil.logMsg("Try and send message with delivery mode of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, -1, Message.DEFAULT_PRIORITY, 0L)");
- producer.send(destination, expTextMessage, -1, Message.DEFAULT_PRIORITY,
- 0L);
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with priority of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, DeliveryMode.NON_PERSISTENT, -1, 0L)");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- -1, 0L);
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with delivery mode of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, -1, Message.DEFAULT_PRIORITY, 0L, CompletionListener)");
- producer.send(destination, expTextMessage, -1, Message.DEFAULT_PRIORITY,
- 0L, new MyCompletionListener());
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with priority of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, DeliveryMode.NON_PERSISTENT, -1, 0L, CompletionListener)");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- -1, 0L, new MyCompletionListener());
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
-
- cleanup();
-
- // set up test tool for Topic
- TestUtil.logMsg("Setup JmsTool for COMMON TOPIC");
- tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
- producer = tool.getDefaultProducer();
- consumer = tool.getDefaultConsumer();
- connection = tool.getDefaultConnection();
- session = tool.getDefaultSession();
- destination = tool.getDefaultDestination();
- connection.start();
- queueTest = false;
-
- TestUtil.logMsg("Creating TextMessage");
- expTextMessage = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "JMSExceptionTests");
-
- try {
- TestUtil.logMsg("Try and set an invalid priority of -1");
- TestUtil.logMsg("Calling MessageProducer.setPriorty(-1)");
- producer.setPriority(-1);
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and set an invalid delivery mode of -1");
- TestUtil.logMsg("Calling MessageProducer.setDeliveryMode(-1)");
- producer.setDeliveryMode(-1);
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with delivery mode of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Message, -1, Message.DEFAULT_PRIORITY, 0L)");
- producer.send(expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L);
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with priority of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Message, DeliveryMode.NON_PERSISTENT, -1, 0L)");
- producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L);
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with delivery mode of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Message, -1, Message.DEFAULT_PRIORITY, 0L, CompletionListener");
- producer.send(expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L,
- new MyCompletionListener());
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with priority of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Message, DeliveryMode.NON_PERSISTENT, -1, 0L, CompletionListener");
- producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L,
- new MyCompletionListener());
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
-
- tool.getDefaultProducer().close();
- producer = tool.getDefaultSession().createProducer((Topic) null);
-
- try {
- TestUtil.logMsg("Try and send message with delivery mode of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, -1, Message.DEFAULT_PRIORITY, 0L)");
- producer.send(destination, expTextMessage, -1, Message.DEFAULT_PRIORITY,
- 0L);
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with priority of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, DeliveryMode.NON_PERSISTENT, -1, 0L)");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- -1, 0L);
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with delivery mode of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, -1, Message.DEFAULT_PRIORITY, 0L, CompletionListener)");
- producer.send(destination, expTextMessage, -1, Message.DEFAULT_PRIORITY,
- 0L, new MyCompletionListener());
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- try {
- TestUtil.logMsg("Try and send message with priority of -1");
- TestUtil.logMsg(
- "Calling MessageProducer.send(Destination, Message, DeliveryMode.NON_PERSISTENT, -1, 0L, CompletionListener)");
- producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT,
- -1, 0L, new MyCompletionListener());
- TestUtil.logErr("Didn't throw JMSException");
- pass = false;
- } catch (JMSException e) {
- TestUtil.logMsg("Caught expected JMSException");
- } catch (Exception e) {
- TestUtil.logErr("Expected JMSException, received " + e.getMessage());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e.getMessage());
- throw new Exception("JMSExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("JMSExceptionTests failed");
- }
- }
-
- private static class MyCompletionListener implements CompletionListener {
-
- public MyCompletionListener() {
- TestUtil.logMsg("MyCompletionListener()");
- }
-
- public void onCompletion(Message message) {
- TestUtil.logMsg("onCompletion()");
- }
-
- public void onException(Message message, Exception exception) {
- TestUtil.logMsg("onException()");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/messageproducertests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/messageproducertests/ClientIT.java
new file mode 100644
index 0000000000..4fe5bc88a9
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/messageproducertests/ClientIT.java
@@ -0,0 +1,2240 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.messageproducertests;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.CompletionListener;
+import jakarta.jms.Connection;
+import jakarta.jms.DeliveryMode;
+import jakarta.jms.Destination;
+import jakarta.jms.InvalidDestinationException;
+import jakarta.jms.JMSException;
+import jakarta.jms.Message;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.Queue;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.messageproducertests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool tool = null;
+
+ // JMS objects
+ transient MessageProducer producer = null;
+
+ transient MessageConsumer consumer = null;
+
+ transient Connection connection = null;
+
+ transient Session session = null;
+
+ transient Destination destination = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ // used for tests
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ boolean queueTest = false;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Closing default Connection");
+ tool.getDefaultConnection().close();
+ if (queueTest) {
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ tool.flushDestination();
+ }
+ tool.closeAllResources();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: queueSendAndRecvTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:321; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Destination, Message) MessageConsumer.receive(timeout)
+ */
+ @Test
+ public void queueSendAndRecvTest1() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueSendAndRecvTest1");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ e.printStackTrace();
+ throw new Exception("queueSendAndRecvTest1", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueSendAndRecvTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: queueSendAndRecvTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:323; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Destination, Message, int, int, long)
+ * MessageConsumer.receive(timeout)
+ */
+ @Test
+ public void queueSendAndRecvTest2() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueSendAndRecvTest2");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.send(Destination, Message, int, int, long)");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY - 1, 0L);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage, deliverymode, priority, time to live");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())
+ || actTextMessage.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
+ || actTextMessage.getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)
+ || actTextMessage.getJMSExpiration() != 0L) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode=" + actTextMessage.getJMSDeliveryMode() + ", expected "
+ + expTextMessage.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority=" + actTextMessage.getJMSPriority() + ", expected "
+ + expTextMessage.getJMSPriority());
+ logger.log(Logger.Level.ERROR, "TimeToLive=" + actTextMessage.getJMSExpiration() + ", expected "
+ + expTextMessage.getJMSExpiration());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ e.printStackTrace();
+ throw new Exception("queueSendAndRecvTest2", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueSendAndRecvTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: queueSendAndRecvTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:317; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Message) MessageConsumer.receive(timeout)
+ */
+ @Test
+ public void queueSendAndRecvTest3() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueSendAndRecvTest3");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.send(Message)");
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ e.printStackTrace();
+ throw new Exception("queueSendAndRecvTest3", e);
+ }
+
+ if (!pass) {
+ throw new Exception("queueSendAndRecvTest3 failed");
+ }
+ }
+
+ /*
+ * @testName: queueSendAndRecvTest4
+ *
+ * @assertion_ids: JMS:JAVADOC:319; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Message, int, int, long)
+ * MessageConsumer.receive(timeout)
+ */
+ @Test
+ public void queueSendAndRecvTest4() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueSendAndRecvTest4");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.send(Message, int, int, long)");
+ producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY - 1, 0L);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage, deliverymode, priority, time to live");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())
+ || actTextMessage.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
+ || actTextMessage.getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)
+ || actTextMessage.getJMSExpiration() != 0L) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode=" + actTextMessage.getJMSDeliveryMode() + ", expected "
+ + expTextMessage.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority=" + actTextMessage.getJMSPriority() + ", expected "
+ + expTextMessage.getJMSPriority());
+ logger.log(Logger.Level.ERROR, "TimeToLive=" + actTextMessage.getJMSExpiration() + ", expected "
+ + expTextMessage.getJMSExpiration());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ e.printStackTrace();
+ throw new Exception("queueSendAndRecvTest4", e);
+ }
+
+ if (!pass) {
+ throw new Exception("queueSendAndRecvTest4 failed");
+ }
+ }
+
+ /*
+ * @testName: queueSetGetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:JAVADOC:301; JMS:JAVADOC:303;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * MessageProducer.setDeliveryMode(int). MessageProducer.getDeliveryMode().
+ */
+ @Test
+ public void queueSetGetDeliveryModeTest() throws Exception {
+ boolean pass = true;
+
+ // Test default case
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ queueTest = true;
+
+ long expDeliveryMode = DeliveryMode.PERSISTENT;
+ logger.log(Logger.Level.INFO, "Calling getDeliveryMode and expect " + expDeliveryMode + " to be returned");
+ long actDeliveryMode = producer.getDeliveryMode();
+ if (actDeliveryMode != expDeliveryMode) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryMode() returned " + actDeliveryMode + ", expected " + expDeliveryMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueSetGetDeliveryModeTest");
+ }
+
+ // Test non-default case
+ try {
+ int expDeliveryMode = DeliveryMode.NON_PERSISTENT;
+ logger.log(Logger.Level.INFO, "Calling setDeliveryMode(" + expDeliveryMode + ")");
+ producer.setDeliveryMode(expDeliveryMode);
+ logger.log(Logger.Level.INFO, "Calling getDeliveryMode and expect " + expDeliveryMode + " to be returned");
+ int actDeliveryMode = producer.getDeliveryMode();
+ if (actDeliveryMode != expDeliveryMode) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryMode() returned " + actDeliveryMode + ", expected " + expDeliveryMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueSetGetDeliveryModeTest");
+ }
+
+ if (!pass) {
+ throw new Exception("queueSetGetDeliveryModeTest failed");
+ }
+ }
+
+ /*
+ * @testName: queueSetGetDeliveryDelayTest
+ *
+ * @assertion_ids: JMS:JAVADOC:907; JMS:JAVADOC:886; JMS:SPEC:261;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * MessageProducer.setDeliveryDelay(long). MessageProducer.getDeliveryDelay().
+ */
+ @Test
+ public void queueSetGetDeliveryDelayTest() throws Exception {
+ boolean pass = true;
+
+ // Test default case
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ queueTest = true;
+
+ long expDeliveryDelay = 0L;
+ logger.log(Logger.Level.INFO,
+ "Calling getDeliveryDelay and expect " + expDeliveryDelay + " to be returned");
+ long actDeliveryDelay = producer.getDeliveryDelay();
+ if (actDeliveryDelay != expDeliveryDelay) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryDelay() returned " + actDeliveryDelay + ", expected " + expDeliveryDelay);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueSetGetDeliveryDelayTest");
+ }
+
+ // Test non-default case
+ try {
+ long expDeliveryDelay = 1L;
+ logger.log(Logger.Level.INFO, "Calling setDeliveryDelay(" + expDeliveryDelay + ")");
+ producer.setDeliveryDelay(expDeliveryDelay);
+ logger.log(Logger.Level.INFO,
+ "Calling getDeliveryDelay and expect " + expDeliveryDelay + " to be returned");
+ long actDeliveryDelay = producer.getDeliveryDelay();
+ if (actDeliveryDelay != expDeliveryDelay) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryDelay() returned " + actDeliveryDelay + ", expected " + expDeliveryDelay);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueSetGetDeliveryDelayTest");
+ }
+
+ if (!pass) {
+ throw new Exception("queueSetGetDeliveryDelayTest failed");
+ }
+ }
+
+ /*
+ * @testName: queueSetGetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:JAVADOC:293; JMS:JAVADOC:295;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * MessageProducer.setDisableMessageID(int).
+ * MessageProducer.getDisableMessageID().
+ */
+ @Test
+ public void queueSetGetDisableMessageIDTest() throws Exception {
+ boolean pass = true;
+ // Test true case
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ queueTest = true;
+
+ boolean expDisableMessageID = true;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageID(" + expDisableMessageID + ")");
+ producer.setDisableMessageID(expDisableMessageID);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageID and expect " + expDisableMessageID + " to be returned");
+ boolean actDisableMessageID = producer.getDisableMessageID();
+ if (actDisableMessageID != expDisableMessageID) {
+ logger.log(Logger.Level.ERROR,
+ "getDisableMessageID() returned " + actDisableMessageID + ", expected " + expDisableMessageID);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueSetGetDisableMessageIDTest");
+ }
+
+ // Test false case
+ try {
+ boolean expDisableMessageID = false;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageID(" + expDisableMessageID + ")");
+ producer.setDisableMessageID(expDisableMessageID);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageID and expect " + expDisableMessageID + " to be returned");
+ boolean actDisableMessageID = producer.getDisableMessageID();
+ if (actDisableMessageID != expDisableMessageID) {
+ logger.log(Logger.Level.ERROR,
+ "getDisableMessageID() returned " + actDisableMessageID + ", expected " + expDisableMessageID);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueSetGetDisableMessageIDTest");
+ }
+
+ if (!pass) {
+ throw new Exception("queueSetGetDisableMessageIDTest failed");
+ }
+ }
+
+ /*
+ * @testName: queueSetGetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:JAVADOC:297; JMS:JAVADOC:299;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * MessageProducer.setDisableMessageTimestamp(int).
+ * MessageProducer.getDisableMessageTimestamp().
+ */
+ @Test
+ public void queueSetGetDisableMessageTimestampTest() throws Exception {
+ boolean pass = true;
+ // Test true case
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ queueTest = true;
+
+ boolean expDisableMessageTimestamp = true;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageTimestamp(" + expDisableMessageTimestamp + ")");
+ producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageTimestamp and expect " + expDisableMessageTimestamp + " to be returned");
+ boolean actDisableMessageTimestamp = producer.getDisableMessageTimestamp();
+ if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
+ logger.log(Logger.Level.ERROR, "getDisableMessageTimestamp() returned " + actDisableMessageTimestamp
+ + ", expected " + expDisableMessageTimestamp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueSetGetDisableMessageTimestampTest");
+ }
+
+ // Test false case
+ try {
+ boolean expDisableMessageTimestamp = false;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageTimestamp(" + expDisableMessageTimestamp + ")");
+ producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageTimestamp and expect " + expDisableMessageTimestamp + " to be returned");
+ boolean actDisableMessageTimestamp = producer.getDisableMessageTimestamp();
+ if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
+ logger.log(Logger.Level.ERROR, "getDisableMessageTimestamp() returned " + actDisableMessageTimestamp
+ + ", expected " + expDisableMessageTimestamp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueSetGetDisableMessageTimestampTest");
+ }
+
+ if (!pass) {
+ throw new Exception("queueSetGetDisableMessageTimestampTest failed");
+ }
+ }
+
+ /*
+ * @testName: queueSetGetPriorityTest
+ *
+ * @assertion_ids: JMS:JAVADOC:305; JMS:JAVADOC:307;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * MessageProducer.setPriority(int). MessageProducer.getPriority().
+ */
+ @Test
+ public void queueSetGetPriorityTest() throws Exception {
+ boolean pass = true;
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ queueTest = true;
+
+ // Test default
+ int expPriority = 4;
+ logger.log(Logger.Level.INFO, "Calling getPriority and expect " + expPriority + " to be returned");
+ int actPriority = producer.getPriority();
+ if (actPriority != expPriority) {
+ logger.log(Logger.Level.ERROR, "getPriority() returned " + actPriority + ", expected " + expPriority);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueSetGetPriorityTest");
+ }
+
+ // Test non-default
+ int expPriority[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
+ // Cycle through all priorties
+ for (int i = 0; i < expPriority.length; i++) {
+ try {
+ logger.log(Logger.Level.INFO, "Calling setPriority(" + expPriority[i] + ")");
+ producer.setPriority(expPriority[i]);
+ logger.log(Logger.Level.INFO, "Calling getPriority and expect " + expPriority[i] + " to be returned");
+ int actPriority = producer.getPriority();
+ if (actPriority != expPriority[i]) {
+ logger.log(Logger.Level.ERROR,
+ "getPriority() returned " + actPriority + ", expected " + expPriority[i]);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueSetGetPriorityTest");
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueSetGetPriorityTest failed");
+ }
+ }
+
+ /*
+ * @testName: queueSetGetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:JAVADOC:309; JMS:JAVADOC:311;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * MessageProducer.setTimeToLive(long). MessageProducer.getTimeToLive()
+ */
+ @Test
+ public void queueSetGetTimeToLiveTest() throws Exception {
+ boolean pass = true;
+
+ try {
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ queueTest = true;
+
+ // Test default
+ long expTimeToLive = 0;
+ logger.log(Logger.Level.INFO, "Calling getTimeToLive and expect " + expTimeToLive + " to be returned");
+ long actTimeToLive = producer.getTimeToLive();
+ if (actTimeToLive != expTimeToLive) {
+ logger.log(Logger.Level.ERROR,
+ "getTimeToLive() returned " + actTimeToLive + ", expected " + expTimeToLive);
+ pass = false;
+ }
+
+ // Test non-default
+ expTimeToLive = 1000;
+ logger.log(Logger.Level.INFO, "Calling setTimeToLive(" + expTimeToLive + ")");
+ producer.setTimeToLive(expTimeToLive);
+ logger.log(Logger.Level.INFO, "Calling getTimeToLive and expect " + expTimeToLive + " to be returned");
+ actTimeToLive = producer.getTimeToLive();
+ if (actTimeToLive != expTimeToLive) {
+ logger.log(Logger.Level.ERROR,
+ "getTimeToLive() returned " + actTimeToLive + ", expected " + expTimeToLive);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueSetGetTimeToLiveTest");
+ }
+
+ if (!pass) {
+ throw new Exception("queueSetGetTimeToLiveTest failed");
+ }
+ }
+
+ /*
+ * @testName: queueInvalidDestinationExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:598; JMS:JAVADOC:601; JMS:JAVADOC:604;
+ * JMS:JAVADOC:607;
+ *
+ * @test_Strategy: Test for InvalidDestinationException from MessageProducer
+ * API's.
+ *
+ * MessageProducer.send(Destination, Message) MessageProducer.send(Destination,
+ * Message, init, int, int)
+ */
+ @Test
+ public void queueInvalidDestinationExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON QUEUE");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = null;
+ connection.start();
+ queueTest = true;
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueInvalidDestinationExceptionTests");
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.ERROR, "Didn't throw InvalidDestinationException");
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected InvalidDestinationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw InvalidDestinationException");
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected InvalidDestinationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e.getMessage());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueInvalidDestinationExceptionTests", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueInvalidDestinationExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: queueUnsupportedOperationExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:599; JMS:JAVADOC:602; JMS:JAVADOC:605;
+ * JMS:JAVADOC:1318;
+ *
+ * @test_Strategy: Test for UnsupportedOperationException from MessageProducer
+ * API's.
+ *
+ * MessageProducer.send(Destination, Message) MessageProducer.send(Destination,
+ * Message, init, int, int) MessageProducer.send(Message)
+ * MessageProducer.send(Message, init, int, int)
+ */
+ @Test
+ public void queueUnsupportedOperationExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON QUEUE");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "queueUnsupportedOperationExceptionTests");
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with destination specified at creation time");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.ERROR, "Didn't throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with destination specified at creation time");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e.getMessage());
+ pass = false;
+ }
+
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with destination not specified at creation time");
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.ERROR, "Didn't throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with destination not specified at creation time");
+ producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e.getMessage());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueUnsupportedOperationExceptionTests", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("queueUnsupportedOperationExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: queueDeliveryDelayTest
+ *
+ * @assertion_ids: JMS:SPEC:261; JMS:JAVADOC:907;
+ *
+ * @test_Strategy: Send message and verify that message is not delivered until
+ * the DeliveryDelay of 30 seconds is reached. Test DeliveryMode.PERSISTENT and
+ * DeliveryMode.NON_PERSISTENT.
+ *
+ * MessageProducer.setDeliveryDelay(30000) MessageProducer.send(Destination,
+ * Message, int, int, long)
+ */
+ @Test
+ public void queueDeliveryDelayTest() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "-----------------------------------------------------------");
+ logger.log(Logger.Level.INFO, "BEGIN TEST queueDeliveryDelayTest with DeliveryDelay=30Secs");
+ logger.log(Logger.Level.INFO, "-----------------------------------------------------------");
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ producer.setDeliveryDelay(30000);
+
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage message = session.createTextMessage("This is a test!");
+
+ logger.log(Logger.Level.INFO, "Set StringProperty COM_SUN_JMS_TESTNAME");
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "queueDeliveryDelayTest");
+
+ logger.log(Logger.Level.INFO, "Sending message with DeliveryMode.PERSISTENT and DeliveryDelay=30Secs");
+ producer.send(destination, message, DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, 0L);
+
+ logger.log(Logger.Level.INFO, "Waiting 15 seconds to receive message");
+ message = (TextMessage) consumer.receive(15000);
+ if (message != null) {
+ logger.log(Logger.Level.ERROR, "FAILED: Message received before delivery delay of 30 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message not available after 15 seconds (CORRECT)");
+ logger.log(Logger.Level.INFO, "Sleeping 15 more seconds before receiving message");
+ Thread.sleep(15000);
+ logger.log(Logger.Level.INFO, "Waiting 15 seconds to receive message");
+ message = (TextMessage) consumer.receive(15000);
+ if (message == null) {
+ logger.log(Logger.Level.ERROR,
+ "FAILED: Message was not received after delivery delay of 30 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message received after 30 seconds expired (CORRECT)");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Sending message with DeliveryMode.NON_PERSISTENT and DeliveryDelay=30Secs");
+ producer.send(destination, message, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L);
+
+ logger.log(Logger.Level.INFO, "Waiting 15 seconds to receive message");
+ message = (TextMessage) consumer.receive(15000);
+ if (message != null) {
+ logger.log(Logger.Level.ERROR, "FAILED: Message received before delivery delay of 30 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message not available after 15 seconds (CORRECT)");
+ logger.log(Logger.Level.INFO, "Sleeping 15 more seconds before receiving message");
+ Thread.sleep(15000);
+ logger.log(Logger.Level.INFO, "Waiting 15 seconds to receive message");
+ message = (TextMessage) consumer.receive(15000);
+ if (message == null) {
+ logger.log(Logger.Level.ERROR,
+ "FAILED: Message was not received after delivery delay of 30 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message received after 30 seconds expired (CORRECT)");
+ }
+ }
+ logger.log(Logger.Level.INFO, "---------------------------------------------------------");
+ logger.log(Logger.Level.INFO, "END TEST queueDeliveryDelayTest with DeliveryDelay=30Secs");
+ logger.log(Logger.Level.INFO, "---------------------------------------------------------");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ e.printStackTrace();
+ throw new Exception("queueDeliveryDelayTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("queueDeliveryDelayTest failed");
+ }
+ }
+
+ /*
+ * @testName: topicSendAndRecvTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:321; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Destination, Message) MessageConsumer.receive(timeout)
+ */
+ @Test
+ public void topicSendAndRecvTest1() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Topic) null);
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicSendAndRecvTest1");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.send(Destination, Message)");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ consumer.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ e.printStackTrace();
+ throw new Exception("topicSendAndRecvTest1", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicSendAndRecvTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: topicSendAndRecvTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:323; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Destination, Message, int, int, long)
+ * MessageConsumer.receive(timeout)
+ */
+ @Test
+ public void topicSendAndRecvTest2() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Topic) null);
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicSendAndRecvTest2");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.send(Destination, Message, int, int, long)");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY - 1, 0L);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage, deliverymode, priority, time to live");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())
+ || actTextMessage.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
+ || actTextMessage.getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)
+ || actTextMessage.getJMSExpiration() != 0L) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode=" + actTextMessage.getJMSDeliveryMode() + ", expected "
+ + expTextMessage.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority=" + actTextMessage.getJMSPriority() + ", expected "
+ + expTextMessage.getJMSPriority());
+ logger.log(Logger.Level.ERROR, "TimeToLive=" + actTextMessage.getJMSExpiration() + ", expected "
+ + expTextMessage.getJMSExpiration());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ e.printStackTrace();
+ throw new Exception("topicSendAndRecvTest2", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicSendAndRecvTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: topicSendAndRecvTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:317; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Message) MessageConsumer.receive(timeout)
+ */
+ @Test
+ public void topicSendAndRecvTest3() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicSendAndRecvTest3");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.send(Message)");
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ e.printStackTrace();
+ throw new Exception("topicSendAndRecvTest3", e);
+ }
+
+ if (!pass) {
+ throw new Exception("topicSendAndRecvTest3 failed");
+ }
+ }
+
+ /*
+ * @testName: topicSendAndRecvTest4
+ *
+ * @assertion_ids: JMS:JAVADOC:319; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Send a message using the following API method and verify the
+ * send and recv of data:
+ *
+ * MessageProducer.send(Message, int, int, long)
+ * MessageConsumer.receive(timeout)
+ */
+ @Test
+ public void topicSendAndRecvTest4() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicSendAndRecvTest4");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.send(Message, int, int, long)");
+ producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY - 1, 0L);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in TextMessage, deliverymode, priority, time to live");
+ if (!actTextMessage.getText().equals(expTextMessage.getText())
+ || actTextMessage.getJMSDeliveryMode() != DeliveryMode.NON_PERSISTENT
+ || actTextMessage.getJMSPriority() != (Message.DEFAULT_PRIORITY - 1)
+ || actTextMessage.getJMSExpiration() != 0L) {
+ logger.log(Logger.Level.ERROR, "Didn't get the right message.");
+ logger.log(Logger.Level.ERROR,
+ "text=" + actTextMessage.getText() + ", expected " + expTextMessage.getText());
+ logger.log(Logger.Level.ERROR, "DeliveryMode=" + actTextMessage.getJMSDeliveryMode() + ", expected "
+ + expTextMessage.getJMSDeliveryMode());
+ logger.log(Logger.Level.ERROR, "Priority=" + actTextMessage.getJMSPriority() + ", expected "
+ + expTextMessage.getJMSPriority());
+ logger.log(Logger.Level.ERROR, "TimeToLive=" + actTextMessage.getJMSExpiration() + ", expected "
+ + expTextMessage.getJMSExpiration());
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ e.printStackTrace();
+ throw new Exception("topicSendAndRecvTest4", e);
+ }
+
+ if (!pass) {
+ throw new Exception("topicSendAndRecvTest4 failed");
+ }
+ }
+
+ /*
+ * @testName: topicSetGetDeliveryModeTest
+ *
+ * @assertion_ids: JMS:JAVADOC:301; JMS:JAVADOC:303;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * MessageProducer.setDeliveryMode(int). MessageProducer.getDeliveryMode().
+ */
+ @Test
+ public void topicSetGetDeliveryModeTest() throws Exception {
+ boolean pass = true;
+
+ // Test default case
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ queueTest = false;
+
+ int expDeliveryMode = DeliveryMode.PERSISTENT;
+ logger.log(Logger.Level.INFO, "Calling getDeliveryMode and expect " + expDeliveryMode + " to be returned");
+ int actDeliveryMode = producer.getDeliveryMode();
+ if (actDeliveryMode != expDeliveryMode) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryMode() returned " + actDeliveryMode + ", expected " + expDeliveryMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("topicSetGetDeliveryModeTest");
+ }
+
+ // Test non-default case
+ try {
+ int expDeliveryMode = DeliveryMode.NON_PERSISTENT;
+ logger.log(Logger.Level.INFO, "Calling setDeliveryMode(" + expDeliveryMode + ")");
+ producer.setDeliveryMode(expDeliveryMode);
+ logger.log(Logger.Level.INFO, "Calling getDeliveryMode and expect " + expDeliveryMode + " to be returned");
+ int actDeliveryMode = producer.getDeliveryMode();
+ if (actDeliveryMode != expDeliveryMode) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryMode() returned " + actDeliveryMode + ", expected " + expDeliveryMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("topicSetGetDeliveryModeTest");
+ }
+
+ if (!pass) {
+ throw new Exception("topicSetGetDeliveryModeTest failed");
+ }
+ }
+
+ /*
+ * @testName: topicSetGetDeliveryDelayTest
+ *
+ * @assertion_ids: JMS:JAVADOC:907; JMS:JAVADOC:886; JMS:SPEC:261;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * MessageProducer.setDeliveryDelay(long). MessageProducer.getDeliveryDelay().
+ */
+ @Test
+ public void topicSetGetDeliveryDelayTest() throws Exception {
+ boolean pass = true;
+
+ // Test default case
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ queueTest = false;
+
+ long expDeliveryDelay = 0L;
+ logger.log(Logger.Level.INFO,
+ "Calling getDeliveryDelay and expect " + expDeliveryDelay + " to be returned");
+ long actDeliveryDelay = producer.getDeliveryDelay();
+ if (actDeliveryDelay != expDeliveryDelay) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryDelay() returned " + actDeliveryDelay + ", expected " + expDeliveryDelay);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("topicSetGetDeliveryDelayTest");
+ }
+
+ // Test non-default case
+ try {
+ long expDeliveryDelay = 1L;
+ logger.log(Logger.Level.INFO, "Calling setDeliveryDelay(" + expDeliveryDelay + ")");
+ producer.setDeliveryDelay(expDeliveryDelay);
+ logger.log(Logger.Level.INFO,
+ "Calling getDeliveryDelay and expect " + expDeliveryDelay + " to be returned");
+ long actDeliveryDelay = producer.getDeliveryDelay();
+ if (actDeliveryDelay != expDeliveryDelay) {
+ logger.log(Logger.Level.ERROR,
+ "getDeliveryDelay() returned " + actDeliveryDelay + ", expected " + expDeliveryDelay);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("topicSetGetDeliveryDelayTest");
+ }
+
+ if (!pass) {
+ throw new Exception("topicSetGetDeliveryDelayTest failed");
+ }
+ }
+
+ /*
+ * @testName: topicSetGetDisableMessageIDTest
+ *
+ * @assertion_ids: JMS:JAVADOC:293; JMS:JAVADOC:295;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * MessageProducer.setDisableMessageID(int).
+ * MessageProducer.getDisableMessageID().
+ */
+ @Test
+ public void topicSetGetDisableMessageIDTest() throws Exception {
+ boolean pass = true;
+ // Test true case
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ queueTest = false;
+
+ boolean expDisableMessageID = true;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageID(" + expDisableMessageID + ")");
+ producer.setDisableMessageID(expDisableMessageID);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageID and expect " + expDisableMessageID + " to be returned");
+ boolean actDisableMessageID = producer.getDisableMessageID();
+ if (actDisableMessageID != expDisableMessageID) {
+ logger.log(Logger.Level.ERROR,
+ "getDisableMessageID() returned " + actDisableMessageID + ", expected " + expDisableMessageID);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("topicSetGetDisableMessageIDTest");
+ }
+
+ // Test false case
+ try {
+ boolean expDisableMessageID = false;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageID(" + expDisableMessageID + ")");
+ producer.setDisableMessageID(expDisableMessageID);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageID and expect " + expDisableMessageID + " to be returned");
+ boolean actDisableMessageID = producer.getDisableMessageID();
+ if (actDisableMessageID != expDisableMessageID) {
+ logger.log(Logger.Level.ERROR,
+ "getDisableMessageID() returned " + actDisableMessageID + ", expected " + expDisableMessageID);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("topicSetGetDisableMessageIDTest");
+ }
+
+ if (!pass) {
+ throw new Exception("topicSetGetDisableMessageIDTest failed");
+ }
+ }
+
+ /*
+ * @testName: topicSetGetDisableMessageTimestampTest
+ *
+ * @assertion_ids: JMS:JAVADOC:297; JMS:JAVADOC:299;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * MessageProducer.setDisableMessageTimestamp(int).
+ * MessageProducer.getDisableMessageTimestamp().
+ */
+ @Test
+ public void topicSetGetDisableMessageTimestampTest() throws Exception {
+ boolean pass = true;
+ // Test true case
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ queueTest = false;
+
+ boolean expDisableMessageTimestamp = true;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageTimestamp(" + expDisableMessageTimestamp + ")");
+ producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageTimestamp and expect " + expDisableMessageTimestamp + " to be returned");
+ boolean actDisableMessageTimestamp = producer.getDisableMessageTimestamp();
+ if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
+ logger.log(Logger.Level.ERROR, "getDisableMessageTimestamp() returned " + actDisableMessageTimestamp
+ + ", expected " + expDisableMessageTimestamp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("topicSetGetDisableMessageTimestampTest");
+ }
+
+ // Test false case
+ try {
+ boolean expDisableMessageTimestamp = false;
+ logger.log(Logger.Level.INFO, "Calling setDisableMessageTimestamp(" + expDisableMessageTimestamp + ")");
+ producer.setDisableMessageTimestamp(expDisableMessageTimestamp);
+ logger.log(Logger.Level.INFO,
+ "Calling getDisableMessageTimestamp and expect " + expDisableMessageTimestamp + " to be returned");
+ boolean actDisableMessageTimestamp = producer.getDisableMessageTimestamp();
+ if (actDisableMessageTimestamp != expDisableMessageTimestamp) {
+ logger.log(Logger.Level.ERROR, "getDisableMessageTimestamp() returned " + actDisableMessageTimestamp
+ + ", expected " + expDisableMessageTimestamp);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("topicSetGetDisableMessageTimestampTest");
+ }
+
+ if (!pass) {
+ throw new Exception("topicSetGetDisableMessageTimestampTest failed");
+ }
+ }
+
+ /*
+ * @testName: topicSetGetPriorityTest
+ *
+ * @assertion_ids: JMS:JAVADOC:305; JMS:JAVADOC:307;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * MessageProducer.setPriority(int). MessageProducer.getPriority().
+ */
+ @Test
+ public void topicSetGetPriorityTest() throws Exception {
+ boolean pass = true;
+ try {
+ // set up test tool for Topic
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ queueTest = false;
+
+ // Test default
+ int expPriority = 4;
+ logger.log(Logger.Level.INFO, "Calling getPriority and expect " + expPriority + " to be returned");
+ int actPriority = producer.getPriority();
+ if (actPriority != expPriority) {
+ logger.log(Logger.Level.ERROR, "getPriority() returned " + actPriority + ", expected " + expPriority);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("topicSetGetPriorityTest");
+ }
+
+ // Test non-default
+ int expPriority[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+
+ // Cycle through all priorties
+ for (int i = 0; i < expPriority.length; i++) {
+ try {
+ logger.log(Logger.Level.INFO, "Calling setPriority(" + expPriority[i] + ")");
+ producer.setPriority(expPriority[i]);
+ logger.log(Logger.Level.INFO, "Calling getPriority and expect " + expPriority[i] + " to be returned");
+ int actPriority = producer.getPriority();
+ if (actPriority != expPriority[i]) {
+ logger.log(Logger.Level.ERROR,
+ "getPriority() returned " + actPriority + ", expected " + expPriority[i]);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("topicSetGetPriorityTest");
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicSetGetPriorityTest failed");
+ }
+ }
+
+ /*
+ * @testName: topicSetGetTimeToLiveTest
+ *
+ * @assertion_ids: JMS:JAVADOC:309; JMS:JAVADOC:311;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * MessageProducer.setTimeToLive(long). MessageProducer.getTimeToLive()
+ *
+ * public void topicSetGetTimeToLiveTest() throws Exception { boolean pass =
+ * true;
+ *
+ * try { // set up test tool for Topic tool = new JmsTool(JmsTool.COMMON_T,
+ * user, password, mode); producer = tool.getDefaultProducer(); connection =
+ * tool.getDefaultConnection(); session = tool.getDefaultSession(); destination
+ * = tool.getDefaultDestination(); queueTest = false;
+ *
+ * // Test default long expTimeToLive = 0;
+ * logger.log(Logger.Level.INFO,"Calling getTimeToLive and expect " +
+ * expTimeToLive + " to be returned"); long actTimeToLive =
+ * producer.getTimeToLive(); if(actTimeToLive != expTimeToLive) {
+ * logger.log(Logger.Level.ERROR,"getTimeToLive() returned "+ actTimeToLive +
+ * ", expected " + expTimeToLive); pass = false; }
+ *
+ * // Test non-default long expTimeToLive = 1000;
+ * logger.log(Logger.Level.INFO,"Calling setTimeToLive("+expTimeToLive+")");
+ * producer.setTimeToLive(expTimeToLive);
+ * logger.log(Logger.Level.INFO,"Calling getTimeToLive and expect " +
+ * expTimeToLive + " to be returned"); long actTimeToLive =
+ * producer.getTimeToLive(); if(actTimeToLive != expTimeToLive) {
+ * logger.log(Logger.Level.ERROR,"getTimeToLive() returned "+ actTimeToLive +
+ * ", expected " + expTimeToLive); pass = false; } } catch (Exception e) {
+ * logger.log(Logger.Level.ERROR,"Caught exception: " + e.getMessage()); throw
+ * new Fault("topicSetGetTimeToLiveTest"); }
+ *
+ * if (!pass) { throw new Exception("topicSetGetTimeToLiveTest failed"); } }
+ *
+ * /*
+ *
+ * @testName: topicInvalidDestinationExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:598; JMS:JAVADOC:601; JMS:JAVADOC:604;
+ * JMS:JAVADOC:607;
+ *
+ * @test_Strategy: Test for InvalidDestinationException from MessageProducer
+ * API's.
+ *
+ * MessageProducer.send(Destination, Message) MessageProducer.send(Destination,
+ * Message, init, int, int)
+ */
+ @Test
+ public void topicInvalidDestinationExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON TOPIC");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = null;
+ connection.start();
+ queueTest = false;
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicInvalidDestinationExceptionTests");
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.ERROR, "Didn't throw InvalidDestinationException");
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected InvalidDestinationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with invalid destination");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw InvalidDestinationException");
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected InvalidDestinationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e.getMessage());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("queueInvalidDestinationExceptionTests", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicInvalidDestinationExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: topicUnsupportedOperationExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:599; JMS:JAVADOC:602; JMS:JAVADOC:605;
+ * JMS:JAVADOC:1318;
+ *
+ * @test_Strategy: Test for UnsupportedOperationException from MessageProducer
+ * API's.
+ *
+ * MessageProducer.send(Destination, Message) MessageProducer.send(Destination,
+ * Message, init, int, int) MessageProducer.send(Message)
+ * MessageProducer.send(Message, init, int, int)
+ *
+ */
+ @Test
+ public void topicUnsupportedOperationExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON TOPIC");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "topicUnsupportedOperationExceptionTests");
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with destination specified at creation time");
+ producer.send(destination, expTextMessage);
+ logger.log(Logger.Level.ERROR, "Didn't throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with destination specified at creation time");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e.getMessage());
+ pass = false;
+ }
+
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+
+ try {
+ logger.log(Logger.Level.INFO, "Send message with destination not specified at creation time");
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.ERROR, "Didn't throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Send message with destination not specified at creation time");
+ producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw UnsupportedOperationException");
+ } catch (UnsupportedOperationException e) {
+ logger.log(Logger.Level.INFO, "Caught expected UnsupportedOperationException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected UnsupportedOperationException, received " + e.getMessage());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("topicUnsupportedOperationExceptionTests", e);
+ } finally {
+ try {
+ producer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("topicUnsupportedOperationExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: topicDeliveryDelayTest
+ *
+ * @assertion_ids: JMS:SPEC:261; JMS:JAVADOC:907;
+ *
+ * @test_Strategy: Send message and verify that message is not delivered until
+ * the DeliveryDelay of 30 seconds is reached. Test DeliveryMode.PERSISTENT and
+ * DeliveryMode.NON_PERSISTENT.
+ *
+ * MessageProducer.setDeliveryDelay(30000) MessageProducer.send(Destination,
+ * Message, int, int, long)
+ */
+ @Test
+ public void topicDeliveryDelayTest() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "-----------------------------------------------------------");
+ logger.log(Logger.Level.INFO, "BEGIN TEST topicDeliveryDelayTest with DeliveryDelay=30Secs");
+ logger.log(Logger.Level.INFO, "-----------------------------------------------------------");
+ // set up test tool for Queue
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ producer.setDeliveryDelay(30000);
+
+ // Send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage message = session.createTextMessage("This is a test!");
+
+ logger.log(Logger.Level.INFO, "Set StringProperty COM_SUN_JMS_TESTNAME");
+ message.setStringProperty("COM_SUN_JMS_TESTNAME", "topicDeliveryDelayTest");
+
+ logger.log(Logger.Level.INFO, "Sending message with DeliveryMode.PERSISTENT and DeliveryDelay=30Secs");
+ producer.send(destination, message, DeliveryMode.PERSISTENT, Message.DEFAULT_PRIORITY, 0L);
+
+ logger.log(Logger.Level.INFO, "Waiting 15 seconds to receive message");
+ message = (TextMessage) consumer.receive(15000);
+ if (message != null) {
+ logger.log(Logger.Level.ERROR, "FAILED: Message received before delivery delay of 30 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message not available after 15 seconds (CORRECT)");
+ logger.log(Logger.Level.INFO, "Sleeping 15 more seconds before receiving message");
+ Thread.sleep(15000);
+ logger.log(Logger.Level.INFO, "Waiting 15 seconds to receive message");
+ message = (TextMessage) consumer.receive(15000);
+ if (message == null) {
+ logger.log(Logger.Level.ERROR,
+ "FAILED: Message was not received after delivery delay of 30 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message received after 30 seconds expired (CORRECT)");
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Sending message with DeliveryMode.NON_PERSISTENT and DeliveryDelay=30Secs");
+ producer.send(destination, message, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, 0L);
+
+ logger.log(Logger.Level.INFO, "Waiting 15 seconds to receive message");
+ message = (TextMessage) consumer.receive(15000);
+ if (message != null) {
+ logger.log(Logger.Level.ERROR, "FAILED: Message received before delivery delay of 30 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message not available after 15 seconds (CORRECT)");
+ logger.log(Logger.Level.INFO, "Sleeping 15 more seconds before receiving message");
+ Thread.sleep(15000);
+ logger.log(Logger.Level.INFO, "Waiting 15 seconds to receive message");
+ message = (TextMessage) consumer.receive(15000);
+ if (message == null) {
+ logger.log(Logger.Level.ERROR,
+ "FAILED: Message was not received after delivery delay of 30 secs elapsed");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message received after 30 seconds expired (CORRECT)");
+ }
+ }
+ logger.log(Logger.Level.INFO, "---------------------------------------------------------");
+ logger.log(Logger.Level.INFO, "END TEST topicDeliveryDelayTest with DeliveryDelay=30Secs");
+ logger.log(Logger.Level.INFO, "---------------------------------------------------------");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ e.printStackTrace();
+ throw new Exception("topicDeliveryDelayTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("topicDeliveryDelayTest failed");
+ }
+ }
+
+ /*
+ * @testName: JMSExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:302; JMS:JAVADOC:306; JMS:JAVADOC:908;
+ * JMS:JAVADOC:310; JMS:JAVADOC:320;
+ *
+ * @test_Strategy: Test for JMSException from MessageProducer API's.
+ *
+ * MessageProducer.setPriority(int) MessageProducer.setDeliveryMode(int)
+ * MessageProducer.send(Message, int, int, long) MessageProducer.send(Message,
+ * int, int, long, CompletionListener) MessageProducer.send(Destination,
+ * Message, int, int, long) MessageProducer.send(Destination, Message, int, int,
+ * long, CompletionListener)
+ */
+ @Test
+ public void JMSExceptionTests() throws Exception {
+ boolean pass = true;
+ TextMessage tempMsg = null;
+ String message = "Where are you!";
+ try {
+ // set up test tool for Queue
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON QUEUE");
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ producer = tool.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = true;
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ TextMessage expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "JMSExceptionTests");
+
+ try {
+ logger.log(Logger.Level.INFO, "Try and set an invalid priority of -1");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.setPriorty(-1)");
+ producer.setPriority(-1);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and set an invalid delivery mode of -1");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.setDeliveryMode(-1)");
+ producer.setDeliveryMode(-1);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with delivery mode of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Message, -1, Message.DEFAULT_PRIORITY, 0L)");
+ producer.send(expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with priority of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Message, DeliveryMode.NON_PERSISTENT, -1, 0L)");
+ producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with delivery mode of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Message, -1, Message.DEFAULT_PRIORITY, 0L, CompletionListener");
+ producer.send(expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L, new MyCompletionListener());
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with priority of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Message, DeliveryMode.NON_PERSISTENT, -1, 0L, CompletionListener");
+ producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L, new MyCompletionListener());
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Queue) null);
+
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with delivery mode of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Destination, Message, -1, Message.DEFAULT_PRIORITY, 0L)");
+ producer.send(destination, expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with priority of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Destination, Message, DeliveryMode.NON_PERSISTENT, -1, 0L)");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with delivery mode of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Destination, Message, -1, Message.DEFAULT_PRIORITY, 0L, CompletionListener)");
+ producer.send(destination, expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L,
+ new MyCompletionListener());
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with priority of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Destination, Message, DeliveryMode.NON_PERSISTENT, -1, 0L, CompletionListener)");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L,
+ new MyCompletionListener());
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+
+ cleanup();
+
+ // set up test tool for Topic
+ logger.log(Logger.Level.INFO, "Setup JmsTool for COMMON TOPIC");
+ tool = new JmsTool(JmsTool.COMMON_T, user, password, mode);
+ producer = tool.getDefaultProducer();
+ consumer = tool.getDefaultConsumer();
+ connection = tool.getDefaultConnection();
+ session = tool.getDefaultSession();
+ destination = tool.getDefaultDestination();
+ connection.start();
+ queueTest = false;
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ expTextMessage = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "JMSExceptionTests");
+
+ try {
+ logger.log(Logger.Level.INFO, "Try and set an invalid priority of -1");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.setPriorty(-1)");
+ producer.setPriority(-1);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and set an invalid delivery mode of -1");
+ logger.log(Logger.Level.INFO, "Calling MessageProducer.setDeliveryMode(-1)");
+ producer.setDeliveryMode(-1);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with delivery mode of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Message, -1, Message.DEFAULT_PRIORITY, 0L)");
+ producer.send(expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with priority of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Message, DeliveryMode.NON_PERSISTENT, -1, 0L)");
+ producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with delivery mode of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Message, -1, Message.DEFAULT_PRIORITY, 0L, CompletionListener");
+ producer.send(expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L, new MyCompletionListener());
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with priority of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Message, DeliveryMode.NON_PERSISTENT, -1, 0L, CompletionListener");
+ producer.send(expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L, new MyCompletionListener());
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+
+ tool.getDefaultProducer().close();
+ producer = tool.getDefaultSession().createProducer((Topic) null);
+
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with delivery mode of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Destination, Message, -1, Message.DEFAULT_PRIORITY, 0L)");
+ producer.send(destination, expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with priority of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Destination, Message, DeliveryMode.NON_PERSISTENT, -1, 0L)");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L);
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with delivery mode of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Destination, Message, -1, Message.DEFAULT_PRIORITY, 0L, CompletionListener)");
+ producer.send(destination, expTextMessage, -1, Message.DEFAULT_PRIORITY, 0L,
+ new MyCompletionListener());
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ try {
+ logger.log(Logger.Level.INFO, "Try and send message with priority of -1");
+ logger.log(Logger.Level.INFO,
+ "Calling MessageProducer.send(Destination, Message, DeliveryMode.NON_PERSISTENT, -1, 0L, CompletionListener)");
+ producer.send(destination, expTextMessage, DeliveryMode.NON_PERSISTENT, -1, 0L,
+ new MyCompletionListener());
+ logger.log(Logger.Level.ERROR, "Didn't throw JMSException");
+ pass = false;
+ } catch (JMSException e) {
+ logger.log(Logger.Level.INFO, "Caught expected JMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected JMSException, received " + e.getMessage());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e.getMessage());
+ throw new Exception("JMSExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("JMSExceptionTests failed");
+ }
+ }
+
+ private static class MyCompletionListener implements CompletionListener {
+
+ public MyCompletionListener() {
+ logger.log(Logger.Level.INFO, "MyCompletionListener()");
+ }
+
+ public void onCompletion(Message message) {
+ logger.log(Logger.Level.INFO, "onCompletion()");
+ }
+
+ public void onException(Message message, Exception exception) {
+ logger.log(Logger.Level.INFO, "onException()");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/runtimeexceptiontests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/runtimeexceptiontests/Client.java
deleted file mode 100644
index df530e95f4..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/runtimeexceptiontests/Client.java
+++ /dev/null
@@ -1,1373 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.core20.runtimeexceptiontests;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.runtimeexceptiontests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props:
- *
- * @exception Fault
- */
-
- public void setup(String[] args, Properties p) throws Exception {
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
-
- public void cleanup() throws Exception {
- }
-
- /* Tests */
-
- /*
- * @testName: transactionRolledBackRuntimeExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:1117;
- *
- * @test_Strategy: Construct TransactionRolledBackRuntimeException(String,
- * String)
- */
- public void transactionRolledBackRuntimeExceptionTest1() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Serious";
- String reason = "Rollback operation not allowed.";
-
- TestUtil
- .logMsg("Test TransactionRolledBackRuntimeException(String, String)");
- jakarta.jms.TransactionRolledBackRuntimeException exceptionToTest = new jakarta.jms.TransactionRolledBackRuntimeException(
- reason, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.TransactionRolledBackRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("transactionRolledBackRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("transactionRolledBackRuntimeExceptionTest1 Failed");
- }
-
- /*
- * @testName: transactionRolledBackRuntimeExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:1118;
- *
- * @test_Strategy: Construct TransactionRolledBackRuntimeException(String)
- */
- public void transactionRolledBackRuntimeExceptionTest2() throws Exception {
- boolean pass = true;
- try {
- String reason = "Rollback operation not allowed.";
-
- TestUtil.logMsg("Test TransactionRolledBackRuntimeException(String)");
- jakarta.jms.TransactionRolledBackRuntimeException exceptionToTest = new jakarta.jms.TransactionRolledBackRuntimeException(
- reason);
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.TransactionRolledBackRuntimeException e) {
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("transactionRolledBackRuntimeExceptionTest2 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("transactionRolledBackRuntimeExceptionTest2 Failed");
- }
-
- /*
- * @testName: transactionRolledBackRuntimeExceptionTest3
- *
- * @assertion_ids: JMS:JAVADOC:1119;
- *
- * @test_Strategy: Construct TransactionRolledBackRuntimeException(String,
- * String, Throwable)
- */
- public void transactionRolledBackRuntimeExceptionTest3() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Serious";
- String reason = "Rollback operation not allowed.";
- jakarta.jms.TransactionRolledBackException exception = new jakarta.jms.TransactionRolledBackException(
- reason);
-
- TestUtil.logMsg(
- "Test TransactionRolledBackRuntimeException(String, String, Throwable)");
- jakarta.jms.TransactionRolledBackRuntimeException exceptionToTest = new jakarta.jms.TransactionRolledBackRuntimeException(
- reason, errorCode, exception);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.TransactionRolledBackRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- if (!exceptionToTest.getCause().equals(exception)) {
- TestUtil.logErr("Incorrect cause " + exceptionToTest.getCause());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("transactionRolledBackRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("transactionRolledBackRuntimeExceptionTest3 Failed");
- }
-
- /*
- * @testName: transactionInProgressRuntimeExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:1402;
- *
- * @test_Strategy: Construct TransactionInProgressRuntimeException(String,
- * String)
- */
- public void transactionInProgressRuntimeExceptionTest1() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Serious";
- String reason = "Transaction already in progress.";
-
- TestUtil
- .logMsg("Test TransactionInProgressRuntimeException(String, String)");
- jakarta.jms.TransactionInProgressRuntimeException exceptionToTest = new jakarta.jms.TransactionInProgressRuntimeException(
- reason, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.TransactionInProgressRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("transactionInProgressRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("transactionInProgressRuntimeExceptionTest1 Failed");
- }
-
- /*
- * @testName: transactionInProgressRuntimeExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:1403;
- *
- * @test_Strategy: Construct TransactionInProgressRuntimeException(String)
- */
- public void transactionInProgressRuntimeExceptionTest2() throws Exception {
- boolean pass = true;
- try {
- String reason = "Transaction already in progress.";
-
- TestUtil.logMsg("Test TransactionInProgressRuntimeException(String)");
- jakarta.jms.TransactionInProgressRuntimeException exceptionToTest = new jakarta.jms.TransactionInProgressRuntimeException(
- reason);
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.TransactionInProgressRuntimeException e) {
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("transactionInProgressRuntimeExceptionTest2 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("transactionInProgressRuntimeExceptionTest2 Failed");
- }
-
- /*
- * @testName: transactionInProgressRuntimeExceptionTest3
- *
- * @assertion_ids: JMS:JAVADOC:1439;
- *
- * @test_Strategy: Construct TransactionInProgressRuntimeException(String,
- * String, Throwable)
- */
- public void transactionInProgressRuntimeExceptionTest3() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Serious";
- String reason = "Transaction already in progress.";
- jakarta.jms.TransactionInProgressRuntimeException exception = new jakarta.jms.TransactionInProgressRuntimeException(
- reason);
-
- TestUtil.logMsg(
- "Test TransactionInProgressRuntimeException(String, String, Throwable)");
- jakarta.jms.TransactionInProgressRuntimeException exceptionToTest = new jakarta.jms.TransactionInProgressRuntimeException(
- reason, errorCode, exception);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.TransactionInProgressRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- if (!exceptionToTest.getCause().equals(exception)) {
- TestUtil.logErr("Incorrect cause " + exceptionToTest.getCause());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("transactionInProgressRuntimeExceptionTest3 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("transactionInProgressRuntimeExceptionTest3 Failed");
- }
-
- /*
- * @testName: resourceAllocationRuntimeExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:1440;
- *
- * @test_Strategy: Construct ResourceAllocationRuntimeException(String,
- * String)
- */
- public void resourceAllocationRuntimeExceptionTest1() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Serious";
- String reason = "Resource allocation failure due to no more resources available.";
-
- TestUtil
- .logMsg("Test ResourceAllocationRuntimeException(String, String)");
- jakarta.jms.ResourceAllocationRuntimeException exceptionToTest = new jakarta.jms.ResourceAllocationRuntimeException(
- reason, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.ResourceAllocationRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("resourceAllocationRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("resourceAllocationRuntimeExceptionTest1 Failed");
- }
-
- /*
- * @testName: resourceAllocationRuntimeExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:1441;
- *
- * @test_Strategy: Construct ResourceAllocationRuntimeException(String)
- */
- public void resourceAllocationRuntimeExceptionTest2() throws Exception {
- boolean pass = true;
- try {
- String reason = "Resource allocation failure due to no more resources available.";
-
- TestUtil.logMsg("Test ResourceAllocationRuntimeException(String)");
- jakarta.jms.ResourceAllocationRuntimeException exceptionToTest = new jakarta.jms.ResourceAllocationRuntimeException(
- reason);
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.ResourceAllocationRuntimeException e) {
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("resourceAllocationRuntimeExceptionTest2 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("resourceAllocationRuntimeExceptionTest2 Failed");
- }
-
- /*
- * @testName: resourceAllocationRuntimeExceptionTest3
- *
- * @assertion_ids: JMS:JAVADOC:1442;
- *
- * @test_Strategy: Construct ResourceAllocationRuntimeException(String,
- * String, Throwable)
- */
- public void resourceAllocationRuntimeExceptionTest3() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Serious";
- String reason = "Resource allocation failure due to no more resources available.";
- jakarta.jms.TransactionRolledBackException exception = new jakarta.jms.TransactionRolledBackException(
- reason);
-
- TestUtil.logMsg(
- "Test ResourceAllocationRuntimeException(String, String, Throwable)");
- jakarta.jms.ResourceAllocationRuntimeException exceptionToTest = new jakarta.jms.ResourceAllocationRuntimeException(
- reason, errorCode, exception);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.ResourceAllocationRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- if (!exceptionToTest.getCause().equals(exception)) {
- TestUtil.logErr("Incorrect cause " + exceptionToTest.getCause());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("resourceAllocationRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("resourceAllocationRuntimeExceptionTest3 Failed");
- }
-
- /*
- * @testName: messageNotWriteableRuntimeExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:1422;
- *
- * @test_Strategy: Construct MessageNotWriteableRuntimeException(String,
- * String)
- */
- public void messageNotWriteableRuntimeExceptionTest1() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Serious";
- String reason = "Writing operation not allowed.";
-
- TestUtil
- .logMsg("Test MessageNotWriteableRuntimeException(String, String)");
- jakarta.jms.MessageNotWriteableRuntimeException exceptionToTest = new jakarta.jms.MessageNotWriteableRuntimeException(
- reason, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.MessageNotWriteableRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("messageNotWriteableRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("messageNotWriteableRuntimeExceptionTest1 Failed");
- }
-
- /*
- * @testName: messageNotWriteableRuntimeExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:1423;
- *
- * @test_Strategy: Construct MessageNotWriteableRuntimeException(String)
- */
- public void messageNotWriteableRuntimeExceptionTest2() throws Exception {
- boolean pass = true;
- try {
- String reason = "Writing operation not allowed.";
-
- TestUtil.logMsg("Test MessageNotWriteableRuntimeException(String)");
- jakarta.jms.MessageNotWriteableRuntimeException exceptionToTest = new jakarta.jms.MessageNotWriteableRuntimeException(
- reason);
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.MessageNotWriteableRuntimeException e) {
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("messageNotWriteableRuntimeExceptionTest2 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("messageNotWriteableRuntimeExceptionTest2 Failed");
- }
-
- /*
- * @testName: messageNotWriteableRuntimeExceptionTest3
- *
- * @assertion_ids: JMS:JAVADOC:1424;
- *
- * @test_Strategy: Construct MessageNotWriteableRuntimeException(String,
- * String, Throwable)
- */
- public void messageNotWriteableRuntimeExceptionTest3() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Serious";
- String reason = "Writing operation not allowed.";
- jakarta.jms.MessageNotWriteableException exception = new jakarta.jms.MessageNotWriteableException(
- reason);
-
- TestUtil.logMsg(
- "Test MessageNotWriteableRuntimeException(String, String, Throwable)");
- jakarta.jms.MessageNotWriteableRuntimeException exceptionToTest = new jakarta.jms.MessageNotWriteableRuntimeException(
- reason, errorCode, exception);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.MessageNotWriteableRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- if (!exceptionToTest.getCause().equals(exception)) {
- TestUtil.logErr("Incorrect cause " + exceptionToTest.getCause());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("messageNotWriteableRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("messageNotWriteableRuntimeExceptionTest3 Failed");
- }
-
- /*
- * @testName: messageFormatRuntimeExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:883;
- *
- * @test_Strategy: Construct MessageFormatRuntimeException(String, String)
- */
- public void messageFormatRuntimeExceptionTest1() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Urgent";
- String reason = "Cannot convert from int to char";
-
- TestUtil.logMsg("Test MessageFormatRuntimeException(String, String)");
- jakarta.jms.MessageFormatRuntimeException exceptionToTest = new jakarta.jms.MessageFormatRuntimeException(
- reason, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.MessageFormatRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
-
- } catch (Exception e) {
- throw new Exception("messageFormatRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("messageFormatRuntimeExceptionTest1 Failed");
- }
-
- /*
- * @testName: messageFormatRuntimeExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:884;
- *
- * @test_Strategy: Construct MessageFormatRuntimeException(String)
- */
- public void messageFormatRuntimeExceptionTest2() throws Exception {
- boolean pass = true;
- try {
- String reason = "Cannot convert from int to char";
-
- TestUtil.logMsg("Test MessageFormatRuntimeException(String)");
- jakarta.jms.MessageFormatRuntimeException exceptionToTest = new jakarta.jms.MessageFormatRuntimeException(
- reason);
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.MessageFormatRuntimeException e) {
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("messageFormatRuntimeExceptionTest2 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("messageFormatRuntimeExceptionTest2 Failed");
- }
-
- /*
- * @testName: messageFormatRuntimeExceptionTest3
- *
- * @assertion_ids: JMS:JAVADOC:885;
- *
- * @test_Strategy: Construct MessageFormatRuntimeException(String, String,
- * Throwable)
- */
- public void messageFormatRuntimeExceptionTest3() throws Exception {
- boolean pass = true;
- try {
- String errorCode = "Urgent";
- String reason = "Cannot convert from int to char";
- jakarta.jms.MessageFormatException exception = new jakarta.jms.MessageFormatException(
- reason);
-
- TestUtil.logMsg(
- "Test MessageFormatRuntimeException(String, String, Throwable)");
- jakarta.jms.MessageFormatRuntimeException exceptionToTest = new jakarta.jms.MessageFormatRuntimeException(
- reason, errorCode, exception);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.MessageFormatRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- if (!exceptionToTest.getCause().equals(exception)) {
- TestUtil.logErr("Incorrect cause " + exceptionToTest.getCause());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("messageFormatRuntimeExceptionTest3 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("messageFormatRuntimeExceptionTest3 Failed");
- }
-
- /*
- * @testName: jmsSecurityRuntimeExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:871;
- *
- * @test_Strategy: Construct JMSSecurityRuntimeException(String, String)
- */
- public void jmsSecurityRuntimeExceptionTest1() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Urgent";
- String reason = "Cannot find the user.";
-
- TestUtil.logMsg("Test JMSSecurityRuntimeException(String, String)");
- jakarta.jms.JMSSecurityRuntimeException exceptionToTest = new jakarta.jms.JMSSecurityRuntimeException(
- reason, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.JMSSecurityRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
-
- } catch (Exception e) {
- throw new Exception("jmsSecurityRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("jmsSecurityRuntimeExceptionTest1 Failed");
- }
-
- /*
- * @testName: jmsSecurityRuntimeExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:872;
- *
- * @test_Strategy: Construct JMSSecurityRuntimeException(String)
- */
- public void jmsSecurityRuntimeExceptionTest2() throws Exception {
- boolean pass = true;
- try {
- String reason = "Cannot find the user.";
- TestUtil.logMsg("Test JMSSecurityRuntimeException(String)");
- jakarta.jms.JMSSecurityRuntimeException exceptionToTest = new jakarta.jms.JMSSecurityRuntimeException(
- reason);
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.JMSSecurityRuntimeException e) {
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("jmsSecurityRuntimeExceptionTest2 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("jmsSecurityRuntimeExceptionTest2 Failed");
- }
-
- /*
- * @testName: jmsSecurityRuntimeExceptionTest3
- *
- * @assertion_ids: JMS:JAVADOC:873;
- *
- * @test_Strategy: Construct JMSSecurityRuntimeException(String, String,
- * Throwable)
- */
- public void jmsSecurityRuntimeExceptionTest3() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Urgent";
- String reason = "Cannot find the user.";
- jakarta.jms.JMSSecurityException exception = new jakarta.jms.JMSSecurityException(
- reason);
-
- TestUtil.logMsg(
- "Test JMSSecurityRuntimeException(String, String, Throwable)");
- jakarta.jms.JMSSecurityRuntimeException exceptionToTest = new jakarta.jms.JMSSecurityRuntimeException(
- reason, errorCode, exception);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.JMSSecurityRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- if (!exceptionToTest.getCause().equals(exception)) {
- TestUtil.logErr("Incorrect cause " + exceptionToTest.getCause());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("jmsSecurityRuntimeExceptionTest3 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("jmsSecurityRuntimeExceptionTest3 Failed");
- }
-
- /*
- * @testName: jmsRuntimeExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:867; JMS:JAVADOC:865;
- *
- * @test_Strategy: Construct JMSRuntimeException(String, String)
- */
- public void jmsRuntimeExceptionTest1() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Warning";
- String reason = "Not a JMS operation";
-
- TestUtil.logMsg("Test JMSRuntimeException(String, String)");
- jakarta.jms.JMSRuntimeException exceptionToTest = new jakarta.jms.JMSRuntimeException(
- reason, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.JMSRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
-
- } catch (Exception e) {
- throw new Exception("jmsRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("jmsRuntimeExceptionTest1 Failed");
- }
-
- /*
- * @testName: jmsRuntimeExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:868;
- *
- * @test_Strategy: Construct JMSRuntimeException(String)
- */
- public void jmsRuntimeExceptionTest2() throws Exception {
- boolean pass = true;
-
- try {
- String reason = "Not a JMS operation";
-
- TestUtil.logMsg("Test JMSRuntimeException(String)");
- jakarta.jms.JMSRuntimeException exceptionToTest = new jakarta.jms.JMSRuntimeException(
- reason);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.JMSRuntimeException e) {
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
-
- } catch (Exception e) {
- throw new Exception("jmsRuntimeExceptionTest2 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("jmsRuntimeExceptionTest2 Failed");
- }
-
- /*
- * @testName: jmsRuntimeExceptionTest3
- *
- * @assertion_ids: JMS:JAVADOC:869;
- *
- * @test_Strategy: Construct JMSRuntimeException(String, String, Throwable)
- */
- public void jmsRuntimeExceptionTest3() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Warning";
- String reason = "Not a JMS operation";
- jakarta.jms.JMSException exception = new jakarta.jms.JMSException(reason);
-
- TestUtil.logMsg("Test JMSRuntimeException(String, String, Throwable)");
- jakarta.jms.JMSRuntimeException exceptionToTest = new jakarta.jms.JMSRuntimeException(
- reason, errorCode, exception);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.JMSRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- if (!exceptionToTest.getCause().equals(exception)) {
- TestUtil.logErr("Incorrect cause " + exceptionToTest.getCause());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("jmsRuntimeExceptionTest3 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("jmsRuntimeExceptionTest3 Failed");
- }
-
- /*
- * @testName: invalidSelectorRuntimeExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:862;
- *
- * @test_Strategy: Construct InvalidSelectorRuntimeException(String, String)
- */
- public void invalidSelectorRuntimeExceptionTest1() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Urgent";
- String reason = "unknown variable";
-
- TestUtil.logMsg("Test InvalidSelectorRuntimeException(String, String)");
- jakarta.jms.InvalidSelectorRuntimeException exceptionToTest = new jakarta.jms.InvalidSelectorRuntimeException(
- reason, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.InvalidSelectorRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
-
- } catch (Exception e) {
- throw new Exception("invalidSelectorRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("invalidSelectorRuntimeExceptionTest1 Failed");
- }
-
- /*
- * @testName: invalidSelectorRuntimeExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:863;
- *
- * @test_Strategy: Construct InvalidSelectorRuntimeException(String)
- */
- public void invalidSelectorRuntimeExceptionTest2() throws Exception {
- boolean pass = true;
- try {
- String reason = "unknown variable";
-
- TestUtil.logMsg("Test InvalidSelectorRuntimeException(String)");
- jakarta.jms.InvalidSelectorRuntimeException exceptionToTest = new jakarta.jms.InvalidSelectorRuntimeException(
- reason);
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.InvalidSelectorRuntimeException e) {
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("invalidSelectorRuntimeExceptionTest2 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("invalidSelectorRuntimeExceptionTest2 Failed");
- }
-
- /*
- * @testName: invalidSelectorRuntimeExceptionTest3
- *
- * @assertion_ids: JMS:JAVADOC:864;
- *
- * @test_Strategy: Construct InvalidSelectorRuntimeException(String, String,
- * Throwable)
- */
- public void invalidSelectorRuntimeExceptionTest3() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Urgent";
- String reason = "unknown variable";
- jakarta.jms.InvalidSelectorException exception = new jakarta.jms.InvalidSelectorException(
- reason);
-
- TestUtil.logMsg(
- "Test InvalidSelectorRuntimeException(String, String, Throwable)");
- jakarta.jms.InvalidSelectorRuntimeException exceptionToTest = new jakarta.jms.InvalidSelectorRuntimeException(
- reason, errorCode, exception);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.InvalidSelectorRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- if (!exceptionToTest.getCause().equals(exception)) {
- TestUtil.logErr("Incorrect cause " + exceptionToTest.getCause());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("invalidSelectorRuntimeExceptionTest3 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("invalidSelectorRuntimeExceptionTest3 Failed");
- }
-
- /*
- * @testName: invalidDestinationRuntimeExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:859;
- *
- * @test_Strategy: Construct InvalidDestinationRuntimeException(String,
- * String)
- */
- public void invalidDestinationRuntimeExceptionTest1() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Urgent";
- String reason = "Destination is Null";
-
- TestUtil
- .logMsg("Test InvalidDestinationRuntimeException(String, String)");
- jakarta.jms.InvalidDestinationRuntimeException exceptionToTest = new jakarta.jms.InvalidDestinationRuntimeException(
- reason, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.InvalidDestinationRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
-
- } catch (Exception e) {
- throw new Exception("invalidDestinationRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("invalidDestinationRuntimeExceptionTest1 Failed");
- }
-
- /*
- * @testName: invalidDestinationRuntimeExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:860;
- *
- * @test_Strategy: Construct InvalidDestinationRuntimeException(String)
- */
- public void invalidDestinationRuntimeExceptionTest2() throws Exception {
- boolean pass = true;
- try {
- String reason = "Destination is Null";
-
- TestUtil.logMsg("Test InvalidDestinationRuntimeException(String)");
- jakarta.jms.InvalidDestinationRuntimeException exceptionToTest = new jakarta.jms.InvalidDestinationRuntimeException(
- reason);
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.InvalidDestinationRuntimeException e) {
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("invalidDestinationRuntimeExceptionTest2 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("invalidDestinationRuntimeExceptionTest2 Failed");
- }
-
- /*
- * @testName: invalidDestinationRuntimeExceptionTest3
- *
- * @assertion_ids: JMS:JAVADOC:861;
- *
- * @test_Strategy: Construct InvalidDestinationRuntimeException(String,
- * String, Throwable)
- */
- public void invalidDestinationRuntimeExceptionTest3() throws Exception {
- boolean pass = true;
- try {
- String errorCode = "Urgent";
- String reason = "Destination is Null";
- jakarta.jms.InvalidDestinationException exception = new jakarta.jms.InvalidDestinationException(
- reason);
-
- TestUtil.logMsg(
- "Test InvalidDestinationRuntimeException(String, String, Throwable)");
- jakarta.jms.InvalidDestinationRuntimeException exceptionToTest = new jakarta.jms.InvalidDestinationRuntimeException(
- reason, errorCode, exception);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.InvalidDestinationRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- if (!exceptionToTest.getCause().equals(exception)) {
- TestUtil.logErr("Incorrect cause " + exceptionToTest.getCause());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("invalidDestinationRuntimeExceptionTest3 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("invalidDestinationRuntimeExceptionTest3 Failed");
- }
-
- /*
- * @testName: invalidClientIDRuntimeExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:856;
- *
- * @test_Strategy: Construct InvalidClientIDRuntimeException(String, String)
- */
- public void invalidClientIDRuntimeExceptionTest1() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Urgent";
- String reason = "Duplicate Client ID";
-
- TestUtil.logMsg("Test InvalidClientIDRuntimeException(String, String)");
- jakarta.jms.InvalidClientIDRuntimeException exceptionToTest = new jakarta.jms.InvalidClientIDRuntimeException(
- reason, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.InvalidClientIDRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
-
- } catch (Exception e) {
- throw new Exception("invalidClientIDRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("invalidClientIDRuntimeExceptionTest1 Failed");
- }
-
- /*
- * @testName: invalidClientIDRuntimeExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:857;
- *
- * @test_Strategy: Construct InvalidClientIDRuntimeException(String)
- */
- public void invalidClientIDRuntimeExceptionTest2() throws Exception {
- boolean pass = true;
- try {
- String reason = "Duplicate Client ID";
-
- TestUtil.logMsg("Test InvalidClientIDRuntimeException(String)");
- jakarta.jms.InvalidClientIDRuntimeException exceptionToTest = new jakarta.jms.InvalidClientIDRuntimeException(
- reason);
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.InvalidClientIDRuntimeException e) {
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("invalidClientIDRuntimeExceptionTest2 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("invalidClientIDRuntimeExceptionTest2 Failed");
- }
-
- /*
- * @testName: invalidClientIDRuntimeExceptionTest3
- *
- * @assertion_ids: JMS:JAVADOC:858;
- *
- * @test_Strategy: Construct InvalidClientIDRuntimeException(String, String,
- * Throwable)
- */
- public void invalidClientIDRuntimeExceptionTest3() throws Exception {
- boolean pass = true;
- try {
- String errorCode = "Urgent";
- String reason = "Duplicate Client ID";
- jakarta.jms.InvalidClientIDException exception = new jakarta.jms.InvalidClientIDException(
- reason);
-
- TestUtil.logMsg(
- "Test InvalidClientIDRuntimeException(String, String, Throwable)");
- jakarta.jms.InvalidClientIDRuntimeException exceptionToTest = new jakarta.jms.InvalidClientIDRuntimeException(
- reason, errorCode, exception);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.InvalidClientIDRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- if (!exceptionToTest.getCause().equals(exception)) {
- TestUtil.logErr("Incorrect cause " + exceptionToTest.getCause());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("invalidClientIDRuntimeExceptionTest3 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("invalidClientIDRuntimeExceptionTest3 Failed");
- }
-
- /*
- * @testName: illegalStateRuntimeExceptionTest1
- *
- * @assertion_ids: JMS:JAVADOC:853;
- *
- * @test_Strategy: Construct IllegalStateRuntimeException(String, String)
- */
- public void illegalStateRuntimeExceptionTest1() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Urgent";
- String reason = "The operation is illegal.";
-
- TestUtil.logMsg("Test IllegalStateRuntimeException(String, String)");
- jakarta.jms.IllegalStateRuntimeException exceptionToTest = new jakarta.jms.IllegalStateRuntimeException(
- reason, errorCode);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
-
- } catch (Exception e) {
- throw new Exception("IllegalStateRuntimeExceptionTest1 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("IllegalStateRuntimeExceptionTest1 Failed");
- }
-
- /*
- * @testName: illegalStateRuntimeExceptionTest2
- *
- * @assertion_ids: JMS:JAVADOC:854;
- *
- * @test_Strategy: Construct IllegalStateRuntimeException(String)
- */
- public void illegalStateRuntimeExceptionTest2() throws Exception {
- boolean pass = true;
-
- try {
- String reason = "The operation is illegal.";
-
- TestUtil.logMsg("Test IllegalStateRuntimeException(String)");
- jakarta.jms.IllegalStateRuntimeException exceptionToTest = new jakarta.jms.IllegalStateRuntimeException(
- reason);
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- }
-
- } catch (Exception e) {
- throw new Exception("illegalStateRuntimeExceptionTest2 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("IllegalStateRuntimeExceptionTest2 Failed");
- }
-
- /*
- * @testName: illegalStateRuntimeExceptionTest3
- *
- * @assertion_ids: JMS:JAVADOC:855;
- *
- * @test_Strategy: Construct IllegalStateRuntimeException(String, String,
- * Throwable)
- */
- public void illegalStateRuntimeExceptionTest3() throws Exception {
- boolean pass = true;
-
- try {
- String errorCode = "Urgent";
- String reason = "The operation is illegal.";
- jakarta.jms.IllegalStateException exception = new jakarta.jms.IllegalStateException(
- reason);
-
- TestUtil.logMsg(
- "Test IllegalStateRuntimeException(String, String, Throwable)");
- jakarta.jms.IllegalStateRuntimeException exceptionToTest = new jakarta.jms.IllegalStateRuntimeException(
- reason, errorCode, exception);
-
- try {
- throw exceptionToTest;
- } catch (jakarta.jms.IllegalStateRuntimeException e) {
- if (!exceptionToTest.getErrorCode().equals(errorCode)) {
- TestUtil
- .logErr("Incorrect ErrorCode " + exceptionToTest.getErrorCode());
- pass = false;
- }
- if (!exceptionToTest.getMessage().equals(reason)) {
- TestUtil.logErr("Incorrect reason " + exceptionToTest.getMessage());
- pass = false;
- }
- if (!exceptionToTest.getCause().equals(exception)) {
- TestUtil.logErr("Incorrect cause " + exceptionToTest.getCause());
- pass = false;
- }
- }
- } catch (Exception e) {
- throw new Exception("illegalStateRuntimeExceptionTest3 Failed: ", e);
- }
-
- if (!pass)
- throw new Exception("illegalStateRuntimeExceptionTest3 Failed");
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/runtimeexceptiontests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/runtimeexceptiontests/ClientIT.java
new file mode 100644
index 0000000000..69ef0e6067
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/runtimeexceptiontests/ClientIT.java
@@ -0,0 +1,1351 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.core20.runtimeexceptiontests;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.runtimeexceptiontests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props:
+ *
+ * @exception Fault
+ */
+
+ @BeforeEach
+ public void setup() throws Exception {
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ }
+
+ /* Tests */
+
+ /*
+ * @testName: transactionRolledBackRuntimeExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1117;
+ *
+ * @test_Strategy: Construct TransactionRolledBackRuntimeException(String,
+ * String)
+ */
+ @Test
+ public void transactionRolledBackRuntimeExceptionTest1() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Serious";
+ String reason = "Rollback operation not allowed.";
+
+ logger.log(Logger.Level.INFO, "Test TransactionRolledBackRuntimeException(String, String)");
+ jakarta.jms.TransactionRolledBackRuntimeException exceptionToTest = new jakarta.jms.TransactionRolledBackRuntimeException(
+ reason, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.TransactionRolledBackRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("transactionRolledBackRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("transactionRolledBackRuntimeExceptionTest1 Failed");
+ }
+
+ /*
+ * @testName: transactionRolledBackRuntimeExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1118;
+ *
+ * @test_Strategy: Construct TransactionRolledBackRuntimeException(String)
+ */
+ @Test
+ public void transactionRolledBackRuntimeExceptionTest2() throws Exception {
+ boolean pass = true;
+ try {
+ String reason = "Rollback operation not allowed.";
+
+ logger.log(Logger.Level.INFO, "Test TransactionRolledBackRuntimeException(String)");
+ jakarta.jms.TransactionRolledBackRuntimeException exceptionToTest = new jakarta.jms.TransactionRolledBackRuntimeException(
+ reason);
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.TransactionRolledBackRuntimeException e) {
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("transactionRolledBackRuntimeExceptionTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("transactionRolledBackRuntimeExceptionTest2 Failed");
+ }
+
+ /*
+ * @testName: transactionRolledBackRuntimeExceptionTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:1119;
+ *
+ * @test_Strategy: Construct TransactionRolledBackRuntimeException(String,
+ * String, Throwable)
+ */
+ @Test
+ public void transactionRolledBackRuntimeExceptionTest3() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Serious";
+ String reason = "Rollback operation not allowed.";
+ jakarta.jms.TransactionRolledBackException exception = new jakarta.jms.TransactionRolledBackException(
+ reason);
+
+ logger.log(Logger.Level.INFO, "Test TransactionRolledBackRuntimeException(String, String, Throwable)");
+ jakarta.jms.TransactionRolledBackRuntimeException exceptionToTest = new jakarta.jms.TransactionRolledBackRuntimeException(
+ reason, errorCode, exception);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.TransactionRolledBackRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ if (!exceptionToTest.getCause().equals(exception)) {
+ logger.log(Logger.Level.ERROR, "Incorrect cause " + exceptionToTest.getCause());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("transactionRolledBackRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("transactionRolledBackRuntimeExceptionTest3 Failed");
+ }
+
+ /*
+ * @testName: transactionInProgressRuntimeExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1402;
+ *
+ * @test_Strategy: Construct TransactionInProgressRuntimeException(String,
+ * String)
+ */
+ @Test
+ public void transactionInProgressRuntimeExceptionTest1() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Serious";
+ String reason = "Transaction already in progress.";
+
+ logger.log(Logger.Level.INFO, "Test TransactionInProgressRuntimeException(String, String)");
+ jakarta.jms.TransactionInProgressRuntimeException exceptionToTest = new jakarta.jms.TransactionInProgressRuntimeException(
+ reason, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.TransactionInProgressRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("transactionInProgressRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("transactionInProgressRuntimeExceptionTest1 Failed");
+ }
+
+ /*
+ * @testName: transactionInProgressRuntimeExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1403;
+ *
+ * @test_Strategy: Construct TransactionInProgressRuntimeException(String)
+ */
+ @Test
+ public void transactionInProgressRuntimeExceptionTest2() throws Exception {
+ boolean pass = true;
+ try {
+ String reason = "Transaction already in progress.";
+
+ logger.log(Logger.Level.INFO, "Test TransactionInProgressRuntimeException(String)");
+ jakarta.jms.TransactionInProgressRuntimeException exceptionToTest = new jakarta.jms.TransactionInProgressRuntimeException(
+ reason);
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.TransactionInProgressRuntimeException e) {
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("transactionInProgressRuntimeExceptionTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("transactionInProgressRuntimeExceptionTest2 Failed");
+ }
+
+ /*
+ * @testName: transactionInProgressRuntimeExceptionTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:1439;
+ *
+ * @test_Strategy: Construct TransactionInProgressRuntimeException(String,
+ * String, Throwable)
+ */
+ @Test
+ public void transactionInProgressRuntimeExceptionTest3() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Serious";
+ String reason = "Transaction already in progress.";
+ jakarta.jms.TransactionInProgressRuntimeException exception = new jakarta.jms.TransactionInProgressRuntimeException(
+ reason);
+
+ logger.log(Logger.Level.INFO, "Test TransactionInProgressRuntimeException(String, String, Throwable)");
+ jakarta.jms.TransactionInProgressRuntimeException exceptionToTest = new jakarta.jms.TransactionInProgressRuntimeException(
+ reason, errorCode, exception);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.TransactionInProgressRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ if (!exceptionToTest.getCause().equals(exception)) {
+ logger.log(Logger.Level.ERROR, "Incorrect cause " + exceptionToTest.getCause());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("transactionInProgressRuntimeExceptionTest3 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("transactionInProgressRuntimeExceptionTest3 Failed");
+ }
+
+ /*
+ * @testName: resourceAllocationRuntimeExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1440;
+ *
+ * @test_Strategy: Construct ResourceAllocationRuntimeException(String, String)
+ */
+ @Test
+ public void resourceAllocationRuntimeExceptionTest1() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Serious";
+ String reason = "Resource allocation failure due to no more resources available.";
+
+ logger.log(Logger.Level.INFO, "Test ResourceAllocationRuntimeException(String, String)");
+ jakarta.jms.ResourceAllocationRuntimeException exceptionToTest = new jakarta.jms.ResourceAllocationRuntimeException(
+ reason, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.ResourceAllocationRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("resourceAllocationRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("resourceAllocationRuntimeExceptionTest1 Failed");
+ }
+
+ /*
+ * @testName: resourceAllocationRuntimeExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1441;
+ *
+ * @test_Strategy: Construct ResourceAllocationRuntimeException(String)
+ */
+ @Test
+ public void resourceAllocationRuntimeExceptionTest2() throws Exception {
+ boolean pass = true;
+ try {
+ String reason = "Resource allocation failure due to no more resources available.";
+
+ logger.log(Logger.Level.INFO, "Test ResourceAllocationRuntimeException(String)");
+ jakarta.jms.ResourceAllocationRuntimeException exceptionToTest = new jakarta.jms.ResourceAllocationRuntimeException(
+ reason);
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.ResourceAllocationRuntimeException e) {
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("resourceAllocationRuntimeExceptionTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("resourceAllocationRuntimeExceptionTest2 Failed");
+ }
+
+ /*
+ * @testName: resourceAllocationRuntimeExceptionTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:1442;
+ *
+ * @test_Strategy: Construct ResourceAllocationRuntimeException(String, String,
+ * Throwable)
+ */
+ @Test
+ public void resourceAllocationRuntimeExceptionTest3() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Serious";
+ String reason = "Resource allocation failure due to no more resources available.";
+ jakarta.jms.TransactionRolledBackException exception = new jakarta.jms.TransactionRolledBackException(
+ reason);
+
+ logger.log(Logger.Level.INFO, "Test ResourceAllocationRuntimeException(String, String, Throwable)");
+ jakarta.jms.ResourceAllocationRuntimeException exceptionToTest = new jakarta.jms.ResourceAllocationRuntimeException(
+ reason, errorCode, exception);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.ResourceAllocationRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ if (!exceptionToTest.getCause().equals(exception)) {
+ logger.log(Logger.Level.ERROR, "Incorrect cause " + exceptionToTest.getCause());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("resourceAllocationRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("resourceAllocationRuntimeExceptionTest3 Failed");
+ }
+
+ /*
+ * @testName: messageNotWriteableRuntimeExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1422;
+ *
+ * @test_Strategy: Construct MessageNotWriteableRuntimeException(String, String)
+ */
+ @Test
+ public void messageNotWriteableRuntimeExceptionTest1() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Serious";
+ String reason = "Writing operation not allowed.";
+
+ logger.log(Logger.Level.INFO, "Test MessageNotWriteableRuntimeException(String, String)");
+ jakarta.jms.MessageNotWriteableRuntimeException exceptionToTest = new jakarta.jms.MessageNotWriteableRuntimeException(
+ reason, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.MessageNotWriteableRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("messageNotWriteableRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("messageNotWriteableRuntimeExceptionTest1 Failed");
+ }
+
+ /*
+ * @testName: messageNotWriteableRuntimeExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1423;
+ *
+ * @test_Strategy: Construct MessageNotWriteableRuntimeException(String)
+ */
+ @Test
+ public void messageNotWriteableRuntimeExceptionTest2() throws Exception {
+ boolean pass = true;
+ try {
+ String reason = "Writing operation not allowed.";
+
+ logger.log(Logger.Level.INFO, "Test MessageNotWriteableRuntimeException(String)");
+ jakarta.jms.MessageNotWriteableRuntimeException exceptionToTest = new jakarta.jms.MessageNotWriteableRuntimeException(
+ reason);
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.MessageNotWriteableRuntimeException e) {
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("messageNotWriteableRuntimeExceptionTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("messageNotWriteableRuntimeExceptionTest2 Failed");
+ }
+
+ /*
+ * @testName: messageNotWriteableRuntimeExceptionTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:1424;
+ *
+ * @test_Strategy: Construct MessageNotWriteableRuntimeException(String, String,
+ * Throwable)
+ */
+ @Test
+ public void messageNotWriteableRuntimeExceptionTest3() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Serious";
+ String reason = "Writing operation not allowed.";
+ jakarta.jms.MessageNotWriteableException exception = new jakarta.jms.MessageNotWriteableException(reason);
+
+ logger.log(Logger.Level.INFO, "Test MessageNotWriteableRuntimeException(String, String, Throwable)");
+ jakarta.jms.MessageNotWriteableRuntimeException exceptionToTest = new jakarta.jms.MessageNotWriteableRuntimeException(
+ reason, errorCode, exception);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.MessageNotWriteableRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ if (!exceptionToTest.getCause().equals(exception)) {
+ logger.log(Logger.Level.ERROR, "Incorrect cause " + exceptionToTest.getCause());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("messageNotWriteableRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("messageNotWriteableRuntimeExceptionTest3 Failed");
+ }
+
+ /*
+ * @testName: messageFormatRuntimeExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:883;
+ *
+ * @test_Strategy: Construct MessageFormatRuntimeException(String, String)
+ */
+ @Test
+ public void messageFormatRuntimeExceptionTest1() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Urgent";
+ String reason = "Cannot convert from int to char";
+
+ logger.log(Logger.Level.INFO, "Test MessageFormatRuntimeException(String, String)");
+ jakarta.jms.MessageFormatRuntimeException exceptionToTest = new jakarta.jms.MessageFormatRuntimeException(
+ reason, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.MessageFormatRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+
+ } catch (Exception e) {
+ throw new Exception("messageFormatRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("messageFormatRuntimeExceptionTest1 Failed");
+ }
+
+ /*
+ * @testName: messageFormatRuntimeExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:884;
+ *
+ * @test_Strategy: Construct MessageFormatRuntimeException(String)
+ */
+ @Test
+ public void messageFormatRuntimeExceptionTest2() throws Exception {
+ boolean pass = true;
+ try {
+ String reason = "Cannot convert from int to char";
+
+ logger.log(Logger.Level.INFO, "Test MessageFormatRuntimeException(String)");
+ jakarta.jms.MessageFormatRuntimeException exceptionToTest = new jakarta.jms.MessageFormatRuntimeException(
+ reason);
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.MessageFormatRuntimeException e) {
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("messageFormatRuntimeExceptionTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("messageFormatRuntimeExceptionTest2 Failed");
+ }
+
+ /*
+ * @testName: messageFormatRuntimeExceptionTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:885;
+ *
+ * @test_Strategy: Construct MessageFormatRuntimeException(String, String,
+ * Throwable)
+ */
+ @Test
+ public void messageFormatRuntimeExceptionTest3() throws Exception {
+ boolean pass = true;
+ try {
+ String errorCode = "Urgent";
+ String reason = "Cannot convert from int to char";
+ jakarta.jms.MessageFormatException exception = new jakarta.jms.MessageFormatException(reason);
+
+ logger.log(Logger.Level.INFO, "Test MessageFormatRuntimeException(String, String, Throwable)");
+ jakarta.jms.MessageFormatRuntimeException exceptionToTest = new jakarta.jms.MessageFormatRuntimeException(
+ reason, errorCode, exception);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.MessageFormatRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ if (!exceptionToTest.getCause().equals(exception)) {
+ logger.log(Logger.Level.ERROR, "Incorrect cause " + exceptionToTest.getCause());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("messageFormatRuntimeExceptionTest3 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("messageFormatRuntimeExceptionTest3 Failed");
+ }
+
+ /*
+ * @testName: jmsSecurityRuntimeExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:871;
+ *
+ * @test_Strategy: Construct JMSSecurityRuntimeException(String, String)
+ */
+ @Test
+ public void jmsSecurityRuntimeExceptionTest1() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Urgent";
+ String reason = "Cannot find the user.";
+
+ logger.log(Logger.Level.INFO, "Test JMSSecurityRuntimeException(String, String)");
+ jakarta.jms.JMSSecurityRuntimeException exceptionToTest = new jakarta.jms.JMSSecurityRuntimeException(
+ reason, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.JMSSecurityRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+
+ } catch (Exception e) {
+ throw new Exception("jmsSecurityRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("jmsSecurityRuntimeExceptionTest1 Failed");
+ }
+
+ /*
+ * @testName: jmsSecurityRuntimeExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:872;
+ *
+ * @test_Strategy: Construct JMSSecurityRuntimeException(String)
+ */
+ @Test
+ public void jmsSecurityRuntimeExceptionTest2() throws Exception {
+ boolean pass = true;
+ try {
+ String reason = "Cannot find the user.";
+ logger.log(Logger.Level.INFO, "Test JMSSecurityRuntimeException(String)");
+ jakarta.jms.JMSSecurityRuntimeException exceptionToTest = new jakarta.jms.JMSSecurityRuntimeException(
+ reason);
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.JMSSecurityRuntimeException e) {
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("jmsSecurityRuntimeExceptionTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("jmsSecurityRuntimeExceptionTest2 Failed");
+ }
+
+ /*
+ * @testName: jmsSecurityRuntimeExceptionTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:873;
+ *
+ * @test_Strategy: Construct JMSSecurityRuntimeException(String, String,
+ * Throwable)
+ */
+ @Test
+ public void jmsSecurityRuntimeExceptionTest3() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Urgent";
+ String reason = "Cannot find the user.";
+ jakarta.jms.JMSSecurityException exception = new jakarta.jms.JMSSecurityException(reason);
+
+ logger.log(Logger.Level.INFO, "Test JMSSecurityRuntimeException(String, String, Throwable)");
+ jakarta.jms.JMSSecurityRuntimeException exceptionToTest = new jakarta.jms.JMSSecurityRuntimeException(
+ reason, errorCode, exception);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.JMSSecurityRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ if (!exceptionToTest.getCause().equals(exception)) {
+ logger.log(Logger.Level.ERROR, "Incorrect cause " + exceptionToTest.getCause());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("jmsSecurityRuntimeExceptionTest3 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("jmsSecurityRuntimeExceptionTest3 Failed");
+ }
+
+ /*
+ * @testName: jmsRuntimeExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:867; JMS:JAVADOC:865;
+ *
+ * @test_Strategy: Construct JMSRuntimeException(String, String)
+ */
+ @Test
+ public void jmsRuntimeExceptionTest1() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Warning";
+ String reason = "Not a JMS operation";
+
+ logger.log(Logger.Level.INFO, "Test JMSRuntimeException(String, String)");
+ jakarta.jms.JMSRuntimeException exceptionToTest = new jakarta.jms.JMSRuntimeException(reason, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.JMSRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+
+ } catch (Exception e) {
+ throw new Exception("jmsRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("jmsRuntimeExceptionTest1 Failed");
+ }
+
+ /*
+ * @testName: jmsRuntimeExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:868;
+ *
+ * @test_Strategy: Construct JMSRuntimeException(String)
+ */
+ @Test
+ public void jmsRuntimeExceptionTest2() throws Exception {
+ boolean pass = true;
+
+ try {
+ String reason = "Not a JMS operation";
+
+ logger.log(Logger.Level.INFO, "Test JMSRuntimeException(String)");
+ jakarta.jms.JMSRuntimeException exceptionToTest = new jakarta.jms.JMSRuntimeException(reason);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.JMSRuntimeException e) {
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+
+ } catch (Exception e) {
+ throw new Exception("jmsRuntimeExceptionTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("jmsRuntimeExceptionTest2 Failed");
+ }
+
+ /*
+ * @testName: jmsRuntimeExceptionTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:869;
+ *
+ * @test_Strategy: Construct JMSRuntimeException(String, String, Throwable)
+ */
+ @Test
+ public void jmsRuntimeExceptionTest3() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Warning";
+ String reason = "Not a JMS operation";
+ jakarta.jms.JMSException exception = new jakarta.jms.JMSException(reason);
+
+ logger.log(Logger.Level.INFO, "Test JMSRuntimeException(String, String, Throwable)");
+ jakarta.jms.JMSRuntimeException exceptionToTest = new jakarta.jms.JMSRuntimeException(reason, errorCode,
+ exception);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.JMSRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ if (!exceptionToTest.getCause().equals(exception)) {
+ logger.log(Logger.Level.ERROR, "Incorrect cause " + exceptionToTest.getCause());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("jmsRuntimeExceptionTest3 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("jmsRuntimeExceptionTest3 Failed");
+ }
+
+ /*
+ * @testName: invalidSelectorRuntimeExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:862;
+ *
+ * @test_Strategy: Construct InvalidSelectorRuntimeException(String, String)
+ */
+ @Test
+ public void invalidSelectorRuntimeExceptionTest1() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Urgent";
+ String reason = "unknown variable";
+
+ logger.log(Logger.Level.INFO, "Test InvalidSelectorRuntimeException(String, String)");
+ jakarta.jms.InvalidSelectorRuntimeException exceptionToTest = new jakarta.jms.InvalidSelectorRuntimeException(
+ reason, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.InvalidSelectorRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+
+ } catch (Exception e) {
+ throw new Exception("invalidSelectorRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("invalidSelectorRuntimeExceptionTest1 Failed");
+ }
+
+ /*
+ * @testName: invalidSelectorRuntimeExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:863;
+ *
+ * @test_Strategy: Construct InvalidSelectorRuntimeException(String)
+ */
+ @Test
+ public void invalidSelectorRuntimeExceptionTest2() throws Exception {
+ boolean pass = true;
+ try {
+ String reason = "unknown variable";
+
+ logger.log(Logger.Level.INFO, "Test InvalidSelectorRuntimeException(String)");
+ jakarta.jms.InvalidSelectorRuntimeException exceptionToTest = new jakarta.jms.InvalidSelectorRuntimeException(
+ reason);
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.InvalidSelectorRuntimeException e) {
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("invalidSelectorRuntimeExceptionTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("invalidSelectorRuntimeExceptionTest2 Failed");
+ }
+
+ /*
+ * @testName: invalidSelectorRuntimeExceptionTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:864;
+ *
+ * @test_Strategy: Construct InvalidSelectorRuntimeException(String, String,
+ * Throwable)
+ */
+ @Test
+ public void invalidSelectorRuntimeExceptionTest3() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Urgent";
+ String reason = "unknown variable";
+ jakarta.jms.InvalidSelectorException exception = new jakarta.jms.InvalidSelectorException(reason);
+
+ logger.log(Logger.Level.INFO, "Test InvalidSelectorRuntimeException(String, String, Throwable)");
+ jakarta.jms.InvalidSelectorRuntimeException exceptionToTest = new jakarta.jms.InvalidSelectorRuntimeException(
+ reason, errorCode, exception);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.InvalidSelectorRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ if (!exceptionToTest.getCause().equals(exception)) {
+ logger.log(Logger.Level.ERROR, "Incorrect cause " + exceptionToTest.getCause());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("invalidSelectorRuntimeExceptionTest3 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("invalidSelectorRuntimeExceptionTest3 Failed");
+ }
+
+ /*
+ * @testName: invalidDestinationRuntimeExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:859;
+ *
+ * @test_Strategy: Construct InvalidDestinationRuntimeException(String, String)
+ */
+ @Test
+ public void invalidDestinationRuntimeExceptionTest1() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Urgent";
+ String reason = "Destination is Null";
+
+ logger.log(Logger.Level.INFO, "Test InvalidDestinationRuntimeException(String, String)");
+ jakarta.jms.InvalidDestinationRuntimeException exceptionToTest = new jakarta.jms.InvalidDestinationRuntimeException(
+ reason, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.InvalidDestinationRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+
+ } catch (Exception e) {
+ throw new Exception("invalidDestinationRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("invalidDestinationRuntimeExceptionTest1 Failed");
+ }
+
+ /*
+ * @testName: invalidDestinationRuntimeExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:860;
+ *
+ * @test_Strategy: Construct InvalidDestinationRuntimeException(String)
+ */
+ @Test
+ public void invalidDestinationRuntimeExceptionTest2() throws Exception {
+ boolean pass = true;
+ try {
+ String reason = "Destination is Null";
+
+ logger.log(Logger.Level.INFO, "Test InvalidDestinationRuntimeException(String)");
+ jakarta.jms.InvalidDestinationRuntimeException exceptionToTest = new jakarta.jms.InvalidDestinationRuntimeException(
+ reason);
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.InvalidDestinationRuntimeException e) {
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("invalidDestinationRuntimeExceptionTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("invalidDestinationRuntimeExceptionTest2 Failed");
+ }
+
+ /*
+ * @testName: invalidDestinationRuntimeExceptionTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:861;
+ *
+ * @test_Strategy: Construct InvalidDestinationRuntimeException(String, String,
+ * Throwable)
+ */
+ @Test
+ public void invalidDestinationRuntimeExceptionTest3() throws Exception {
+ boolean pass = true;
+ try {
+ String errorCode = "Urgent";
+ String reason = "Destination is Null";
+ jakarta.jms.InvalidDestinationException exception = new jakarta.jms.InvalidDestinationException(reason);
+
+ logger.log(Logger.Level.INFO, "Test InvalidDestinationRuntimeException(String, String, Throwable)");
+ jakarta.jms.InvalidDestinationRuntimeException exceptionToTest = new jakarta.jms.InvalidDestinationRuntimeException(
+ reason, errorCode, exception);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.InvalidDestinationRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ if (!exceptionToTest.getCause().equals(exception)) {
+ logger.log(Logger.Level.ERROR, "Incorrect cause " + exceptionToTest.getCause());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("invalidDestinationRuntimeExceptionTest3 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("invalidDestinationRuntimeExceptionTest3 Failed");
+ }
+
+ /*
+ * @testName: invalidClientIDRuntimeExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:856;
+ *
+ * @test_Strategy: Construct InvalidClientIDRuntimeException(String, String)
+ */
+ @Test
+ public void invalidClientIDRuntimeExceptionTest1() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Urgent";
+ String reason = "Duplicate Client ID";
+
+ logger.log(Logger.Level.INFO, "Test InvalidClientIDRuntimeException(String, String)");
+ jakarta.jms.InvalidClientIDRuntimeException exceptionToTest = new jakarta.jms.InvalidClientIDRuntimeException(
+ reason, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.InvalidClientIDRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+
+ } catch (Exception e) {
+ throw new Exception("invalidClientIDRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("invalidClientIDRuntimeExceptionTest1 Failed");
+ }
+
+ /*
+ * @testName: invalidClientIDRuntimeExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:857;
+ *
+ * @test_Strategy: Construct InvalidClientIDRuntimeException(String)
+ */
+ @Test
+ public void invalidClientIDRuntimeExceptionTest2() throws Exception {
+ boolean pass = true;
+ try {
+ String reason = "Duplicate Client ID";
+
+ logger.log(Logger.Level.INFO, "Test InvalidClientIDRuntimeException(String)");
+ jakarta.jms.InvalidClientIDRuntimeException exceptionToTest = new jakarta.jms.InvalidClientIDRuntimeException(
+ reason);
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.InvalidClientIDRuntimeException e) {
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("invalidClientIDRuntimeExceptionTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("invalidClientIDRuntimeExceptionTest2 Failed");
+ }
+
+ /*
+ * @testName: invalidClientIDRuntimeExceptionTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:858;
+ *
+ * @test_Strategy: Construct InvalidClientIDRuntimeException(String, String,
+ * Throwable)
+ */
+ @Test
+ public void invalidClientIDRuntimeExceptionTest3() throws Exception {
+ boolean pass = true;
+ try {
+ String errorCode = "Urgent";
+ String reason = "Duplicate Client ID";
+ jakarta.jms.InvalidClientIDException exception = new jakarta.jms.InvalidClientIDException(reason);
+
+ logger.log(Logger.Level.INFO, "Test InvalidClientIDRuntimeException(String, String, Throwable)");
+ jakarta.jms.InvalidClientIDRuntimeException exceptionToTest = new jakarta.jms.InvalidClientIDRuntimeException(
+ reason, errorCode, exception);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.InvalidClientIDRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ if (!exceptionToTest.getCause().equals(exception)) {
+ logger.log(Logger.Level.ERROR, "Incorrect cause " + exceptionToTest.getCause());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("invalidClientIDRuntimeExceptionTest3 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("invalidClientIDRuntimeExceptionTest3 Failed");
+ }
+
+ /*
+ * @testName: illegalStateRuntimeExceptionTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:853;
+ *
+ * @test_Strategy: Construct IllegalStateRuntimeException(String, String)
+ */
+ @Test
+ public void illegalStateRuntimeExceptionTest1() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Urgent";
+ String reason = "The operation is illegal.";
+
+ logger.log(Logger.Level.INFO, "Test IllegalStateRuntimeException(String, String)");
+ jakarta.jms.IllegalStateRuntimeException exceptionToTest = new jakarta.jms.IllegalStateRuntimeException(
+ reason, errorCode);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+
+ } catch (Exception e) {
+ throw new Exception("IllegalStateRuntimeExceptionTest1 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("IllegalStateRuntimeExceptionTest1 Failed");
+ }
+
+ /*
+ * @testName: illegalStateRuntimeExceptionTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:854;
+ *
+ * @test_Strategy: Construct IllegalStateRuntimeException(String)
+ */
+ @Test
+ public void illegalStateRuntimeExceptionTest2() throws Exception {
+ boolean pass = true;
+
+ try {
+ String reason = "The operation is illegal.";
+
+ logger.log(Logger.Level.INFO, "Test IllegalStateRuntimeException(String)");
+ jakarta.jms.IllegalStateRuntimeException exceptionToTest = new jakarta.jms.IllegalStateRuntimeException(
+ reason);
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ }
+
+ } catch (Exception e) {
+ throw new Exception("illegalStateRuntimeExceptionTest2 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("IllegalStateRuntimeExceptionTest2 Failed");
+ }
+
+ /*
+ * @testName: illegalStateRuntimeExceptionTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:855;
+ *
+ * @test_Strategy: Construct IllegalStateRuntimeException(String, String,
+ * Throwable)
+ */
+ @Test
+ public void illegalStateRuntimeExceptionTest3() throws Exception {
+ boolean pass = true;
+
+ try {
+ String errorCode = "Urgent";
+ String reason = "The operation is illegal.";
+ jakarta.jms.IllegalStateException exception = new jakarta.jms.IllegalStateException(reason);
+
+ logger.log(Logger.Level.INFO, "Test IllegalStateRuntimeException(String, String, Throwable)");
+ jakarta.jms.IllegalStateRuntimeException exceptionToTest = new jakarta.jms.IllegalStateRuntimeException(
+ reason, errorCode, exception);
+
+ try {
+ throw exceptionToTest;
+ } catch (jakarta.jms.IllegalStateRuntimeException e) {
+ if (!exceptionToTest.getErrorCode().equals(errorCode)) {
+ logger.log(Logger.Level.ERROR, "Incorrect ErrorCode " + exceptionToTest.getErrorCode());
+ pass = false;
+ }
+ if (!exceptionToTest.getMessage().equals(reason)) {
+ logger.log(Logger.Level.ERROR, "Incorrect reason " + exceptionToTest.getMessage());
+ pass = false;
+ }
+ if (!exceptionToTest.getCause().equals(exception)) {
+ logger.log(Logger.Level.ERROR, "Incorrect cause " + exceptionToTest.getCause());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("illegalStateRuntimeExceptionTest3 Failed: ", e);
+ }
+
+ if (!pass)
+ throw new Exception("illegalStateRuntimeExceptionTest3 Failed");
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/sessiontests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/sessiontests/Client.java
deleted file mode 100644
index 349bf041a5..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/core20/sessiontests/Client.java
+++ /dev/null
@@ -1,3712 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2022 Contributors to Eclipse Foundation. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id: Client.java 68655 2012-11-21 16:26:50Z af70133 $
- */
-package com.sun.ts.tests.jms.core20.sessiontests;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-
-import jakarta.jms.BytesMessage;
-import jakarta.jms.Connection;
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.Destination;
-import jakarta.jms.InvalidDestinationException;
-import jakarta.jms.InvalidSelectorException;
-import jakarta.jms.JMSException;
-import jakarta.jms.MapMessage;
-import jakarta.jms.Message;
-import jakarta.jms.MessageConsumer;
-import jakarta.jms.MessageProducer;
-import jakarta.jms.ObjectMessage;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueBrowser;
-import jakarta.jms.Session;
-import jakarta.jms.StreamMessage;
-import jakarta.jms.TemporaryQueue;
-import jakarta.jms.TemporaryTopic;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicSubscriber;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.core20.sessiontests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS tool which creates and/or looks up the JMS administered objects
- private transient JmsTool toolT = null;
-
- private transient JmsTool toolT2 = null;
-
- private transient JmsTool toolQ = null;
-
- // JMS objects
- private transient ConnectionFactory cf = null;
-
- private transient Topic topic = null;
-
- private transient Queue queue = null;
-
- private transient Destination destination = null;
-
- private transient Connection connection = null;
-
- private transient Session session = null;
-
- private transient MessageProducer producer = null;
-
- private transient MessageConsumer consumer = null;
-
- private transient MessageConsumer consumer2 = null;
-
- private transient TopicSubscriber subscriber = null;
-
- private transient TopicSubscriber subscriber2 = null;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- String vehicle = null;
-
- // used for tests
- private static final String lookupDurableTopicFactory = "DURABLE_SUB_CONNECTION_FACTORY";
-
- private static final String lookupNormalTopicFactory = "MyTopicConnectionFactory";
-
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- ArrayList connections = null;
-
- boolean queueTest = false;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * setupGlobalVarsQ() for Queue
- */
- public void setupGlobalVarsQ() throws Exception {
- cf = toolQ.getConnectionFactory();
- destination = toolQ.getDefaultDestination();
- session = toolQ.getDefaultSession();
- connection = toolQ.getDefaultConnection();
- producer = toolQ.getDefaultProducer();
- consumer = toolQ.getDefaultConsumer();
- queue = (Queue) destination;
- connection.start();
- queueTest = true;
- }
-
- /*
- * setupGlobalVarsT() for Topic with normal connection factory (clientid not
- * set)
- */
- public void setupGlobalVarsT() throws Exception {
- cf = toolT.getConnectionFactory();
- destination = toolT.getDefaultDestination();
- session = toolT.getDefaultSession();
- connection = toolT.getDefaultConnection();
- producer = toolT.getDefaultProducer();
- consumer = toolT.getDefaultConsumer();
- topic = (Topic) destination;
- connection.start();
- queueTest = false;
- }
-
- /*
- * setupGlobalVarsT2() for Topic with durable connection factory (clientid
- * set)
- */
- public void setupGlobalVarsT2() throws Exception {
- cf = toolT2.getConnectionFactory();
- destination = toolT2.getDefaultDestination();
- session = toolT2.getDefaultSession();
- connection = toolT2.getDefaultConnection();
- producer = toolT2.getDefaultProducer();
- consumer = toolT2.getDefaultConsumer();
- topic = (Topic) destination;
- connection.start();
- queueTest = false;
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- vehicle = p.getProperty("vehicle");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- connections = new ArrayList(5);
-
- // set up JmsTool for COMMON_T setup (normal factory has clientid not set)
- toolT = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupNormalTopicFactory, mode);
-
- // set up JmsTool for COMMON_Q setup
- toolQ = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- TestUtil.logMsg("Closing default Connection");
- toolQ.getDefaultConnection().close();
- toolT.getDefaultConnection().close();
- if (toolT2 != null)
- toolT2.getDefaultConnection().close();
- if (queueTest) {
- TestUtil.logMsg("Flush any messages left on Queue");
- toolQ.flushDestination();
- }
- toolQ.closeAllResources();
- toolT.closeAllResources();
- if (toolT2 != null)
- toolT2.closeAllResources();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * Cleanup method for tests that use durable subscriptions
- */
- private void cleanupSubscription(MessageConsumer consumer, Session session,
- String subName) {
- if (consumer != null) {
- try {
- TestUtil.logTrace("Closing durable consumer: " + consumer);
- consumer.close();
- } catch (Exception e) {
- TestUtil.logErr("exception during close: ", e);
- }
- }
-
- if (session != null) {
- try {
- TestUtil.logTrace("Unsubscribing \"" + subName + "\"");
- session.unsubscribe(subName);
- } catch (Exception e) {
- TestUtil.logErr("exception during unsubscribe: ", e);
- }
- }
- }
-
- private void cleanupSubscription(TopicSubscriber tSub, Session session,
- String subName) {
- if (tSub != null) {
- try {
- TestUtil.logTrace("Closing durable subscriber: " + tSub);
- tSub.close();
- } catch (Exception e) {
- TestUtil.logErr("exception during close: ", e);
- }
- }
-
- if (session != null) {
- try {
- TestUtil.logTrace("Unsubscribing \"" + subName + "\"");
- session.unsubscribe(subName);
- } catch (Exception e) {
- TestUtil.logErr("exception during unsubscribe: ", e);
- }
- }
- }
-
- /*
- * @testName: sendRecvMsgsOfEachMsgTypeTopicTest
- *
- * @assertion_ids: JMS:JAVADOC:209; JMS:JAVADOC:212; JMS:JAVADOC:213;
- * JMS:JAVADOC:215; JMS:JAVADOC:217; JMS:JAVADOC:219; JMS:JAVADOC:221;
- * JMS:JAVADOC:223; JMS:JAVADOC:242; JMS:JAVADOC:317; JMS:JAVADOC:504;
- * JMS:JAVADOC:510;
- *
- * @test_Strategy: Send and receive messages of each message type: Message,
- * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Tests
- * the following API's
- *
- * ConnectionFactory.createConnection(String, String)
- * Connection.createSession(boolean, int) Session.createMessage()
- * Session.createBytesMessage() Session.createMapMessage()
- * Session.createObjectMessage() Session.createObjectMessage(Serializable
- * object) Session.createStreamMessage() Session.createTextMessage()
- * Session.createTextMessage(String) Session.createConsumer(Destination)
- * Session.createProducer(Destination) MessageProducer.send(Message)
- * MessageConsumer.receive(long timeout)
- */
- public void sendRecvMsgsOfEachMsgTypeTopicTest() throws Exception {
- boolean pass = true;
- try {
- // Setup for Topic
- setupGlobalVarsT();
-
- // send and receive Message
- TestUtil.logMsg("Send Message");
- Message msg = session.createMessage();
- TestUtil.logMsg("Set some values in Message");
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvMsgsOfEachMsgTypeTopicTest");
- msg.setBooleanProperty("booleanProperty", true);
- producer.send(msg);
- TestUtil.logMsg("Receive Message");
- Message msgRecv = consumer.receive(timeout);
- if (msgRecv == null) {
- throw new Exception("Did not receive Message");
- }
- TestUtil.logMsg("Check the values in Message");
- if (msgRecv.getBooleanProperty("booleanProperty") == true) {
- TestUtil.logMsg("booleanproperty is correct");
- } else {
- TestUtil.logMsg("booleanproperty is incorrect");
- pass = false;
- }
-
- // send and receive BytesMessage
- TestUtil.logMsg("Send BytesMessage");
- BytesMessage bMsg = session.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvMsgsOfEachMsgTypeTopicTest");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- producer.send(bMsg);
- TestUtil.logMsg("Receive BytesMessage");
- BytesMessage bMsgRecv = (BytesMessage) consumer.receive(timeout);
- if (bMsgRecv == null) {
- throw new Exception("Did not receive BytesMessage");
- }
- TestUtil.logMsg("Check the values in BytesMessage");
- if (bMsgRecv.readByte() == (byte) 1) {
- TestUtil.logMsg("bytevalue is correct");
- } else {
- TestUtil.logMsg("bytevalue is incorrect");
- pass = false;
- }
- if (bMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
-
- // send and receive MapMessage
- TestUtil.logMsg("Send MapMessage");
- MapMessage mMsg = session.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvMsgsOfEachMsgTypeTopicTest");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- producer.send(mMsg);
- TestUtil.logMsg("Receive MapMessage");
- MapMessage mMsgRecv = (MapMessage) consumer.receive(timeout);
- if (mMsgRecv == null) {
- throw new Exception("Did not receive MapMessage");
- }
- TestUtil.logMsg("Check the values in MapMessage");
- Enumeration list = mMsgRecv.getMapNames();
- String name = null;
- while (list.hasMoreElements()) {
- name = (String) list.nextElement();
- if (name.equals("booleanvalue")) {
- if (mMsgRecv.getBoolean(name) == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logErr("booleanvalue is incorrect");
- pass = false;
- }
- } else if (name.equals("intvalue")) {
- if (mMsgRecv.getInt(name) == 10) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logErr("intvalue is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Unexpected name of [" + name + "] in MapMessage");
- pass = false;
- }
- }
-
- // send and receive ObjectMessage
- TestUtil.logMsg("Send ObjectMessage");
- StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
- TestUtil.logMsg("Set some values in ObjectMessage");
- ObjectMessage oMsg = session.createObjectMessage();
- oMsg.setObject(sb1);
- oMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvMsgsOfEachMsgTypeTopicTest");
- producer.send(oMsg);
- TestUtil.logMsg("Receive ObjectMessage");
- ObjectMessage oMsgRecv = (ObjectMessage) consumer.receive(timeout);
- if (oMsgRecv == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- TestUtil.logMsg("Check the value in ObjectMessage");
- StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
- if (sb2.toString().equals(sb1.toString())) {
- TestUtil.logMsg("objectvalue is correct");
- } else {
- TestUtil.logErr("objectvalue is incorrect");
- pass = false;
- }
-
- // send and receive ObjectMessage passing object as param
- TestUtil.logMsg("Send ObjectMessage passing object as param");
- sb1 = new StringBuffer("This is a StringBuffer");
- TestUtil
- .logMsg("Set some values in ObjectMessage passing object as param");
- oMsg = session.createObjectMessage(sb1);
- oMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvMsgsOfEachMsgTypeTopicTest");
- producer.send(oMsg);
- TestUtil.logMsg("Receive ObjectMessage");
- oMsgRecv = (ObjectMessage) consumer.receive(timeout);
- if (oMsgRecv == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- TestUtil.logMsg("Check the value in ObjectMessage");
- sb2 = (StringBuffer) oMsgRecv.getObject();
- if (sb2.toString().equals(sb1.toString())) {
- TestUtil.logMsg("objectvalue is correct");
- } else {
- TestUtil.logErr("objectvalue is incorrect");
- pass = false;
- }
-
- // send and receive StreamMessage
- TestUtil.logMsg("Send StreamMessage");
- StreamMessage sMsg = session.createStreamMessage();
- TestUtil.logMsg("Set some values in StreamMessage");
- sMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvMsgsOfEachMsgTypeTopicTest");
- sMsg.writeBoolean(true);
- sMsg.writeInt((int) 22);
- producer.send(sMsg);
- TestUtil.logMsg("Receive StreamMessage");
- StreamMessage sMsgRecv = (StreamMessage) consumer.receive(timeout);
- if (sMsgRecv == null) {
- throw new Exception("Did not receive StreamMessage");
- }
- TestUtil.logMsg("Check the values in StreamMessage");
- if (sMsgRecv.readBoolean() == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logMsg("booleanvalue is incorrect");
- pass = false;
- }
- if (sMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
-
- // send and receive TextMessage
- TestUtil.logMsg("Send TextMessage");
- TextMessage tMsg = session.createTextMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvMsgsOfEachMsgTypeTopicTest");
- tMsg.setText("Hello There!");
- producer.send(tMsg);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage tMsgRecv = (TextMessage) consumer.receive(timeout);
- if (tMsgRecv == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (tMsgRecv.getText().equals("Hello There!")) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect");
- pass = false;
- }
-
- // send and receive TextMessage passing string as param
- TestUtil.logMsg("Send TextMessage");
- tMsg = session.createTextMessage("Where are you!");
- TestUtil.logMsg("Set some values in TextMessage");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvMsgsOfEachMsgTypeTopicTest");
- producer.send(tMsg);
- TestUtil.logMsg("Receive TextMessage");
- tMsgRecv = (TextMessage) consumer.receive(timeout);
- if (tMsgRecv == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (tMsgRecv.getText().equals("Where are you!")) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("sendRecvMsgsOfEachMsgTypeTopicTest", e);
- }
-
- if (!pass) {
- throw new Exception("sendRecvMsgsOfEachMsgTypeTopicTest failed");
- }
- }
-
- /*
- * @testName: createTemporayTopicTest
- *
- * @assertion_ids: JMS:JAVADOC:93;
- *
- * @test_Strategy: Test the following APIs:
- *
- * Session.createTemporaryTopic().
- *
- * Send and receive a TextMessage to temporary topic. Compare send and recv
- * message for equality.
- */
- public void createTemporayTopicTest() throws Exception {
- boolean pass = true;
- try {
-
- String message = "a text message";
-
- // Setup for Topic
- setupGlobalVarsT();
-
- // create a TemporaryTopic
- TestUtil.logMsg("Creating TemporaryTopic");
- TemporaryTopic tempTopic = session.createTemporaryTopic();
-
- // Create a MessageConsumer for this Temporary Topic
- TestUtil.logMsg("Creating MessageConsumer for TemporaryTopic");
- MessageConsumer tConsumer = session.createConsumer(tempTopic);
-
- // Create a MessageProducer for this Temporary Topic
- TestUtil.logMsg("Creating MessageProducer for TemporaryTopic");
- MessageProducer tProducer = session.createProducer(tempTopic);
-
- // Send TextMessage to temporary topic
- TestUtil.logMsg("Creating TextMessage with text [" + message + "]");
- TextMessage tMsg = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createTemporayTopicTest");
- TestUtil.logMsg("Send TextMessage to temporaty topic");
- tProducer.send(tMsg);
-
- // Receive TextMessage from temporary topic
- TestUtil.logMsg("Receive TextMessage from temporaty topic");
- TextMessage tMsgRecv = (TextMessage) tConsumer.receive(timeout);
- if (tMsgRecv == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (tMsgRecv.getText().equals(message)) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect");
- pass = false;
- }
-
- TestUtil.logMsg(
- "Attempting to delete temporary topic with an open consumer should not be allowed");
- try {
- tempTopic.delete();
- pass = false;
- TestUtil
- .logErr("TemporaryTopic.delete() didn't throw expected Exception");
- } catch (JMSException em) {
- TestUtil.logMsg("Received expected JMSException: ");
- } catch (Exception e) {
- TestUtil.logErr("Received unexpected Exception: " + e);
- pass = false;
- }
-
- TestUtil.logMsg("Now close the open consumer");
- try {
- tConsumer.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Attempting to delete temporary topic with no open consumer should be allowed");
- try {
- tempTopic.delete();
- } catch (Exception e) {
- pass = false;
- TestUtil.logErr("Received unexpected Exception: ", e);
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createTemporayTopicTest");
- }
-
- if (!pass) {
- throw new Exception("createTemporayTopicTest failed");
- }
- }
-
- /*
- * @testName: getTransactedTopicTest
- *
- * @assertion_ids: JMS:JAVADOC:225;
- *
- * @test_Strategy: Test the following APIs:
- *
- * Session.getTransacted().
- */
- public void getTransactedTopicTest() throws Exception {
- boolean pass = true;
-
- // Test for transacted mode false
- try {
- // Setup for Topic
- setupGlobalVarsT();
- session.close();
-
- session = connection.createSession(Session.AUTO_ACKNOWLEDGE);
- boolean expTransacted = false;
- TestUtil.logMsg("Calling getTransacted and expect " + expTransacted
- + " to be returned");
- boolean actTransacted = session.getTransacted();
- if (actTransacted != expTransacted) {
- TestUtil.logErr("getTransacted() returned " + actTransacted
- + ", expected " + expTransacted);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getTransactedTopicTest", e);
- } finally {
- try {
- if (session != null)
- session.close();
- } catch (Exception e) {
- }
- }
-
- // Test for transacted mode true
- if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
- try {
- session = connection.createSession(Session.SESSION_TRANSACTED);
- boolean expTransacted = true;
- TestUtil.logMsg("Calling getTransacted and expect " + expTransacted
- + " to be returned");
- boolean actTransacted = session.getTransacted();
- if (actTransacted != expTransacted) {
- TestUtil.logErr("getTransacted() returned " + actTransacted
- + ", expected " + expTransacted);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getTransactedTopicTest", e);
- } finally {
- try {
- if (session != null)
- session.close();
- } catch (Exception e) {
- }
- }
- }
-
- if (!pass) {
- throw new Exception("getTransactedTopicTest failed");
- }
- }
-
- /*
- * @testName: getAcknowledgeModeTopicTest
- *
- * @assertion_ids: JMS:JAVADOC:227;
- *
- * @test_Strategy: Test the following APIs:
- *
- * Session.getAcknowledgeMode().
- */
- public void getAcknowledgeModeTopicTest() throws Exception {
- boolean pass = true;
-
- // Test for AUTO_ACKNOWLEDGE mode
- try {
- // Setup for Topic
- setupGlobalVarsT();
- session.close();
-
- session = connection.createSession(Session.AUTO_ACKNOWLEDGE);
- int expAcknowledgeMode = Session.AUTO_ACKNOWLEDGE;
- TestUtil.logMsg("Calling getAcknowledgeMode and expect "
- + expAcknowledgeMode + " to be returned");
- int actAcknowledgeMode = session.getAcknowledgeMode();
- if (actAcknowledgeMode != expAcknowledgeMode) {
- TestUtil.logErr("getAcknowledgeMode() returned " + actAcknowledgeMode
- + ", expected " + expAcknowledgeMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getAcknowledgeModeTopicTest", e);
- } finally {
- try {
- if (session != null)
- session.close();
- } catch (Exception e) {
- }
- }
-
- // Test for DUPS_OK_ACKNOWLEDGE mode
- try {
- session = connection.createSession(Session.DUPS_OK_ACKNOWLEDGE);
- int expAcknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
- TestUtil.logMsg("Calling getAcknowledgeMode and expect "
- + expAcknowledgeMode + " to be returned");
- int actAcknowledgeMode = session.getAcknowledgeMode();
- if (actAcknowledgeMode != expAcknowledgeMode) {
- TestUtil.logErr("getAcknowledgeMode() returned " + actAcknowledgeMode
- + ", expected " + expAcknowledgeMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getAcknowledgeModeTopicTest", e);
- } finally {
- try {
- if (session != null)
- session.close();
- } catch (Exception e) {
- }
- }
-
- // Test for SESSION_TRANSACTED mode
- if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
- try {
- session = connection.createSession(Session.SESSION_TRANSACTED);
- int expAcknowledgeMode = Session.SESSION_TRANSACTED;
- TestUtil.logMsg("Calling getAcknowledgeMode and expect "
- + expAcknowledgeMode + " to be returned");
- int actAcknowledgeMode = session.getAcknowledgeMode();
- if (actAcknowledgeMode != expAcknowledgeMode) {
- TestUtil.logErr("getAcknowledgeMode() returned " + actAcknowledgeMode
- + ", expected " + expAcknowledgeMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getAcknowledgeModeTopicTest", e);
- } finally {
- try {
- if (session != null)
- session.close();
- } catch (Exception e) {
- }
- }
- }
-
- if (!pass) {
- throw new Exception("getAcknowledgeModeTopicTest failed");
- }
- }
-
- /*
- * @testName: createConsumerProducerTopicTest
- *
- * @assertion_ids: JMS:JAVADOC:244; JMS:JAVADOC:246; JMS:JAVADOC:248;
- * JMS:JAVADOC:224; JMS:JAVADOC:242; JMS:JAVADOC:221; JMS:JAVADOC:504;
- * JMS:JAVADOC:510; JMS:JAVADOC:597; JMS:JAVADOC:334;
- *
- * @test_Strategy: Test the following APIs:
- *
- * ConnectionFactory.createConnection(String, String)
- * Connection.createSession(boolean, int) Session.createTextMessage(String)
- * Session.createConsumer(Destination) Session.createConsumer(Destination,
- * String) Session.createConsumer(Destination, String, boolean)
- * Session.createProducer(Destination) MessageProducer.send(Message)
- * MessageConsumer.receive(long timeout)
- *
- * 1. Create a MessageConsumer with selector to consumer just the last message
- * in the Topic with boolproperty (lastMessage=TRUE). 2. Create a
- * MessageConsumer again to consume all the messages in the Topic. 3. Send x
- * text messages to a Topic. 4. Verify that both consumers work as expected.
- */
- public void createConsumerProducerTopicTest() throws Exception {
- boolean pass = true;
- MessageConsumer consumerSelect = null;
- try {
- TextMessage tempMsg = null;
- Enumeration msgs = null;
-
- // Setup for Topic
- setupGlobalVarsT();
- consumer.close();
-
- // Create selective MessageConsumer to consume messages in Topic with
- // boolean
- // property (lastMessage=TRUE)
- TestUtil.logMsg(
- "Create selective consumer to consume messages in Topic with boolproperty (lastMessage=TRUE)");
- consumerSelect = session.createConsumer(destination, "lastMessage=TRUE");
-
- // Create normal MessageConsumer to consume all messages in Topic
- TestUtil
- .logMsg("Create normal consumer to consume all messages in Topic");
- consumer = session.createConsumer(destination);
-
- // send "numMessages" messages to Topic plus end of stream message
- TestUtil.logMsg("Send " + numMessages + " messsages to Topic");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createConsumerProducerTopicTest" + i);
- tempMsg.setJMSType("");
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg(
- "Consume messages with selective consumer which has boolproperty (lastMessage=TRUE)");
- if (consumerSelect != null)
- tempMsg = (TextMessage) consumerSelect.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("MessageConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + numMessages + " missing from Topic");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + numMessages)) {
- TestUtil.logErr(
- "Received [" + tempMsg.getText() + "] expected [Message 3]");
- pass = false;
- } else {
- TestUtil.logMsg("Received expected message: " + tempMsg.getText());
- }
-
- // Try to receive one more message (should return null)
- TestUtil.logMsg("Make sure selective consumer receives no more messages");
- if (consumerSelect != null)
- tempMsg = (TextMessage) consumerSelect.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("MessageConsumer.receive() returned a message ["
- + tempMsg.getText() + "] (Expected NULL)");
- TestUtil.logErr(
- "MessageConsumer with selector should have returned just 1 message");
- pass = false;
- } else {
- TestUtil.logMsg("No more messages for selective consumer (Correct)");
- }
-
- try {
- if (consumerSelect != null)
- consumerSelect.close();
- } catch (Exception e) {
- }
-
- TestUtil.logMsg("Consume all messages with normal consumer");
- for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("MessageConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + msgCount + " missing from Topic");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + msgCount)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + msgCount + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received message: " + tempMsg.getText());
- }
- }
-
- // Try to receive one more message (should return null)
- TestUtil.logMsg("Make sure normal consumer receives no more messages");
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg != null) {
- TestUtil
- .logErr("Received [" + tempMsg.getText() + "] expected no message");
- TestUtil.logErr("MessageConsumer should have returned " + numMessages
- + " messages");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createConsumerProducerTopicTest");
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("createConsumerProducerTopicTest failed");
- }
- }
-
- /*
- * @testName: createDurableSubscriberTopicTest1
- *
- * @assertion_ids: JMS:JAVADOC:254;
- *
- * @test_Strategy: Creates a durable subscription with the specified name on
- * the specified topic, and creates a TopicSubscriber on that durable
- * subscription.
- *
- * This uses a connection factory WITH client identifier set. The client
- * identifer MUST be set for this API.
- *
- * Tests the following API method:
- *
- * Session.createDurableSubscriber(Topic, String)
- *
- * 1. Send a text message to a Topic. 2. Consume message via the
- * TopicSubscriber created.
- */
- public void createDurableSubscriberTopicTest1() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- TopicSubscriber tSub = null;
- try {
- TextMessage expTextMessage = null;
-
- // set up JmsTool for COMMON_T setup (durable factory has clientid set)
- toolT.getDefaultConnection().close();
- toolT.closeAllResources();
- toolT2 = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupDurableTopicFactory, mode);
-
- // Setup for Topic
- setupGlobalVarsT2();
-
- // Create Durable Subscription and a TopicSubscriber for it
- TestUtil
- .logMsg("Create a Durable Subscription and a TopicSubscriber for it");
- tSub = session.createDurableSubscriber(topic,
- "createDurableSubscriberTopicTest1");
-
- TestUtil.logMsg("Send message to Topic");
- expTextMessage = session.createTextMessage(message);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createDurableSubscriberTopicTest1");
- producer.send(expTextMessage);
- TestUtil.logMsg("Message sent");
-
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) tSub.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createDurableSubscriberTopicTest1", e);
- } finally {
- try {
- cleanupSubscription(tSub, session, "createDurableSubscriberTopicTest1");
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("createDurableSubscriberTopicTest1 failed");
- }
- }
-
- /*
- * @testName: createDurableSubscriberTopicTest2
- *
- * @assertion_ids: JMS:JAVADOC:256;
- *
- * @test_Strategy: Creates a durable subscription with the specified name on
- * the specified topic, and creates a TopicSubscriber on that durable
- * subscription, specifying a message selector and whether messages published
- * by its own connection should be delivered to it.
- *
- * This uses a connection factory WITH client identifier set. The client
- * identifer MUST be set for this API.
- *
- * Tests the following API method:
- *
- * Session.createDurableSubscriber(Topic,String,String,boolean)
- *
- * 1 Create a durable subscriber on the specified topic, and create a
- * TopicSubscriber with the specified message selector 2 Send a number of
- * messages to the destination 3 Test both noLocal=true and noLocal=false
- * cases 4 Verify message with specified selector received by listener in the
- * noLocal=false case only.
- *
- */
- public void createDurableSubscriberTopicTest2() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- TopicSubscriber tSub = null;
- try {
- // set up JmsTool for COMMON_T setup (durable factory has clientid set)
- toolT.getDefaultConnection().close();
- toolT.closeAllResources();
- toolT2 = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupDurableTopicFactory, mode);
-
- // Setup for Topic
- setupGlobalVarsT2();
-
- // Create Durable Subscription and a TopicSubscriber for it
- // Test the noLocal=false case with message selector
- TestUtil
- .logMsg("Create a Durable Subscription and a TopicSubscriber for it");
- tSub = session.createDurableSubscriber(topic,
- "createDurableSubscriberTopicTest2", "lastMessage = TRUE", false);
-
- // send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " to Topic");
- for (int i = 1; i <= numMessages; i++) {
- TextMessage tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createDurableSubscriberTopicTest2" + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg("Receive TextMessage");
- TextMessage expTextMessage = session
- .createTextMessage("Message " + numMessages);
- TextMessage actTextMessage = (TextMessage) tSub.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createDurableSubscriberTopicTest2", e);
- } finally {
- try {
- cleanupSubscription(tSub, session, "createDurableSubscriberTopicTest2");
- } catch (Exception e) {
- }
- }
-
- try {
-
- // Create Durable Subscription and a TopicSubscriber for it
- // Test the noLocal=true case with message selector
- TestUtil
- .logMsg("Create a Durable Subscription and a TopicSubscriber for it");
- tSub = session.createDurableSubscriber(topic,
- "createDurableSubscriberTopicTest2", "lastMessage = TRUE", true);
-
- // send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " to Topic");
- for (int i = 1; i <= numMessages; i++) {
- TextMessage tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createDurableSubscriberTopicTest2" + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) tSub.receive(timeout);
-
- if (actTextMessage != null) {
- TestUtil.logErr("message were delivered when noLocal=true");
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createDurableSubscriberTopicTest2", e);
- } finally {
- try {
- cleanupSubscription(tSub, session, "createDurableSubscriberTopicTest2");
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("createDurableSubscriberTopicTest2 failed");
- }
- }
-
- /*
- * @testName: createDurableConsumerTopicTest1
- *
- * @assertion_ids: JMS:JAVADOC:1087;
- *
- * @test_Strategy: Creates a durable subscription with the specified name on
- * the specified topic, and creates a MessageConsumer on that durable
- * subscription.
- *
- * This uses a connection factory WITH client identifier set. The client
- * identifer MUST be set for this API.
- *
- * Tests the following API method:
- *
- * Session.createDurableConsumer(Topic, String)
- *
- * 1. Create a durable subscription with the specified name on the specified
- * topic and create a durable MessageConsumer on that durable subscription.
- * This uses a connection factory WITH client identifier set. 2. Send
- * TextMessage (message1) to the Topic. 3. Consume message via MessageConsumer
- * created. Verify message1 received. 4. Close consumer. 5. Send another
- * TextMessage (message2) to the Topic. 6. Recreate the durable
- * MessageConsumer on that durable subscription. 7. Consume message via
- * MessageConsumer created. Verify message2 received.
- */
- public void createDurableConsumerTopicTest1() throws Exception {
- boolean pass = true;
- String message1 = "Where are you!";
- String message2 = "Who are you!";
- MessageConsumer tCon = null;
- try {
- TextMessage expTextMessage = null;
-
- // set up JmsTool for COMMON_T setup (durable factory has clientid set)
- toolT.getDefaultConnection().close();
- toolT.closeAllResources();
- toolT2 = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupDurableTopicFactory, mode);
-
- // Setup for Topic
- setupGlobalVarsT2();
-
- // Create Durable Subscription and a MessageConsumer for it
- TestUtil
- .logMsg("Create a Durable Subscription and a MessageConsumer for it");
- tCon = session.createDurableConsumer(topic,
- "createDurableConsumerTopicTest1");
-
- TestUtil.logMsg("Send TextMessage message1 to Topic");
- expTextMessage = session.createTextMessage(message1);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createDurableConsumerTopicTest1");
- producer.send(expTextMessage);
- TestUtil.logMsg("TextMessage message1 sent");
-
- TestUtil.logMsg("Receive TextMessage message1");
- TextMessage actTextMessage = (TextMessage) tCon.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage message1");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- TestUtil.logMsg("Close durable MessageConsumer");
- tCon.close();
-
- TestUtil.logMsg("Send TextMessage message2 to Topic");
- expTextMessage = session.createTextMessage(message1);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createDurableConsumerTopicTest1");
- producer.send(expTextMessage);
- TestUtil.logMsg("TextMessage message2 sent");
-
- // Recreate Durable Subscription and a MessageConsumer for it
- TestUtil.logMsg(
- "Recreate a Durable Subscription and a MessageConsumer for it");
- tCon = session.createDurableConsumer(topic,
- "createDurableConsumerTopicTest1");
-
- TestUtil.logMsg("Receive TextMessage message2");
- actTextMessage = (TextMessage) tCon.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage message2");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createDurableConsumerTopicTest1", e);
- } finally {
- try {
- cleanupSubscription(tCon, session, "createDurableConsumerTopicTest1");
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("createDurableConsumerTopicTest1 failed");
- }
- }
-
- /*
- * @testName: createDurableConsumerTopicTest2
- *
- * @assertion_ids: JMS:JAVADOC:1090;
- *
- * @test_Strategy: Creates a durable subscription with the specified name on
- * the specified topic, and creates a MessageConsumer on that durable
- * subscription, specifying a message selector and whether messages published
- * by its own connection should be delivered to it.
- *
- * This uses a connection factory WITH client identifier set. The client
- * identifer MUST be set for this API.
- *
- * Tests the following API method:
- *
- * Session.createDurableConsumer(Topic,String,String,boolean)
- *
- * 1. Create a durable subscription with the specified name on the specified
- * topic and create a durable MessageConsumer on that durable subscription
- * specifing a message selector and whether messages published by its own
- * connection should be delivered to it. 2. Send a number of messages to the
- * Topic. 3. Test both noLocal=true and noLocal=false cases. 4. Verify message
- * with specified selector received by MessageConsumer in the noLocal=false
- * case only.
- *
- */
- public void createDurableConsumerTopicTest2() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- MessageConsumer tCon = null;
- try {
- // set up JmsTool for COMMON_T setup (durable factory has clientid set)
- toolT.getDefaultConnection().close();
- toolT.closeAllResources();
- toolT2 = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupDurableTopicFactory, mode);
-
- // Setup for Topic
- setupGlobalVarsT2();
-
- // Create Durable Subscription and a MessageConsumer for it
- // Test the noLocal=false case with message selector
- TestUtil.logMsg(
- "Create a Durable Subscription and a MessageConsumer with message selector, noLocal=false");
- tCon = session.createDurableConsumer(topic,
- "createDurableConsumerTopicTest2", "lastMessage = TRUE", false);
-
- // send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " to Topic");
- for (int i = 1; i <= numMessages; i++) {
- TextMessage tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createDurableConsumerTopicTest2" + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg("Receive TextMessage");
- TestUtil.logMsg(
- "This is noLacal=false case so expect to get just last message");
- TextMessage expTextMessage = session
- .createTextMessage("Message " + numMessages);
- TextMessage actTextMessage = (TextMessage) tCon.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createDurableConsumerTopicTest2", e);
- } finally {
- try {
- cleanupSubscription(tCon, session, "createDurableConsumerTopicTest2");
- } catch (Exception e) {
- }
- }
-
- try {
- // Create Durable Subscription and a MessageConsumer for it
- // Test the noLocal=true case with message selector
- TestUtil.logMsg(
- "Create a Durable Subscription and a MessageConsumer with message selector, noLocal=true");
- tCon = session.createDurableConsumer(topic,
- "createDurableConsumerTopicTest2", "lastMessage = TRUE", true);
-
- // send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " to Topic");
- for (int i = 1; i <= numMessages; i++) {
- TextMessage tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createDurableConsumerTopicTest2" + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg("Receive TextMessage");
- TextMessage actTextMessage = (TextMessage) tCon.receive(timeout);
-
- if (actTextMessage != null) {
- TestUtil.logErr("Message was delivered when noLocal=true");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createDurableConsumerTopicTest2", e);
- } finally {
- try {
- cleanupSubscription(tCon, session, "createDurableConsumerTopicTest2");
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("createDurableConsumerTopicTest2 failed");
- }
- }
-
- /*
- * @testName: createSharedConsumerTopicTest1
- *
- * @assertion_ids: JMS:JAVADOC:1163; JMS:SPEC:269;
- *
- * @test_Strategy: Creates a shared non-durable subscription with the
- * specified name on the specified topic, and creates a MessageConsumer on
- * that subscription.
- *
- * Tests the following API method:
- *
- * Session.createSharedConsumer(Topic, String)
- *
- * 1. Creates a shared non-durable subscription with the specified name on the
- * specified topic, and creates a MessageConsumer on that subscription. 2.
- * Create a second MessageConsumer on that subscription. 3. Send a text
- * message to the Topic. 4. Consume message via the first MessageConsumer and
- * message should be received. 5. Attempt to consume message via second
- * MessageConsumer and no message should be received. 6. Re-Send a text
- * message to the Topic. 7. Consume message via the second MessageConsumer and
- * message should be received. 8. Attempt to consume message via first
- * MessageConsumer and no message should be received.
- */
- public void createSharedConsumerTopicTest1() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- String sharedSubscriptionName = "createSharedConsumerTopicTest1";
- TextMessage expTextMessage = null;
- try {
- // Setup for Topic
- setupGlobalVarsT();
-
- // Create shared non-durable Subscription and a MessageConsumer for it
- TestUtil.logMsg(
- "Create a shared non-durable Subscription and a MessageConsumer for it");
- consumer.close();
- consumer = session.createSharedConsumer(topic, sharedSubscriptionName);
-
- // Create a second MessageConsumer for the subscription
- TestUtil.logMsg("Create a second MessageConsumer for the Subscription");
- consumer2 = session.createSharedConsumer(topic, sharedSubscriptionName);
-
- TestUtil.logMsg("Send message to Topic");
- expTextMessage = session.createTextMessage(message);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- sharedSubscriptionName);
- producer.send(expTextMessage);
- TestUtil.logMsg("Message sent");
-
- TestUtil.logMsg("Receive TextMessage from consumer1");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
-
- TestUtil.logMsg(
- "Attempt to Receive TextMessage from consumer2 - there should be none");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage != null) {
- throw new Exception("Did receive TextMessage - unexpected.");
- } else
- TestUtil.logMsg("Did not receive TextMessage - expected.");
-
- TestUtil.logMsg("Send another message to Topic");
- expTextMessage = session.createTextMessage(message);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- sharedSubscriptionName);
- producer.send(expTextMessage);
- TestUtil.logMsg("Message sent");
-
- TestUtil.logMsg("Receive TextMessage from consumer2");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- TestUtil.logMsg(
- "Attempt to Receive TextMessage from consumer1 - there should be none");
- actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage != null) {
- throw new Exception("Did receive TextMessage - unexpected.");
- } else
- TestUtil.logMsg("Did not receive TextMessage - expected.");
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createSharedConsumerTopicTest1", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- if (consumer2 != null)
- consumer2.close();
- } catch (Exception e) {
- TestUtil.logMsg("Ignoring exception closing consumers: " + e);
- }
- }
-
- if (!pass) {
- throw new Exception("createSharedConsumerTopicTest1 failed");
- }
- }
-
- /*
- * @testName: createSharedConsumerTopicTest2
- *
- * @assertion_ids: JMS:JAVADOC:1167; JMS:SPEC:269; JMS:SPEC:270;
- *
- * @test_Strategy: Creates a shared non-durable subscription with the
- * specified name on the specified topic, and creates a MessageConsumer on
- * that subscription, specifying a message selector.
- *
- * Tests the following API method:
- *
- * Session.createSharedConsumer(Topic, String, String)
- *
- * 1. Create a shared non-durable subscription with the specified name on the
- * specified topic, and creates a MessageConsumer on that subscription,
- * specifying a message selector. 2. Create a second MessageConsumer on that
- * subscription. 3. Send a text message to the Topic. 4. Consume message via
- * first MessageConsumer and message selector and message should be received.
- * 5. Attempt to consume message via second MessageConsumer and message
- * selector and no message received. 6. Re-Send a text message to the Topic.
- * 7. Consume message via second MessageConsumer and message selector and
- * message should be received. 8. Attempt to consume message via first
- * MessageConsumer and message selector and no message received.
- */
- public void createSharedConsumerTopicTest2() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- String sharedSubscriptionName = "createSharedConsumerTopicTest2";
- try {
- // Setup for Topic
- setupGlobalVarsT();
-
- // Create shared non-durable Subscription and a MessageConsumer for it
- TestUtil.logMsg(
- "Create a shared non-durable Subscription and a MessageConsumer for it");
- consumer.close();
- consumer = session.createSharedConsumer(topic, sharedSubscriptionName,
- "lastMessage = TRUE");
-
- // Create a second MessageConsumer for the subscription
- TestUtil.logMsg("Create a second MessageConsumer for the Subscription");
- consumer2 = session.createSharedConsumer(topic, sharedSubscriptionName,
- "lastMessage = TRUE");
-
- // send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " to Topic");
- for (int i = 1; i <= numMessages; i++) {
- TextMessage tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- sharedSubscriptionName + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg("Receive TextMessage from consumer1");
- TextMessage expTextMessage = session
- .createTextMessage("Message " + numMessages);
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
-
- TestUtil.logMsg(
- "Attempt to Receive TextMessage from consumer2 - there should be none");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage != null) {
- throw new Exception("Did receive TextMessage - unexpected.");
- } else
- TestUtil.logMsg("Did not receive TextMessage - expected.");
-
- // send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " to Topic");
- for (int i = 1; i <= numMessages; i++) {
- TextMessage tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- sharedSubscriptionName + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg("Receive TextMessage from consumer2");
- expTextMessage = session.createTextMessage("Message " + numMessages);
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- TestUtil.logMsg(
- "Attempt to Receive TextMessage from consumer1 - there should be none");
- actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage != null) {
- throw new Exception("Did receive TextMessage - unexpected.");
- } else
- TestUtil.logMsg("Did not receive TextMessage - expected.");
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createSharedConsumerTopicTest2", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- if (consumer2 != null)
- consumer2.close();
- } catch (Exception e) {
- TestUtil.logMsg("Ignoring exception closing consumers: " + e);
- }
- }
-
- if (!pass) {
- throw new Exception("createSharedConsumerTopicTest2 failed");
- }
- }
-
- /*
- * @testName: createSharedDurableConsumerTopicTest1
- *
- * @assertion_ids: JMS:JAVADOC:1393;
- *
- * @test_Strategy: Creates a shared durable subscription with the specified
- * name on the specified topic and creates a JMSConsumer on that durable
- * subscription.
- *
- * This uses a connection factory WITH client identifier set.
- *
- * Tests the following API method:
- *
- * Session.createSharedDurableConsumer(Topic, String)
- *
- * 1. Create a shared durable subscription with the specified name on the
- * specified topic and create a durable JMSConsumer on that durable
- * subscription. This uses a connection factory WITH client identifier set. 2.
- * Create a 2nd JMSConsumer for it. 3. Send TextMessage (message1) to the
- * Topic. 3. Consume message via 1st JMSConsumer created. Verify message1
- * received. 4. Close 1st consumer. 5. Send another TextMessage (message2) to
- * the Topic. 6. Consume message via 2nd JMSConsumer created. Verify message2
- * received.
- */
- public void createSharedDurableConsumerTopicTest1() throws Exception {
- boolean pass = true;
- String message1 = "Message1!";
- String message2 = "Message2!";
- String durableSubscriptionName = "createSharedDurableConsumerTopicTest1";
- try {
- // set up JmsTool for COMMON_T setup (durable factory has clientid set)
- toolT.getDefaultConnection().close();
- toolT.closeAllResources();
- toolT2 = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupDurableTopicFactory, mode);
-
- // Setup for Topic
- setupGlobalVarsT2();
-
- TextMessage expTextMessage = null;
-
- // Create a shared Durable Subscription and a JMSConsumer for it
- TestUtil.logMsg(
- "Create a shared Durable Subscription and 1st JMSConsumer for it");
- consumer = session.createSharedDurableConsumer(topic,
- durableSubscriptionName);
-
- // Create 2nd JMSConsumer for it
- TestUtil.logMsg("Create 2nd JMSConsumer for it");
- consumer2 = session.createSharedDurableConsumer(topic,
- durableSubscriptionName);
-
- TestUtil.logMsg("Send TextMessage message1 to Topic");
- expTextMessage = session.createTextMessage(message1);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createSharedDurableConsumerTopicTest1");
- producer.send(expTextMessage);
- TestUtil.logMsg("TextMessage message1 sent");
-
- TestUtil.logMsg("Receive TextMessage message1 from consumer1");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage message1");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- TestUtil.logMsg("Close 1st shared durable JMSConsumer");
- consumer.close();
-
- TestUtil.logMsg("Send TextMessage message2 to Topic");
- expTextMessage = session.createTextMessage(message2);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createSharedDurableConsumerTopicTest1");
- producer.send(expTextMessage);
- TestUtil.logMsg("TextMessage message2 sent");
-
- TestUtil.logMsg("Receive TextMessage message2 from consumer2");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage message2");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
-
- TestUtil
- .logMsg("Now there should be no more messages to receive from topic");
-
- TestUtil
- .logMsg("Recreate Durable Subscription and 1st JMSConsumer for it");
- consumer = session.createSharedDurableConsumer(topic,
- durableSubscriptionName);
-
- TestUtil
- .logMsg("Try and receive a message from consumer1 (should get NONE)");
- actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage != null) {
- TestUtil.logErr("Consumer1 received a message (FAIL)");
- pass = false;
- } else {
- TestUtil.logMsg("Consumer1 didn't receive a message (PASS)");
- }
-
- TestUtil
- .logMsg("Try and receive a message from consumer2 (should get NONE)");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage != null) {
- TestUtil.logErr("Consumer2 received a message (FAIL)");
- pass = false;
- throw new Exception("Consumer2 received a message (FAIL)");
- } else {
- TestUtil.logMsg("Consumer2 didn't receive a message (PASS)");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createSharedDurableConsumerTopicTest1", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- cleanupSubscription(consumer2, session, durableSubscriptionName);
- toolT2.getDefaultConnection().close();
- toolT2.closeAllResources();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- if (!pass) {
- throw new Exception("createSharedDurableConsumerTopicTest1 failed");
- }
- }
-
- /*
- * @testName: createSharedDurableConsumerTopicTest2
- *
- * @assertion_ids: JMS:JAVADOC:1396;
- *
- * @test_Strategy: Creates a shared durable subscription with the specified
- * name on the specified topic and creates a JMSConsumer on that durable
- * subscription, specifying a message selector and whether messages published
- * by its own connection should be delivered to it.
- *
- * This uses a connection factory WITH client identifier set.
- *
- * Tests the following API method:
- *
- * Session.createSharedDurableConsumer(Topic,String,String)
- *
- * 1. Create a shared durable subscription with the specified name on the
- * specified topic and create a durable JMSConsumer on that durable
- * subscription specifing a message selector and whether messages published by
- * its own connection should be delivered to it. This uses a connection
- * factory WITH client identifier set. 2. Create a 2nd JMSConsumer for it. 3.
- * Send a number of messages to the Topic.
- *
- */
- public void createSharedDurableConsumerTopicTest2() throws Exception {
- boolean pass = true;
- String durableSubscriptionName = "createSharedDurableConsumerTopicTest2";
- try {
- // set up JmsTool for COMMON_T setup (durable factory has clientid set)
- toolT.getDefaultConnection().close();
- toolT.closeAllResources();
- toolT2 = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupDurableTopicFactory, mode);
-
- // Setup for Topic
- setupGlobalVarsT2();
-
- // Create a shared Durable Subscription and a JMSConsumer for it
- TestUtil.logMsg(
- "Create shared Durable Subscription and 1st JMSConsumer with message selector");
- consumer = session.createSharedDurableConsumer(topic,
- durableSubscriptionName, "lastMessage = TRUE");
- // Create 2nd JMSConsumer for it
- TestUtil.logMsg("Create 2nd JMSConsumer with message selector");
- consumer2 = session.createSharedDurableConsumer(topic,
- durableSubscriptionName, "lastMessage = TRUE");
-
- // send "numMessages" messages to Topic
- TestUtil.logMsg("Send " + numMessages + " messages to Topic");
- for (int i = 1; i <= numMessages; i++) {
- TextMessage tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createSharedDurableConsumerTopicTest2" + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- TestUtil.logMsg("Receive TextMessage from consumer1");
- TextMessage expTextMessage = session
- .createTextMessage("Message " + numMessages);
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createSharedDurableConsumerTopicTest2", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- cleanupSubscription(consumer2, session, durableSubscriptionName);
- toolT2.getDefaultConnection().close();
- toolT2.closeAllResources();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- if (!pass) {
- throw new Exception("createSharedDurableConsumerTopicTest2 failed");
- }
- }
-
- /*
- * @testName: createSharedDurableConsumerTopicTest3
- *
- * @assertion_ids: JMS:JAVADOC:1393;
- *
- * @test_Strategy: Creates a shared durable subscription with the specified
- * name on the specified topic and creates a JMSConsumer on that durable
- * subscription.
- *
- * This uses a connection factory WITH client identifier unset.
- *
- * Tests the following API method:
- *
- * Session.createSharedDurableConsumer(Topic, String)
- *
- * 1. Create a shared durable subscription with the specified name on the
- * specified topic and create a durable JMSConsumer on that durable
- * subscription. This uses a connection factory WITH client identifier unset.
- * 2. Create a 2nd JMSConsumer for it. 3. Send TextMessage (message1) to the
- * Topic. 3. Consume message via 1st JMSConsumer created. Verify message1
- * received. 4. Close 1st consumer. 5. Send another TextMessage (message2) to
- * the Topic. 6. Consume message via 2nd JMSConsumer created. Verify message2
- * received.
- */
- public void createSharedDurableConsumerTopicTest3() throws Exception {
- boolean pass = true;
- String message1 = "Message1!";
- String message2 = "Message2!";
- String durableSubscriptionName = "createSharedDurableConsumerTopicTest3";
- try {
- // Setup for Topic
- setupGlobalVarsT();
-
- TextMessage expTextMessage = null;
-
- // Create a shared Durable Subscription and a JMSConsumer for it
- TestUtil.logMsg(
- "Create a shared Durable Subscription and 1st JMSConsumer for it");
- consumer = session.createSharedDurableConsumer(topic,
- durableSubscriptionName);
-
- // Create 2nd JMSConsumer for it
- TestUtil.logMsg("Create 2nd JMSConsumer for it");
- consumer2 = session.createSharedDurableConsumer(topic,
- durableSubscriptionName);
-
- TestUtil.logMsg("Send TextMessage message1 to Topic");
- expTextMessage = session.createTextMessage(message1);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createSharedDurableConsumerTopicTest3");
- producer.send(expTextMessage);
- TestUtil.logMsg("TextMessage message1 sent");
-
- TestUtil.logMsg("Receive TextMessage message1 from consumer1");
- TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage message1");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- TestUtil.logMsg("Close 1st shared durable JMSConsumer");
- consumer.close();
-
- TestUtil.logMsg("Send TextMessage message2 to Topic");
- expTextMessage = session.createTextMessage(message2);
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createSharedDurableConsumerTopicTest3");
- producer.send(expTextMessage);
- TestUtil.logMsg("TextMessage message2 sent");
-
- TestUtil.logMsg("Receive TextMessage message2 from consumer2");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage message2");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
-
- TestUtil
- .logMsg("Now there should be no more messages to receive from topic");
-
- TestUtil
- .logMsg("Recreate Durable Subscription and 1st JMSConsumer for it");
- consumer = session.createSharedDurableConsumer(topic,
- durableSubscriptionName);
-
- TestUtil
- .logMsg("Try and receive a message from consumer1 (should get NONE)");
- actTextMessage = (TextMessage) consumer.receive(timeout);
- if (actTextMessage != null) {
- TestUtil.logErr("Consumer1 received a message (FAIL)");
- pass = false;
- } else {
- TestUtil.logMsg("Consumer1 didn't receive a message (PASS)");
- }
-
- TestUtil
- .logMsg("Try and receive a message from consumer2 (should get NONE)");
- actTextMessage = (TextMessage) consumer2.receive(timeout);
- if (actTextMessage != null) {
- TestUtil.logErr("Consumer2 received a message (FAIL)");
- pass = false;
- } else {
- TestUtil.logMsg("Consumer2 didn't receive a message (PASS)");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createSharedDurableConsumerTopicTest3", e);
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- cleanupSubscription(consumer2, session, durableSubscriptionName);
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("createSharedDurableConsumerTopicTest3 failed");
- }
- }
-
- /*
- * @testName: invalidDestinationExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1089; JMS:JAVADOC:1092; JMS:JAVADOC:643;
- * JMS:JAVADOC:644; JMS:JAVADOC:1165; JMS:JAVADOC:1169; JMS:JAVADOC:1395;
- * JMS:JAVADOC:1398;
- *
- * @test_Strategy: Pass an invalid topic and test for
- * InvalidDestinationException.
- *
- * Session.createDurableSubscriber(Topic, String)
- * Session.createDurableSubscriber(Topic, String, String, boolean)
- * Session.createDurableConsumer(Topic, String)
- * Session.createDurableConsumer(Topic, String, String, boolean)
- * Session.createSharedConsumer(Topic, String)
- * Session.createSharedConsumer(Topic, String, String)
- * Session.createSharedDurableConsumer(Topic, String)
- * Session.createSharedDurableConsumer(Topic, String, String)
- */
- public void invalidDestinationExceptionTests() throws Exception {
- boolean pass = true;
- Destination invalidDestination = null;
- Topic invalidTopic = null;
- try {
- // set up JmsTool for COMMON_T setup (durable factory has clientid set)
- toolT.getDefaultConnection().close();
- toolT.closeAllResources();
- toolT2 = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupDurableTopicFactory, mode);
-
- // Setup for Topic
- setupGlobalVarsT2();
-
- TestUtil.logMsg(
- "Testing Session.createDurableSubscriber(Topic, String) for InvalidDestinationException");
- try {
- TestUtil.logMsg(
- "Calling Session.createDurableSubscriber(Topic, String) -> expect InvalidDestinationException");
- session.createDurableSubscriber(invalidTopic,
- "InvalidDestinationException");
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Got InvalidDestinationException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidDestinationException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing Session.createDurableSubscriber(Topic, String, String, boolean) for InvalidDestinationException");
- try {
- TestUtil.logMsg(
- "Calling Session.createDurableSubscriber(Topic, String, String, boolean) -> expect InvalidDestinationException");
- session.createDurableSubscriber(invalidTopic,
- "InvalidDestinationException", "lastMessage = TRUE", false);
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Got InvalidDestinationException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidDestinationException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing Session.createDurableConsumer(Topic, String) for InvalidDestinationException");
- try {
- TestUtil.logMsg(
- "Calling Session.createDurableConsumer(Topic, String) -> expect InvalidDestinationException");
- session.createDurableConsumer(invalidTopic,
- "InvalidDestinationException");
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Got InvalidDestinationException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidDestinationException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing Session.createDurableConsumer(Topic, String, String, boolean) for InvalidDestinationException");
- try {
- TestUtil.logMsg(
- "Calling Session.createDurableConsumer(Topic, String, String, boolean) -> expect InvalidDestinationException");
- session.createDurableConsumer(invalidTopic,
- "InvalidDestinationException", "lastMessage = TRUE", false);
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Got InvalidDestinationException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidDestinationException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing Session.createSharedConsumer(Topic, String) for InvalidDestinationException");
- try {
- TestUtil.logMsg(
- "Calling Session.createSharedConsumer(Topic, String) for InvalidDestinationException");
- session.createSharedConsumer(invalidTopic,
- "InvalidDestinationException");
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Got InvalidDestinationException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidDestinationException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing Session.createSharedConsumer(Topic, String, String) for InvalidDestinationException");
- try {
- TestUtil.logMsg(
- "Calling Session.createSharedConsumer(Topic, String, String) for InvalidDestinationException");
- session.createSharedConsumer(invalidTopic,
- "InvalidDestinationException", "lastMessage = TRUE");
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Got InvalidDestinationException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidDestinationException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing Session.createSharedDurableConsumer(Topic, String) for InvalidDestinationException");
- try {
- TestUtil.logMsg(
- "Calling Session.createSharedDurableConsumer(Topic, String) -> expect InvalidDestinationException");
- session.createSharedDurableConsumer(invalidTopic,
- "InvalidDestinationException");
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Got InvalidDestinationException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidDestinationException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing Session.createSharedDurableConsumer(Topic, String, String) for InvalidDestinationException");
- try {
- TestUtil.logMsg(
- "Calling Session.createSharedDurableConsumer(Topic, String, String) -> expect InvalidDestinationException");
- session.createSharedDurableConsumer(invalidTopic,
- "InvalidDestinationException", "lastMessage = TRUE");
- } catch (InvalidDestinationException e) {
- TestUtil.logMsg("Got InvalidDestinationException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidDestinationException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("invalidDestinationExceptionTests", e);
- }
-
- if (!pass) {
- throw new Exception("invalidDestinationExceptionTests failed");
- }
- }
-
- /*
- * @testName: invalidSelectorExceptionTopicTests
- *
- * @assertion_ids: JMS:JAVADOC:1093; JMS:JAVADOC:1399; JMS:JAVADOC:1166;
- * JMS:JAVADOC:1170;
- *
- * @test_Strategy: Pass an invalid selector and test for
- * InvalidSelectorException.
- *
- * Session.createDurableConsumer(Topic, String, String, boolean)
- * Session.createSharedConsumer(Topic, String, String)
- * Session.createSharedDurableConsumer(Topic, String, String)
- */
- public void invalidSelectorExceptionTopicTests() throws Exception {
- boolean pass = true;
- String invalidMessageSelector = "=TEST 'test'";
- try {
- // set up JmsTool for COMMON_T setup (durable factory has clientid set)
- toolT.getDefaultConnection().close();
- toolT.closeAllResources();
- toolT2 = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupDurableTopicFactory, mode);
-
- // Setup for Topic
- setupGlobalVarsT2();
-
- TestUtil.logMsg(
- "Testing Session.createDurableConsumer(Topic, String, String, boolean) for InvalidSelectorException");
- try {
- TestUtil.logMsg(
- "Calling Session.createDurableConsumer(Topic, String, String, boolean) -> expect InvalidSelectorException");
- session.createDurableConsumer(topic, "InvalidSelectorException",
- invalidMessageSelector, false);
- } catch (InvalidSelectorException e) {
- TestUtil.logMsg("Got InvalidSelectorException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidSelectorException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing Session.createSharedConsumer(Topic, String, String) for InvalidSelectorException");
- try {
- TestUtil.logMsg(
- "Calling Session.createSharedConsumer(Topic, String, String) for InvalidSelectorException");
- session.createSharedConsumer(topic, "InvalidSelectorException",
- invalidMessageSelector);
- } catch (InvalidSelectorException e) {
- TestUtil.logMsg("Got InvalidSelectorException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidSelectorException, received " + e);
- pass = false;
- }
-
- TestUtil.logMsg(
- "Testing Session.createSharedDurableConsumer(Topic, String, String) for InvalidSelectorException");
- try {
- TestUtil.logMsg(
- "Calling Session.createSharedDurableConsumer(Topic, String, String) -> expect InvalidSelectorException");
- session.createSharedDurableConsumer(topic, "InvalidSelectorException",
- invalidMessageSelector);
- } catch (InvalidSelectorException e) {
- TestUtil.logMsg("Got InvalidSelectorException as expected.");
- } catch (Exception e) {
- TestUtil.logErr("Expected InvalidSelectorException, received " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("invalidSelectorExceptionTopicTests", e);
- }
-
- if (!pass) {
- throw new Exception("invalidSelectorExceptionTopicTests failed");
- }
- }
-
- /*
- * @testName: illegalStateExceptionTests
- *
- * @assertion_ids: JMS:SPEC:185.9; JMS:SPEC:185.10; JMS:SPEC:185;
- * JMS:JAVADOC:1349; JMS:JAVADOC:1350; JMS:JAVADOC:1390; JMS:JAVADOC:1391;
- *
- * @test_Strategy: Create a QueueSession and call Topic specific methods
- * inherited from Session, and verify that jakarta.jms.IllegalStateException is
- * thrown.
- *
- * Call the following topic methods on a QueueSession:
- *
- * QueueSession.createDurableConsumer(Topic, String)
- * QueueSession.createDurableConsumer(Topic, String, String, boolean)
- * QueueSession.createSharedConsumer(Topic, String)
- * QueueSession.createSharedConsumer(Topic, String, String)
- * QueueSession.createSharedDurableConsumer(Topic, String)
- * QueueSession.createSharedDurableConsumer(Topic, String, String)
- *
- * Test jakarta.jms.IllegalStateException from the following API's. Also test
- * when nolocal=true and client id is not set.
- *
- * Session.createDurableSubscriber(Topic, String)
- * Session.createDurableSubscriber(Topic, String, String, boolean)
- * Session.createDurableConsumer(Topic, String)
- * Session.createDurableConsumer(Topic, String, String, boolean)
- */
- public void illegalStateExceptionTests() throws Exception {
- JmsTool toolq = null;
- String lookupNormalTopicFactory = "MyTopicConnectionFactory";
- boolean pass = true;
- MessageConsumer consumer = null;
- TopicSubscriber subscriber = null;
- try {
- // Set up JmsTool for Queue setup
- toolq = new JmsTool(JmsTool.QUEUE, user, password, mode);
-
- Destination destination = toolT.getDefaultDestination();
- Topic topic = (Topic) destination;
- try {
- TestUtil.logMsg(
- "Calling QueueSession.createDurableConsumer(Topic, String)");
- toolq.getDefaultQueueSession().createDurableConsumer(topic, "mySub1");
- pass = false;
- TestUtil.logErr("QueueSession.createDurableConsumer(Topic, String) "
- + "didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg("Got expected IllegalStateException from "
- + "QueueSession.createDurableConsumer(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Calling QueueSession.createDurableConsumer(Topic, String, String, boolean)");
- toolq.getDefaultQueueSession().createDurableConsumer(topic, "mySub1",
- "TEST = 'test'", false);
- pass = false;
- TestUtil.logErr(
- "QueueSession.createDurableConsumer(Topic, String, String, boolean) "
- + "didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg("Got expected IllegalStateException from "
- + "QueueSession.createDurableConsumer(Topic, String, String, boolean)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil
- .logMsg("Calling QueueSession.createSharedConsumer(Topic, String)");
- toolq.getDefaultQueueSession().createSharedConsumer(topic, "mySub1");
- pass = false;
- TestUtil.logErr("QueueSession.createSharedConsumer(Topic, String) "
- + "didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg("Got expected IllegalStateException from "
- + "QueueSession.createSharedConsumer(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Calling QueueSession.createSharedConsumer(Topic, String, String)");
- toolq.getDefaultQueueSession().createSharedConsumer(topic, "mySub1",
- "TEST = 'test'");
- pass = false;
- TestUtil
- .logErr("QueueSession.createSharedConsumer(Topic, String, String) "
- + "didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg("Got expected IllegalStateException from "
- + "QueueSession.createSharedConsumer(Topic, String, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Calling QueueSession.createSharedDurableConsumer(Topic, String)");
- toolq.getDefaultQueueSession().createSharedDurableConsumer(topic,
- "mySub1");
- pass = false;
- TestUtil
- .logErr("QueueSession.createSharedDurableConsumer(Topic, String) "
- + "didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg("Got expected IllegalStateException from "
- + "QueueSession.createSharedDurableConsumer(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Calling QueueSession.createSharedDurableConsumer(Topic, String, String)");
- toolq.getDefaultQueueSession().createSharedDurableConsumer(topic,
- "mySub1", "TEST = 'test'");
- pass = false;
- TestUtil.logErr(
- "QueueSession.createSharedDurableConsumer(Topic, String, String) "
- + "didn't throw expected IllegalStateException.");
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg("Got expected IllegalStateException from "
- + "QueueSession.createSharedDurableConsumer(Topic, String, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Create a Durable Subscriber with clientid unset (expect IllegalStateException");
- TestUtil
- .logMsg("Calling Session.createDurableSubscriber(Topic, String)");
- subscriber = toolT.getDefaultSession().createDurableSubscriber(topic,
- "mySub1");
- pass = false;
- TestUtil.logErr("Session.createDurableSubscriber(Topic, String) "
- + "didn't throw expected IllegalStateException.");
- try {
- subscriber.close();
- toolT.getDefaultSession().unsubscribe("mySub1");
- } catch (Exception e) {
- }
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg("Got expected IllegalStateException from "
- + "Session.createDurableSubscriber(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Create a Durable Subscriber with noLocal=true and clientid unset (expect IllegalStateException");
- TestUtil.logMsg(
- "Calling Session.createDurableSubscriber(Topic, String, String, boolean)");
- subscriber = toolT.getDefaultSession().createDurableSubscriber(topic,
- "mySub1", "TEST = 'test'", true);
- pass = false;
- TestUtil.logErr(
- "Session.createDurableSubscriber(Topic, String, String, boolean) "
- + "didn't throw expected IllegalStateException.");
- try {
- subscriber.close();
- toolT.getDefaultSession().unsubscribe("mySub1");
- } catch (Exception e) {
- }
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg("Got expected IllegalStateException from "
- + "Session.createDurableSubscriber(Topic, String, String, boolean)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Create a Durable Consumer with clientid unset (expect IllegalStateException");
- TestUtil.logMsg("Calling Session.createDurableConsumer(Topic, String)");
- consumer = toolT.getDefaultSession().createDurableConsumer(topic,
- "mySub1");
- pass = false;
- TestUtil.logErr("Session.createDurableConsumer(Topic, String) "
- + "didn't throw expected IllegalStateException.");
- try {
- consumer.close();
- toolT.getDefaultSession().unsubscribe("mySub1");
- } catch (Exception e) {
- }
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg("Got expected IllegalStateException from "
- + "Session.createDurableConsumer(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
-
- try {
- TestUtil.logMsg(
- "Create a Durable Consumer with noLocal=true and clientid unset (expect IllegalStateException");
- TestUtil.logMsg(
- "Calling Session.createDurableConsumer(Topic, String, String, boolean)");
- consumer = toolT.getDefaultSession().createDurableConsumer(topic,
- "mySub1", "TEST = 'test'", true);
- pass = false;
- TestUtil.logErr(
- "Session.createDurableConsumer(Topic, String, String, boolean) "
- + "didn't throw expected IllegalStateException.");
- try {
- consumer.close();
- toolT.getDefaultSession().unsubscribe("mySub1");
- } catch (Exception e) {
- }
- } catch (jakarta.jms.IllegalStateException ex) {
- TestUtil.logMsg("Got expected IllegalStateException from "
- + "Session.createDurableConsumer(Topic, String, String, boolean)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("illegalStateExceptionTests Failed");
- } finally {
- try {
- toolq.getDefaultQueueConnection().close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- }
-
- if (!pass) {
- throw new Exception("illegalStateExceptionTests Failed");
- }
- }
-
- /*
- * @testName: jMSExceptionTests
- *
- * @assertion_ids: JMS:JAVADOC:1091; JMS:JAVADOC:257; JMS:JAVADOC:1090;
- * JMS:JAVADOC:1164; JMS:JAVADOC:1168; JMS:JAVADOC:1394; JMS:JAVADOC:1397;
- *
- * @test_Strategy: Test JMSException conditions from various API methods.
- *
- * TopicSession.createDurableSubscriber(Topic, String)
- * TopicSession.createDurableSubscriber(Topic, String. String, boolean)
- * Session.createDurableSubscriber(Topic, String)
- * Session.createDurableSubscriber(Topic, String. String, boolean)
- * Session.createDurableConsumer(Topic, String)
- * Session.createDurableConsumer(Topic, String. String, boolean)
- * Session.createSharedConsumer(Topic, String)
- * Session.createSharedConsumer(Topic, String, String)
- * Session.createSharedDurableConsumer(Topic, String)
- * Session.createSharedDurableConsumer(Topic, String. String)
- */
- public void jMSExceptionTests() throws Exception {
- boolean pass = true;
- JmsTool toolt = null;
- Topic mytopic = null;
- try {
- // Setup for Topic
- setupGlobalVarsT();
-
- // Create second Topic
- mytopic = (Topic) toolT.createNewTopic("MY_TOPIC2");
-
- // set up JmsTool for TOPIC setup (normal factory no clientid set)
- toolt = new JmsTool(JmsTool.TOPIC, user, password,
- lookupNormalTopicFactory, mode);
-
- try {
- TestUtil.logMsg(
- "Create a Durable TopicSubscriber with noLocal=true and clientid unset (expect JMSException");
- TestUtil.logMsg(
- "Calling TopicSession.createDurableSubscriber(Topic, String, String, boolean)");
- subscriber = toolt.getDefaultTopicSession()
- .createDurableSubscriber(topic, "mySub1", "TEST = 'test'", true);
- pass = false;
- TestUtil.logErr(
- "TopicSession.createDurableSubscriber(Topic, String, String, boolean) "
- + "didn't throw expected JMSException.");
- } catch (jakarta.jms.JMSException ex) {
- TestUtil.logMsg("Got expected JMSException from "
- + "TopicSession.createDurableSubscriber(Topic, String, String, boolean)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (subscriber != null)
- subscriber.close();
- toolt.getDefaultTopicConnection().close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- }
-
- try {
- TestUtil.logMsg(
- "Create a Durable Consumer with noLocal=true and clientid unset (expect JMSException");
- TestUtil.logMsg(
- "Calling Session.createDurableConsumer(Topic, String, String, boolean)");
- consumer = null;
- consumer = session.createDurableConsumer(topic, "mySub1",
- "TEST = 'test'", true);
- pass = false;
- TestUtil.logErr(
- "Session.createDurableConsumer(Topic, String, String, boolean) "
- + "didn't throw expected JMSException.");
- } catch (jakarta.jms.JMSException ex) {
- TestUtil.logMsg("Got expected JMSException from "
- + "Session.createDurableConsumer(Topic, String, String, boolean)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- }
-
- try {
- TestUtil.logMsg(
- "Create a Durable TopicSubscriber with noLocal=true and clientid unset (expect JMSException");
- TestUtil.logMsg(
- "Calling Session.createDurableSubscriber(Topic, String, String, boolean)");
- subscriber = null;
- subscriber = session.createDurableSubscriber(topic, "mySub1",
- "TEST = 'test'", true);
- pass = false;
- TestUtil.logErr(
- "Session.createDurableSubscriber(Topic, String, String, boolean) "
- + "didn't throw expected JMSException.");
- } catch (jakarta.jms.JMSException ex) {
- TestUtil.logMsg("Got expected JMSException from "
- + "Session.createDurableSubscriber(Topic, String, String, boolean)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (subscriber != null)
- subscriber.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("jMSExceptionTests Failed");
- }
-
- try {
- // Setup for Durable Topic
- toolT.getDefaultConnection().close();
- toolT.closeAllResources();
- // set up JmsTool for COMMON_T setup (durable factory has clientid set)
- toolT2 = new JmsTool(JmsTool.COMMON_T, user, password,
- lookupDurableTopicFactory, mode);
- setupGlobalVarsT2();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- throw new Exception("jMSExceptionTests Failed");
- }
-
- // Create durable subscriber specifying topic and name
- // Create second durable subscriber with same name but specifying different
- // topic,
- // Verify JMSException is thrown.
- try {
- TestUtil.logMsg("Create durable subscriber");
- TestUtil.logMsg("Calling Session.createDurableSubscriber(Topic, String)");
- subscriber = subscriber2 = null;
- subscriber = session.createDurableSubscriber(topic,
- "dummySubSCJMSException");
- TestUtil.logMsg(
- "Create second durable subscriber with same name but different topic");
- TestUtil.logMsg("Calling Session.createDurableSubscriber(Topic, String)");
- subscriber2 = session.createDurableSubscriber(mytopic,
- "dummySubSCJMSException");
- TestUtil.logMsg("Verify that JMSException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSException");
- } catch (JMSException ex) {
- TestUtil.logMsg("Got expected JMSException from "
- + "Session.createDurableSubscriber(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (subscriber != null)
- subscriber.close();
- if (subscriber2 != null)
- subscriber2.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- // Create durable subscriber specifying topic, name, message selector and
- // nolcal
- // Create second durable subscriber with same name but specifying different
- // topic
- // message selector, or nolocal. Verify JMSException is thrown.
- try {
- TestUtil.logMsg("Create durable subscriber");
- TestUtil.logMsg(
- "Calling Session.createDurableSubscriber(Topic, String, String, boolean)");
- subscriber = subscriber2 = null;
- subscriber = session.createDurableSubscriber(topic,
- "dummySubSCJMSException", "TEST = 'test'", false);
- TestUtil.logMsg(
- "Create second durable subscriber with same name but different topic");
- TestUtil.logMsg(
- "Calling Session.createDurableSubscriber(Topic, String, String, boolean)");
- subscriber2 = session.createDurableSubscriber(mytopic,
- "dummySubSCJMSException", "TEST = 'test'", false);
- TestUtil.logMsg("Verify that JMSException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSException");
- } catch (JMSException ex) {
- TestUtil.logMsg("Got expected JMSException from "
- + "Session.createDurableSubscriber(Topic, String, String, boolean)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (subscriber != null)
- subscriber.close();
- if (subscriber2 != null)
- subscriber2.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- // Create shared consumer specifying topic and name
- // Create second shared consumer with same name but specifying different
- // topic,
- // Verify JMSException is thrown.
- try {
- TestUtil.logMsg("Create shared consumer");
- TestUtil.logMsg("Calling Session.createSharedConsumer(Topic, String)");
- consumer = consumer2 = null;
- consumer = session.createSharedConsumer(topic, "dummySubSCJMSException");
- TestUtil.logMsg(
- "Create second shared consumer with same name but different topic");
- TestUtil.logMsg("Calling Session.createSharedConsumer(Topic, String)");
- consumer2 = session.createSharedConsumer(mytopic,
- "dummySubSCJMSException");
- TestUtil.logMsg("Verify that JMSException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSException");
- } catch (JMSException ex) {
- TestUtil.logMsg("Got expected JMSException from "
- + "Session.createSharedConsumer(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- if (consumer2 != null)
- consumer2.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- // Create shared consumer specifying topic and name and message selector
- // Create second shared consumer with same name but specifying different
- // topic and message selector
- // Verify JMSException is thrown.
- try {
- TestUtil.logMsg("Create shared consumer");
- TestUtil.logMsg(
- "Calling Session.createSharedConsumer(Topic, String, String)");
- consumer = consumer2 = null;
- consumer = session.createSharedConsumer(topic, "dummySubSCJMSException",
- "TEST = 'test'");
- TestUtil.logMsg(
- "Create second shared consumer with same name but different topic");
- TestUtil.logMsg(
- "Calling Session.createSharedConsumer(Topic, String, String)");
- consumer2 = session.createSharedConsumer(mytopic,
- "dummySubSCJMSException", "TEST = 'test'");
- TestUtil.logMsg("Verify that JMSException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSException");
- } catch (JMSException ex) {
- TestUtil.logMsg("Got expected JMSException from "
- + "Session.createSharedConsumer(Topic, String, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- if (consumer2 != null)
- consumer2.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- // Create shared durable subscription specifying topic, name. selector.
- // Create second shared durable subscription with same name but specifying
- // different topic,
- // selector. Verify JMSException is thrown.
- try {
- TestUtil.logMsg("Create shared durable subscription");
- TestUtil.logMsg(
- "Calling Session.createSharedDurableConsumer(Topic, String, String)");
- consumer = consumer2 = null;
- consumer = session.createSharedDurableConsumer(topic,
- "dummySubSJMSException", "TEST = 'test'");
- TestUtil.logMsg(
- "Create second shared durable subscription with same name but different other args");
- TestUtil.logMsg(
- "Calling Session.createSharedDurableConsumer(Topic, String, String)");
- consumer2 = session.createSharedDurableConsumer(mytopic,
- "dummySubSJMSException", "TEST = 'test2'");
- TestUtil.logMsg("Verify that JMSException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSException");
- } catch (JMSException ex) {
- TestUtil.logMsg("Got expected JMSException from "
- + "Session.createSharedDurableConsumer(Topic, String, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer2 != null)
- consumer2.close();
- cleanupSubscription(consumer, session, "dummySubSJMSException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- // Create durable subscription specifying topic and name
- // Create second durable subscription with same name but specifying
- // different topic,
- // Verify JMSException is thrown.
- try {
- TestUtil.logMsg("Create durable subscription");
- TestUtil.logMsg("Calling Session.createDurableConsumer(Topic, String)");
- consumer = consumer2 = null;
- consumer = session.createDurableConsumer(topic, "dummySubDJMSException");
- TestUtil.logMsg(
- "Create second durable subscription with same name but different topic");
- TestUtil.logMsg("Calling Session.createDurableConsumer(Topic, String)");
- consumer2 = session.createDurableConsumer(mytopic,
- "dummySubDJMSException");
- TestUtil.logMsg("Verify that JMSException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSException");
- } catch (JMSException ex) {
- TestUtil.logMsg("Got expected JMSException from "
- + "Session.createDurableConsumer(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer2 != null)
- consumer2.close();
- cleanupSubscription(consumer, session, "dummySubDJMSException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- // Create shared durable subscription specifying topic and name
- // Create second shared durable subscription with same name but specifying
- // different topic,
- // Verify JMSException is thrown.
- try {
- TestUtil.logMsg("Create shared durable subscription");
- TestUtil
- .logMsg("Calling Session.createSharedDurableConsumer(Topic, String)");
- consumer = consumer2 = null;
- consumer = session.createSharedDurableConsumer(topic,
- "dummySubSDJMSException");
- TestUtil.logMsg(
- "Create second shared durable subscription with same name but different topic");
- TestUtil
- .logMsg("Calling Session.createSharedDurableConsumer(Topic, String)");
- consumer2 = session.createSharedDurableConsumer(mytopic,
- "dummySubSDJMSException");
- TestUtil.logMsg("Verify that JMSException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSException");
- } catch (JMSException ex) {
- TestUtil.logMsg("Got expected JMSException from "
- + "Session.createSharedDurableConsumer(Topic, String)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer2 != null)
- consumer2.close();
- cleanupSubscription(consumer, session, "dummySubSDJMSException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- // Create durable subscription specifying topic, name. selector, and nolocal
- // value.
- // Create second durable subscription with same name but specifying
- // different topic,
- // selector, or nolocal value. Verify JMSException is thrown.
- try {
- TestUtil.logMsg("Create durable subscription");
- TestUtil.logMsg(
- "Calling Session.createDurableConsumer(Topic, String, String, boolean)");
- consumer = consumer2 = null;
- consumer = session.createDurableConsumer(topic, "dummySubDJMSException",
- "TEST = 'test'", false);
- TestUtil.logMsg(
- "Create second durable subscription with same name but different other args");
- TestUtil.logMsg(
- "Calling Session.createDurableConsumer(Topic, String, String, boolean)");
- consumer2 = session.createDurableConsumer(mytopic,
- "dummySubDJMSException", "TEST = 'test2'", false);
- TestUtil.logMsg("Verify that JMSException is thrown");
- pass = false;
- TestUtil.logErr("Didn't throw expected JMSException");
- } catch (JMSException ex) {
- TestUtil.logMsg("Got expected JMSException from "
- + "Session.createDurableConsumer(Topic, String, String, boolean)");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- pass = false;
- } finally {
- try {
- if (consumer2 != null)
- consumer2.close();
- cleanupSubscription(consumer, session, "dummySubDJMSException");
- toolT.getDefaultConnection().close();
- toolT.closeAllResources();
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- }
- }
-
- if (!pass) {
- throw new Exception("jMSExceptionTests Failed");
- }
- }
-
- /*
- * @testName: sendAndRecvMsgsOfEachMsgTypeQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:209; JMS:JAVADOC:212; JMS:JAVADOC:213;
- * JMS:JAVADOC:215; JMS:JAVADOC:217; JMS:JAVADOC:219; JMS:JAVADOC:221;
- * JMS:JAVADOC:223; JMS:JAVADOC:242; JMS:JAVADOC:317; JMS:JAVADOC:504;
- * JMS:JAVADOC:510;
- *
- * @test_Strategy: Send and receive messages of each message type: Message,
- * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Tests
- * the following API's
- *
- * ConnectionFactory.createConnection(String, String)
- * Connection.createSession(boolean, int) Session.createMessage()
- * Session.createBytesMessage() Session.createMapMessage()
- * Session.createObjectMessage() Session.createObjectMessage(Serializable
- * object) Session.createStreamMessage() Session.createTextMessage()
- * Session.createTextMessage(String) Session.createConsumer(Destination)
- * Session.createProducer(Destination) MessageProducer.send(Message)
- * MessageConsumer.receive(long timeout)
- */
- public void sendAndRecvMsgsOfEachMsgTypeQueueTest() throws Exception {
- boolean pass = true;
- try {
- // Setup for Queue
- setupGlobalVarsQ();
-
- // send and receive Message
- TestUtil.logMsg("Send Message");
- Message msg = session.createMessage();
- TestUtil.logMsg("Set some values in Message");
- msg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeQueueTest");
- msg.setBooleanProperty("booleanProperty", true);
- producer.send(msg);
- TestUtil.logMsg("Receive Message");
- Message msgRecv = consumer.receive(timeout);
- if (msgRecv == null) {
- throw new Exception("Did not receive Message");
- }
- TestUtil.logMsg("Check the values in Message");
- if (msgRecv.getBooleanProperty("booleanProperty") == true) {
- TestUtil.logMsg("booleanproperty is correct");
- } else {
- TestUtil.logMsg("booleanproperty is incorrect");
- pass = false;
- }
-
- // send and receive BytesMessage
- TestUtil.logMsg("Send BytesMessage");
- BytesMessage bMsg = session.createBytesMessage();
- TestUtil.logMsg("Set some values in BytesMessage");
- bMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeQueueTest");
- bMsg.writeByte((byte) 1);
- bMsg.writeInt((int) 22);
- producer.send(bMsg);
- TestUtil.logMsg("Receive BytesMessage");
- BytesMessage bMsgRecv = (BytesMessage) consumer.receive(timeout);
- if (bMsgRecv == null) {
- throw new Exception("Did not receive BytesMessage");
- }
- TestUtil.logMsg("Check the values in BytesMessage");
- if (bMsgRecv.readByte() == (byte) 1) {
- TestUtil.logMsg("bytevalue is correct");
- } else {
- TestUtil.logMsg("bytevalue is incorrect");
- pass = false;
- }
- if (bMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
-
- // send and receive MapMessage
- TestUtil.logMsg("Send MapMessage");
- MapMessage mMsg = session.createMapMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- mMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeQueueTest");
- mMsg.setBoolean("booleanvalue", true);
- mMsg.setInt("intvalue", (int) 10);
- producer.send(mMsg);
- TestUtil.logMsg("Receive MapMessage");
- MapMessage mMsgRecv = (MapMessage) consumer.receive(timeout);
- if (mMsgRecv == null) {
- throw new Exception("Did not receive MapMessage");
- }
- TestUtil.logMsg("Check the values in MapMessage");
- Enumeration list = mMsgRecv.getMapNames();
- String name = null;
- while (list.hasMoreElements()) {
- name = (String) list.nextElement();
- if (name.equals("booleanvalue")) {
- if (mMsgRecv.getBoolean(name) == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logErr("booleanvalue is incorrect");
- pass = false;
- }
- } else if (name.equals("intvalue")) {
- if (mMsgRecv.getInt(name) == 10) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logErr("intvalue is incorrect");
- pass = false;
- }
- } else {
- TestUtil.logErr("Unexpected name of [" + name + "] in MapMessage");
- pass = false;
- }
- }
-
- // send and receive ObjectMessage
- TestUtil.logMsg("Send ObjectMessage");
- StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
- TestUtil.logMsg("Set some values in ObjectMessage");
- ObjectMessage oMsg = session.createObjectMessage();
- oMsg.setObject(sb1);
- oMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeQueueTest");
- producer.send(oMsg);
- TestUtil.logMsg("Receive ObjectMessage");
- ObjectMessage oMsgRecv = (ObjectMessage) consumer.receive(timeout);
- if (oMsgRecv == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- TestUtil.logMsg("Check the value in ObjectMessage");
- StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
- if (sb2.toString().equals(sb1.toString())) {
- TestUtil.logMsg("objectvalue is correct");
- } else {
- TestUtil.logErr("objectvalue is incorrect");
- pass = false;
- }
-
- // send and receive ObjectMessage passing object as param
- TestUtil.logMsg("Send ObjectMessage passing object as param");
- sb1 = new StringBuffer("This is a StringBuffer");
- TestUtil
- .logMsg("Set some values in ObjectMessage passing object as param");
- oMsg = session.createObjectMessage(sb1);
- oMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeQueueTest");
- producer.send(oMsg);
- TestUtil.logMsg("Receive ObjectMessage");
- oMsgRecv = (ObjectMessage) consumer.receive(timeout);
- if (oMsgRecv == null) {
- throw new Exception("Did not receive ObjectMessage");
- }
- TestUtil.logMsg("Check the value in ObjectMessage");
- sb2 = (StringBuffer) oMsgRecv.getObject();
- if (sb2.toString().equals(sb1.toString())) {
- TestUtil.logMsg("objectvalue is correct");
- } else {
- TestUtil.logErr("objectvalue is incorrect");
- pass = false;
- }
-
- // send and receive StreamMessage
- TestUtil.logMsg("Send StreamMessage");
- StreamMessage sMsg = session.createStreamMessage();
- TestUtil.logMsg("Set some values in StreamMessage");
- sMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeQueueTest");
- sMsg.writeBoolean(true);
- sMsg.writeInt((int) 22);
- producer.send(sMsg);
- TestUtil.logMsg("Receive StreamMessage");
- StreamMessage sMsgRecv = (StreamMessage) consumer.receive(timeout);
- if (sMsgRecv == null) {
- throw new Exception("Did not receive StreamMessage");
- }
- TestUtil.logMsg("Check the values in StreamMessage");
- if (sMsgRecv.readBoolean() == true) {
- TestUtil.logMsg("booleanvalue is correct");
- } else {
- TestUtil.logMsg("booleanvalue is incorrect");
- pass = false;
- }
- if (sMsgRecv.readInt() == (int) 22) {
- TestUtil.logMsg("intvalue is correct");
- } else {
- TestUtil.logMsg("intvalue is incorrect");
- pass = false;
- }
-
- // send and receive TextMessage
- TestUtil.logMsg("Send TextMessage");
- TextMessage tMsg = session.createTextMessage();
- TestUtil.logMsg("Set some values in MapMessage");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeQueueTest");
- tMsg.setText("Hello There!");
- producer.send(tMsg);
- TestUtil.logMsg("Receive TextMessage");
- TextMessage tMsgRecv = (TextMessage) consumer.receive(timeout);
- if (tMsgRecv == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (tMsgRecv.getText().equals("Hello There!")) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect");
- pass = false;
- }
-
- // send and receive TextMessage passing string as param
- TestUtil.logMsg("Send TextMessage");
- tMsg = session.createTextMessage("Where are you!");
- TestUtil.logMsg("Set some values in TextMessage");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvMsgsOfEachMsgTypeQueueTest");
- producer.send(tMsg);
- TestUtil.logMsg("Receive TextMessage");
- tMsgRecv = (TextMessage) consumer.receive(timeout);
- if (tMsgRecv == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (tMsgRecv.getText().equals("Where are you!")) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("sendAndRecvMsgsOfEachMsgTypeQueueTest", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvMsgsOfEachMsgTypeQueueTest failed");
- }
- }
-
- /*
- * @testName: createTemporayQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:194;
- *
- * @test_Strategy: Test the following APIs:
- *
- * Session.createTemporaryQueue().
- *
- * Send and receive a TextMessage to temporary queue. Compare send and recv
- * message for equality.
- */
- public void createTemporayQueueTest() throws Exception {
- boolean pass = true;
- MessageConsumer tConsumer = null;
- try {
-
- String message = "a text message";
-
- // Setup for Queue
- setupGlobalVarsQ();
-
- // create a TemporaryQueue
- TestUtil.logMsg("Creating TemporaryQueue");
- TemporaryQueue tempQueue = session.createTemporaryQueue();
-
- // Create a MessageConsumer for this Temporary Queue
- TestUtil.logMsg("Creating MessageConsumer");
- tConsumer = session.createConsumer(tempQueue);
-
- // Create a MessageProducer for this Temporary Queue
- TestUtil.logMsg("Creating MessageProducer");
- MessageProducer tProducer = session.createProducer(tempQueue);
-
- // Send TextMessage to temporary queue
- TestUtil.logMsg("Creating TextMessage with text [" + message + "]");
- TextMessage tMsg = session.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createTemporayQueueTest");
- TestUtil.logMsg("Send TextMessage to temporaty queue");
- tProducer.send(tMsg);
-
- // Receive TextMessage from temporary queue
- TestUtil.logMsg("Receive TextMessage from temporaty queue");
- TextMessage tMsgRecv = null;
- if (tConsumer != null)
- tMsgRecv = (TextMessage) tConsumer.receive(timeout);
- if (tMsgRecv == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (tMsgRecv.getText().equals(message)) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr("TextMessage is incorrect");
- pass = false;
- }
-
- TestUtil.logMsg(
- "Attempting to delete temporary queue with an open consumer should not be allowed");
- try {
- tempQueue.delete();
- pass = false;
- TestUtil
- .logErr("TemporaryQueue.delete() didn't throw expected Exception");
- } catch (JMSException em) {
- TestUtil.logMsg("Received expected JMSException: ");
- } catch (Exception e) {
- TestUtil.logErr("Received unexpected JMSException: " + e);
- pass = false;
- }
-
- try {
- if (tConsumer != null)
- tConsumer.close();
- } catch (Exception e) {
- }
-
- TestUtil.logMsg(
- "Attempting to delete temporary queue with no open consumer should be allowed");
- try {
- tempQueue.delete();
- } catch (Exception e) {
- pass = false;
- TestUtil.logErr("Received unexpected Exception: ", e);
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createTemporayQueueTest");
- }
-
- if (!pass) {
- throw new Exception("createTemporayQueueTest failed");
- }
- }
-
- /*
- * @testName: createQueueBrowserTest
- *
- * @assertion_ids: JMS:JAVADOC:258; JMS:JAVADOC:260;
- *
- * @test_Strategy: Test the following APIs:
- *
- * Session.createBrowser(Queue) Session.createBrowser(Queue, String)
- *
- * 1. Send x text messages to a Queue. 2. Create a QueueBrowser with selector
- * to browse just the last message in the Queue. 3. Create a QueueBrowser
- * again to browse all the messages in the queue.
- */
- public void createQueueBrowserTest() throws Exception {
- boolean pass = true;
- QueueBrowser qBrowser = null;
- try {
- TextMessage tempMsg = null;
- Enumeration msgs = null;
-
- // Setup for Queue
- setupGlobalVarsQ();
- consumer.close();
-
- // send "numMessages" messages to Queue plus end of stream message
- TestUtil.logMsg("Send " + numMessages + " to Queue");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createQueueBrowserTest" + i);
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- // create QueueBrowser to peek at last message in Queue using message
- // selector
- TestUtil.logMsg(
- "Create QueueBrowser to peek at last message in Queue using message selector");
- qBrowser = session.createBrowser(queue, "lastMessage = TRUE");
-
- // check that browser just has the last message in the Queue
- TestUtil.logMsg("Check that browser has just the last message");
- int msgCount = 0;
- msgs = qBrowser.getEnumeration();
- while (msgs.hasMoreElements()) {
- tempMsg = (TextMessage) msgs.nextElement();
- if (!tempMsg.getText().equals("Message " + numMessages)) {
- TestUtil.logErr("Found [" + tempMsg.getText()
- + "] in browser expected [Message 3]");
- pass = false;
- } else {
- TestUtil.logMsg("Found correct [Message 3] in browser");
- }
- msgCount++;
- }
- if (msgCount != 1) {
- TestUtil
- .logErr("Found " + msgCount + " messages in browser expected 1");
- pass = false;
- } else {
- TestUtil.logMsg("Found 1 message in browser (correct)");
- }
- qBrowser.close();
-
- // create QueueBrowser to peek at all messages in the Queue
- TestUtil
- .logMsg("Create QueueBrowser to browse all messages in the Queue");
- qBrowser = session.createBrowser(queue);
-
- // check for messages
- TestUtil.logMsg(
- "Check that browser contains all " + numMessages + " messages");
- msgCount = 0;
- int msgIndex = 1;
- msgs = qBrowser.getEnumeration();
- while (msgs.hasMoreElements()) {
- tempMsg = (TextMessage) msgs.nextElement();
- if (!tempMsg.getText().equals("Message " + msgIndex)) {
- TestUtil.logErr("Found [" + tempMsg.getText()
- + "] in browser expected [Message " + msgIndex + "]");
- pass = false;
- }
- msgCount++;
- msgIndex++;
- }
- if (msgCount != numMessages) {
- TestUtil.logErr("Found " + msgCount + " messages in browser expected "
- + numMessages);
- pass = false;
- } else {
- TestUtil
- .logMsg("Found " + numMessages + " messages in browser (correct)");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createQueueBrowserTest");
- } finally {
- try {
- if (qBrowser != null)
- qBrowser.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("createQueueBrowserTest failed");
- }
- }
-
- /*
- * @testName: getTransactedQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:225;
- *
- * @test_Strategy: Test the following APIs:
- *
- * Session.getTransacted().
- */
- public void getTransactedQueueTest() throws Exception {
- boolean pass = true;
-
- // Test for transacted mode false
- try {
- // Setup for Queue
- setupGlobalVarsQ();
- session.close();
-
- session = connection.createSession(Session.AUTO_ACKNOWLEDGE);
- boolean expTransacted = false;
- TestUtil.logMsg("Calling getTransacted and expect " + expTransacted
- + " to be returned");
- boolean actTransacted = session.getTransacted();
- if (actTransacted != expTransacted) {
- TestUtil.logErr("getTransacted() returned " + actTransacted
- + ", expected " + expTransacted);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getTransactedQueueTest", e);
- } finally {
- try {
- if (session != null)
- session.close();
- } catch (Exception e) {
- }
- }
-
- // Test for transacted mode true
- if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
- try {
- session = connection.createSession(Session.SESSION_TRANSACTED);
- boolean expTransacted = true;
- TestUtil.logMsg("Calling getTransacted and expect " + expTransacted
- + " to be returned");
- boolean actTransacted = session.getTransacted();
- if (actTransacted != expTransacted) {
- TestUtil.logErr("getTransacted() returned " + actTransacted
- + ", expected " + expTransacted);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getTransactedQueueTest", e);
- } finally {
- try {
- if (session != null)
- session.close();
- } catch (Exception e) {
- }
- }
- }
-
- if (!pass) {
- throw new Exception("getTransactedQueueTest failed");
- }
- }
-
- /*
- * @testName: getAcknowledgeModeQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:227;
- *
- * @test_Strategy: Test the following APIs:
- *
- * Session.getAcknowledgeMode().
- */
- public void getAcknowledgeModeQueueTest() throws Exception {
- boolean pass = true;
-
- // Test for AUTO_ACKNOWLEDGE mode
- try {
- // Setup for Queue
- setupGlobalVarsQ();
- session.close();
-
- session = connection.createSession(Session.AUTO_ACKNOWLEDGE);
- int expAcknowledgeMode = Session.AUTO_ACKNOWLEDGE;
- TestUtil.logMsg("Calling getAcknowledgeMode and expect "
- + expAcknowledgeMode + " to be returned");
- int actAcknowledgeMode = session.getAcknowledgeMode();
- if (actAcknowledgeMode != expAcknowledgeMode) {
- TestUtil.logErr("getAcknowledgeMode() returned " + actAcknowledgeMode
- + ", expected " + expAcknowledgeMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getAcknowledgeModeTopicTest", e);
- } finally {
- try {
- if (session != null)
- session.close();
- } catch (Exception e) {
- }
- }
-
- // Test for DUPS_OK_ACKNOWLEDGE mode
- try {
- session = connection.createSession(Session.DUPS_OK_ACKNOWLEDGE);
- int expAcknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
- TestUtil.logMsg("Calling getAcknowledgeMode and expect "
- + expAcknowledgeMode + " to be returned");
- int actAcknowledgeMode = session.getAcknowledgeMode();
- if (actAcknowledgeMode != expAcknowledgeMode) {
- TestUtil.logErr("getAcknowledgeMode() returned " + actAcknowledgeMode
- + ", expected " + expAcknowledgeMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getAcknowledgeModeTopicTest", e);
- } finally {
- try {
- if (session != null)
- session.close();
- } catch (Exception e) {
- }
- }
-
- // Test for SESSION_TRANSACTED mode
- if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
- try {
- session = connection.createSession(Session.SESSION_TRANSACTED);
- int expAcknowledgeMode = Session.SESSION_TRANSACTED;
- TestUtil.logMsg("Calling getAcknowledgeMode and expect "
- + expAcknowledgeMode + " to be returned");
- int actAcknowledgeMode = session.getAcknowledgeMode();
- if (actAcknowledgeMode != expAcknowledgeMode) {
- TestUtil.logErr("getAcknowledgeMode() returned " + actAcknowledgeMode
- + ", expected " + expAcknowledgeMode);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("getAcknowledgeModeTopicTest", e);
- } finally {
- try {
- if (session != null)
- session.close();
- } catch (Exception e) {
- }
- }
- }
-
- if (!pass) {
- throw new Exception("getAcknowledgeModeQueueTest failed");
- }
- }
-
- /*
- * @testName: createConsumerProducerQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:221; JMS:JAVADOC:242; JMS:JAVADOC:244;
- * JMS:JAVADOC:246; JMS:JAVADOC:248; JMS:JAVADOC:504; JMS:JAVADOC:510;
- * JMS:JAVADOC:597; JMS:JAVADOC:334;
- *
- * @test_Strategy: Test the following APIs:
- *
- * ConnectionFactory.createConnection(String, String)
- * Connection.createSession(boolean, int) Session.createTextMessage(String)
- * Session.createConsumer(Destination) Session.createConsumer(Destination,
- * String) Session.createConsumer(Destination, String, boolean)
- * Session.createProducer(Destination) MessageProducer.send(Message)
- * MessageConsumer.receive(long timeout)
- *
- * 1. Send x text messages to a Queue. 2. Create a MessageConsumer with
- * selector to consume just the last message in the Queue. 3. Create a
- * MessageConsumer again to consume the rest of the messages in the Queue.
- */
- public void createConsumerProducerQueueTest() throws Exception {
- boolean pass = true;
- try {
- TextMessage tempMsg = null;
- Enumeration msgs = null;
-
- // Setup for Queue
- setupGlobalVarsQ();
- consumer.close();
-
- // send "numMessages" messages to Queue plus end of stream message
- TestUtil.logMsg("Send " + numMessages + " messages to Queue");
- for (int i = 1; i <= numMessages; i++) {
- tempMsg = session.createTextMessage("Message " + i);
- tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "createConsumerProducerQueueTest" + i);
- tempMsg.setJMSType("");
- if (i == numMessages) {
- tempMsg.setBooleanProperty("lastMessage", true);
- } else {
- tempMsg.setBooleanProperty("lastMessage", false);
- }
- producer.send(tempMsg);
- TestUtil.logMsg("Message " + i + " sent");
- }
-
- // Create MessageConsumer to consume last message in Queue using message
- // selector
- TestUtil.logMsg(
- "Create selective consumer to consume messages in Queue with boolproperty (lastMessage=TRUE)");
- consumer = session.createConsumer(destination, "lastMessage=TRUE");
-
- TestUtil.logMsg(
- "Consume messages with selective consumer which has boolproperty (lastMessage=TRUE)");
- if (consumer != null)
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("MessageConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + numMessages + " missing from Queue");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + numMessages)) {
- TestUtil.logErr(
- "Received [" + tempMsg.getText() + "] expected [Message 3]");
- pass = false;
- } else {
- TestUtil.logMsg("Received expected message: " + tempMsg.getText());
- }
-
- // Try to receive one more message (should return null)
- TestUtil.logMsg("Make sure selective consumer receives no more messages");
- if (consumer != null)
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("MessageConsumer.receive() returned NULL");
- TestUtil.logErr(
- "MessageConsumer with selector should have returned just 1 message");
- pass = false;
- }
-
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
-
- // Create MessageConsumer to consume rest of messages in Queue
- TestUtil.logMsg("Consume rest of messages with normal consumer");
- consumer = session.createConsumer(destination);
- for (int msgCount = 1; msgCount < numMessages; msgCount++) {
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg == null) {
- TestUtil.logErr("MessageConsumer.receive() returned NULL");
- TestUtil.logErr("Message " + msgCount + " missing from Queue");
- pass = false;
- } else if (!tempMsg.getText().equals("Message " + msgCount)) {
- TestUtil.logErr("Received [" + tempMsg.getText()
- + "] expected [Message " + msgCount + "]");
- pass = false;
- } else {
- TestUtil.logMsg("Received message: " + tempMsg.getText());
- }
- }
-
- // Try to receive one more message (should return null)
- TestUtil.logMsg("Make sure normal consumer receives no more messages");
- tempMsg = (TextMessage) consumer.receive(timeout);
- if (tempMsg != null) {
- TestUtil.logErr("MessageConsumer should have returned "
- + (numMessages - 1) + " message");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- e.printStackTrace();
- throw new Exception("createConsumerProducerQueueTest");
- } finally {
- try {
- if (consumer != null)
- consumer.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("createConsumerProducerQueueTest failed");
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/core20/sessiontests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/core20/sessiontests/ClientIT.java
new file mode 100644
index 0000000000..290c0b9755
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/core20/sessiontests/ClientIT.java
@@ -0,0 +1,3534 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022 Contributors to Eclipse Foundation. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id: Client.java 68655 2012-11-21 16:26:50Z af70133 $
+ */
+package com.sun.ts.tests.jms.core20.sessiontests;
+
+import java.lang.System.Logger;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.tests.jms.common.JmsTool;
+
+import jakarta.jms.BytesMessage;
+import jakarta.jms.Connection;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.Destination;
+import jakarta.jms.InvalidDestinationException;
+import jakarta.jms.InvalidSelectorException;
+import jakarta.jms.JMSException;
+import jakarta.jms.MapMessage;
+import jakarta.jms.Message;
+import jakarta.jms.MessageConsumer;
+import jakarta.jms.MessageProducer;
+import jakarta.jms.ObjectMessage;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueBrowser;
+import jakarta.jms.Session;
+import jakarta.jms.StreamMessage;
+import jakarta.jms.TemporaryQueue;
+import jakarta.jms.TemporaryTopic;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicSubscriber;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.core20.sessiontests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // JMS tool which creates and/or looks up the JMS administered objects
+ private transient JmsTool toolT = null;
+
+ private transient JmsTool toolT2 = null;
+
+ private transient JmsTool toolQ = null;
+
+ // JMS objects
+ private transient ConnectionFactory cf = null;
+
+ private transient Topic topic = null;
+
+ private transient Queue queue = null;
+
+ private transient Destination destination = null;
+
+ private transient Connection connection = null;
+
+ private transient Session session = null;
+
+ private transient MessageProducer producer = null;
+
+ private transient MessageConsumer consumer = null;
+
+ private transient MessageConsumer consumer2 = null;
+
+ private transient TopicSubscriber subscriber = null;
+
+ private transient TopicSubscriber subscriber2 = null;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ String vehicle = null;
+
+ // used for tests
+ private static final String lookupDurableTopicFactory = "DURABLE_SUB_CONNECTION_FACTORY";
+
+ private static final String lookupNormalTopicFactory = "MyTopicConnectionFactory";
+
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ ArrayList connections = null;
+
+ boolean queueTest = false;
+
+ /*
+ * setupGlobalVarsQ() for Queue
+ */
+ public void setupGlobalVarsQ() throws Exception {
+ cf = toolQ.getConnectionFactory();
+ destination = toolQ.getDefaultDestination();
+ session = toolQ.getDefaultSession();
+ connection = toolQ.getDefaultConnection();
+ producer = toolQ.getDefaultProducer();
+ consumer = toolQ.getDefaultConsumer();
+ queue = (Queue) destination;
+ connection.start();
+ queueTest = true;
+ }
+
+ /*
+ * setupGlobalVarsT() for Topic with normal connection factory (clientid not
+ * set)
+ */
+ public void setupGlobalVarsT() throws Exception {
+ cf = toolT.getConnectionFactory();
+ destination = toolT.getDefaultDestination();
+ session = toolT.getDefaultSession();
+ connection = toolT.getDefaultConnection();
+ producer = toolT.getDefaultProducer();
+ consumer = toolT.getDefaultConsumer();
+ topic = (Topic) destination;
+ connection.start();
+ queueTest = false;
+ }
+
+ /*
+ * setupGlobalVarsT2() for Topic with durable connection factory (clientid set)
+ */
+ public void setupGlobalVarsT2() throws Exception {
+ cf = toolT2.getConnectionFactory();
+ destination = toolT2.getDefaultDestination();
+ session = toolT2.getDefaultSession();
+ connection = toolT2.getDefaultConnection();
+ producer = toolT2.getDefaultProducer();
+ consumer = toolT2.getDefaultConsumer();
+ topic = (Topic) destination;
+ connection.start();
+ queueTest = false;
+ }
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ vehicle = System.getProperty("vehicle");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ connections = new ArrayList(5);
+
+ // set up JmsTool for COMMON_T setup (normal factory has clientid not set)
+ toolT = new JmsTool(JmsTool.COMMON_T, user, password, lookupNormalTopicFactory, mode);
+
+ // set up JmsTool for COMMON_Q setup
+ toolQ = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Closing default Connection");
+ toolQ.getDefaultConnection().close();
+ toolT.getDefaultConnection().close();
+ if (toolT2 != null)
+ toolT2.getDefaultConnection().close();
+ if (queueTest) {
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ toolQ.flushDestination();
+ }
+ toolQ.closeAllResources();
+ toolT.closeAllResources();
+ if (toolT2 != null)
+ toolT2.closeAllResources();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * Cleanup method for tests that use durable subscriptions
+ */
+ private void cleanupSubscription(MessageConsumer consumer, Session session, String subName) {
+ if (consumer != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Closing durable consumer: " + consumer);
+ consumer.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "exception during close: ", e);
+ }
+ }
+
+ if (session != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Unsubscribing \"" + subName + "\"");
+ session.unsubscribe(subName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "exception during unsubscribe: ", e);
+ }
+ }
+ }
+
+ private void cleanupSubscription(TopicSubscriber tSub, Session session, String subName) {
+ if (tSub != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Closing durable subscriber: " + tSub);
+ tSub.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "exception during close: ", e);
+ }
+ }
+
+ if (session != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Unsubscribing \"" + subName + "\"");
+ session.unsubscribe(subName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "exception during unsubscribe: ", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: sendRecvMsgsOfEachMsgTypeTopicTest
+ *
+ * @assertion_ids: JMS:JAVADOC:209; JMS:JAVADOC:212; JMS:JAVADOC:213;
+ * JMS:JAVADOC:215; JMS:JAVADOC:217; JMS:JAVADOC:219; JMS:JAVADOC:221;
+ * JMS:JAVADOC:223; JMS:JAVADOC:242; JMS:JAVADOC:317; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510;
+ *
+ * @test_Strategy: Send and receive messages of each message type: Message,
+ * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Tests
+ * the following API's
+ *
+ * ConnectionFactory.createConnection(String, String)
+ * Connection.createSession(boolean, int) Session.createMessage()
+ * Session.createBytesMessage() Session.createMapMessage()
+ * Session.createObjectMessage() Session.createObjectMessage(Serializable
+ * object) Session.createStreamMessage() Session.createTextMessage()
+ * Session.createTextMessage(String) Session.createConsumer(Destination)
+ * Session.createProducer(Destination) MessageProducer.send(Message)
+ * MessageConsumer.receive(long timeout)
+ */
+ @Test
+ public void sendRecvMsgsOfEachMsgTypeTopicTest() throws Exception {
+ boolean pass = true;
+ try {
+ // Setup for Topic
+ setupGlobalVarsT();
+
+ // send and receive Message
+ logger.log(Logger.Level.INFO, "Send Message");
+ Message msg = session.createMessage();
+ logger.log(Logger.Level.INFO, "Set some values in Message");
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvMsgsOfEachMsgTypeTopicTest");
+ msg.setBooleanProperty("booleanProperty", true);
+ producer.send(msg);
+ logger.log(Logger.Level.INFO, "Receive Message");
+ Message msgRecv = consumer.receive(timeout);
+ if (msgRecv == null) {
+ throw new Exception("Did not receive Message");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in Message");
+ if (msgRecv.getBooleanProperty("booleanProperty") == true) {
+ logger.log(Logger.Level.INFO, "booleanproperty is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanproperty is incorrect");
+ pass = false;
+ }
+
+ // send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Send BytesMessage");
+ BytesMessage bMsg = session.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvMsgsOfEachMsgTypeTopicTest");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ producer.send(bMsg);
+ logger.log(Logger.Level.INFO, "Receive BytesMessage");
+ BytesMessage bMsgRecv = (BytesMessage) consumer.receive(timeout);
+ if (bMsgRecv == null) {
+ throw new Exception("Did not receive BytesMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in BytesMessage");
+ if (bMsgRecv.readByte() == (byte) 1) {
+ logger.log(Logger.Level.INFO, "bytevalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "bytevalue is incorrect");
+ pass = false;
+ }
+ if (bMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+
+ // send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send MapMessage");
+ MapMessage mMsg = session.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvMsgsOfEachMsgTypeTopicTest");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ producer.send(mMsg);
+ logger.log(Logger.Level.INFO, "Receive MapMessage");
+ MapMessage mMsgRecv = (MapMessage) consumer.receive(timeout);
+ if (mMsgRecv == null) {
+ throw new Exception("Did not receive MapMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in MapMessage");
+ Enumeration list = mMsgRecv.getMapNames();
+ String name = null;
+ while (list.hasMoreElements()) {
+ name = (String) list.nextElement();
+ if (name.equals("booleanvalue")) {
+ if (mMsgRecv.getBoolean(name) == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "booleanvalue is incorrect");
+ pass = false;
+ }
+ } else if (name.equals("intvalue")) {
+ if (mMsgRecv.getInt(name) == 10) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "intvalue is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected name of [" + name + "] in MapMessage");
+ pass = false;
+ }
+ }
+
+ // send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Send ObjectMessage");
+ StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ ObjectMessage oMsg = session.createObjectMessage();
+ oMsg.setObject(sb1);
+ oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvMsgsOfEachMsgTypeTopicTest");
+ producer.send(oMsg);
+ logger.log(Logger.Level.INFO, "Receive ObjectMessage");
+ ObjectMessage oMsgRecv = (ObjectMessage) consumer.receive(timeout);
+ if (oMsgRecv == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in ObjectMessage");
+ StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
+ if (sb2.toString().equals(sb1.toString())) {
+ logger.log(Logger.Level.INFO, "objectvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "objectvalue is incorrect");
+ pass = false;
+ }
+
+ // send and receive ObjectMessage passing object as param
+ logger.log(Logger.Level.INFO, "Send ObjectMessage passing object as param");
+ sb1 = new StringBuffer("This is a StringBuffer");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage passing object as param");
+ oMsg = session.createObjectMessage(sb1);
+ oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvMsgsOfEachMsgTypeTopicTest");
+ producer.send(oMsg);
+ logger.log(Logger.Level.INFO, "Receive ObjectMessage");
+ oMsgRecv = (ObjectMessage) consumer.receive(timeout);
+ if (oMsgRecv == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in ObjectMessage");
+ sb2 = (StringBuffer) oMsgRecv.getObject();
+ if (sb2.toString().equals(sb1.toString())) {
+ logger.log(Logger.Level.INFO, "objectvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "objectvalue is incorrect");
+ pass = false;
+ }
+
+ // send and receive StreamMessage
+ logger.log(Logger.Level.INFO, "Send StreamMessage");
+ StreamMessage sMsg = session.createStreamMessage();
+ logger.log(Logger.Level.INFO, "Set some values in StreamMessage");
+ sMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvMsgsOfEachMsgTypeTopicTest");
+ sMsg.writeBoolean(true);
+ sMsg.writeInt((int) 22);
+ producer.send(sMsg);
+ logger.log(Logger.Level.INFO, "Receive StreamMessage");
+ StreamMessage sMsgRecv = (StreamMessage) consumer.receive(timeout);
+ if (sMsgRecv == null) {
+ throw new Exception("Did not receive StreamMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in StreamMessage");
+ if (sMsgRecv.readBoolean() == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanvalue is incorrect");
+ pass = false;
+ }
+ if (sMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Send TextMessage");
+ TextMessage tMsg = session.createTextMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvMsgsOfEachMsgTypeTopicTest");
+ tMsg.setText("Hello There!");
+ producer.send(tMsg);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage tMsgRecv = (TextMessage) consumer.receive(timeout);
+ if (tMsgRecv == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (tMsgRecv.getText().equals("Hello There!")) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect");
+ pass = false;
+ }
+
+ // send and receive TextMessage passing string as param
+ logger.log(Logger.Level.INFO, "Send TextMessage");
+ tMsg = session.createTextMessage("Where are you!");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvMsgsOfEachMsgTypeTopicTest");
+ producer.send(tMsg);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ tMsgRecv = (TextMessage) consumer.receive(timeout);
+ if (tMsgRecv == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (tMsgRecv.getText().equals("Where are you!")) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("sendRecvMsgsOfEachMsgTypeTopicTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendRecvMsgsOfEachMsgTypeTopicTest failed");
+ }
+ }
+
+ /*
+ * @testName: createTemporayTopicTest
+ *
+ * @assertion_ids: JMS:JAVADOC:93;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * Session.createTemporaryTopic().
+ *
+ * Send and receive a TextMessage to temporary topic. Compare send and recv
+ * message for equality.
+ */
+ @Test
+ public void createTemporayTopicTest() throws Exception {
+ boolean pass = true;
+ try {
+
+ String message = "a text message";
+
+ // Setup for Topic
+ setupGlobalVarsT();
+
+ // create a TemporaryTopic
+ logger.log(Logger.Level.INFO, "Creating TemporaryTopic");
+ TemporaryTopic tempTopic = session.createTemporaryTopic();
+
+ // Create a MessageConsumer for this Temporary Topic
+ logger.log(Logger.Level.INFO, "Creating MessageConsumer for TemporaryTopic");
+ MessageConsumer tConsumer = session.createConsumer(tempTopic);
+
+ // Create a MessageProducer for this Temporary Topic
+ logger.log(Logger.Level.INFO, "Creating MessageProducer for TemporaryTopic");
+ MessageProducer tProducer = session.createProducer(tempTopic);
+
+ // Send TextMessage to temporary topic
+ logger.log(Logger.Level.INFO, "Creating TextMessage with text [" + message + "]");
+ TextMessage tMsg = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createTemporayTopicTest");
+ logger.log(Logger.Level.INFO, "Send TextMessage to temporaty topic");
+ tProducer.send(tMsg);
+
+ // Receive TextMessage from temporary topic
+ logger.log(Logger.Level.INFO, "Receive TextMessage from temporaty topic");
+ TextMessage tMsgRecv = (TextMessage) tConsumer.receive(timeout);
+ if (tMsgRecv == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (tMsgRecv.getText().equals(message)) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Attempting to delete temporary topic with an open consumer should not be allowed");
+ try {
+ tempTopic.delete();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TemporaryTopic.delete() didn't throw expected Exception");
+ } catch (JMSException em) {
+ logger.log(Logger.Level.INFO, "Received expected JMSException: ");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Received unexpected Exception: " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO, "Now close the open consumer");
+ try {
+ tConsumer.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Attempting to delete temporary topic with no open consumer should be allowed");
+ try {
+ tempTopic.delete();
+ } catch (Exception e) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received unexpected Exception: ", e);
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createTemporayTopicTest");
+ }
+
+ if (!pass) {
+ throw new Exception("createTemporayTopicTest failed");
+ }
+ }
+
+ /*
+ * @testName: getTransactedTopicTest
+ *
+ * @assertion_ids: JMS:JAVADOC:225;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * Session.getTransacted().
+ */
+ @Test
+ public void getTransactedTopicTest() throws Exception {
+ boolean pass = true;
+
+ // Test for transacted mode false
+ try {
+ // Setup for Topic
+ setupGlobalVarsT();
+ session.close();
+
+ session = connection.createSession(Session.AUTO_ACKNOWLEDGE);
+ boolean expTransacted = false;
+ logger.log(Logger.Level.INFO, "Calling getTransacted and expect " + expTransacted + " to be returned");
+ boolean actTransacted = session.getTransacted();
+ if (actTransacted != expTransacted) {
+ logger.log(Logger.Level.ERROR,
+ "getTransacted() returned " + actTransacted + ", expected " + expTransacted);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getTransactedTopicTest", e);
+ } finally {
+ try {
+ if (session != null)
+ session.close();
+ } catch (Exception e) {
+ }
+ }
+
+ // Test for transacted mode true
+ if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
+ try {
+ session = connection.createSession(Session.SESSION_TRANSACTED);
+ boolean expTransacted = true;
+ logger.log(Logger.Level.INFO, "Calling getTransacted and expect " + expTransacted + " to be returned");
+ boolean actTransacted = session.getTransacted();
+ if (actTransacted != expTransacted) {
+ logger.log(Logger.Level.ERROR,
+ "getTransacted() returned " + actTransacted + ", expected " + expTransacted);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getTransactedTopicTest", e);
+ } finally {
+ try {
+ if (session != null)
+ session.close();
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("getTransactedTopicTest failed");
+ }
+ }
+
+ /*
+ * @testName: getAcknowledgeModeTopicTest
+ *
+ * @assertion_ids: JMS:JAVADOC:227;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * Session.getAcknowledgeMode().
+ */
+ @Test
+ public void getAcknowledgeModeTopicTest() throws Exception {
+ boolean pass = true;
+
+ // Test for AUTO_ACKNOWLEDGE mode
+ try {
+ // Setup for Topic
+ setupGlobalVarsT();
+ session.close();
+
+ session = connection.createSession(Session.AUTO_ACKNOWLEDGE);
+ int expAcknowledgeMode = Session.AUTO_ACKNOWLEDGE;
+ logger.log(Logger.Level.INFO,
+ "Calling getAcknowledgeMode and expect " + expAcknowledgeMode + " to be returned");
+ int actAcknowledgeMode = session.getAcknowledgeMode();
+ if (actAcknowledgeMode != expAcknowledgeMode) {
+ logger.log(Logger.Level.ERROR,
+ "getAcknowledgeMode() returned " + actAcknowledgeMode + ", expected " + expAcknowledgeMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getAcknowledgeModeTopicTest", e);
+ } finally {
+ try {
+ if (session != null)
+ session.close();
+ } catch (Exception e) {
+ }
+ }
+
+ // Test for DUPS_OK_ACKNOWLEDGE mode
+ try {
+ session = connection.createSession(Session.DUPS_OK_ACKNOWLEDGE);
+ int expAcknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
+ logger.log(Logger.Level.INFO,
+ "Calling getAcknowledgeMode and expect " + expAcknowledgeMode + " to be returned");
+ int actAcknowledgeMode = session.getAcknowledgeMode();
+ if (actAcknowledgeMode != expAcknowledgeMode) {
+ logger.log(Logger.Level.ERROR,
+ "getAcknowledgeMode() returned " + actAcknowledgeMode + ", expected " + expAcknowledgeMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getAcknowledgeModeTopicTest", e);
+ } finally {
+ try {
+ if (session != null)
+ session.close();
+ } catch (Exception e) {
+ }
+ }
+
+ // Test for SESSION_TRANSACTED mode
+ if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
+ try {
+ session = connection.createSession(Session.SESSION_TRANSACTED);
+ int expAcknowledgeMode = Session.SESSION_TRANSACTED;
+ logger.log(Logger.Level.INFO,
+ "Calling getAcknowledgeMode and expect " + expAcknowledgeMode + " to be returned");
+ int actAcknowledgeMode = session.getAcknowledgeMode();
+ if (actAcknowledgeMode != expAcknowledgeMode) {
+ logger.log(Logger.Level.ERROR,
+ "getAcknowledgeMode() returned " + actAcknowledgeMode + ", expected " + expAcknowledgeMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getAcknowledgeModeTopicTest", e);
+ } finally {
+ try {
+ if (session != null)
+ session.close();
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("getAcknowledgeModeTopicTest failed");
+ }
+ }
+
+ /*
+ * @testName: createConsumerProducerTopicTest
+ *
+ * @assertion_ids: JMS:JAVADOC:244; JMS:JAVADOC:246; JMS:JAVADOC:248;
+ * JMS:JAVADOC:224; JMS:JAVADOC:242; JMS:JAVADOC:221; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:597; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * ConnectionFactory.createConnection(String, String)
+ * Connection.createSession(boolean, int) Session.createTextMessage(String)
+ * Session.createConsumer(Destination) Session.createConsumer(Destination,
+ * String) Session.createConsumer(Destination, String, boolean)
+ * Session.createProducer(Destination) MessageProducer.send(Message)
+ * MessageConsumer.receive(long timeout)
+ *
+ * 1. Create a MessageConsumer with selector to consumer just the last message
+ * in the Topic with boolproperty (lastMessage=TRUE). 2. Create a
+ * MessageConsumer again to consume all the messages in the Topic. 3. Send x
+ * text messages to a Topic. 4. Verify that both consumers work as expected.
+ */
+ @Test
+ public void createConsumerProducerTopicTest() throws Exception {
+ boolean pass = true;
+ MessageConsumer consumerSelect = null;
+ try {
+ TextMessage tempMsg = null;
+ Enumeration msgs = null;
+
+ // Setup for Topic
+ setupGlobalVarsT();
+ consumer.close();
+
+ // Create selective MessageConsumer to consume messages in Topic with
+ // boolean
+ // property (lastMessage=TRUE)
+ logger.log(Logger.Level.INFO,
+ "Create selective consumer to consume messages in Topic with boolproperty (lastMessage=TRUE)");
+ consumerSelect = session.createConsumer(destination, "lastMessage=TRUE");
+
+ // Create normal MessageConsumer to consume all messages in Topic
+ logger.log(Logger.Level.INFO, "Create normal consumer to consume all messages in Topic");
+ consumer = session.createConsumer(destination);
+
+ // send "numMessages" messages to Topic plus end of stream message
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messsages to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createConsumerProducerTopicTest" + i);
+ tempMsg.setJMSType("");
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Consume messages with selective consumer which has boolproperty (lastMessage=TRUE)");
+ if (consumerSelect != null)
+ tempMsg = (TextMessage) consumerSelect.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "MessageConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + numMessages + " missing from Topic");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + numMessages)) {
+ logger.log(Logger.Level.ERROR, "Received [" + tempMsg.getText() + "] expected [Message 3]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received expected message: " + tempMsg.getText());
+ }
+
+ // Try to receive one more message (should return null)
+ logger.log(Logger.Level.INFO, "Make sure selective consumer receives no more messages");
+ if (consumerSelect != null)
+ tempMsg = (TextMessage) consumerSelect.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR,
+ "MessageConsumer.receive() returned a message [" + tempMsg.getText() + "] (Expected NULL)");
+ logger.log(Logger.Level.ERROR, "MessageConsumer with selector should have returned just 1 message");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "No more messages for selective consumer (Correct)");
+ }
+
+ try {
+ if (consumerSelect != null)
+ consumerSelect.close();
+ } catch (Exception e) {
+ }
+
+ logger.log(Logger.Level.INFO, "Consume all messages with normal consumer");
+ for (int msgCount = 1; msgCount <= numMessages; msgCount++) {
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "MessageConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + msgCount + " missing from Topic");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + msgCount)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + msgCount + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message: " + tempMsg.getText());
+ }
+ }
+
+ // Try to receive one more message (should return null)
+ logger.log(Logger.Level.INFO, "Make sure normal consumer receives no more messages");
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR, "Received [" + tempMsg.getText() + "] expected no message");
+ logger.log(Logger.Level.ERROR, "MessageConsumer should have returned " + numMessages + " messages");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createConsumerProducerTopicTest");
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createConsumerProducerTopicTest failed");
+ }
+ }
+
+ /*
+ * @testName: createDurableSubscriberTopicTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:254;
+ *
+ * @test_Strategy: Creates a durable subscription with the specified name on the
+ * specified topic, and creates a TopicSubscriber on that durable subscription.
+ *
+ * This uses a connection factory WITH client identifier set. The client
+ * identifer MUST be set for this API.
+ *
+ * Tests the following API method:
+ *
+ * Session.createDurableSubscriber(Topic, String)
+ *
+ * 1. Send a text message to a Topic. 2. Consume message via the TopicSubscriber
+ * created.
+ */
+ @Test
+ public void createDurableSubscriberTopicTest1() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ TopicSubscriber tSub = null;
+ try {
+ TextMessage expTextMessage = null;
+
+ // set up JmsTool for COMMON_T setup (durable factory has clientid set)
+ toolT.getDefaultConnection().close();
+ toolT.closeAllResources();
+ toolT2 = new JmsTool(JmsTool.COMMON_T, user, password, lookupDurableTopicFactory, mode);
+
+ // Setup for Topic
+ setupGlobalVarsT2();
+
+ // Create Durable Subscription and a TopicSubscriber for it
+ logger.log(Logger.Level.INFO, "Create a Durable Subscription and a TopicSubscriber for it");
+ tSub = session.createDurableSubscriber(topic, "createDurableSubscriberTopicTest1");
+
+ logger.log(Logger.Level.INFO, "Send message to Topic");
+ expTextMessage = session.createTextMessage(message);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createDurableSubscriberTopicTest1");
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.INFO, "Message sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) tSub.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createDurableSubscriberTopicTest1", e);
+ } finally {
+ try {
+ cleanupSubscription(tSub, session, "createDurableSubscriberTopicTest1");
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createDurableSubscriberTopicTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: createDurableSubscriberTopicTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:256;
+ *
+ * @test_Strategy: Creates a durable subscription with the specified name on the
+ * specified topic, and creates a TopicSubscriber on that durable subscription,
+ * specifying a message selector and whether messages published by its own
+ * connection should be delivered to it.
+ *
+ * This uses a connection factory WITH client identifier set. The client
+ * identifer MUST be set for this API.
+ *
+ * Tests the following API method:
+ *
+ * Session.createDurableSubscriber(Topic,String,String,boolean)
+ *
+ * 1 Create a durable subscriber on the specified topic, and create a
+ * TopicSubscriber with the specified message selector 2 Send a number of
+ * messages to the destination 3 Test both noLocal=true and noLocal=false cases
+ * 4 Verify message with specified selector received by listener in the
+ * noLocal=false case only.
+ *
+ */
+ @Test
+ public void createDurableSubscriberTopicTest2() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ TopicSubscriber tSub = null;
+ try {
+ // set up JmsTool for COMMON_T setup (durable factory has clientid set)
+ toolT.getDefaultConnection().close();
+ toolT.closeAllResources();
+ toolT2 = new JmsTool(JmsTool.COMMON_T, user, password, lookupDurableTopicFactory, mode);
+
+ // Setup for Topic
+ setupGlobalVarsT2();
+
+ // Create Durable Subscription and a TopicSubscriber for it
+ // Test the noLocal=false case with message selector
+ logger.log(Logger.Level.INFO, "Create a Durable Subscription and a TopicSubscriber for it");
+ tSub = session.createDurableSubscriber(topic, "createDurableSubscriberTopicTest2", "lastMessage = TRUE",
+ false);
+
+ // send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ TextMessage tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createDurableSubscriberTopicTest2" + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage expTextMessage = session.createTextMessage("Message " + numMessages);
+ TextMessage actTextMessage = (TextMessage) tSub.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createDurableSubscriberTopicTest2", e);
+ } finally {
+ try {
+ cleanupSubscription(tSub, session, "createDurableSubscriberTopicTest2");
+ } catch (Exception e) {
+ }
+ }
+
+ try {
+
+ // Create Durable Subscription and a TopicSubscriber for it
+ // Test the noLocal=true case with message selector
+ logger.log(Logger.Level.INFO, "Create a Durable Subscription and a TopicSubscriber for it");
+ tSub = session.createDurableSubscriber(topic, "createDurableSubscriberTopicTest2", "lastMessage = TRUE",
+ true);
+
+ // send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ TextMessage tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createDurableSubscriberTopicTest2" + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) tSub.receive(timeout);
+
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "message were delivered when noLocal=true");
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createDurableSubscriberTopicTest2", e);
+ } finally {
+ try {
+ cleanupSubscription(tSub, session, "createDurableSubscriberTopicTest2");
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createDurableSubscriberTopicTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: createDurableConsumerTopicTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1087;
+ *
+ * @test_Strategy: Creates a durable subscription with the specified name on the
+ * specified topic, and creates a MessageConsumer on that durable subscription.
+ *
+ * This uses a connection factory WITH client identifier set. The client
+ * identifer MUST be set for this API.
+ *
+ * Tests the following API method:
+ *
+ * Session.createDurableConsumer(Topic, String)
+ *
+ * 1. Create a durable subscription with the specified name on the specified
+ * topic and create a durable MessageConsumer on that durable subscription. This
+ * uses a connection factory WITH client identifier set. 2. Send TextMessage
+ * (message1) to the Topic. 3. Consume message via MessageConsumer created.
+ * Verify message1 received. 4. Close consumer. 5. Send another TextMessage
+ * (message2) to the Topic. 6. Recreate the durable MessageConsumer on that
+ * durable subscription. 7. Consume message via MessageConsumer created. Verify
+ * message2 received.
+ */
+ @Test
+ public void createDurableConsumerTopicTest1() throws Exception {
+ boolean pass = true;
+ String message1 = "Where are you!";
+ String message2 = "Who are you!";
+ MessageConsumer tCon = null;
+ try {
+ TextMessage expTextMessage = null;
+
+ // set up JmsTool for COMMON_T setup (durable factory has clientid set)
+ toolT.getDefaultConnection().close();
+ toolT.closeAllResources();
+ toolT2 = new JmsTool(JmsTool.COMMON_T, user, password, lookupDurableTopicFactory, mode);
+
+ // Setup for Topic
+ setupGlobalVarsT2();
+
+ // Create Durable Subscription and a MessageConsumer for it
+ logger.log(Logger.Level.INFO, "Create a Durable Subscription and a MessageConsumer for it");
+ tCon = session.createDurableConsumer(topic, "createDurableConsumerTopicTest1");
+
+ logger.log(Logger.Level.INFO, "Send TextMessage message1 to Topic");
+ expTextMessage = session.createTextMessage(message1);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createDurableConsumerTopicTest1");
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.INFO, "TextMessage message1 sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage message1");
+ TextMessage actTextMessage = (TextMessage) tCon.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage message1");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Close durable MessageConsumer");
+ tCon.close();
+
+ logger.log(Logger.Level.INFO, "Send TextMessage message2 to Topic");
+ expTextMessage = session.createTextMessage(message1);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createDurableConsumerTopicTest1");
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.INFO, "TextMessage message2 sent");
+
+ // Recreate Durable Subscription and a MessageConsumer for it
+ logger.log(Logger.Level.INFO, "Recreate a Durable Subscription and a MessageConsumer for it");
+ tCon = session.createDurableConsumer(topic, "createDurableConsumerTopicTest1");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage message2");
+ actTextMessage = (TextMessage) tCon.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage message2");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createDurableConsumerTopicTest1", e);
+ } finally {
+ try {
+ cleanupSubscription(tCon, session, "createDurableConsumerTopicTest1");
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createDurableConsumerTopicTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: createDurableConsumerTopicTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1090;
+ *
+ * @test_Strategy: Creates a durable subscription with the specified name on the
+ * specified topic, and creates a MessageConsumer on that durable subscription,
+ * specifying a message selector and whether messages published by its own
+ * connection should be delivered to it.
+ *
+ * This uses a connection factory WITH client identifier set. The client
+ * identifer MUST be set for this API.
+ *
+ * Tests the following API method:
+ *
+ * Session.createDurableConsumer(Topic,String,String,boolean)
+ *
+ * 1. Create a durable subscription with the specified name on the specified
+ * topic and create a durable MessageConsumer on that durable subscription
+ * specifing a message selector and whether messages published by its own
+ * connection should be delivered to it. 2. Send a number of messages to the
+ * Topic. 3. Test both noLocal=true and noLocal=false cases. 4. Verify message
+ * with specified selector received by MessageConsumer in the noLocal=false case
+ * only.
+ *
+ */
+ @Test
+ public void createDurableConsumerTopicTest2() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ MessageConsumer tCon = null;
+ try {
+ // set up JmsTool for COMMON_T setup (durable factory has clientid set)
+ toolT.getDefaultConnection().close();
+ toolT.closeAllResources();
+ toolT2 = new JmsTool(JmsTool.COMMON_T, user, password, lookupDurableTopicFactory, mode);
+
+ // Setup for Topic
+ setupGlobalVarsT2();
+
+ // Create Durable Subscription and a MessageConsumer for it
+ // Test the noLocal=false case with message selector
+ logger.log(Logger.Level.INFO,
+ "Create a Durable Subscription and a MessageConsumer with message selector, noLocal=false");
+ tCon = session.createDurableConsumer(topic, "createDurableConsumerTopicTest2", "lastMessage = TRUE", false);
+
+ // send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ TextMessage tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createDurableConsumerTopicTest2" + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ logger.log(Logger.Level.INFO, "This is noLacal=false case so expect to get just last message");
+ TextMessage expTextMessage = session.createTextMessage("Message " + numMessages);
+ TextMessage actTextMessage = (TextMessage) tCon.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createDurableConsumerTopicTest2", e);
+ } finally {
+ try {
+ cleanupSubscription(tCon, session, "createDurableConsumerTopicTest2");
+ } catch (Exception e) {
+ }
+ }
+
+ try {
+ // Create Durable Subscription and a MessageConsumer for it
+ // Test the noLocal=true case with message selector
+ logger.log(Logger.Level.INFO,
+ "Create a Durable Subscription and a MessageConsumer with message selector, noLocal=true");
+ tCon = session.createDurableConsumer(topic, "createDurableConsumerTopicTest2", "lastMessage = TRUE", true);
+
+ // send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ TextMessage tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createDurableConsumerTopicTest2" + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage actTextMessage = (TextMessage) tCon.receive(timeout);
+
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "Message was delivered when noLocal=true");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createDurableConsumerTopicTest2", e);
+ } finally {
+ try {
+ cleanupSubscription(tCon, session, "createDurableConsumerTopicTest2");
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createDurableConsumerTopicTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: createSharedConsumerTopicTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1163; JMS:SPEC:269;
+ *
+ * @test_Strategy: Creates a shared non-durable subscription with the specified
+ * name on the specified topic, and creates a MessageConsumer on that
+ * subscription.
+ *
+ * Tests the following API method:
+ *
+ * Session.createSharedConsumer(Topic, String)
+ *
+ * 1. Creates a shared non-durable subscription with the specified name on the
+ * specified topic, and creates a MessageConsumer on that subscription. 2.
+ * Create a second MessageConsumer on that subscription. 3. Send a text message
+ * to the Topic. 4. Consume message via the first MessageConsumer and message
+ * should be received. 5. Attempt to consume message via second MessageConsumer
+ * and no message should be received. 6. Re-Send a text message to the Topic. 7.
+ * Consume message via the second MessageConsumer and message should be
+ * received. 8. Attempt to consume message via first MessageConsumer and no
+ * message should be received.
+ */
+ @Test
+ public void createSharedConsumerTopicTest1() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ String sharedSubscriptionName = "createSharedConsumerTopicTest1";
+ TextMessage expTextMessage = null;
+ try {
+ // Setup for Topic
+ setupGlobalVarsT();
+
+ // Create shared non-durable Subscription and a MessageConsumer for it
+ logger.log(Logger.Level.INFO, "Create a shared non-durable Subscription and a MessageConsumer for it");
+ consumer.close();
+ consumer = session.createSharedConsumer(topic, sharedSubscriptionName);
+
+ // Create a second MessageConsumer for the subscription
+ logger.log(Logger.Level.INFO, "Create a second MessageConsumer for the Subscription");
+ consumer2 = session.createSharedConsumer(topic, sharedSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Send message to Topic");
+ expTextMessage = session.createTextMessage(message);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", sharedSubscriptionName);
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.INFO, "Message sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage from consumer1");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Attempt to Receive TextMessage from consumer2 - there should be none");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage != null) {
+ throw new Exception("Did receive TextMessage - unexpected.");
+ } else
+ logger.log(Logger.Level.INFO, "Did not receive TextMessage - expected.");
+
+ logger.log(Logger.Level.INFO, "Send another message to Topic");
+ expTextMessage = session.createTextMessage(message);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", sharedSubscriptionName);
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.INFO, "Message sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage from consumer2");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Attempt to Receive TextMessage from consumer1 - there should be none");
+ actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage != null) {
+ throw new Exception("Did receive TextMessage - unexpected.");
+ } else
+ logger.log(Logger.Level.INFO, "Did not receive TextMessage - expected.");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createSharedConsumerTopicTest1", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ if (consumer2 != null)
+ consumer2.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Ignoring exception closing consumers: " + e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createSharedConsumerTopicTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: createSharedConsumerTopicTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1167; JMS:SPEC:269; JMS:SPEC:270;
+ *
+ * @test_Strategy: Creates a shared non-durable subscription with the specified
+ * name on the specified topic, and creates a MessageConsumer on that
+ * subscription, specifying a message selector.
+ *
+ * Tests the following API method:
+ *
+ * Session.createSharedConsumer(Topic, String, String)
+ *
+ * 1. Create a shared non-durable subscription with the specified name on the
+ * specified topic, and creates a MessageConsumer on that subscription,
+ * specifying a message selector. 2. Create a second MessageConsumer on that
+ * subscription. 3. Send a text message to the Topic. 4. Consume message via
+ * first MessageConsumer and message selector and message should be received. 5.
+ * Attempt to consume message via second MessageConsumer and message selector
+ * and no message received. 6. Re-Send a text message to the Topic. 7. Consume
+ * message via second MessageConsumer and message selector and message should be
+ * received. 8. Attempt to consume message via first MessageConsumer and message
+ * selector and no message received.
+ */
+ @Test
+ public void createSharedConsumerTopicTest2() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ String sharedSubscriptionName = "createSharedConsumerTopicTest2";
+ try {
+ // Setup for Topic
+ setupGlobalVarsT();
+
+ // Create shared non-durable Subscription and a MessageConsumer for it
+ logger.log(Logger.Level.INFO, "Create a shared non-durable Subscription and a MessageConsumer for it");
+ consumer.close();
+ consumer = session.createSharedConsumer(topic, sharedSubscriptionName, "lastMessage = TRUE");
+
+ // Create a second MessageConsumer for the subscription
+ logger.log(Logger.Level.INFO, "Create a second MessageConsumer for the Subscription");
+ consumer2 = session.createSharedConsumer(topic, sharedSubscriptionName, "lastMessage = TRUE");
+
+ // send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ TextMessage tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", sharedSubscriptionName + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage from consumer1");
+ TextMessage expTextMessage = session.createTextMessage("Message " + numMessages);
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Attempt to Receive TextMessage from consumer2 - there should be none");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage != null) {
+ throw new Exception("Did receive TextMessage - unexpected.");
+ } else
+ logger.log(Logger.Level.INFO, "Did not receive TextMessage - expected.");
+
+ // send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ TextMessage tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", sharedSubscriptionName + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage from consumer2");
+ expTextMessage = session.createTextMessage("Message " + numMessages);
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Attempt to Receive TextMessage from consumer1 - there should be none");
+ actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage != null) {
+ throw new Exception("Did receive TextMessage - unexpected.");
+ } else
+ logger.log(Logger.Level.INFO, "Did not receive TextMessage - expected.");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createSharedConsumerTopicTest2", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ if (consumer2 != null)
+ consumer2.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.INFO, "Ignoring exception closing consumers: " + e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createSharedConsumerTopicTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: createSharedDurableConsumerTopicTest1
+ *
+ * @assertion_ids: JMS:JAVADOC:1393;
+ *
+ * @test_Strategy: Creates a shared durable subscription with the specified name
+ * on the specified topic and creates a JMSConsumer on that durable
+ * subscription.
+ *
+ * This uses a connection factory WITH client identifier set.
+ *
+ * Tests the following API method:
+ *
+ * Session.createSharedDurableConsumer(Topic, String)
+ *
+ * 1. Create a shared durable subscription with the specified name on the
+ * specified topic and create a durable JMSConsumer on that durable
+ * subscription. This uses a connection factory WITH client identifier set. 2.
+ * Create a 2nd JMSConsumer for it. 3. Send TextMessage (message1) to the Topic.
+ * 3. Consume message via 1st JMSConsumer created. Verify message1 received. 4.
+ * Close 1st consumer. 5. Send another TextMessage (message2) to the Topic. 6.
+ * Consume message via 2nd JMSConsumer created. Verify message2 received.
+ */
+ @Test
+ public void createSharedDurableConsumerTopicTest1() throws Exception {
+ boolean pass = true;
+ String message1 = "Message1!";
+ String message2 = "Message2!";
+ String durableSubscriptionName = "createSharedDurableConsumerTopicTest1";
+ try {
+ // set up JmsTool for COMMON_T setup (durable factory has clientid set)
+ toolT.getDefaultConnection().close();
+ toolT.closeAllResources();
+ toolT2 = new JmsTool(JmsTool.COMMON_T, user, password, lookupDurableTopicFactory, mode);
+
+ // Setup for Topic
+ setupGlobalVarsT2();
+
+ TextMessage expTextMessage = null;
+
+ // Create a shared Durable Subscription and a JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create a shared Durable Subscription and 1st JMSConsumer for it");
+ consumer = session.createSharedDurableConsumer(topic, durableSubscriptionName);
+
+ // Create 2nd JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create 2nd JMSConsumer for it");
+ consumer2 = session.createSharedDurableConsumer(topic, durableSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Send TextMessage message1 to Topic");
+ expTextMessage = session.createTextMessage(message1);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createSharedDurableConsumerTopicTest1");
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.INFO, "TextMessage message1 sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage message1 from consumer1");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage message1");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Close 1st shared durable JMSConsumer");
+ consumer.close();
+
+ logger.log(Logger.Level.INFO, "Send TextMessage message2 to Topic");
+ expTextMessage = session.createTextMessage(message2);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createSharedDurableConsumerTopicTest1");
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.INFO, "TextMessage message2 sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage message2 from consumer2");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage message2");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Now there should be no more messages to receive from topic");
+
+ logger.log(Logger.Level.INFO, "Recreate Durable Subscription and 1st JMSConsumer for it");
+ consumer = session.createSharedDurableConsumer(topic, durableSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Try and receive a message from consumer1 (should get NONE)");
+ actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "Consumer1 received a message (FAIL)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Consumer1 didn't receive a message (PASS)");
+ }
+
+ logger.log(Logger.Level.INFO, "Try and receive a message from consumer2 (should get NONE)");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "Consumer2 received a message (FAIL)");
+ pass = false;
+ throw new Exception("Consumer2 received a message (FAIL)");
+ } else {
+ logger.log(Logger.Level.INFO, "Consumer2 didn't receive a message (PASS)");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createSharedDurableConsumerTopicTest1", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ cleanupSubscription(consumer2, session, durableSubscriptionName);
+ toolT2.getDefaultConnection().close();
+ toolT2.closeAllResources();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createSharedDurableConsumerTopicTest1 failed");
+ }
+ }
+
+ /*
+ * @testName: createSharedDurableConsumerTopicTest2
+ *
+ * @assertion_ids: JMS:JAVADOC:1396;
+ *
+ * @test_Strategy: Creates a shared durable subscription with the specified name
+ * on the specified topic and creates a JMSConsumer on that durable
+ * subscription, specifying a message selector and whether messages published by
+ * its own connection should be delivered to it.
+ *
+ * This uses a connection factory WITH client identifier set.
+ *
+ * Tests the following API method:
+ *
+ * Session.createSharedDurableConsumer(Topic,String,String)
+ *
+ * 1. Create a shared durable subscription with the specified name on the
+ * specified topic and create a durable JMSConsumer on that durable subscription
+ * specifing a message selector and whether messages published by its own
+ * connection should be delivered to it. This uses a connection factory WITH
+ * client identifier set. 2. Create a 2nd JMSConsumer for it. 3. Send a number
+ * of messages to the Topic.
+ *
+ */
+ @Test
+ public void createSharedDurableConsumerTopicTest2() throws Exception {
+ boolean pass = true;
+ String durableSubscriptionName = "createSharedDurableConsumerTopicTest2";
+ try {
+ // set up JmsTool for COMMON_T setup (durable factory has clientid set)
+ toolT.getDefaultConnection().close();
+ toolT.closeAllResources();
+ toolT2 = new JmsTool(JmsTool.COMMON_T, user, password, lookupDurableTopicFactory, mode);
+
+ // Setup for Topic
+ setupGlobalVarsT2();
+
+ // Create a shared Durable Subscription and a JMSConsumer for it
+ logger.log(Logger.Level.INFO,
+ "Create shared Durable Subscription and 1st JMSConsumer with message selector");
+ consumer = session.createSharedDurableConsumer(topic, durableSubscriptionName, "lastMessage = TRUE");
+ // Create 2nd JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create 2nd JMSConsumer with message selector");
+ consumer2 = session.createSharedDurableConsumer(topic, durableSubscriptionName, "lastMessage = TRUE");
+
+ // send "numMessages" messages to Topic
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Topic");
+ for (int i = 1; i <= numMessages; i++) {
+ TextMessage tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createSharedDurableConsumerTopicTest2" + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage from consumer1");
+ TextMessage expTextMessage = session.createTextMessage("Message " + numMessages);
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createSharedDurableConsumerTopicTest2", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ cleanupSubscription(consumer2, session, durableSubscriptionName);
+ toolT2.getDefaultConnection().close();
+ toolT2.closeAllResources();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createSharedDurableConsumerTopicTest2 failed");
+ }
+ }
+
+ /*
+ * @testName: createSharedDurableConsumerTopicTest3
+ *
+ * @assertion_ids: JMS:JAVADOC:1393;
+ *
+ * @test_Strategy: Creates a shared durable subscription with the specified name
+ * on the specified topic and creates a JMSConsumer on that durable
+ * subscription.
+ *
+ * This uses a connection factory WITH client identifier unset.
+ *
+ * Tests the following API method:
+ *
+ * Session.createSharedDurableConsumer(Topic, String)
+ *
+ * 1. Create a shared durable subscription with the specified name on the
+ * specified topic and create a durable JMSConsumer on that durable
+ * subscription. This uses a connection factory WITH client identifier unset. 2.
+ * Create a 2nd JMSConsumer for it. 3. Send TextMessage (message1) to the Topic.
+ * 3. Consume message via 1st JMSConsumer created. Verify message1 received. 4.
+ * Close 1st consumer. 5. Send another TextMessage (message2) to the Topic. 6.
+ * Consume message via 2nd JMSConsumer created. Verify message2 received.
+ */
+ @Test
+ public void createSharedDurableConsumerTopicTest3() throws Exception {
+ boolean pass = true;
+ String message1 = "Message1!";
+ String message2 = "Message2!";
+ String durableSubscriptionName = "createSharedDurableConsumerTopicTest3";
+ try {
+ // Setup for Topic
+ setupGlobalVarsT();
+
+ TextMessage expTextMessage = null;
+
+ // Create a shared Durable Subscription and a JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create a shared Durable Subscription and 1st JMSConsumer for it");
+ consumer = session.createSharedDurableConsumer(topic, durableSubscriptionName);
+
+ // Create 2nd JMSConsumer for it
+ logger.log(Logger.Level.INFO, "Create 2nd JMSConsumer for it");
+ consumer2 = session.createSharedDurableConsumer(topic, durableSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Send TextMessage message1 to Topic");
+ expTextMessage = session.createTextMessage(message1);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createSharedDurableConsumerTopicTest3");
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.INFO, "TextMessage message1 sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage message1 from consumer1");
+ TextMessage actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage message1");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.INFO, "Close 1st shared durable JMSConsumer");
+ consumer.close();
+
+ logger.log(Logger.Level.INFO, "Send TextMessage message2 to Topic");
+ expTextMessage = session.createTextMessage(message2);
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "createSharedDurableConsumerTopicTest3");
+ producer.send(expTextMessage);
+ logger.log(Logger.Level.INFO, "TextMessage message2 sent");
+
+ logger.log(Logger.Level.INFO, "Receive TextMessage message2 from consumer2");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage message2");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+
+ logger.log(Logger.Level.INFO, "Now there should be no more messages to receive from topic");
+
+ logger.log(Logger.Level.INFO, "Recreate Durable Subscription and 1st JMSConsumer for it");
+ consumer = session.createSharedDurableConsumer(topic, durableSubscriptionName);
+
+ logger.log(Logger.Level.INFO, "Try and receive a message from consumer1 (should get NONE)");
+ actTextMessage = (TextMessage) consumer.receive(timeout);
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "Consumer1 received a message (FAIL)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Consumer1 didn't receive a message (PASS)");
+ }
+
+ logger.log(Logger.Level.INFO, "Try and receive a message from consumer2 (should get NONE)");
+ actTextMessage = (TextMessage) consumer2.receive(timeout);
+ if (actTextMessage != null) {
+ logger.log(Logger.Level.ERROR, "Consumer2 received a message (FAIL)");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Consumer2 didn't receive a message (PASS)");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createSharedDurableConsumerTopicTest3", e);
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ cleanupSubscription(consumer2, session, durableSubscriptionName);
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createSharedDurableConsumerTopicTest3 failed");
+ }
+ }
+
+ /*
+ * @testName: invalidDestinationExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1089; JMS:JAVADOC:1092; JMS:JAVADOC:643;
+ * JMS:JAVADOC:644; JMS:JAVADOC:1165; JMS:JAVADOC:1169; JMS:JAVADOC:1395;
+ * JMS:JAVADOC:1398;
+ *
+ * @test_Strategy: Pass an invalid topic and test for
+ * InvalidDestinationException.
+ *
+ * Session.createDurableSubscriber(Topic, String)
+ * Session.createDurableSubscriber(Topic, String, String, boolean)
+ * Session.createDurableConsumer(Topic, String)
+ * Session.createDurableConsumer(Topic, String, String, boolean)
+ * Session.createSharedConsumer(Topic, String)
+ * Session.createSharedConsumer(Topic, String, String)
+ * Session.createSharedDurableConsumer(Topic, String)
+ * Session.createSharedDurableConsumer(Topic, String, String)
+ */
+ @Test
+ public void invalidDestinationExceptionTests() throws Exception {
+ boolean pass = true;
+ Destination invalidDestination = null;
+ Topic invalidTopic = null;
+ try {
+ // set up JmsTool for COMMON_T setup (durable factory has clientid set)
+ toolT.getDefaultConnection().close();
+ toolT.closeAllResources();
+ toolT2 = new JmsTool(JmsTool.COMMON_T, user, password, lookupDurableTopicFactory, mode);
+
+ // Setup for Topic
+ setupGlobalVarsT2();
+
+ logger.log(Logger.Level.INFO,
+ "Testing Session.createDurableSubscriber(Topic, String) for InvalidDestinationException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createDurableSubscriber(Topic, String) -> expect InvalidDestinationException");
+ session.createDurableSubscriber(invalidTopic, "InvalidDestinationException");
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing Session.createDurableSubscriber(Topic, String, String, boolean) for InvalidDestinationException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createDurableSubscriber(Topic, String, String, boolean) -> expect InvalidDestinationException");
+ session.createDurableSubscriber(invalidTopic, "InvalidDestinationException", "lastMessage = TRUE",
+ false);
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing Session.createDurableConsumer(Topic, String) for InvalidDestinationException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createDurableConsumer(Topic, String) -> expect InvalidDestinationException");
+ session.createDurableConsumer(invalidTopic, "InvalidDestinationException");
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing Session.createDurableConsumer(Topic, String, String, boolean) for InvalidDestinationException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createDurableConsumer(Topic, String, String, boolean) -> expect InvalidDestinationException");
+ session.createDurableConsumer(invalidTopic, "InvalidDestinationException", "lastMessage = TRUE", false);
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing Session.createSharedConsumer(Topic, String) for InvalidDestinationException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createSharedConsumer(Topic, String) for InvalidDestinationException");
+ session.createSharedConsumer(invalidTopic, "InvalidDestinationException");
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing Session.createSharedConsumer(Topic, String, String) for InvalidDestinationException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createSharedConsumer(Topic, String, String) for InvalidDestinationException");
+ session.createSharedConsumer(invalidTopic, "InvalidDestinationException", "lastMessage = TRUE");
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing Session.createSharedDurableConsumer(Topic, String) for InvalidDestinationException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createSharedDurableConsumer(Topic, String) -> expect InvalidDestinationException");
+ session.createSharedDurableConsumer(invalidTopic, "InvalidDestinationException");
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing Session.createSharedDurableConsumer(Topic, String, String) for InvalidDestinationException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createSharedDurableConsumer(Topic, String, String) -> expect InvalidDestinationException");
+ session.createSharedDurableConsumer(invalidTopic, "InvalidDestinationException", "lastMessage = TRUE");
+ } catch (InvalidDestinationException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidDestinationException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidDestinationException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("invalidDestinationExceptionTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("invalidDestinationExceptionTests failed");
+ }
+ }
+
+ /*
+ * @testName: invalidSelectorExceptionTopicTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1093; JMS:JAVADOC:1399; JMS:JAVADOC:1166;
+ * JMS:JAVADOC:1170;
+ *
+ * @test_Strategy: Pass an invalid selector and test for
+ * InvalidSelectorException.
+ *
+ * Session.createDurableConsumer(Topic, String, String, boolean)
+ * Session.createSharedConsumer(Topic, String, String)
+ * Session.createSharedDurableConsumer(Topic, String, String)
+ */
+ @Test
+ public void invalidSelectorExceptionTopicTests() throws Exception {
+ boolean pass = true;
+ String invalidMessageSelector = "=TEST 'test'";
+ try {
+ // set up JmsTool for COMMON_T setup (durable factory has clientid set)
+ toolT.getDefaultConnection().close();
+ toolT.closeAllResources();
+ toolT2 = new JmsTool(JmsTool.COMMON_T, user, password, lookupDurableTopicFactory, mode);
+
+ // Setup for Topic
+ setupGlobalVarsT2();
+
+ logger.log(Logger.Level.INFO,
+ "Testing Session.createDurableConsumer(Topic, String, String, boolean) for InvalidSelectorException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createDurableConsumer(Topic, String, String, boolean) -> expect InvalidSelectorException");
+ session.createDurableConsumer(topic, "InvalidSelectorException", invalidMessageSelector, false);
+ } catch (InvalidSelectorException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidSelectorException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidSelectorException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing Session.createSharedConsumer(Topic, String, String) for InvalidSelectorException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createSharedConsumer(Topic, String, String) for InvalidSelectorException");
+ session.createSharedConsumer(topic, "InvalidSelectorException", invalidMessageSelector);
+ } catch (InvalidSelectorException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidSelectorException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidSelectorException, received " + e);
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Testing Session.createSharedDurableConsumer(Topic, String, String) for InvalidSelectorException");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createSharedDurableConsumer(Topic, String, String) -> expect InvalidSelectorException");
+ session.createSharedDurableConsumer(topic, "InvalidSelectorException", invalidMessageSelector);
+ } catch (InvalidSelectorException e) {
+ logger.log(Logger.Level.INFO, "Got InvalidSelectorException as expected.");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Expected InvalidSelectorException, received " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("invalidSelectorExceptionTopicTests", e);
+ }
+
+ if (!pass) {
+ throw new Exception("invalidSelectorExceptionTopicTests failed");
+ }
+ }
+
+ /*
+ * @testName: illegalStateExceptionTests
+ *
+ * @assertion_ids: JMS:SPEC:185.9; JMS:SPEC:185.10; JMS:SPEC:185;
+ * JMS:JAVADOC:1349; JMS:JAVADOC:1350; JMS:JAVADOC:1390; JMS:JAVADOC:1391;
+ *
+ * @test_Strategy: Create a QueueSession and call Topic specific methods
+ * inherited from Session, and verify that jakarta.jms.IllegalStateException is
+ * thrown.
+ *
+ * Call the following topic methods on a QueueSession:
+ *
+ * QueueSession.createDurableConsumer(Topic, String)
+ * QueueSession.createDurableConsumer(Topic, String, String, boolean)
+ * QueueSession.createSharedConsumer(Topic, String)
+ * QueueSession.createSharedConsumer(Topic, String, String)
+ * QueueSession.createSharedDurableConsumer(Topic, String)
+ * QueueSession.createSharedDurableConsumer(Topic, String, String)
+ *
+ * Test jakarta.jms.IllegalStateException from the following API's. Also test
+ * when nolocal=true and client id is not set.
+ *
+ * Session.createDurableSubscriber(Topic, String)
+ * Session.createDurableSubscriber(Topic, String, String, boolean)
+ * Session.createDurableConsumer(Topic, String)
+ * Session.createDurableConsumer(Topic, String, String, boolean)
+ */
+ @Test
+ public void illegalStateExceptionTests() throws Exception {
+ JmsTool toolq = null;
+ String lookupNormalTopicFactory = "MyTopicConnectionFactory";
+ boolean pass = true;
+ MessageConsumer consumer = null;
+ TopicSubscriber subscriber = null;
+ try {
+ // Set up JmsTool for Queue setup
+ toolq = new JmsTool(JmsTool.QUEUE, user, password, mode);
+
+ Destination destination = toolT.getDefaultDestination();
+ Topic topic = (Topic) destination;
+ try {
+ logger.log(Logger.Level.INFO, "Calling QueueSession.createDurableConsumer(Topic, String)");
+ toolq.getDefaultQueueSession().createDurableConsumer(topic, "mySub1");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "QueueSession.createDurableConsumer(Topic, String) "
+ + "didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateException from "
+ + "QueueSession.createDurableConsumer(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling QueueSession.createDurableConsumer(Topic, String, String, boolean)");
+ toolq.getDefaultQueueSession().createDurableConsumer(topic, "mySub1", "TEST = 'test'", false);
+ pass = false;
+ logger.log(Logger.Level.ERROR, "QueueSession.createDurableConsumer(Topic, String, String, boolean) "
+ + "didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateException from "
+ + "QueueSession.createDurableConsumer(Topic, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO, "Calling QueueSession.createSharedConsumer(Topic, String)");
+ toolq.getDefaultQueueSession().createSharedConsumer(topic, "mySub1");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "QueueSession.createSharedConsumer(Topic, String) "
+ + "didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateException from "
+ + "QueueSession.createSharedConsumer(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO, "Calling QueueSession.createSharedConsumer(Topic, String, String)");
+ toolq.getDefaultQueueSession().createSharedConsumer(topic, "mySub1", "TEST = 'test'");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "QueueSession.createSharedConsumer(Topic, String, String) "
+ + "didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateException from "
+ + "QueueSession.createSharedConsumer(Topic, String, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO, "Calling QueueSession.createSharedDurableConsumer(Topic, String)");
+ toolq.getDefaultQueueSession().createSharedDurableConsumer(topic, "mySub1");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "QueueSession.createSharedDurableConsumer(Topic, String) "
+ + "didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateException from "
+ + "QueueSession.createSharedDurableConsumer(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Calling QueueSession.createSharedDurableConsumer(Topic, String, String)");
+ toolq.getDefaultQueueSession().createSharedDurableConsumer(topic, "mySub1", "TEST = 'test'");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "QueueSession.createSharedDurableConsumer(Topic, String, String) "
+ + "didn't throw expected IllegalStateException.");
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateException from "
+ + "QueueSession.createSharedDurableConsumer(Topic, String, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Create a Durable Subscriber with clientid unset (expect IllegalStateException");
+ logger.log(Logger.Level.INFO, "Calling Session.createDurableSubscriber(Topic, String)");
+ subscriber = toolT.getDefaultSession().createDurableSubscriber(topic, "mySub1");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Session.createDurableSubscriber(Topic, String) "
+ + "didn't throw expected IllegalStateException.");
+ try {
+ subscriber.close();
+ toolT.getDefaultSession().unsubscribe("mySub1");
+ } catch (Exception e) {
+ }
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateException from " + "Session.createDurableSubscriber(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Create a Durable Subscriber with noLocal=true and clientid unset (expect IllegalStateException");
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createDurableSubscriber(Topic, String, String, boolean)");
+ subscriber = toolT.getDefaultSession().createDurableSubscriber(topic, "mySub1", "TEST = 'test'", true);
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Session.createDurableSubscriber(Topic, String, String, boolean) "
+ + "didn't throw expected IllegalStateException.");
+ try {
+ subscriber.close();
+ toolT.getDefaultSession().unsubscribe("mySub1");
+ } catch (Exception e) {
+ }
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateException from "
+ + "Session.createDurableSubscriber(Topic, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Create a Durable Consumer with clientid unset (expect IllegalStateException");
+ logger.log(Logger.Level.INFO, "Calling Session.createDurableConsumer(Topic, String)");
+ consumer = toolT.getDefaultSession().createDurableConsumer(topic, "mySub1");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Session.createDurableConsumer(Topic, String) "
+ + "didn't throw expected IllegalStateException.");
+ try {
+ consumer.close();
+ toolT.getDefaultSession().unsubscribe("mySub1");
+ } catch (Exception e) {
+ }
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected IllegalStateException from " + "Session.createDurableConsumer(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Create a Durable Consumer with noLocal=true and clientid unset (expect IllegalStateException");
+ logger.log(Logger.Level.INFO, "Calling Session.createDurableConsumer(Topic, String, String, boolean)");
+ consumer = toolT.getDefaultSession().createDurableConsumer(topic, "mySub1", "TEST = 'test'", true);
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Session.createDurableConsumer(Topic, String, String, boolean) "
+ + "didn't throw expected IllegalStateException.");
+ try {
+ consumer.close();
+ toolT.getDefaultSession().unsubscribe("mySub1");
+ } catch (Exception e) {
+ }
+ } catch (jakarta.jms.IllegalStateException ex) {
+ logger.log(Logger.Level.INFO, "Got expected IllegalStateException from "
+ + "Session.createDurableConsumer(Topic, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("illegalStateExceptionTests Failed");
+ } finally {
+ try {
+ toolq.getDefaultQueueConnection().close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("illegalStateExceptionTests Failed");
+ }
+ }
+
+ /*
+ * @testName: jMSExceptionTests
+ *
+ * @assertion_ids: JMS:JAVADOC:1091; JMS:JAVADOC:257; JMS:JAVADOC:1090;
+ * JMS:JAVADOC:1164; JMS:JAVADOC:1168; JMS:JAVADOC:1394; JMS:JAVADOC:1397;
+ *
+ * @test_Strategy: Test JMSException conditions from various API methods.
+ *
+ * TopicSession.createDurableSubscriber(Topic, String)
+ * TopicSession.createDurableSubscriber(Topic, String. String, boolean)
+ * Session.createDurableSubscriber(Topic, String)
+ * Session.createDurableSubscriber(Topic, String. String, boolean)
+ * Session.createDurableConsumer(Topic, String)
+ * Session.createDurableConsumer(Topic, String. String, boolean)
+ * Session.createSharedConsumer(Topic, String)
+ * Session.createSharedConsumer(Topic, String, String)
+ * Session.createSharedDurableConsumer(Topic, String)
+ * Session.createSharedDurableConsumer(Topic, String. String)
+ */
+ @Test
+ public void jMSExceptionTests() throws Exception {
+ boolean pass = true;
+ JmsTool toolt = null;
+ Topic mytopic = null;
+ try {
+ // Setup for Topic
+ setupGlobalVarsT();
+
+ // Create second Topic
+ mytopic = (Topic) toolT.createNewTopic("MY_TOPIC2");
+
+ // set up JmsTool for TOPIC setup (normal factory no clientid set)
+ toolt = new JmsTool(JmsTool.TOPIC, user, password, lookupNormalTopicFactory, mode);
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Create a Durable TopicSubscriber with noLocal=true and clientid unset (expect JMSException");
+ logger.log(Logger.Level.INFO,
+ "Calling TopicSession.createDurableSubscriber(Topic, String, String, boolean)");
+ subscriber = toolt.getDefaultTopicSession().createDurableSubscriber(topic, "mySub1", "TEST = 'test'",
+ true);
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TopicSession.createDurableSubscriber(Topic, String, String, boolean) "
+ + "didn't throw expected JMSException.");
+ } catch (jakarta.jms.JMSException ex) {
+ logger.log(Logger.Level.INFO, "Got expected JMSException from "
+ + "TopicSession.createDurableSubscriber(Topic, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (subscriber != null)
+ subscriber.close();
+ toolt.getDefaultTopicConnection().close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ }
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Create a Durable Consumer with noLocal=true and clientid unset (expect JMSException");
+ logger.log(Logger.Level.INFO, "Calling Session.createDurableConsumer(Topic, String, String, boolean)");
+ consumer = null;
+ consumer = session.createDurableConsumer(topic, "mySub1", "TEST = 'test'", true);
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Session.createDurableConsumer(Topic, String, String, boolean) "
+ + "didn't throw expected JMSException.");
+ } catch (jakarta.jms.JMSException ex) {
+ logger.log(Logger.Level.INFO, "Got expected JMSException from "
+ + "Session.createDurableConsumer(Topic, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ }
+
+ try {
+ logger.log(Logger.Level.INFO,
+ "Create a Durable TopicSubscriber with noLocal=true and clientid unset (expect JMSException");
+ logger.log(Logger.Level.INFO,
+ "Calling Session.createDurableSubscriber(Topic, String, String, boolean)");
+ subscriber = null;
+ subscriber = session.createDurableSubscriber(topic, "mySub1", "TEST = 'test'", true);
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Session.createDurableSubscriber(Topic, String, String, boolean) "
+ + "didn't throw expected JMSException.");
+ } catch (jakarta.jms.JMSException ex) {
+ logger.log(Logger.Level.INFO, "Got expected JMSException from "
+ + "Session.createDurableSubscriber(Topic, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (subscriber != null)
+ subscriber.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("jMSExceptionTests Failed");
+ }
+
+ try {
+ // Setup for Durable Topic
+ toolT.getDefaultConnection().close();
+ toolT.closeAllResources();
+ // set up JmsTool for COMMON_T setup (durable factory has clientid set)
+ toolT2 = new JmsTool(JmsTool.COMMON_T, user, password, lookupDurableTopicFactory, mode);
+ setupGlobalVarsT2();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ throw new Exception("jMSExceptionTests Failed");
+ }
+
+ // Create durable subscriber specifying topic and name
+ // Create second durable subscriber with same name but specifying different
+ // topic,
+ // Verify JMSException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create durable subscriber");
+ logger.log(Logger.Level.INFO, "Calling Session.createDurableSubscriber(Topic, String)");
+ subscriber = subscriber2 = null;
+ subscriber = session.createDurableSubscriber(topic, "dummySubSCJMSException");
+ logger.log(Logger.Level.INFO, "Create second durable subscriber with same name but different topic");
+ logger.log(Logger.Level.INFO, "Calling Session.createDurableSubscriber(Topic, String)");
+ subscriber2 = session.createDurableSubscriber(mytopic, "dummySubSCJMSException");
+ logger.log(Logger.Level.INFO, "Verify that JMSException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSException");
+ } catch (JMSException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected JMSException from " + "Session.createDurableSubscriber(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (subscriber != null)
+ subscriber.close();
+ if (subscriber2 != null)
+ subscriber2.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ // Create durable subscriber specifying topic, name, message selector and
+ // nolcal
+ // Create second durable subscriber with same name but specifying different
+ // topic
+ // message selector, or nolocal. Verify JMSException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create durable subscriber");
+ logger.log(Logger.Level.INFO, "Calling Session.createDurableSubscriber(Topic, String, String, boolean)");
+ subscriber = subscriber2 = null;
+ subscriber = session.createDurableSubscriber(topic, "dummySubSCJMSException", "TEST = 'test'", false);
+ logger.log(Logger.Level.INFO, "Create second durable subscriber with same name but different topic");
+ logger.log(Logger.Level.INFO, "Calling Session.createDurableSubscriber(Topic, String, String, boolean)");
+ subscriber2 = session.createDurableSubscriber(mytopic, "dummySubSCJMSException", "TEST = 'test'", false);
+ logger.log(Logger.Level.INFO, "Verify that JMSException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSException");
+ } catch (JMSException ex) {
+ logger.log(Logger.Level.INFO, "Got expected JMSException from "
+ + "Session.createDurableSubscriber(Topic, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (subscriber != null)
+ subscriber.close();
+ if (subscriber2 != null)
+ subscriber2.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ // Create shared consumer specifying topic and name
+ // Create second shared consumer with same name but specifying different
+ // topic,
+ // Verify JMSException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create shared consumer");
+ logger.log(Logger.Level.INFO, "Calling Session.createSharedConsumer(Topic, String)");
+ consumer = consumer2 = null;
+ consumer = session.createSharedConsumer(topic, "dummySubSCJMSException");
+ logger.log(Logger.Level.INFO, "Create second shared consumer with same name but different topic");
+ logger.log(Logger.Level.INFO, "Calling Session.createSharedConsumer(Topic, String)");
+ consumer2 = session.createSharedConsumer(mytopic, "dummySubSCJMSException");
+ logger.log(Logger.Level.INFO, "Verify that JMSException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSException");
+ } catch (JMSException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected JMSException from " + "Session.createSharedConsumer(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ if (consumer2 != null)
+ consumer2.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ // Create shared consumer specifying topic and name and message selector
+ // Create second shared consumer with same name but specifying different
+ // topic and message selector
+ // Verify JMSException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create shared consumer");
+ logger.log(Logger.Level.INFO, "Calling Session.createSharedConsumer(Topic, String, String)");
+ consumer = consumer2 = null;
+ consumer = session.createSharedConsumer(topic, "dummySubSCJMSException", "TEST = 'test'");
+ logger.log(Logger.Level.INFO, "Create second shared consumer with same name but different topic");
+ logger.log(Logger.Level.INFO, "Calling Session.createSharedConsumer(Topic, String, String)");
+ consumer2 = session.createSharedConsumer(mytopic, "dummySubSCJMSException", "TEST = 'test'");
+ logger.log(Logger.Level.INFO, "Verify that JMSException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSException");
+ } catch (JMSException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected JMSException from " + "Session.createSharedConsumer(Topic, String, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ if (consumer2 != null)
+ consumer2.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ // Create shared durable subscription specifying topic, name. selector.
+ // Create second shared durable subscription with same name but specifying
+ // different topic,
+ // selector. Verify JMSException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create shared durable subscription");
+ logger.log(Logger.Level.INFO, "Calling Session.createSharedDurableConsumer(Topic, String, String)");
+ consumer = consumer2 = null;
+ consumer = session.createSharedDurableConsumer(topic, "dummySubSJMSException", "TEST = 'test'");
+ logger.log(Logger.Level.INFO,
+ "Create second shared durable subscription with same name but different other args");
+ logger.log(Logger.Level.INFO, "Calling Session.createSharedDurableConsumer(Topic, String, String)");
+ consumer2 = session.createSharedDurableConsumer(mytopic, "dummySubSJMSException", "TEST = 'test2'");
+ logger.log(Logger.Level.INFO, "Verify that JMSException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSException");
+ } catch (JMSException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected JMSException from " + "Session.createSharedDurableConsumer(Topic, String, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer2 != null)
+ consumer2.close();
+ cleanupSubscription(consumer, session, "dummySubSJMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ // Create durable subscription specifying topic and name
+ // Create second durable subscription with same name but specifying
+ // different topic,
+ // Verify JMSException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create durable subscription");
+ logger.log(Logger.Level.INFO, "Calling Session.createDurableConsumer(Topic, String)");
+ consumer = consumer2 = null;
+ consumer = session.createDurableConsumer(topic, "dummySubDJMSException");
+ logger.log(Logger.Level.INFO, "Create second durable subscription with same name but different topic");
+ logger.log(Logger.Level.INFO, "Calling Session.createDurableConsumer(Topic, String)");
+ consumer2 = session.createDurableConsumer(mytopic, "dummySubDJMSException");
+ logger.log(Logger.Level.INFO, "Verify that JMSException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSException");
+ } catch (JMSException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected JMSException from " + "Session.createDurableConsumer(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer2 != null)
+ consumer2.close();
+ cleanupSubscription(consumer, session, "dummySubDJMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ // Create shared durable subscription specifying topic and name
+ // Create second shared durable subscription with same name but specifying
+ // different topic,
+ // Verify JMSException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create shared durable subscription");
+ logger.log(Logger.Level.INFO, "Calling Session.createSharedDurableConsumer(Topic, String)");
+ consumer = consumer2 = null;
+ consumer = session.createSharedDurableConsumer(topic, "dummySubSDJMSException");
+ logger.log(Logger.Level.INFO,
+ "Create second shared durable subscription with same name but different topic");
+ logger.log(Logger.Level.INFO, "Calling Session.createSharedDurableConsumer(Topic, String)");
+ consumer2 = session.createSharedDurableConsumer(mytopic, "dummySubSDJMSException");
+ logger.log(Logger.Level.INFO, "Verify that JMSException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSException");
+ } catch (JMSException ex) {
+ logger.log(Logger.Level.INFO,
+ "Got expected JMSException from " + "Session.createSharedDurableConsumer(Topic, String)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer2 != null)
+ consumer2.close();
+ cleanupSubscription(consumer, session, "dummySubSDJMSException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ // Create durable subscription specifying topic, name. selector, and nolocal
+ // value.
+ // Create second durable subscription with same name but specifying
+ // different topic,
+ // selector, or nolocal value. Verify JMSException is thrown.
+ try {
+ logger.log(Logger.Level.INFO, "Create durable subscription");
+ logger.log(Logger.Level.INFO, "Calling Session.createDurableConsumer(Topic, String, String, boolean)");
+ consumer = consumer2 = null;
+ consumer = session.createDurableConsumer(topic, "dummySubDJMSException", "TEST = 'test'", false);
+ logger.log(Logger.Level.INFO, "Create second durable subscription with same name but different other args");
+ logger.log(Logger.Level.INFO, "Calling Session.createDurableConsumer(Topic, String, String, boolean)");
+ consumer2 = session.createDurableConsumer(mytopic, "dummySubDJMSException", "TEST = 'test2'", false);
+ logger.log(Logger.Level.INFO, "Verify that JMSException is thrown");
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Didn't throw expected JMSException");
+ } catch (JMSException ex) {
+ logger.log(Logger.Level.INFO, "Got expected JMSException from "
+ + "Session.createDurableConsumer(Topic, String, String, boolean)");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (consumer2 != null)
+ consumer2.close();
+ cleanupSubscription(consumer, session, "dummySubDJMSException");
+ toolT.getDefaultConnection().close();
+ toolT.closeAllResources();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("jMSExceptionTests Failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvMsgsOfEachMsgTypeQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:209; JMS:JAVADOC:212; JMS:JAVADOC:213;
+ * JMS:JAVADOC:215; JMS:JAVADOC:217; JMS:JAVADOC:219; JMS:JAVADOC:221;
+ * JMS:JAVADOC:223; JMS:JAVADOC:242; JMS:JAVADOC:317; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510;
+ *
+ * @test_Strategy: Send and receive messages of each message type: Message,
+ * BytesMessage, MapMessage, ObjectMessage, StreamMessage, TextMessage. Tests
+ * the following API's
+ *
+ * ConnectionFactory.createConnection(String, String)
+ * Connection.createSession(boolean, int) Session.createMessage()
+ * Session.createBytesMessage() Session.createMapMessage()
+ * Session.createObjectMessage() Session.createObjectMessage(Serializable
+ * object) Session.createStreamMessage() Session.createTextMessage()
+ * Session.createTextMessage(String) Session.createConsumer(Destination)
+ * Session.createProducer(Destination) MessageProducer.send(Message)
+ * MessageConsumer.receive(long timeout)
+ */
+ @Test
+ public void sendAndRecvMsgsOfEachMsgTypeQueueTest() throws Exception {
+ boolean pass = true;
+ try {
+ // Setup for Queue
+ setupGlobalVarsQ();
+
+ // send and receive Message
+ logger.log(Logger.Level.INFO, "Send Message");
+ Message msg = session.createMessage();
+ logger.log(Logger.Level.INFO, "Set some values in Message");
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeQueueTest");
+ msg.setBooleanProperty("booleanProperty", true);
+ producer.send(msg);
+ logger.log(Logger.Level.INFO, "Receive Message");
+ Message msgRecv = consumer.receive(timeout);
+ if (msgRecv == null) {
+ throw new Exception("Did not receive Message");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in Message");
+ if (msgRecv.getBooleanProperty("booleanProperty") == true) {
+ logger.log(Logger.Level.INFO, "booleanproperty is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanproperty is incorrect");
+ pass = false;
+ }
+
+ // send and receive BytesMessage
+ logger.log(Logger.Level.INFO, "Send BytesMessage");
+ BytesMessage bMsg = session.createBytesMessage();
+ logger.log(Logger.Level.INFO, "Set some values in BytesMessage");
+ bMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeQueueTest");
+ bMsg.writeByte((byte) 1);
+ bMsg.writeInt((int) 22);
+ producer.send(bMsg);
+ logger.log(Logger.Level.INFO, "Receive BytesMessage");
+ BytesMessage bMsgRecv = (BytesMessage) consumer.receive(timeout);
+ if (bMsgRecv == null) {
+ throw new Exception("Did not receive BytesMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in BytesMessage");
+ if (bMsgRecv.readByte() == (byte) 1) {
+ logger.log(Logger.Level.INFO, "bytevalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "bytevalue is incorrect");
+ pass = false;
+ }
+ if (bMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+
+ // send and receive MapMessage
+ logger.log(Logger.Level.INFO, "Send MapMessage");
+ MapMessage mMsg = session.createMapMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ mMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeQueueTest");
+ mMsg.setBoolean("booleanvalue", true);
+ mMsg.setInt("intvalue", (int) 10);
+ producer.send(mMsg);
+ logger.log(Logger.Level.INFO, "Receive MapMessage");
+ MapMessage mMsgRecv = (MapMessage) consumer.receive(timeout);
+ if (mMsgRecv == null) {
+ throw new Exception("Did not receive MapMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in MapMessage");
+ Enumeration list = mMsgRecv.getMapNames();
+ String name = null;
+ while (list.hasMoreElements()) {
+ name = (String) list.nextElement();
+ if (name.equals("booleanvalue")) {
+ if (mMsgRecv.getBoolean(name) == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "booleanvalue is incorrect");
+ pass = false;
+ }
+ } else if (name.equals("intvalue")) {
+ if (mMsgRecv.getInt(name) == 10) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "intvalue is incorrect");
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Unexpected name of [" + name + "] in MapMessage");
+ pass = false;
+ }
+ }
+
+ // send and receive ObjectMessage
+ logger.log(Logger.Level.INFO, "Send ObjectMessage");
+ StringBuffer sb1 = new StringBuffer("This is a StringBuffer");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage");
+ ObjectMessage oMsg = session.createObjectMessage();
+ oMsg.setObject(sb1);
+ oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeQueueTest");
+ producer.send(oMsg);
+ logger.log(Logger.Level.INFO, "Receive ObjectMessage");
+ ObjectMessage oMsgRecv = (ObjectMessage) consumer.receive(timeout);
+ if (oMsgRecv == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in ObjectMessage");
+ StringBuffer sb2 = (StringBuffer) oMsgRecv.getObject();
+ if (sb2.toString().equals(sb1.toString())) {
+ logger.log(Logger.Level.INFO, "objectvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "objectvalue is incorrect");
+ pass = false;
+ }
+
+ // send and receive ObjectMessage passing object as param
+ logger.log(Logger.Level.INFO, "Send ObjectMessage passing object as param");
+ sb1 = new StringBuffer("This is a StringBuffer");
+ logger.log(Logger.Level.INFO, "Set some values in ObjectMessage passing object as param");
+ oMsg = session.createObjectMessage(sb1);
+ oMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeQueueTest");
+ producer.send(oMsg);
+ logger.log(Logger.Level.INFO, "Receive ObjectMessage");
+ oMsgRecv = (ObjectMessage) consumer.receive(timeout);
+ if (oMsgRecv == null) {
+ throw new Exception("Did not receive ObjectMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in ObjectMessage");
+ sb2 = (StringBuffer) oMsgRecv.getObject();
+ if (sb2.toString().equals(sb1.toString())) {
+ logger.log(Logger.Level.INFO, "objectvalue is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "objectvalue is incorrect");
+ pass = false;
+ }
+
+ // send and receive StreamMessage
+ logger.log(Logger.Level.INFO, "Send StreamMessage");
+ StreamMessage sMsg = session.createStreamMessage();
+ logger.log(Logger.Level.INFO, "Set some values in StreamMessage");
+ sMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeQueueTest");
+ sMsg.writeBoolean(true);
+ sMsg.writeInt((int) 22);
+ producer.send(sMsg);
+ logger.log(Logger.Level.INFO, "Receive StreamMessage");
+ StreamMessage sMsgRecv = (StreamMessage) consumer.receive(timeout);
+ if (sMsgRecv == null) {
+ throw new Exception("Did not receive StreamMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the values in StreamMessage");
+ if (sMsgRecv.readBoolean() == true) {
+ logger.log(Logger.Level.INFO, "booleanvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "booleanvalue is incorrect");
+ pass = false;
+ }
+ if (sMsgRecv.readInt() == (int) 22) {
+ logger.log(Logger.Level.INFO, "intvalue is correct");
+ } else {
+ logger.log(Logger.Level.INFO, "intvalue is incorrect");
+ pass = false;
+ }
+
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Send TextMessage");
+ TextMessage tMsg = session.createTextMessage();
+ logger.log(Logger.Level.INFO, "Set some values in MapMessage");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeQueueTest");
+ tMsg.setText("Hello There!");
+ producer.send(tMsg);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ TextMessage tMsgRecv = (TextMessage) consumer.receive(timeout);
+ if (tMsgRecv == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (tMsgRecv.getText().equals("Hello There!")) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect");
+ pass = false;
+ }
+
+ // send and receive TextMessage passing string as param
+ logger.log(Logger.Level.INFO, "Send TextMessage");
+ tMsg = session.createTextMessage("Where are you!");
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvMsgsOfEachMsgTypeQueueTest");
+ producer.send(tMsg);
+ logger.log(Logger.Level.INFO, "Receive TextMessage");
+ tMsgRecv = (TextMessage) consumer.receive(timeout);
+ if (tMsgRecv == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (tMsgRecv.getText().equals("Where are you!")) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("sendAndRecvMsgsOfEachMsgTypeQueueTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvMsgsOfEachMsgTypeQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: createTemporayQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:194;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * Session.createTemporaryQueue().
+ *
+ * Send and receive a TextMessage to temporary queue. Compare send and recv
+ * message for equality.
+ */
+ @Test
+ public void createTemporayQueueTest() throws Exception {
+ boolean pass = true;
+ MessageConsumer tConsumer = null;
+ try {
+
+ String message = "a text message";
+
+ // Setup for Queue
+ setupGlobalVarsQ();
+
+ // create a TemporaryQueue
+ logger.log(Logger.Level.INFO, "Creating TemporaryQueue");
+ TemporaryQueue tempQueue = session.createTemporaryQueue();
+
+ // Create a MessageConsumer for this Temporary Queue
+ logger.log(Logger.Level.INFO, "Creating MessageConsumer");
+ tConsumer = session.createConsumer(tempQueue);
+
+ // Create a MessageProducer for this Temporary Queue
+ logger.log(Logger.Level.INFO, "Creating MessageProducer");
+ MessageProducer tProducer = session.createProducer(tempQueue);
+
+ // Send TextMessage to temporary queue
+ logger.log(Logger.Level.INFO, "Creating TextMessage with text [" + message + "]");
+ TextMessage tMsg = session.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ tMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createTemporayQueueTest");
+ logger.log(Logger.Level.INFO, "Send TextMessage to temporaty queue");
+ tProducer.send(tMsg);
+
+ // Receive TextMessage from temporary queue
+ logger.log(Logger.Level.INFO, "Receive TextMessage from temporaty queue");
+ TextMessage tMsgRecv = null;
+ if (tConsumer != null)
+ tMsgRecv = (TextMessage) tConsumer.receive(timeout);
+ if (tMsgRecv == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (tMsgRecv.getText().equals(message)) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Attempting to delete temporary queue with an open consumer should not be allowed");
+ try {
+ tempQueue.delete();
+ pass = false;
+ logger.log(Logger.Level.ERROR, "TemporaryQueue.delete() didn't throw expected Exception");
+ } catch (JMSException em) {
+ logger.log(Logger.Level.INFO, "Received expected JMSException: ");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Received unexpected JMSException: " + e);
+ pass = false;
+ }
+
+ try {
+ if (tConsumer != null)
+ tConsumer.close();
+ } catch (Exception e) {
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Attempting to delete temporary queue with no open consumer should be allowed");
+ try {
+ tempQueue.delete();
+ } catch (Exception e) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Received unexpected Exception: ", e);
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createTemporayQueueTest");
+ }
+
+ if (!pass) {
+ throw new Exception("createTemporayQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: createQueueBrowserTest
+ *
+ * @assertion_ids: JMS:JAVADOC:258; JMS:JAVADOC:260;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * Session.createBrowser(Queue) Session.createBrowser(Queue, String)
+ *
+ * 1. Send x text messages to a Queue. 2. Create a QueueBrowser with selector to
+ * browse just the last message in the Queue. 3. Create a QueueBrowser again to
+ * browse all the messages in the queue.
+ */
+ @Test
+ public void createQueueBrowserTest() throws Exception {
+ boolean pass = true;
+ QueueBrowser qBrowser = null;
+ try {
+ TextMessage tempMsg = null;
+ Enumeration msgs = null;
+
+ // Setup for Queue
+ setupGlobalVarsQ();
+ consumer.close();
+
+ // send "numMessages" messages to Queue plus end of stream message
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " to Queue");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createQueueBrowserTest" + i);
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ // create QueueBrowser to peek at last message in Queue using message
+ // selector
+ logger.log(Logger.Level.INFO,
+ "Create QueueBrowser to peek at last message in Queue using message selector");
+ qBrowser = session.createBrowser(queue, "lastMessage = TRUE");
+
+ // check that browser just has the last message in the Queue
+ logger.log(Logger.Level.INFO, "Check that browser has just the last message");
+ int msgCount = 0;
+ msgs = qBrowser.getEnumeration();
+ while (msgs.hasMoreElements()) {
+ tempMsg = (TextMessage) msgs.nextElement();
+ if (!tempMsg.getText().equals("Message " + numMessages)) {
+ logger.log(Logger.Level.ERROR, "Found [" + tempMsg.getText() + "] in browser expected [Message 3]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Found correct [Message 3] in browser");
+ }
+ msgCount++;
+ }
+ if (msgCount != 1) {
+ logger.log(Logger.Level.ERROR, "Found " + msgCount + " messages in browser expected 1");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Found 1 message in browser (correct)");
+ }
+ qBrowser.close();
+
+ // create QueueBrowser to peek at all messages in the Queue
+ logger.log(Logger.Level.INFO, "Create QueueBrowser to browse all messages in the Queue");
+ qBrowser = session.createBrowser(queue);
+
+ // check for messages
+ logger.log(Logger.Level.INFO, "Check that browser contains all " + numMessages + " messages");
+ msgCount = 0;
+ int msgIndex = 1;
+ msgs = qBrowser.getEnumeration();
+ while (msgs.hasMoreElements()) {
+ tempMsg = (TextMessage) msgs.nextElement();
+ if (!tempMsg.getText().equals("Message " + msgIndex)) {
+ logger.log(Logger.Level.ERROR,
+ "Found [" + tempMsg.getText() + "] in browser expected [Message " + msgIndex + "]");
+ pass = false;
+ }
+ msgCount++;
+ msgIndex++;
+ }
+ if (msgCount != numMessages) {
+ logger.log(Logger.Level.ERROR, "Found " + msgCount + " messages in browser expected " + numMessages);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Found " + numMessages + " messages in browser (correct)");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createQueueBrowserTest");
+ } finally {
+ try {
+ if (qBrowser != null)
+ qBrowser.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createQueueBrowserTest failed");
+ }
+ }
+
+ /*
+ * @testName: getTransactedQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:225;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * Session.getTransacted().
+ */
+ @Test
+ public void getTransactedQueueTest() throws Exception {
+ boolean pass = true;
+
+ // Test for transacted mode false
+ try {
+ // Setup for Queue
+ setupGlobalVarsQ();
+ session.close();
+
+ session = connection.createSession(Session.AUTO_ACKNOWLEDGE);
+ boolean expTransacted = false;
+ logger.log(Logger.Level.INFO, "Calling getTransacted and expect " + expTransacted + " to be returned");
+ boolean actTransacted = session.getTransacted();
+ if (actTransacted != expTransacted) {
+ logger.log(Logger.Level.ERROR,
+ "getTransacted() returned " + actTransacted + ", expected " + expTransacted);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getTransactedQueueTest", e);
+ } finally {
+ try {
+ if (session != null)
+ session.close();
+ } catch (Exception e) {
+ }
+ }
+
+ // Test for transacted mode true
+ if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
+ try {
+ session = connection.createSession(Session.SESSION_TRANSACTED);
+ boolean expTransacted = true;
+ logger.log(Logger.Level.INFO, "Calling getTransacted and expect " + expTransacted + " to be returned");
+ boolean actTransacted = session.getTransacted();
+ if (actTransacted != expTransacted) {
+ logger.log(Logger.Level.ERROR,
+ "getTransacted() returned " + actTransacted + ", expected " + expTransacted);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getTransactedQueueTest", e);
+ } finally {
+ try {
+ if (session != null)
+ session.close();
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("getTransactedQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: getAcknowledgeModeQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:227;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * Session.getAcknowledgeMode().
+ */
+ @Test
+ public void getAcknowledgeModeQueueTest() throws Exception {
+ boolean pass = true;
+
+ // Test for AUTO_ACKNOWLEDGE mode
+ try {
+ // Setup for Queue
+ setupGlobalVarsQ();
+ session.close();
+
+ session = connection.createSession(Session.AUTO_ACKNOWLEDGE);
+ int expAcknowledgeMode = Session.AUTO_ACKNOWLEDGE;
+ logger.log(Logger.Level.INFO,
+ "Calling getAcknowledgeMode and expect " + expAcknowledgeMode + " to be returned");
+ int actAcknowledgeMode = session.getAcknowledgeMode();
+ if (actAcknowledgeMode != expAcknowledgeMode) {
+ logger.log(Logger.Level.ERROR,
+ "getAcknowledgeMode() returned " + actAcknowledgeMode + ", expected " + expAcknowledgeMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getAcknowledgeModeTopicTest", e);
+ } finally {
+ try {
+ if (session != null)
+ session.close();
+ } catch (Exception e) {
+ }
+ }
+
+ // Test for DUPS_OK_ACKNOWLEDGE mode
+ try {
+ session = connection.createSession(Session.DUPS_OK_ACKNOWLEDGE);
+ int expAcknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
+ logger.log(Logger.Level.INFO,
+ "Calling getAcknowledgeMode and expect " + expAcknowledgeMode + " to be returned");
+ int actAcknowledgeMode = session.getAcknowledgeMode();
+ if (actAcknowledgeMode != expAcknowledgeMode) {
+ logger.log(Logger.Level.ERROR,
+ "getAcknowledgeMode() returned " + actAcknowledgeMode + ", expected " + expAcknowledgeMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getAcknowledgeModeTopicTest", e);
+ } finally {
+ try {
+ if (session != null)
+ session.close();
+ } catch (Exception e) {
+ }
+ }
+
+ // Test for SESSION_TRANSACTED mode
+ if ((vehicle.equals("appclient") || vehicle.equals("standalone"))) {
+ try {
+ session = connection.createSession(Session.SESSION_TRANSACTED);
+ int expAcknowledgeMode = Session.SESSION_TRANSACTED;
+ logger.log(Logger.Level.INFO,
+ "Calling getAcknowledgeMode and expect " + expAcknowledgeMode + " to be returned");
+ int actAcknowledgeMode = session.getAcknowledgeMode();
+ if (actAcknowledgeMode != expAcknowledgeMode) {
+ logger.log(Logger.Level.ERROR,
+ "getAcknowledgeMode() returned " + actAcknowledgeMode + ", expected " + expAcknowledgeMode);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("getAcknowledgeModeTopicTest", e);
+ } finally {
+ try {
+ if (session != null)
+ session.close();
+ } catch (Exception e) {
+ }
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("getAcknowledgeModeQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: createConsumerProducerQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:221; JMS:JAVADOC:242; JMS:JAVADOC:244;
+ * JMS:JAVADOC:246; JMS:JAVADOC:248; JMS:JAVADOC:504; JMS:JAVADOC:510;
+ * JMS:JAVADOC:597; JMS:JAVADOC:334;
+ *
+ * @test_Strategy: Test the following APIs:
+ *
+ * ConnectionFactory.createConnection(String, String)
+ * Connection.createSession(boolean, int) Session.createTextMessage(String)
+ * Session.createConsumer(Destination) Session.createConsumer(Destination,
+ * String) Session.createConsumer(Destination, String, boolean)
+ * Session.createProducer(Destination) MessageProducer.send(Message)
+ * MessageConsumer.receive(long timeout)
+ *
+ * 1. Send x text messages to a Queue. 2. Create a MessageConsumer with selector
+ * to consume just the last message in the Queue. 3. Create a MessageConsumer
+ * again to consume the rest of the messages in the Queue.
+ */
+ @Test
+ public void createConsumerProducerQueueTest() throws Exception {
+ boolean pass = true;
+ try {
+ TextMessage tempMsg = null;
+ Enumeration msgs = null;
+
+ // Setup for Queue
+ setupGlobalVarsQ();
+ consumer.close();
+
+ // send "numMessages" messages to Queue plus end of stream message
+ logger.log(Logger.Level.INFO, "Send " + numMessages + " messages to Queue");
+ for (int i = 1; i <= numMessages; i++) {
+ tempMsg = session.createTextMessage("Message " + i);
+ tempMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "createConsumerProducerQueueTest" + i);
+ tempMsg.setJMSType("");
+ if (i == numMessages) {
+ tempMsg.setBooleanProperty("lastMessage", true);
+ } else {
+ tempMsg.setBooleanProperty("lastMessage", false);
+ }
+ producer.send(tempMsg);
+ logger.log(Logger.Level.INFO, "Message " + i + " sent");
+ }
+
+ // Create MessageConsumer to consume last message in Queue using message
+ // selector
+ logger.log(Logger.Level.INFO,
+ "Create selective consumer to consume messages in Queue with boolproperty (lastMessage=TRUE)");
+ consumer = session.createConsumer(destination, "lastMessage=TRUE");
+
+ logger.log(Logger.Level.INFO,
+ "Consume messages with selective consumer which has boolproperty (lastMessage=TRUE)");
+ if (consumer != null)
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "MessageConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + numMessages + " missing from Queue");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + numMessages)) {
+ logger.log(Logger.Level.ERROR, "Received [" + tempMsg.getText() + "] expected [Message 3]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received expected message: " + tempMsg.getText());
+ }
+
+ // Try to receive one more message (should return null)
+ logger.log(Logger.Level.INFO, "Make sure selective consumer receives no more messages");
+ if (consumer != null)
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR, "MessageConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "MessageConsumer with selector should have returned just 1 message");
+ pass = false;
+ }
+
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+
+ // Create MessageConsumer to consume rest of messages in Queue
+ logger.log(Logger.Level.INFO, "Consume rest of messages with normal consumer");
+ consumer = session.createConsumer(destination);
+ for (int msgCount = 1; msgCount < numMessages; msgCount++) {
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg == null) {
+ logger.log(Logger.Level.ERROR, "MessageConsumer.receive() returned NULL");
+ logger.log(Logger.Level.ERROR, "Message " + msgCount + " missing from Queue");
+ pass = false;
+ } else if (!tempMsg.getText().equals("Message " + msgCount)) {
+ logger.log(Logger.Level.ERROR,
+ "Received [" + tempMsg.getText() + "] expected [Message " + msgCount + "]");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Received message: " + tempMsg.getText());
+ }
+ }
+
+ // Try to receive one more message (should return null)
+ logger.log(Logger.Level.INFO, "Make sure normal consumer receives no more messages");
+ tempMsg = (TextMessage) consumer.receive(timeout);
+ if (tempMsg != null) {
+ logger.log(Logger.Level.ERROR,
+ "MessageConsumer should have returned " + (numMessages - 1) + " message");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ e.printStackTrace();
+ throw new Exception("createConsumerProducerQueueTest");
+ } finally {
+ try {
+ if (consumer != null)
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("createConsumerProducerQueueTest failed");
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/queueCMTTests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/queueCMTTests/Client.java
deleted file mode 100644
index 7f137f43b0..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/queueCMTTests/Client.java
+++ /dev/null
@@ -1,1166 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.ejb.queueCMTTests;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.commonee.Tests;
-
-import jakarta.ejb.EJB;
-import jakarta.jms.DeliveryMode;
-import jakarta.jms.Queue;
-
-public class Client extends EETest {
-
- private static final String testName = "com.sun.ts.tests.jms.ee.ejb.queueCMTTests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- @EJB(name = "ejb/QueueTests")
- private static Tests beanRef;
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- if (beanRef == null) {
- throw new Exception("@EJB injection failed");
- }
-
- props = p;
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
-
- beanRef.initLogging(props);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /*
- * cleanup() is called after each test
- */
- public void cleanup() throws Exception {
- }
-
- private void flushTheQueue() throws Exception {
- JmsTool tool = null;
- try {
- tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
-
- } catch (Exception e) {
- TestUtil.logErr("Error creating JmsTool and closing Connection", e);
- } finally {
- try {
- tool.flushQueue();
- } catch (Exception e) {
- TestUtil.logErr("Error flush : ", e);
- }
-
- try {
- TestUtil.logTrace("Closing default QueueConnection");
- tool.getDefaultQueueConnection().close();
- } catch (Exception e) {
- TestUtil.logErr("Error clsoing connection : ", e);
- }
- }
- }
-
- /*
- * @testName: bytesMessageFullMsgTests
- *
- * @assertion_ids: JMS:JAVADOC:560; JMS:JAVADOC:562; JMS:JAVADOC:564;
- * JMS:JAVADOC:566; JMS:JAVADOC:568; JMS:JAVADOC:570; JMS:JAVADOC:572;
- * JMS:JAVADOC:574; JMS:JAVADOC:576; JMS:JAVADOC:578; JMS:JAVADOC:580;
- * JMS:JAVADOC:582; JMS:JAVADOC:534; JMS:JAVADOC:536; JMS:JAVADOC:540;
- * JMS:JAVADOC:544; JMS:JAVADOC:546; JMS:JAVADOC:548; JMS:JAVADOC:550;
- * JMS:JAVADOC:552; JMS:JAVADOC:554; JMS:JAVADOC:556; JMS:JAVADOC:558;
- * JMS:JAVADOC:538; JMS:JAVADOC:542; JMS:JAVADOC:532;
- *
- * @test_Strategy: Write to a BytesMessage using each type of method. Verify
- * the BytesMessage received.
- */
-
- public void bytesMessageFullMsgTests() throws Exception {
-
- try {
- beanRef.sendFullBytesMessage_Q(testName);
-
- // Check to see if correct message received
- if (!beanRef.verifyFullBytesMessage())
- throw new Exception("didn't get the right message");
-
- } catch (Exception e) {
- logErr("Caught Exception in test bytesMessageFullMsgTests: ", e);
- throw new Exception("bytesMessageFullMsgTests", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: mapMessageFullMsgTest
- *
- * @assertion_ids: JMS:SPEC:74; JMS:JAVADOC:211; JMS:JAVADOC:457;
- * JMS:JAVADOC:459; JMS:JAVADOC:475; JMS:JAVADOC:477; JMS:JAVADOC:479;
- * JMS:JAVADOC:461; JMS:JAVADOC:463; JMS:JAVADOC:465; JMS:JAVADOC:467;
- * JMS:JAVADOC:469; JMS:JAVADOC:471; JMS:JAVADOC:473; JMS:JAVADOC:433;
- * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:439; JMS:JAVADOC:441;
- * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
- * JMS:JAVADOC:451; JMS:JAVADOC:453;
- *
- * @test_Strategy: Write to a MapMessage using each type of method. Verify the
- * MapMessage received.
- */
-
- public void mapMessageFullMsgTest() throws Exception {
-
- try {
- beanRef.sendFullMapMessage_Q(testName);
-
- // Check to see if correct message received
- if (!beanRef.verifyFullMapMessage())
- throw new Exception("didn't get the right message");
-
- } catch (Exception e) {
- logErr("Caught Exception in test mapMessageFullMsgTest: ", e);
- throw new Exception("mapMessageFullMsgTest", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: streamMessageFullMsgTest
- *
- * @assertion_ids: JMS:SPEC:82; JMS:JAVADOC:150; JMS:JAVADOC:152;
- * JMS:JAVADOC:154; JMS:JAVADOC:156; JMS:JAVADOC:158; JMS:JAVADOC:160;
- * JMS:JAVADOC:162; JMS:JAVADOC:164; JMS:JAVADOC:166; JMS:JAVADOC:168;
- * JMS:JAVADOC:170; JMS:JAVADOC:172; JMS:JAVADOC:128; JMS:JAVADOC:130;
- * JMS:JAVADOC:132; JMS:JAVADOC:134; JMS:JAVADOC:136; JMS:JAVADOC:138;
- * JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
- * JMS:JAVADOC:148;
- *
- * @test_Strategy: Write to a StreamMessage using each type of method. Verify
- * the StreamMessage received.
- */
-
- public void streamMessageFullMsgTest() throws Exception {
-
- try {
- beanRef.sendFullStreamMessage_Q(testName);
-
- // Check to see if correct message received
- if (!beanRef.verifyFullStreamMessage())
- throw new Exception("didn't get the right message");
-
- } catch (Exception e) {
- logErr("Caught Exception in test streamMessageFullMsgTest: ", e);
- throw new Exception("streamMessageFullMsgTest", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: msgHdrIDTest
- *
- * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343;
- *
- * @test_Strategy: Send and receive single Text, map, bytes, stream, and
- * object message call getJMSMessageID and verify that it starts with ID:
- */
-
- public void msgHdrIDTest() throws Exception {
- String id = null;
- boolean pass = true;
-
- try {
- beanRef.sendTextMessage_Q(testName);
-
- // Get JMSMessageID
- id = beanRef.getMessageID();
- if (!chkMessageID(id)) {
- TestUtil
- .logErr("TextMessage: JMSMessageID does not start with ID:" + id);
- pass = false;
- }
-
- beanRef.sendFullBytesMessage_Q(testName);
-
- // Get JMSMessageID
- id = beanRef.getMessageID();
- if (!chkMessageID(id)) {
- TestUtil
- .logErr("BytesMessage: JMSMessageID does not start with ID:" + id);
- pass = false;
- }
-
- beanRef.sendFullMapMessage_Q(testName);
-
- // Get JMSMessageID
- id = beanRef.getMessageID();
- if (!chkMessageID(id)) {
- TestUtil
- .logErr("MapMessage: JMSMessageID does not start with ID:" + id);
- pass = false;
- }
-
- beanRef.sendFullStreamMessage_Q(testName);
-
- // Get JMSMessageID
- id = beanRef.getMessageID();
- if (!chkMessageID(id)) {
- TestUtil
- .logErr("StreamMessage: JMSMessageID does not start with ID:" + id);
- pass = false;
- }
-
- beanRef.sendObjectMessage_Q(testName);
-
- // Get JMSMessageID
- id = beanRef.getMessageID();
- if (!chkMessageID(id)) {
- TestUtil
- .logErr("ObjectMessage: JMSMessageID does not start with ID:" + id);
- pass = false;
- }
-
- if (!pass)
- throw new Exception(
- "msgHdrIDTest failed with at least one type of JMS Message");
-
- } catch (Exception e) {
- logErr("Caught Exception in test msgHdrIDTest: ", e);
- throw new Exception("msgHdrIDTest", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * helper method for JMSMessage Header Tests. verifies that the JMSMessageID
- * starts with ID:
- *
- * @param String returned from getJMSMessageID
- *
- * @return boolean true if id correctly starts with ID:
- */
-
- private boolean chkMessageID(String id) {
- boolean retcode = true;
- int index = 0;
-
- // message id must start with ID: - unless it is null
- if (id == null) {
- ;
- } else if (id.startsWith("ID:")) {
- ;
- } else {
- retcode = false;
- }
- return retcode;
- }
-
- /*
- * @testName: msgHdrTimeStampTest
- *
- * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347;
- *
- * @test_Strategy: Send a Text, Map, Bytes, Stream, and Object messages. Check
- * time of send against the time send returns. JMSTimeStamp should be between
- * these two.
- */
-
- public void msgHdrTimeStampTest() throws Exception {
- java.util.ArrayList sendValue = null;
- boolean pass = true;
- long timeBeforeSend;
- long timeAfterSend;
- long JMSTimestamp;
-
- try {
- sendValue = beanRef.sendTextMessage_Q(testName);
-
- // Get JMSMessageTimestamp
- JMSTimestamp = beanRef.getTimeStamp();
- if (!(((Long) sendValue.get(0)).longValue() <= JMSTimestamp)
- || !(((Long) sendValue.get(1)).longValue() >= JMSTimestamp)) {
- TestUtil.logErr("TextMessage: JMSMessageTimestamp return wrong value:"
- + JMSTimestamp);
- TestUtil.logErr("should be between time before send " + sendValue.get(0)
- + " and time after send " + sendValue.get(1));
- pass = false;
- }
-
- sendValue = beanRef.sendFullBytesMessage_Q(testName);
-
- // Get JMSMessageTimestamp
- JMSTimestamp = beanRef.getTimeStamp();
- if (!(((Long) sendValue.get(0)).longValue() <= JMSTimestamp)
- || !(((Long) sendValue.get(1)).longValue() >= JMSTimestamp)) {
- TestUtil.logErr("BytesMessage: JMSMessageTimestamp return wrong value:"
- + JMSTimestamp);
- TestUtil.logErr("should be between time before send " + sendValue.get(0)
- + " and time after send " + sendValue.get(1));
- pass = false;
- }
-
- sendValue = beanRef.sendFullMapMessage_Q(testName);
-
- // Get JMSMessageTimestamp
- JMSTimestamp = beanRef.getTimeStamp();
- if (!(((Long) sendValue.get(0)).longValue() <= JMSTimestamp)
- || !(((Long) sendValue.get(1)).longValue() >= JMSTimestamp)) {
- TestUtil.logErr("MapMessage: JMSMessageTimestamp return wrong value:"
- + JMSTimestamp);
- TestUtil.logErr("should be between time before send " + sendValue.get(0)
- + " and time after send " + sendValue.get(1));
- pass = false;
- }
-
- sendValue = beanRef.sendFullStreamMessage_Q(testName);
-
- // Get JMSMessageTimestamp
- JMSTimestamp = beanRef.getTimeStamp();
- if (!(((Long) sendValue.get(0)).longValue() <= JMSTimestamp)
- || !(((Long) sendValue.get(1)).longValue() >= JMSTimestamp)) {
- TestUtil
- .logErr("StreamMessage: JMSMessageTimestamp return wrong value: "
- + JMSTimestamp);
- TestUtil.logErr("should be between time before send " + sendValue.get(0)
- + " and time after send " + sendValue.get(1));
- pass = false;
- }
-
- sendValue = beanRef.sendObjectMessage_Q(testName);
-
- // Get JMSMessageTimestamp
- JMSTimestamp = beanRef.getTimeStamp();
- if (!(((Long) sendValue.get(0)).longValue() <= JMSTimestamp)
- || !(((Long) sendValue.get(1)).longValue() >= JMSTimestamp)) {
- TestUtil
- .logErr("ObjectMessage: JMSMessageTimestamp return wrong value: "
- + JMSTimestamp);
- TestUtil.logErr("should be between time before send " + sendValue.get(0)
- + " and time after send " + sendValue.get(1));
- pass = false;
- }
-
- if (!pass)
- throw new Exception(
- "msgHdrTimeStampTest failed with at least one type of JMS Message");
-
- } catch (Exception e) {
- logErr("Caught Exception in test msgHdrTimeStampTest: ", e);
- throw new Exception("msgHdrTimeStampTest", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: msgHdrCorlIdTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- * @test_Strategy: Send a message to a Queue with CorrelationID set. Receive
- * the msg and verify the correlationid is as set by client.
- */
-
- public void msgHdrCorlIdTest() throws Exception {
- boolean pass = true;
- String jmsCorrelationID = "JMSTCKCorrelationID";
-
- try {
- beanRef.sendTextMessage_Q(testName);
-
- String tmp = beanRef.getCorrelationID();
- if (!tmp.equals(jmsCorrelationID)) {
- TestUtil
- .logErr("TextMessage: incorrect JMSCorrelationID returned: " + tmp);
- pass = false;
- }
-
- beanRef.sendFullBytesMessage_Q(testName);
-
- tmp = beanRef.getCorrelationID();
- if (!tmp.equals(jmsCorrelationID)) {
- TestUtil.logErr(
- "BytesMessage: incorrect JMSCorrelationID returned: " + tmp);
- pass = false;
- }
-
- beanRef.sendFullMapMessage_Q(testName);
- tmp = beanRef.getCorrelationID();
-
- if (!tmp.equals(jmsCorrelationID)) {
- TestUtil
- .logErr("MapMessage: incorrect JMSCorrelationID returned:" + tmp);
- pass = false;
- }
-
- beanRef.sendFullStreamMessage_Q(testName);
- tmp = beanRef.getCorrelationID();
-
- if (!tmp.equals(jmsCorrelationID)) {
- TestUtil.logErr(
- "StreamMessage: incorrect JMSCorrelationID returned:" + tmp);
- pass = false;
- }
-
- beanRef.sendObjectMessage_Q(testName);
- tmp = beanRef.getCorrelationID();
-
- if (!tmp.equals(jmsCorrelationID)) {
- TestUtil.logErr(
- "ObjectMessage: incorrect JMSCorrelationID returned:" + tmp);
- pass = false;
- }
-
- if (!pass)
- throw new Exception(
- "msgHdrCorlIdTest failed with at least one type of JMS Message");
-
- } catch (Exception e) {
- logErr("Caught Exception in test msgHdrCorlIdTest: ", e);
- throw new Exception("msgHdrCorlIdTest", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: msgHdrReplyToTest
- *
- * @assertion_ids: JMS:SPEC:12; JMS:JAVADOC:359; JMS:JAVADOC:361;
- * JMS:JAVADOC:286; JMS:JAVADOC:289; JMS:JAVADOC:562; JMS:JAVADOC:166;
- * JMS:SPEC:246.8;
- *
- * @test_Strategy: Send a message to a Queue with ReplyTo set to null. Send a
- * message to a Queue with ReplyTo set to a destination. Test with Text, Map,
- * Object, Bytes, and Stream messages. Verify on receive that in both cases
- * ReplyTo is as set by Client.
- */
-
- public void msgHdrReplyToTest() throws Exception {
- boolean pass = true;
- String QueueName = null;
- String QueueName_used = null;
-
- try {
- beanRef.sendTextMessage_Q(testName);
- QueueName = beanRef.getReplyTo();
-
- if (QueueName != null) {
- TestUtil.logErr("TextMessage: null JMSReplyTo should be returned");
- pass = false;
- }
-
- beanRef.sendTextMessage_Q(testName, true);
- QueueName = beanRef.getReplyTo();
- QueueName_used = beanRef.getDestination_1();
-
- if (!QueueName.equals(QueueName_used)) {
- TestUtil
- .logErr("TextMessage: incorrect JMSReplyTo returned: " + QueueName);
- TestUtil.logErr("TextMessage: expecting: " + QueueName_used);
- pass = false;
- } else {
- TestUtil.logTrace("TextMessage: passed");
- }
-
- beanRef.sendFullBytesMessage_Q(testName);
- QueueName = beanRef.getReplyTo();
-
- if (QueueName != null) {
- TestUtil.logErr("BytesMessage: null JMSReplyTo should be returned");
- pass = false;
- }
-
- beanRef.sendBytesMessage_Q(testName, true);
- QueueName = beanRef.getReplyTo();
-
- if (!QueueName.equals(QueueName_used)) {
- TestUtil
- .logErr("BytesMessage: incorrect JMSReplyTo returned:" + QueueName);
- TestUtil.logErr("BytesMessage: expecting: " + QueueName_used);
- pass = false;
- } else {
- TestUtil.logTrace("BytesMessage: passed");
- }
-
- beanRef.sendFullMapMessage_Q(testName);
- QueueName = beanRef.getReplyTo();
-
- if (QueueName != null) {
- TestUtil.logErr(
- "MapMessage: null JMSReplyTo should be returned:" + QueueName);
- pass = false;
- }
-
- beanRef.sendMapMessage_Q(testName, true);
- QueueName = beanRef.getReplyTo();
-
- if (!QueueName.equals(QueueName_used)) {
- TestUtil
- .logErr("MapMessage: incorrect JMSReplyTo returned: " + QueueName);
- TestUtil.logErr("MapMessage: expecting: " + QueueName_used);
- pass = false;
- } else {
- TestUtil.logTrace("MapMessage: passed");
- }
-
- beanRef.sendFullStreamMessage_Q(testName);
- QueueName = beanRef.getReplyTo();
-
- if (QueueName != null) {
- TestUtil.logErr(
- "StreamMessage: null JMSReplyTo should be returned: " + QueueName);
- pass = false;
- }
-
- beanRef.sendStreamMessage_Q(testName, true);
- QueueName = beanRef.getReplyTo();
-
- if (!QueueName.equals(QueueName_used)) {
- TestUtil.logErr(
- "StreamMessage: incorrect JMSReplyTo returned: " + QueueName);
- TestUtil.logErr("StreamMessage: expecting: " + QueueName_used);
- pass = false;
- } else {
- TestUtil.logTrace("StreamMessage: passed");
- }
-
- beanRef.sendObjectMessage_Q(testName);
- QueueName = beanRef.getReplyTo();
-
- if (QueueName != null) {
- TestUtil.logErr(
- "ObjectMessage: null JMSReplyTo should be returned" + QueueName);
- pass = false;
- }
-
- beanRef.sendObjectMessage_Q(testName, true);
- QueueName = beanRef.getReplyTo();
-
- if (!QueueName.equals(QueueName_used)) {
- TestUtil.logErr(
- "ObjectMessage: incorrect JMSReplyTo returned: " + QueueName);
- TestUtil.logErr("ObjectMessage: expecting: " + QueueName_used);
- pass = false;
- } else {
- TestUtil.logTrace("ObjectMessage: passed");
- }
-
- if (!pass)
- throw new Exception(
- "msgHdrReplyToTest failed with at least one type of JMS Message");
-
- } catch (Exception e) {
- logErr("Caught Exception in test msgHdrReplyToTest: ", e);
- throw new Exception("msgHdrReplyToTest", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: msgHdrJMSTypeTest
- *
- * @assertion_ids: JMS:SPEC:246.9; JMS:JAVADOC:375; JMS:JAVADOC:377;
- *
- * @test_Strategy: Send a message to a Queue with JMSType set to TESTMSG. Test
- * with Text, Map, Object, Bytes, and Stream messages. Verify on receive.
- */
-
- public void msgHdrJMSTypeTest() throws Exception {
- boolean pass = true;
- String type = "JMSTCKTESTMSG";
-
- try {
- beanRef.sendTextMessage_Q(testName);
-
- if (!beanRef.getType().equals(type)) {
- TestUtil.logErr(
- "TextMessage: wrong JMSType returned: " + beanRef.getType());
- pass = false;
- }
-
- beanRef.sendFullBytesMessage_Q(testName);
-
- if (!beanRef.getType().equals(type)) {
- TestUtil.logErr("BytesMessage: wrong JMSType returned");
- pass = false;
- }
-
- beanRef.sendFullMapMessage_Q(testName);
-
- if (!beanRef.getType().equals(type)) {
- TestUtil.logErr("MapMessage: wrong JMSType returned");
- pass = false;
- }
-
- beanRef.sendFullStreamMessage_Q(testName);
-
- if (!beanRef.getType().equals(type)) {
- TestUtil.logErr(
- "StreamMessage: wrong JMSType returned" + beanRef.getType());
- pass = false;
- }
-
- beanRef.sendObjectMessage_Q(testName);
-
- if (!beanRef.getType().equals(type)) {
- TestUtil.logErr(
- "ObjectMessage: wrong JMSType returned" + beanRef.getType());
- pass = false;
- }
-
- if (!pass)
- throw new Exception(
- "msgHdrJMSTypeTest failed with at least one type of JMS Message");
-
- } catch (Exception e) {
- logErr("Caught Exception in test msgHdrJMSTypeTest: ", e);
- throw new Exception("msgHdrJMSTypeTest", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: msgHdrJMSPriorityTest
- *
- * @assertion_ids: JMS:SPEC:16; JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140;
- * JMS:JAVADOC:305; JMS:JAVADOC:383;
- *
- * @test_Strategy: Send a message to a Queue with JMSPriority set to 2. Test
- * with Text, Map, Object, Bytes, and Stream messages. Verify JMSPriority
- * value on receive.
- */
-
- public void msgHdrJMSPriorityTest() throws Exception {
- boolean pass = true;
- int priority = 2;
-
- try {
- beanRef.sendTextMessage_Q(testName);
-
- if (beanRef.getPriority() != priority) {
- TestUtil.logErr("TextMessage: wrong JMSPriority returned: "
- + beanRef.getPriority());
- pass = false;
- }
-
- beanRef.sendFullBytesMessage_Q(testName);
-
- if (beanRef.getPriority() != priority) {
- TestUtil.logErr("BytesMessage: wrong JMSPriority returned: "
- + beanRef.getPriority());
- pass = false;
- }
-
- beanRef.sendFullMapMessage_Q(testName);
-
- if (beanRef.getPriority() != priority) {
- TestUtil.logErr(
- "MapMessage: wrong JMSPriority returned: " + beanRef.getPriority());
- pass = false;
- }
-
- beanRef.sendFullStreamMessage_Q(testName);
-
- if (beanRef.getPriority() != priority) {
- TestUtil.logErr("StreamMessage: wrong JMSPriority returned: "
- + beanRef.getPriority());
- pass = false;
- }
-
- beanRef.sendObjectMessage_Q(testName);
-
- if (beanRef.getPriority() != priority) {
- TestUtil.logErr("ObjectMessage: wrong JMSPriority returned: "
- + beanRef.getPriority());
- pass = false;
- }
-
- if (!pass)
- throw new Exception(
- "msgHdrJMSPriorityTest failed with at least one type of JMS Message");
-
- } catch (Exception e) {
- logErr("Caught Exception in test msgHdrJMSPriorityTest: ", e);
- throw new Exception("msgHdrJMSPriorityTest", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: msgHdrJMSExpirationTest
- *
- * @assertion_ids: JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140;
- * JMS:JAVADOC:309; JMS:JAVADOC:379;
- *
- * @test_Strategy: Send a message to a Queue with time to live set to 0. Test
- * with Text, Map, Object, Bytes, and Stream messages.
- */
-
- public void msgHdrJMSExpirationTest() throws Exception {
- boolean pass = true;
- long forever = 0;
-
- try {
- beanRef.sendTextMessage_Q(testName);
-
- if (beanRef.getExpiration() != forever) {
- TestUtil.logErr("TextMessage: wrong JMSExpiration returned: "
- + beanRef.getExpiration());
- pass = false;
- }
-
- beanRef.sendFullBytesMessage_Q(testName);
-
- if (beanRef.getExpiration() != forever) {
- TestUtil.logErr("BytesMessage: wrong JMSExpiration returned: "
- + beanRef.getExpiration());
- pass = false;
- }
-
- beanRef.sendFullMapMessage_Q(testName);
-
- if (beanRef.getExpiration() != forever) {
- TestUtil.logErr("MapMessage: wrong JMSExpiration returned: "
- + beanRef.getExpiration());
- pass = false;
- }
-
- beanRef.sendFullStreamMessage_Q(testName);
-
- if (beanRef.getExpiration() != forever) {
- TestUtil.logErr("StreamMessage: wrong JMSExpiration returned: "
- + beanRef.getExpiration());
- pass = false;
- }
-
- beanRef.sendObjectMessage_Q(testName);
-
- if (beanRef.getExpiration() != forever) {
- TestUtil.logErr("ObjectMessage: wrong JMSExpiration returned: "
- + beanRef.getExpiration());
- pass = false;
- }
-
- if (!pass)
- throw new Exception(
- "msgHdrJMSExpirationTest failed with at least one type of JMS Message");
-
- } catch (Exception e) {
- logErr("Caught Exception in test msgHdrJMSExpirationTest: ", e);
- throw new Exception("msgHdrJMSExpirationTest");
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: msgHdrJMSDestinationTest
- *
- * @assertion_ids: JMS:SPEC:2; JMS:JAVADOC:363; JMS:JAVADOC:286;
- *
- * @test_Strategy: Create and send a message to a Queue. Verify on receive
- * that JMSDestination is set to the Queue. Test with Text, Map, Object,
- * Bytes, and Stream messages.
- */
-
- public void msgHdrJMSDestinationTest() throws Exception {
- boolean pass = true;
- long forever = 0;
- String dest = null;
- String dest_used = null;
-
- try {
- beanRef.sendTextMessage_Q(testName);
- dest = beanRef.getDestination();
- dest_used = beanRef.getDestination_1();
-
- if (!dest.equals(dest_used)) {
- TestUtil.logErr("TextMessage: wrong JMSDestination returned: " + dest);
- TestUtil.logErr("Expecting " + dest_used);
- pass = false;
- } else {
- TestUtil.logTrace("TextMessage: msgHdrJMSDestinationTest passed.");
- }
-
- beanRef.sendFullBytesMessage_Q(testName);
-
- if (!(beanRef.getDestination()).equals(dest_used)) {
- TestUtil.logErr("BytesMessage: wrong JMSDestination returned: " + dest);
- TestUtil.logErr("Expecting " + dest_used);
- pass = false;
- } else {
- TestUtil.logTrace("BytesMessage: msgHdrJMSDestinationTest passed.");
- }
-
- beanRef.sendFullMapMessage_Q(testName);
-
- if (!(beanRef.getDestination()).equals(dest_used)) {
- TestUtil.logErr("MapMessage: wrong JMSDestination returned: " + dest);
- TestUtil.logErr("Expecting " + dest_used);
- pass = false;
- } else {
- TestUtil.logTrace("MapMessage: msgHdrJMSDestinationTest passed.");
- }
-
- beanRef.sendFullStreamMessage_Q(testName);
-
- if (!(beanRef.getDestination()).equals(dest_used)) {
- TestUtil
- .logErr("StreamMessage: wrong JMSDestination returned: " + dest);
- TestUtil.logErr("Expecting " + dest_used);
- pass = false;
- } else {
- TestUtil.logTrace("StreamMessage: msgHdrJMSDestinationTest passed.");
- }
-
- beanRef.sendObjectMessage_Q(testName);
-
- if (!(beanRef.getDestination()).equals(dest_used)) {
- TestUtil
- .logErr("ObjectMessage: wrong JMSDestination returned: " + dest);
- TestUtil.logErr("Expecting " + dest_used);
- pass = false;
- } else {
- TestUtil.logTrace("ObjectMessage: msgHdrJMSDestinationTest passed.");
- }
-
- if (!pass)
- throw new Exception(
- "msgHdrJMSDestinationTest failed with at least one type of JMS Message");
-
- } catch (Exception e) {
- logErr("Caught Exception in test msgHdrJMSDestinationTest: ", e);
- throw new Exception("msgHdrJMSDestinationTest", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: msgHdrJMSDeliveryModeTest
- *
- * @assertion_ids: JMS:SPEC:3; JMS:SPEC:140; JMS:JAVADOC:367; JMS:SPEC:246.2;
- * JMS:JAVADOC:301;
- *
- * @test_Strategy: Create and send a message to a Queue. Verify on receive
- * that JMSDeliveryMode is set as the default delivery mode of persistent.
- * Create another message with a nonpersistent delivery mode. Test with Text,
- * Map, Object, Bytes, and Stream messages.
- */
-
- public void msgHdrJMSDeliveryModeTest() throws Exception {
- boolean pass = true;
- long forever = 0;
-
- try {
- beanRef.sendTextMessage_Q(testName);
-
- if (beanRef.getDeliveryMode() != DeliveryMode.PERSISTENT) {
- TestUtil.logErr("TextMessage: wrong DeliveryMode returned: "
- + beanRef.getDeliveryMode());
- pass = false;
- }
-
- beanRef.sendTextMessage_Q(testName, false, DeliveryMode.NON_PERSISTENT);
-
- if (beanRef.getDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- TestUtil.logErr("TextMessage: wrong DeliveryMode returned: "
- + beanRef.getDeliveryMode());
- pass = false;
- }
-
- beanRef.sendFullBytesMessage_Q(testName);
-
- if (beanRef.getDeliveryMode() != DeliveryMode.PERSISTENT) {
- TestUtil.logErr("BytesMessage: wrong DeliveryMode returned: ");
- pass = false;
- }
-
- beanRef.sendBytesMessage_Q(testName, false, DeliveryMode.NON_PERSISTENT);
-
- if (beanRef.getDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- TestUtil.logErr("BytesMessage: wrong DeliveryMode returned: ");
- pass = false;
- }
-
- beanRef.sendFullMapMessage_Q(testName);
-
- if (beanRef.getDeliveryMode() != DeliveryMode.PERSISTENT) {
- TestUtil.logErr("MapMessage: wrong DeliveryMode returned: ");
- pass = false;
- }
-
- beanRef.sendMapMessage_Q(testName, false, DeliveryMode.NON_PERSISTENT);
-
- if (beanRef.getDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- TestUtil.logErr("MapMessage: wrong DeliveryMode returned: ");
- pass = false;
- }
-
- beanRef.sendFullStreamMessage_Q(testName);
-
- if (beanRef.getDeliveryMode() != DeliveryMode.PERSISTENT) {
- TestUtil.logErr("StreamMessage: wrong DeliveryMode returned: ");
- pass = false;
- }
-
- beanRef.sendStreamMessage_Q(testName, false, DeliveryMode.NON_PERSISTENT);
-
- if (beanRef.getDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- TestUtil.logErr("StreamMessage: wrong DeliveryMode returned: ");
- pass = false;
- }
-
- beanRef.sendObjectMessage_Q(testName);
-
- if (beanRef.getDeliveryMode() != DeliveryMode.PERSISTENT) {
- TestUtil.logErr("ObjectMessage: wrong DeliveryMode returned: ");
- pass = false;
- }
-
- beanRef.sendObjectMessage_Q(testName, false, DeliveryMode.NON_PERSISTENT);
-
- if (beanRef.getDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
- TestUtil.logErr("ObjectMessage: wrong DeliveryMode returned: ");
- pass = false;
- }
-
- if (!pass)
- throw new Exception(
- "msgHdrJMSDeliveryModeTest failed with at least one type of JMS Message");
-
- } catch (Exception e) {
- logErr("Caught Exception in test msgHdrJMSDeliveryModeTest: ", e);
- throw new Exception("msgHdrJMSDeliveryModeTest", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: messageOrderTest
- *
- * @assertion_ids: JMS:SPEC:146; JMS:JAVADOC:122;
- *
- * @test_Strategy: Send messages to a Queue and receive them. Verify that the
- * order of received messages matches the order of messages sent through the
- * text of the sent messages.
- */
-
- public void messageOrderTest() throws Exception {
- int numMessages = 3;
- String text[] = new String[numMessages];
-
- try {
- for (int i = 0; i < numMessages; i++) {
- text[i] = "message order test " + i;
- beanRef.sendTextMessage_Q(testName + i, text[i]);
- }
-
- for (int i = 0; i < numMessages; i++) {
-
- if (!beanRef.getText().equals(text[i])) {
- logErr("Received message: ");
- throw new Exception("received wrong message");
- }
- }
-
- } catch (Exception e) {
- logErr("Caught Exception in test messageOrderTest: ", e);
- throw new Exception("messageOrderTest", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: nullDestinationTest
- *
- * @assertion_ids: JMS:SPEC:139; JMS:JAVADOC:188; JMS:JAVADOC:202;
- *
- * @test_Strategy: Create a QueueSender with null destination. Send a message
- * using the QueueSender specifying destination in send and verify receiving
- * the message
- */
- public void nullDestinationTest() throws Exception {
- String text = "JMS TCK test for null Destination";
- Queue testQueue = null;
-
- try {
- beanRef.sendTextMessage_Q(testName, text, testQueue);
-
- if (!beanRef.getText().equals(text)) {
- throw new Exception("received wrong message");
- }
-
- } catch (Exception e) {
- logErr("Caught Exception in test nullDestinationTest: ", e);
- throw new Exception("nullDestinationTest", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/queueCMTTests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/queueCMTTests/ClientIT.java
new file mode 100644
index 0000000000..ab0268435d
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/queueCMTTests/ClientIT.java
@@ -0,0 +1,1123 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.ejb.queueCMTTests;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.commonee.Tests;
+
+import jakarta.ejb.EJB;
+import jakarta.jms.DeliveryMode;
+import jakarta.jms.Queue;
+
+
+public class ClientIT {
+
+ private static final String testName = "com.sun.ts.tests.jms.ee.ejb.queueCMTTests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ @EJB(name = "ejb/QueueTests")
+ private static Tests beanRef;
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ if (beanRef == null) {
+ throw new Exception("@EJB injection failed");
+ }
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+
+ beanRef.initLogging(props);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /*
+ * cleanup() is called after each test
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ }
+
+ private void flushTheQueue() throws Exception {
+ JmsTool tool = null;
+ try {
+ tool = new JmsTool(JmsTool.QUEUE, user, password, mode);
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error creating JmsTool and closing Connection", e);
+ } finally {
+ try {
+ tool.flushQueue();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error flush : ", e);
+ }
+
+ try {
+ logger.log(Logger.Level.TRACE, "Closing default QueueConnection");
+ tool.getDefaultQueueConnection().close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error clsoing connection : ", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: bytesMessageFullMsgTests
+ *
+ * @assertion_ids: JMS:JAVADOC:560; JMS:JAVADOC:562; JMS:JAVADOC:564;
+ * JMS:JAVADOC:566; JMS:JAVADOC:568; JMS:JAVADOC:570; JMS:JAVADOC:572;
+ * JMS:JAVADOC:574; JMS:JAVADOC:576; JMS:JAVADOC:578; JMS:JAVADOC:580;
+ * JMS:JAVADOC:582; JMS:JAVADOC:534; JMS:JAVADOC:536; JMS:JAVADOC:540;
+ * JMS:JAVADOC:544; JMS:JAVADOC:546; JMS:JAVADOC:548; JMS:JAVADOC:550;
+ * JMS:JAVADOC:552; JMS:JAVADOC:554; JMS:JAVADOC:556; JMS:JAVADOC:558;
+ * JMS:JAVADOC:538; JMS:JAVADOC:542; JMS:JAVADOC:532;
+ *
+ * @test_Strategy: Write to a BytesMessage using each type of method. Verify the
+ * BytesMessage received.
+ */
+ @Test
+ public void bytesMessageFullMsgTests() throws Exception {
+
+ try {
+ beanRef.sendFullBytesMessage_Q(testName);
+
+ // Check to see if correct message received
+ if (!beanRef.verifyFullBytesMessage())
+ throw new Exception("didn't get the right message");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test bytesMessageFullMsgTests: ", e);
+ throw new Exception("bytesMessageFullMsgTests", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: mapMessageFullMsgTest
+ *
+ * @assertion_ids: JMS:SPEC:74; JMS:JAVADOC:211; JMS:JAVADOC:457;
+ * JMS:JAVADOC:459; JMS:JAVADOC:475; JMS:JAVADOC:477; JMS:JAVADOC:479;
+ * JMS:JAVADOC:461; JMS:JAVADOC:463; JMS:JAVADOC:465; JMS:JAVADOC:467;
+ * JMS:JAVADOC:469; JMS:JAVADOC:471; JMS:JAVADOC:473; JMS:JAVADOC:433;
+ * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:439; JMS:JAVADOC:441;
+ * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
+ * JMS:JAVADOC:451; JMS:JAVADOC:453;
+ *
+ * @test_Strategy: Write to a MapMessage using each type of method. Verify the
+ * MapMessage received.
+ */
+ @Test
+ public void mapMessageFullMsgTest() throws Exception {
+
+ try {
+ beanRef.sendFullMapMessage_Q(testName);
+
+ // Check to see if correct message received
+ if (!beanRef.verifyFullMapMessage())
+ throw new Exception("didn't get the right message");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test mapMessageFullMsgTest: ", e);
+ throw new Exception("mapMessageFullMsgTest", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: streamMessageFullMsgTest
+ *
+ * @assertion_ids: JMS:SPEC:82; JMS:JAVADOC:150; JMS:JAVADOC:152;
+ * JMS:JAVADOC:154; JMS:JAVADOC:156; JMS:JAVADOC:158; JMS:JAVADOC:160;
+ * JMS:JAVADOC:162; JMS:JAVADOC:164; JMS:JAVADOC:166; JMS:JAVADOC:168;
+ * JMS:JAVADOC:170; JMS:JAVADOC:172; JMS:JAVADOC:128; JMS:JAVADOC:130;
+ * JMS:JAVADOC:132; JMS:JAVADOC:134; JMS:JAVADOC:136; JMS:JAVADOC:138;
+ * JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
+ * JMS:JAVADOC:148;
+ *
+ * @test_Strategy: Write to a StreamMessage using each type of method. Verify
+ * the StreamMessage received.
+ */
+ @Test
+ public void streamMessageFullMsgTest() throws Exception {
+
+ try {
+ beanRef.sendFullStreamMessage_Q(testName);
+
+ // Check to see if correct message received
+ if (!beanRef.verifyFullStreamMessage())
+ throw new Exception("didn't get the right message");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test streamMessageFullMsgTest: ", e);
+ throw new Exception("streamMessageFullMsgTest", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: msgHdrIDTest
+ *
+ * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343;
+ *
+ * @test_Strategy: Send and receive single Text, map, bytes, stream, and object
+ * message call getJMSMessageID and verify that it starts with ID:
+ */
+ @Test
+ public void msgHdrIDTest() throws Exception {
+ String id = null;
+ boolean pass = true;
+
+ try {
+ beanRef.sendTextMessage_Q(testName);
+
+ // Get JMSMessageID
+ id = beanRef.getMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "TextMessage: JMSMessageID does not start with ID:" + id);
+ pass = false;
+ }
+
+ beanRef.sendFullBytesMessage_Q(testName);
+
+ // Get JMSMessageID
+ id = beanRef.getMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "BytesMessage: JMSMessageID does not start with ID:" + id);
+ pass = false;
+ }
+
+ beanRef.sendFullMapMessage_Q(testName);
+
+ // Get JMSMessageID
+ id = beanRef.getMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "MapMessage: JMSMessageID does not start with ID:" + id);
+ pass = false;
+ }
+
+ beanRef.sendFullStreamMessage_Q(testName);
+
+ // Get JMSMessageID
+ id = beanRef.getMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "StreamMessage: JMSMessageID does not start with ID:" + id);
+ pass = false;
+ }
+
+ beanRef.sendObjectMessage_Q(testName);
+
+ // Get JMSMessageID
+ id = beanRef.getMessageID();
+ if (!chkMessageID(id)) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage: JMSMessageID does not start with ID:" + id);
+ pass = false;
+ }
+
+ if (!pass)
+ throw new Exception("msgHdrIDTest failed with at least one type of JMS Message");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test msgHdrIDTest: ", e);
+ throw new Exception("msgHdrIDTest", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * helper method for JMSMessage Header Tests. verifies that the JMSMessageID
+ * starts with ID:
+ *
+ * @param String returned from getJMSMessageID
+ *
+ * @return boolean true if id correctly starts with ID:
+ */
+
+ private boolean chkMessageID(String id) {
+ boolean retcode = true;
+ int index = 0;
+
+ // message id must start with ID: - unless it is null
+ if (id == null) {
+ ;
+ } else if (id.startsWith("ID:")) {
+ ;
+ } else {
+ retcode = false;
+ }
+ return retcode;
+ }
+
+ /*
+ * @testName: msgHdrTimeStampTest
+ *
+ * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347;
+ *
+ * @test_Strategy: Send a Text, Map, Bytes, Stream, and Object messages. Check
+ * time of send against the time send returns. JMSTimeStamp should be between
+ * these two.
+ */
+ @Test
+ public void msgHdrTimeStampTest() throws Exception {
+ java.util.ArrayList sendValue = null;
+ boolean pass = true;
+ long timeBeforeSend;
+ long timeAfterSend;
+ long JMSTimestamp;
+
+ try {
+ sendValue = beanRef.sendTextMessage_Q(testName);
+
+ // Get JMSMessageTimestamp
+ JMSTimestamp = beanRef.getTimeStamp();
+ if (!(((Long) sendValue.get(0)).longValue() <= JMSTimestamp)
+ || !(((Long) sendValue.get(1)).longValue() >= JMSTimestamp)) {
+ logger.log(Logger.Level.ERROR, "TextMessage: JMSMessageTimestamp return wrong value:" + JMSTimestamp);
+ logger.log(Logger.Level.ERROR, "should be between time before send " + sendValue.get(0)
+ + " and time after send " + sendValue.get(1));
+ pass = false;
+ }
+
+ sendValue = beanRef.sendFullBytesMessage_Q(testName);
+
+ // Get JMSMessageTimestamp
+ JMSTimestamp = beanRef.getTimeStamp();
+ if (!(((Long) sendValue.get(0)).longValue() <= JMSTimestamp)
+ || !(((Long) sendValue.get(1)).longValue() >= JMSTimestamp)) {
+ logger.log(Logger.Level.ERROR, "BytesMessage: JMSMessageTimestamp return wrong value:" + JMSTimestamp);
+ logger.log(Logger.Level.ERROR, "should be between time before send " + sendValue.get(0)
+ + " and time after send " + sendValue.get(1));
+ pass = false;
+ }
+
+ sendValue = beanRef.sendFullMapMessage_Q(testName);
+
+ // Get JMSMessageTimestamp
+ JMSTimestamp = beanRef.getTimeStamp();
+ if (!(((Long) sendValue.get(0)).longValue() <= JMSTimestamp)
+ || !(((Long) sendValue.get(1)).longValue() >= JMSTimestamp)) {
+ logger.log(Logger.Level.ERROR, "MapMessage: JMSMessageTimestamp return wrong value:" + JMSTimestamp);
+ logger.log(Logger.Level.ERROR, "should be between time before send " + sendValue.get(0)
+ + " and time after send " + sendValue.get(1));
+ pass = false;
+ }
+
+ sendValue = beanRef.sendFullStreamMessage_Q(testName);
+
+ // Get JMSMessageTimestamp
+ JMSTimestamp = beanRef.getTimeStamp();
+ if (!(((Long) sendValue.get(0)).longValue() <= JMSTimestamp)
+ || !(((Long) sendValue.get(1)).longValue() >= JMSTimestamp)) {
+ logger.log(Logger.Level.ERROR,
+ "StreamMessage: JMSMessageTimestamp return wrong value: " + JMSTimestamp);
+ logger.log(Logger.Level.ERROR, "should be between time before send " + sendValue.get(0)
+ + " and time after send " + sendValue.get(1));
+ pass = false;
+ }
+
+ sendValue = beanRef.sendObjectMessage_Q(testName);
+
+ // Get JMSMessageTimestamp
+ JMSTimestamp = beanRef.getTimeStamp();
+ if (!(((Long) sendValue.get(0)).longValue() <= JMSTimestamp)
+ || !(((Long) sendValue.get(1)).longValue() >= JMSTimestamp)) {
+ logger.log(Logger.Level.ERROR,
+ "ObjectMessage: JMSMessageTimestamp return wrong value: " + JMSTimestamp);
+ logger.log(Logger.Level.ERROR, "should be between time before send " + sendValue.get(0)
+ + " and time after send " + sendValue.get(1));
+ pass = false;
+ }
+
+ if (!pass)
+ throw new Exception("msgHdrTimeStampTest failed with at least one type of JMS Message");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test msgHdrTimeStampTest: ", e);
+ throw new Exception("msgHdrTimeStampTest", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: msgHdrCorlIdTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ * @test_Strategy: Send a message to a Queue with CorrelationID set. Receive the
+ * msg and verify the correlationid is as set by client.
+ */
+ @Test
+ public void msgHdrCorlIdTest() throws Exception {
+ boolean pass = true;
+ String jmsCorrelationID = "JMSTCKCorrelationID";
+
+ try {
+ beanRef.sendTextMessage_Q(testName);
+
+ String tmp = beanRef.getCorrelationID();
+ if (!tmp.equals(jmsCorrelationID)) {
+ logger.log(Logger.Level.ERROR, "TextMessage: incorrect JMSCorrelationID returned: " + tmp);
+ pass = false;
+ }
+
+ beanRef.sendFullBytesMessage_Q(testName);
+
+ tmp = beanRef.getCorrelationID();
+ if (!tmp.equals(jmsCorrelationID)) {
+ logger.log(Logger.Level.ERROR, "BytesMessage: incorrect JMSCorrelationID returned: " + tmp);
+ pass = false;
+ }
+
+ beanRef.sendFullMapMessage_Q(testName);
+ tmp = beanRef.getCorrelationID();
+
+ if (!tmp.equals(jmsCorrelationID)) {
+ logger.log(Logger.Level.ERROR, "MapMessage: incorrect JMSCorrelationID returned:" + tmp);
+ pass = false;
+ }
+
+ beanRef.sendFullStreamMessage_Q(testName);
+ tmp = beanRef.getCorrelationID();
+
+ if (!tmp.equals(jmsCorrelationID)) {
+ logger.log(Logger.Level.ERROR, "StreamMessage: incorrect JMSCorrelationID returned:" + tmp);
+ pass = false;
+ }
+
+ beanRef.sendObjectMessage_Q(testName);
+ tmp = beanRef.getCorrelationID();
+
+ if (!tmp.equals(jmsCorrelationID)) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage: incorrect JMSCorrelationID returned:" + tmp);
+ pass = false;
+ }
+
+ if (!pass)
+ throw new Exception("msgHdrCorlIdTest failed with at least one type of JMS Message");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test msgHdrCorlIdTest: ", e);
+ throw new Exception("msgHdrCorlIdTest", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: msgHdrReplyToTest
+ *
+ * @assertion_ids: JMS:SPEC:12; JMS:JAVADOC:359; JMS:JAVADOC:361;
+ * JMS:JAVADOC:286; JMS:JAVADOC:289; JMS:JAVADOC:562; JMS:JAVADOC:166;
+ * JMS:SPEC:246.8;
+ *
+ * @test_Strategy: Send a message to a Queue with ReplyTo set to null. Send a
+ * message to a Queue with ReplyTo set to a destination. Test with Text, Map,
+ * Object, Bytes, and Stream messages. Verify on receive that in both cases
+ * ReplyTo is as set by Client.
+ */
+ @Test
+ public void msgHdrReplyToTest() throws Exception {
+ boolean pass = true;
+ String QueueName = null;
+ String QueueName_used = null;
+
+ try {
+ beanRef.sendTextMessage_Q(testName);
+ QueueName = beanRef.getReplyTo();
+
+ if (QueueName != null) {
+ logger.log(Logger.Level.ERROR, "TextMessage: null JMSReplyTo should be returned");
+ pass = false;
+ }
+
+ beanRef.sendTextMessage_Q(testName, true);
+ QueueName = beanRef.getReplyTo();
+ QueueName_used = beanRef.getDestination_1();
+
+ if (!QueueName.equals(QueueName_used)) {
+ logger.log(Logger.Level.ERROR, "TextMessage: incorrect JMSReplyTo returned: " + QueueName);
+ logger.log(Logger.Level.ERROR, "TextMessage: expecting: " + QueueName_used);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "TextMessage: passed");
+ }
+
+ beanRef.sendFullBytesMessage_Q(testName);
+ QueueName = beanRef.getReplyTo();
+
+ if (QueueName != null) {
+ logger.log(Logger.Level.ERROR, "BytesMessage: null JMSReplyTo should be returned");
+ pass = false;
+ }
+
+ beanRef.sendBytesMessage_Q(testName, true);
+ QueueName = beanRef.getReplyTo();
+
+ if (!QueueName.equals(QueueName_used)) {
+ logger.log(Logger.Level.ERROR, "BytesMessage: incorrect JMSReplyTo returned:" + QueueName);
+ logger.log(Logger.Level.ERROR, "BytesMessage: expecting: " + QueueName_used);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "BytesMessage: passed");
+ }
+
+ beanRef.sendFullMapMessage_Q(testName);
+ QueueName = beanRef.getReplyTo();
+
+ if (QueueName != null) {
+ logger.log(Logger.Level.ERROR, "MapMessage: null JMSReplyTo should be returned:" + QueueName);
+ pass = false;
+ }
+
+ beanRef.sendMapMessage_Q(testName, true);
+ QueueName = beanRef.getReplyTo();
+
+ if (!QueueName.equals(QueueName_used)) {
+ logger.log(Logger.Level.ERROR, "MapMessage: incorrect JMSReplyTo returned: " + QueueName);
+ logger.log(Logger.Level.ERROR, "MapMessage: expecting: " + QueueName_used);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "MapMessage: passed");
+ }
+
+ beanRef.sendFullStreamMessage_Q(testName);
+ QueueName = beanRef.getReplyTo();
+
+ if (QueueName != null) {
+ logger.log(Logger.Level.ERROR, "StreamMessage: null JMSReplyTo should be returned: " + QueueName);
+ pass = false;
+ }
+
+ beanRef.sendStreamMessage_Q(testName, true);
+ QueueName = beanRef.getReplyTo();
+
+ if (!QueueName.equals(QueueName_used)) {
+ logger.log(Logger.Level.ERROR, "StreamMessage: incorrect JMSReplyTo returned: " + QueueName);
+ logger.log(Logger.Level.ERROR, "StreamMessage: expecting: " + QueueName_used);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "StreamMessage: passed");
+ }
+
+ beanRef.sendObjectMessage_Q(testName);
+ QueueName = beanRef.getReplyTo();
+
+ if (QueueName != null) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage: null JMSReplyTo should be returned" + QueueName);
+ pass = false;
+ }
+
+ beanRef.sendObjectMessage_Q(testName, true);
+ QueueName = beanRef.getReplyTo();
+
+ if (!QueueName.equals(QueueName_used)) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage: incorrect JMSReplyTo returned: " + QueueName);
+ logger.log(Logger.Level.ERROR, "ObjectMessage: expecting: " + QueueName_used);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "ObjectMessage: passed");
+ }
+
+ if (!pass)
+ throw new Exception("msgHdrReplyToTest failed with at least one type of JMS Message");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test msgHdrReplyToTest: ", e);
+ throw new Exception("msgHdrReplyToTest", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSTypeTest
+ *
+ * @assertion_ids: JMS:SPEC:246.9; JMS:JAVADOC:375; JMS:JAVADOC:377;
+ *
+ * @test_Strategy: Send a message to a Queue with JMSType set to TESTMSG. Test
+ * with Text, Map, Object, Bytes, and Stream messages. Verify on receive.
+ */
+ @Test
+ public void msgHdrJMSTypeTest() throws Exception {
+ boolean pass = true;
+ String type = "JMSTCKTESTMSG";
+
+ try {
+ beanRef.sendTextMessage_Q(testName);
+
+ if (!beanRef.getType().equals(type)) {
+ logger.log(Logger.Level.ERROR, "TextMessage: wrong JMSType returned: " + beanRef.getType());
+ pass = false;
+ }
+
+ beanRef.sendFullBytesMessage_Q(testName);
+
+ if (!beanRef.getType().equals(type)) {
+ logger.log(Logger.Level.ERROR, "BytesMessage: wrong JMSType returned");
+ pass = false;
+ }
+
+ beanRef.sendFullMapMessage_Q(testName);
+
+ if (!beanRef.getType().equals(type)) {
+ logger.log(Logger.Level.ERROR, "MapMessage: wrong JMSType returned");
+ pass = false;
+ }
+
+ beanRef.sendFullStreamMessage_Q(testName);
+
+ if (!beanRef.getType().equals(type)) {
+ logger.log(Logger.Level.ERROR, "StreamMessage: wrong JMSType returned" + beanRef.getType());
+ pass = false;
+ }
+
+ beanRef.sendObjectMessage_Q(testName);
+
+ if (!beanRef.getType().equals(type)) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage: wrong JMSType returned" + beanRef.getType());
+ pass = false;
+ }
+
+ if (!pass)
+ throw new Exception("msgHdrJMSTypeTest failed with at least one type of JMS Message");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test msgHdrJMSTypeTest: ", e);
+ throw new Exception("msgHdrJMSTypeTest", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSPriorityTest
+ *
+ * @assertion_ids: JMS:SPEC:16; JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140;
+ * JMS:JAVADOC:305; JMS:JAVADOC:383;
+ *
+ * @test_Strategy: Send a message to a Queue with JMSPriority set to 2. Test
+ * with Text, Map, Object, Bytes, and Stream messages. Verify JMSPriority value
+ * on receive.
+ */
+ @Test
+ public void msgHdrJMSPriorityTest() throws Exception {
+ boolean pass = true;
+ int priority = 2;
+
+ try {
+ beanRef.sendTextMessage_Q(testName);
+
+ if (beanRef.getPriority() != priority) {
+ logger.log(Logger.Level.ERROR, "TextMessage: wrong JMSPriority returned: " + beanRef.getPriority());
+ pass = false;
+ }
+
+ beanRef.sendFullBytesMessage_Q(testName);
+
+ if (beanRef.getPriority() != priority) {
+ logger.log(Logger.Level.ERROR, "BytesMessage: wrong JMSPriority returned: " + beanRef.getPriority());
+ pass = false;
+ }
+
+ beanRef.sendFullMapMessage_Q(testName);
+
+ if (beanRef.getPriority() != priority) {
+ logger.log(Logger.Level.ERROR, "MapMessage: wrong JMSPriority returned: " + beanRef.getPriority());
+ pass = false;
+ }
+
+ beanRef.sendFullStreamMessage_Q(testName);
+
+ if (beanRef.getPriority() != priority) {
+ logger.log(Logger.Level.ERROR, "StreamMessage: wrong JMSPriority returned: " + beanRef.getPriority());
+ pass = false;
+ }
+
+ beanRef.sendObjectMessage_Q(testName);
+
+ if (beanRef.getPriority() != priority) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage: wrong JMSPriority returned: " + beanRef.getPriority());
+ pass = false;
+ }
+
+ if (!pass)
+ throw new Exception("msgHdrJMSPriorityTest failed with at least one type of JMS Message");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test msgHdrJMSPriorityTest: ", e);
+ throw new Exception("msgHdrJMSPriorityTest", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSExpirationTest
+ *
+ * @assertion_ids: JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140; JMS:JAVADOC:309;
+ * JMS:JAVADOC:379;
+ *
+ * @test_Strategy: Send a message to a Queue with time to live set to 0. Test
+ * with Text, Map, Object, Bytes, and Stream messages.
+ */
+ @Test
+ public void msgHdrJMSExpirationTest() throws Exception {
+ boolean pass = true;
+ long forever = 0;
+
+ try {
+ beanRef.sendTextMessage_Q(testName);
+
+ if (beanRef.getExpiration() != forever) {
+ logger.log(Logger.Level.ERROR, "TextMessage: wrong JMSExpiration returned: " + beanRef.getExpiration());
+ pass = false;
+ }
+
+ beanRef.sendFullBytesMessage_Q(testName);
+
+ if (beanRef.getExpiration() != forever) {
+ logger.log(Logger.Level.ERROR,
+ "BytesMessage: wrong JMSExpiration returned: " + beanRef.getExpiration());
+ pass = false;
+ }
+
+ beanRef.sendFullMapMessage_Q(testName);
+
+ if (beanRef.getExpiration() != forever) {
+ logger.log(Logger.Level.ERROR, "MapMessage: wrong JMSExpiration returned: " + beanRef.getExpiration());
+ pass = false;
+ }
+
+ beanRef.sendFullStreamMessage_Q(testName);
+
+ if (beanRef.getExpiration() != forever) {
+ logger.log(Logger.Level.ERROR,
+ "StreamMessage: wrong JMSExpiration returned: " + beanRef.getExpiration());
+ pass = false;
+ }
+
+ beanRef.sendObjectMessage_Q(testName);
+
+ if (beanRef.getExpiration() != forever) {
+ logger.log(Logger.Level.ERROR,
+ "ObjectMessage: wrong JMSExpiration returned: " + beanRef.getExpiration());
+ pass = false;
+ }
+
+ if (!pass)
+ throw new Exception("msgHdrJMSExpirationTest failed with at least one type of JMS Message");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test msgHdrJMSExpirationTest: ", e);
+ throw new Exception("msgHdrJMSExpirationTest");
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSDestinationTest
+ *
+ * @assertion_ids: JMS:SPEC:2; JMS:JAVADOC:363; JMS:JAVADOC:286;
+ *
+ * @test_Strategy: Create and send a message to a Queue. Verify on receive that
+ * JMSDestination is set to the Queue. Test with Text, Map, Object, Bytes, and
+ * Stream messages.
+ */
+ @Test
+ public void msgHdrJMSDestinationTest() throws Exception {
+ boolean pass = true;
+ long forever = 0;
+ String dest = null;
+ String dest_used = null;
+
+ try {
+ beanRef.sendTextMessage_Q(testName);
+ dest = beanRef.getDestination();
+ dest_used = beanRef.getDestination_1();
+
+ if (!dest.equals(dest_used)) {
+ logger.log(Logger.Level.ERROR, "TextMessage: wrong JMSDestination returned: " + dest);
+ logger.log(Logger.Level.ERROR, "Expecting " + dest_used);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "TextMessage: msgHdrJMSDestinationTest passed.");
+ }
+
+ beanRef.sendFullBytesMessage_Q(testName);
+
+ if (!(beanRef.getDestination()).equals(dest_used)) {
+ logger.log(Logger.Level.ERROR, "BytesMessage: wrong JMSDestination returned: " + dest);
+ logger.log(Logger.Level.ERROR, "Expecting " + dest_used);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "BytesMessage: msgHdrJMSDestinationTest passed.");
+ }
+
+ beanRef.sendFullMapMessage_Q(testName);
+
+ if (!(beanRef.getDestination()).equals(dest_used)) {
+ logger.log(Logger.Level.ERROR, "MapMessage: wrong JMSDestination returned: " + dest);
+ logger.log(Logger.Level.ERROR, "Expecting " + dest_used);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "MapMessage: msgHdrJMSDestinationTest passed.");
+ }
+
+ beanRef.sendFullStreamMessage_Q(testName);
+
+ if (!(beanRef.getDestination()).equals(dest_used)) {
+ logger.log(Logger.Level.ERROR, "StreamMessage: wrong JMSDestination returned: " + dest);
+ logger.log(Logger.Level.ERROR, "Expecting " + dest_used);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "StreamMessage: msgHdrJMSDestinationTest passed.");
+ }
+
+ beanRef.sendObjectMessage_Q(testName);
+
+ if (!(beanRef.getDestination()).equals(dest_used)) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage: wrong JMSDestination returned: " + dest);
+ logger.log(Logger.Level.ERROR, "Expecting " + dest_used);
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "ObjectMessage: msgHdrJMSDestinationTest passed.");
+ }
+
+ if (!pass)
+ throw new Exception("msgHdrJMSDestinationTest failed with at least one type of JMS Message");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test msgHdrJMSDestinationTest: ", e);
+ throw new Exception("msgHdrJMSDestinationTest", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: msgHdrJMSDeliveryModeTest
+ *
+ * @assertion_ids: JMS:SPEC:3; JMS:SPEC:140; JMS:JAVADOC:367; JMS:SPEC:246.2;
+ * JMS:JAVADOC:301;
+ *
+ * @test_Strategy: Create and send a message to a Queue. Verify on receive that
+ * JMSDeliveryMode is set as the default delivery mode of persistent. Create
+ * another message with a nonpersistent delivery mode. Test with Text, Map,
+ * Object, Bytes, and Stream messages.
+ */
+ @Test
+ public void msgHdrJMSDeliveryModeTest() throws Exception {
+ boolean pass = true;
+ long forever = 0;
+
+ try {
+ beanRef.sendTextMessage_Q(testName);
+
+ if (beanRef.getDeliveryMode() != DeliveryMode.PERSISTENT) {
+ logger.log(Logger.Level.ERROR,
+ "TextMessage: wrong DeliveryMode returned: " + beanRef.getDeliveryMode());
+ pass = false;
+ }
+
+ beanRef.sendTextMessage_Q(testName, false, DeliveryMode.NON_PERSISTENT);
+
+ if (beanRef.getDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ logger.log(Logger.Level.ERROR,
+ "TextMessage: wrong DeliveryMode returned: " + beanRef.getDeliveryMode());
+ pass = false;
+ }
+
+ beanRef.sendFullBytesMessage_Q(testName);
+
+ if (beanRef.getDeliveryMode() != DeliveryMode.PERSISTENT) {
+ logger.log(Logger.Level.ERROR, "BytesMessage: wrong DeliveryMode returned: ");
+ pass = false;
+ }
+
+ beanRef.sendBytesMessage_Q(testName, false, DeliveryMode.NON_PERSISTENT);
+
+ if (beanRef.getDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ logger.log(Logger.Level.ERROR, "BytesMessage: wrong DeliveryMode returned: ");
+ pass = false;
+ }
+
+ beanRef.sendFullMapMessage_Q(testName);
+
+ if (beanRef.getDeliveryMode() != DeliveryMode.PERSISTENT) {
+ logger.log(Logger.Level.ERROR, "MapMessage: wrong DeliveryMode returned: ");
+ pass = false;
+ }
+
+ beanRef.sendMapMessage_Q(testName, false, DeliveryMode.NON_PERSISTENT);
+
+ if (beanRef.getDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ logger.log(Logger.Level.ERROR, "MapMessage: wrong DeliveryMode returned: ");
+ pass = false;
+ }
+
+ beanRef.sendFullStreamMessage_Q(testName);
+
+ if (beanRef.getDeliveryMode() != DeliveryMode.PERSISTENT) {
+ logger.log(Logger.Level.ERROR, "StreamMessage: wrong DeliveryMode returned: ");
+ pass = false;
+ }
+
+ beanRef.sendStreamMessage_Q(testName, false, DeliveryMode.NON_PERSISTENT);
+
+ if (beanRef.getDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ logger.log(Logger.Level.ERROR, "StreamMessage: wrong DeliveryMode returned: ");
+ pass = false;
+ }
+
+ beanRef.sendObjectMessage_Q(testName);
+
+ if (beanRef.getDeliveryMode() != DeliveryMode.PERSISTENT) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage: wrong DeliveryMode returned: ");
+ pass = false;
+ }
+
+ beanRef.sendObjectMessage_Q(testName, false, DeliveryMode.NON_PERSISTENT);
+
+ if (beanRef.getDeliveryMode() != DeliveryMode.NON_PERSISTENT) {
+ logger.log(Logger.Level.ERROR, "ObjectMessage: wrong DeliveryMode returned: ");
+ pass = false;
+ }
+
+ if (!pass)
+ throw new Exception("msgHdrJMSDeliveryModeTest failed with at least one type of JMS Message");
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test msgHdrJMSDeliveryModeTest: ", e);
+ throw new Exception("msgHdrJMSDeliveryModeTest", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: messageOrderTest
+ *
+ * @assertion_ids: JMS:SPEC:146; JMS:JAVADOC:122;
+ *
+ * @test_Strategy: Send messages to a Queue and receive them. Verify that the
+ * order of received messages matches the order of messages sent through the
+ * text of the sent messages.
+ */
+ @Test
+ public void messageOrderTest() throws Exception {
+ int numMessages = 3;
+ String text[] = new String[numMessages];
+
+ try {
+ for (int i = 0; i < numMessages; i++) {
+ text[i] = "message order test " + i;
+ beanRef.sendTextMessage_Q(testName + i, text[i]);
+ }
+
+ for (int i = 0; i < numMessages; i++) {
+
+ if (!beanRef.getText().equals(text[i])) {
+ logger.log(Logger.Level.ERROR, "Received message: ");
+ throw new Exception("received wrong message");
+ }
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test messageOrderTest: ", e);
+ throw new Exception("messageOrderTest", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: nullDestinationTest
+ *
+ * @assertion_ids: JMS:SPEC:139; JMS:JAVADOC:188; JMS:JAVADOC:202;
+ *
+ * @test_Strategy: Create a QueueSender with null destination. Send a message
+ * using the QueueSender specifying destination in send and verify receiving the
+ * message
+ */
+ @Test
+ public void nullDestinationTest() throws Exception {
+ String text = "JMS TCK test for null Destination";
+ Queue testQueue = null;
+
+ try {
+ beanRef.sendTextMessage_Q(testName, text, testQueue);
+
+ if (!beanRef.getText().equals(text)) {
+ throw new Exception("received wrong message");
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught Exception in test nullDestinationTest: ", e);
+ throw new Exception("nullDestinationTest", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/sessionQtests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/sessionQtests/Client.java
deleted file mode 100644
index 8e88fd7a5d..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/sessionQtests/Client.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * @(#)Client.java 1.8 03/05/16
- */
-package com.sun.ts.tests.jms.ee.ejb.sessionQtests;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsTool;
-import com.sun.ts.tests.jms.commonee.Tests;
-
-import jakarta.ejb.EJB;
-
-public class Client extends EETest {
-
- private static final String testName = "com.sun.ts.tests.jms.ee.ejb.sessionQtests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- @EJB(name = "ejb/SessionTestsQ")
- private static Tests beanRef;
-
- /* Run test in standalone mode */
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. Tests that require
- * multiple Destinations create the extras within the test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- if (beanRef == null) {
- throw new Exception("@EJB injection failed");
- }
-
- props = p;
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
-
- beanRef.initLogging(props);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /*
- * cleanup() is called after each test
- */
- public void cleanup() throws Exception {
- }
-
- private void flushTheQueue() throws Exception {
- JmsTool tool = null;
- try {
- tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
-
- TestUtil.logTrace("Closing default Connection");
- tool.getDefaultConnection().close();
-
- } catch (Exception e) {
- TestUtil.logErr("Error creating JmsTool and closing Connection", e);
- } finally {
- try {
- tool.flushDestination();
- } catch (Exception e) {
- TestUtil.logErr("Error flush Destination: ", e);
- }
- }
- }
-
- /*
- * @testName: simpleSendReceiveQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:334; JMS:JAVADOC:122; JMS:JAVADOC:504;
- * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
- * JMS:JAVADOC:317;
- *
- * @test_Strategy: Create a Text Message, send use a MessageProducer and
- * receive it use a MessageConsumer via a Queue
- */
- public void simpleSendReceiveQueueTest() throws Exception {
- String testMessage = "Just a test";
- String messageReceived = null;
-
- try {
-
- beanRef.sendTextMessage_CQ(testName, testMessage);
- messageReceived = beanRef.receiveTextMessage_CQ();
-
- // Check to see if correct message received
- if (messageReceived != null) {
- if (messageReceived.equals(testMessage)) {
- logMsg("Message text: \"" + messageReceived + "\"");
- logMsg("Received correct message");
- } else {
- throw new Exception("didn't get the right message");
- }
- } else {
- throw new Exception("didn't get any message");
- }
- } catch (Exception e) {
- logErr("simpleSendReceiveQueueTest failed: ", e);
- throw new Exception("simpleSendReceiveQueueTest failed !", e);
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-
- /*
- * @testName: selectorAndBrowserTests
- *
- * @assertion_ids: JMS:JAVADOC:502; JMS:JAVADOC:504; JMS:JAVADOC:510;
- * JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:246; JMS:JAVADOC:317;
- * JMS:JAVADOC:334; JMS:JAVADOC:258; JMS:JAVADOC:260; JMS:JAVADOC:338;
- * JMS:JAVADOC:221; JMS:SPEC:148; JMS:SPEC:149; JMS:JAVADOC:278;
- * JMS:JAVADOC:280; JMS:JAVADOC:282; JMS:JAVADOC:284; JMS:JAVADOC:288;
- *
- * @test_Strategy: 1. Create two TextMessages, send use a MessageProducer 2.
- * Create a QueueBrowser to browse the Queue so that all two messages can be
- * seen. 3. Use the QueueBrowser to test getQueue 4. Create a QueueBrowser
- * with selector to browse the Queue so that only one message can be seen; 5.
- * Use the above QueueBrowser to test getMessageSelector 6. Create a
- * MessageConsumer with a message selector so that only last message received.
- * 7. Then create another MessageConsumer to verify all messages except the
- * last message can be received from the Queue.
- */
-
- public void selectorAndBrowserTests() throws Exception {
- String testMessage = "Just a test: selectorAndBrowserTests";
- boolean pass = true;
- String messageReceived = null;
-
- try {
-
- beanRef.sendMessageP_CQ(testName, testMessage, false);
- beanRef.sendMessagePP_CQ(testName, testMessage, true, "TEST", "test");
-
- int msgNum = beanRef.browseTextMessage_CQ(2, testMessage);
- TestUtil.logTrace("Default browser found " + msgNum + " messages");
-
- if (!beanRef.getQueue()) {
- TestUtil.logErr("Error: QueueBrowser.getQueue test failed");
- pass = false;
- }
-
- msgNum = beanRef.browseMessageS_CQ(1, testMessage, "TEST = 'test'");
- TestUtil.logTrace("Selective browser find " + msgNum + " messages");
-
- if (!beanRef.getSelector("TEST = 'test'")) {
- TestUtil.logErr("Error: QueueBrowser.getMessageSelector test failed");
- pass = false;
- }
-
- if (pass != true)
- throw new Exception("selectorAndBrowserTests Failed!");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("selectorAndBrowserTests");
- } finally {
- try {
- flushTheQueue();
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/sessionQtests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/sessionQtests/ClientIT.java
new file mode 100644
index 0000000000..08c1ca288d
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/sessionQtests/ClientIT.java
@@ -0,0 +1,238 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * @(#)Client.java 1.8 03/05/16
+ */
+package com.sun.ts.tests.jms.ee.ejb.sessionQtests;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsTool;
+import com.sun.ts.tests.jms.commonee.Tests;
+
+import jakarta.ejb.EJB;
+
+
+public class ClientIT {
+
+ private static final String testName = "com.sun.ts.tests.jms.ee.ejb.sessionQtests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ @EJB(name = "ejb/SessionTestsQ")
+ private static Tests beanRef;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. Tests that require
+ * multiple Destinations create the extras within the test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ if (beanRef == null) {
+ throw new Exception("@EJB injection failed");
+ }
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+
+ beanRef.initLogging(props);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /*
+ * cleanup() is called after each test
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ }
+
+ private void flushTheQueue() throws Exception {
+ JmsTool tool = null;
+ try {
+ tool = new JmsTool(JmsTool.COMMON_Q, user, password, mode);
+
+ logger.log(Logger.Level.TRACE, "Closing default Connection");
+ tool.getDefaultConnection().close();
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error creating JmsTool and closing Connection", e);
+ } finally {
+ try {
+ tool.flushDestination();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error flush Destination: ", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: simpleSendReceiveQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:334; JMS:JAVADOC:122; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
+ * JMS:JAVADOC:317;
+ *
+ * @test_Strategy: Create a Text Message, send use a MessageProducer and receive
+ * it use a MessageConsumer via a Queue
+ */
+ @Test
+ public void simpleSendReceiveQueueTest() throws Exception {
+ String testMessage = "Just a test";
+ String messageReceived = null;
+
+ try {
+
+ beanRef.sendTextMessage_CQ(testName, testMessage);
+ messageReceived = beanRef.receiveTextMessage_CQ();
+
+ // Check to see if correct message received
+ if (messageReceived != null) {
+ if (messageReceived.equals(testMessage)) {
+ logger.log(Logger.Level.INFO, "Message text: \"" + messageReceived + "\"");
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ throw new Exception("didn't get the right message");
+ }
+ } else {
+ throw new Exception("didn't get any message");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "simpleSendReceiveQueueTest failed: ", e);
+ throw new Exception("simpleSendReceiveQueueTest failed !", e);
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+
+ /*
+ * @testName: selectorAndBrowserTests
+ *
+ * @assertion_ids: JMS:JAVADOC:502; JMS:JAVADOC:504; JMS:JAVADOC:510;
+ * JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:246; JMS:JAVADOC:317;
+ * JMS:JAVADOC:334; JMS:JAVADOC:258; JMS:JAVADOC:260; JMS:JAVADOC:338;
+ * JMS:JAVADOC:221; JMS:SPEC:148; JMS:SPEC:149; JMS:JAVADOC:278;
+ * JMS:JAVADOC:280; JMS:JAVADOC:282; JMS:JAVADOC:284; JMS:JAVADOC:288;
+ *
+ * @test_Strategy: 1. Create two TextMessages, send use a MessageProducer 2.
+ * Create a QueueBrowser to browse the Queue so that all two messages can be
+ * seen. 3. Use the QueueBrowser to test getQueue 4. Create a QueueBrowser with
+ * selector to browse the Queue so that only one message can be seen; 5. Use the
+ * above QueueBrowser to test getMessageSelector 6. Create a MessageConsumer
+ * with a message selector so that only last message received. 7. Then create
+ * another MessageConsumer to verify all messages except the last message can be
+ * received from the Queue.
+ */
+ @Test
+ public void selectorAndBrowserTests() throws Exception {
+ String testMessage = "Just a test: selectorAndBrowserTests";
+ boolean pass = true;
+ String messageReceived = null;
+
+ try {
+
+ beanRef.sendMessageP_CQ(testName, testMessage, false);
+ beanRef.sendMessagePP_CQ(testName, testMessage, true, "TEST", "test");
+
+ int msgNum = beanRef.browseTextMessage_CQ(2, testMessage);
+ logger.log(Logger.Level.TRACE, "Default browser found " + msgNum + " messages");
+
+ if (!beanRef.getQueue()) {
+ logger.log(Logger.Level.ERROR, "Error: QueueBrowser.getQueue test failed");
+ pass = false;
+ }
+
+ msgNum = beanRef.browseMessageS_CQ(1, testMessage, "TEST = 'test'");
+ logger.log(Logger.Level.TRACE, "Selective browser find " + msgNum + " messages");
+
+ if (!beanRef.getSelector("TEST = 'test'")) {
+ logger.log(Logger.Level.ERROR, "Error: QueueBrowser.getMessageSelector test failed");
+ pass = false;
+ }
+
+ if (pass != true)
+ throw new Exception("selectorAndBrowserTests Failed!");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("selectorAndBrowserTests");
+ } finally {
+ try {
+ flushTheQueue();
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/sessionTtests/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/sessionTtests/Client.java
deleted file mode 100644
index 9145cc7bb2..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/sessionTtests/Client.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.ejb.sessionTtests;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.TestsT;
-
-import jakarta.annotation.Resource;
-import jakarta.ejb.EJB;
-import jakarta.jms.Connection;
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.Session;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicSubscriber;
-
-public class Client extends EETest {
-
- private static final String testName = "com.sun.ts.tests.jms.ee.ejb.sessionTtests.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- private transient Connection connr = null;
-
- @Resource(name = "jms/DURABLE_SUB_CONNECTION_FACTORY")
- private static ConnectionFactory cf;
-
- @Resource(name = "jms/MY_TOPIC")
- // private static Destination testDestination;
- private static Topic testDestination;
-
- private String name = "ctssub";
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- @EJB(name = "ejb/SessionTestsT")
- private static TestsT beanRef;
-
- /* Run test in standalone mode */
-
- public static void main(String[] args) {
- Client theTestsT = new Client();
- Status s = theTestsT.run(args, System.out, System.err);
-
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Creates Administrator object and deletes all previous Destinations.
- * Individual tests create the JmsTool object with one default Queue and/or
- * Topic Connection, as well as a default Queue and Topic. TestsT that require
- * multiple Destinations create the extras within the test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
-
- if (beanRef == null) {
- throw new Exception("@EJB injection failed");
- }
-
- if (cf == null || testDestination == null) {
- throw new Exception("@Resource injection failed");
- }
-
- props = p;
-
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
-
- beanRef.initLogging(props);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /*
- * cleanup() is called after each test
- */
- public void cleanup() throws Exception {
- }
-
- /*
- * @testName: simpleSendReceiveT
- *
- * @assertion_ids: JMS:JAVADOC:504; JMS:JAVADOC:510; JMS:JAVADOC:242;
- * JMS:JAVADOC:244; JMS:JAVADOC:317; JMS:JAVADOC:334; JMS:JAVADOC:221;
- *
- * @test_Strategy: Create a Text Message, send use a MessageProducer and
- * receive it use a MessageConsumer via a Topic
- */
- public void simpleSendReceiveT() throws Exception {
- String testMessage = "Just a test from simpleSendReceiveT";
- String messageReceived = null;
-
- try {
- connr = cf.createConnection(user, password);
- if (connr.getClientID() == null)
- connr.setClientID("cts");
-
- Session sessr = connr.createSession(true, Session.AUTO_ACKNOWLEDGE);
- TopicSubscriber recr = sessr.createDurableSubscriber(testDestination,
- name);
-
- try {
- recr.close();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception closing topic subscriber: ", e);
- }
- try {
- connr.close();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception closing connection: ", e);
- }
-
- beanRef.sendTextMessage_CT(testName, testMessage);
- messageReceived = beanRef.receiveTextMessage_CT();
-
- // Check to see if correct message received
- if (messageReceived == null) {
- throw new Exception("Null message received!");
- } else if (!messageReceived.equals(testMessage)) {
- throw new Exception("EJB didn't get the right message");
- } else {
- TestUtil.logMsg("Correct Message received");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("simpleSendReceiveT");
- } finally {
- try {
- connr = cf.createConnection(user, password);
-
- Session sessr = connr.createSession(true, Session.AUTO_ACKNOWLEDGE);
-
- try {
- sessr.unsubscribe(name);
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception unsubscribing: ", e);
- }
-
- try {
- connr.close();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception closing connection: ", e);
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception creating Connection: ", e);
- }
-
- try {
- if (null != beanRef)
- beanRef.remove();
- } catch (Exception e) {
- TestUtil.logErr("[Client] Ignoring Exception on " + "bean remove", e);
- }
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/sessionTtests/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/sessionTtests/ClientIT.java
new file mode 100644
index 0000000000..607879a10a
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/ejb/sessionTtests/ClientIT.java
@@ -0,0 +1,214 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.ejb.sessionTtests;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.commonee.TestsT;
+
+import jakarta.annotation.Resource;
+import jakarta.ejb.EJB;
+import jakarta.jms.Connection;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.Session;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicSubscriber;
+
+
+public class ClientIT {
+
+ private static final String testName = "com.sun.ts.tests.jms.ee.ejb.sessionTtests.ClientIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ private transient Connection connr = null;
+
+ @Resource(name = "jms/DURABLE_SUB_CONNECTION_FACTORY")
+ private static ConnectionFactory cf;
+
+ @Resource(name = "jms/MY_TOPIC")
+ // private static Destination testDestination;
+ private static Topic testDestination;
+
+ private String name = "ctssub";
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ @EJB(name = "ejb/SessionTestsT")
+ private static TestsT beanRef;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Creates Administrator object and deletes all previous Destinations.
+ * Individual tests create the JmsTool object with one default Queue and/or
+ * Topic Connection, as well as a default Queue and Topic. TestsT that require
+ * multiple Destinations create the extras within the test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ if (beanRef == null) {
+ throw new Exception("@EJB injection failed");
+ }
+
+ if (cf == null || testDestination == null) {
+ throw new Exception("@Resource injection failed");
+ }
+
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+
+ beanRef.initLogging(props);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /*
+ * cleanup() is called after each test
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ }
+
+ /*
+ * @testName: simpleSendReceiveT
+ *
+ * @assertion_ids: JMS:JAVADOC:504; JMS:JAVADOC:510; JMS:JAVADOC:242;
+ * JMS:JAVADOC:244; JMS:JAVADOC:317; JMS:JAVADOC:334; JMS:JAVADOC:221;
+ *
+ * @test_Strategy: Create a Text Message, send use a MessageProducer and receive
+ * it use a MessageConsumer via a Topic
+ */
+ @Test
+ public void simpleSendReceiveT() throws Exception {
+ String testMessage = "Just a test from simpleSendReceiveT";
+ String messageReceived = null;
+
+ try {
+ connr = cf.createConnection(user, password);
+ if (connr.getClientID() == null)
+ connr.setClientID("cts");
+
+ Session sessr = connr.createSession(true, Session.AUTO_ACKNOWLEDGE);
+ TopicSubscriber recr = sessr.createDurableSubscriber(testDestination, name);
+
+ try {
+ recr.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception closing topic subscriber: ", e);
+ }
+ try {
+ connr.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception closing connection: ", e);
+ }
+
+ beanRef.sendTextMessage_CT(testName, testMessage);
+ messageReceived = beanRef.receiveTextMessage_CT();
+
+ // Check to see if correct message received
+ if (messageReceived == null) {
+ throw new Exception("Null message received!");
+ } else if (!messageReceived.equals(testMessage)) {
+ throw new Exception("EJB didn't get the right message");
+ } else {
+ logger.log(Logger.Level.INFO, "Correct Message received");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("simpleSendReceiveT");
+ } finally {
+ try {
+ connr = cf.createConnection(user, password);
+
+ Session sessr = connr.createSession(true, Session.AUTO_ACKNOWLEDGE);
+
+ try {
+ sessr.unsubscribe(name);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception unsubscribing: ", e);
+ }
+
+ try {
+ connr.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception closing connection: ", e);
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception creating Connection: ", e);
+ }
+
+ try {
+ if (null != beanRef)
+ beanRef.remove();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "[Client] Ignoring Exception on " + "bean remove", e);
+ }
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/ejbweb/xa/TransactionTests.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/ejbweb/xa/TransactionTests.java
deleted file mode 100644
index e078191408..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/ejbweb/xa/TransactionTests.java
+++ /dev/null
@@ -1,937 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.ejbweb.xa;
-
-import java.util.Enumeration;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TSNamingContext;
-import com.sun.ts.lib.util.TSNamingContextInterface;
-import com.sun.ts.lib.util.TestUtil;
-
-import jakarta.jms.Message;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueBrowser;
-import jakarta.jms.QueueConnection;
-import jakarta.jms.QueueConnectionFactory;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueSender;
-import jakarta.jms.QueueSession;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicConnection;
-import jakarta.jms.TopicConnectionFactory;
-import jakarta.jms.TopicPublisher;
-import jakarta.jms.TopicSession;
-import jakarta.jms.TopicSubscriber;
-import jakarta.transaction.UserTransaction;
-
-public class TransactionTests extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.ee.ejbweb.xa.TransactionTests";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // Naming specific member variables
- private TSNamingContextInterface context = null;
-
- private Properties props = null;
-
- private String jmsUser;
-
- private String jmsPassword;
-
- long timeout;
-
- private transient QueueConnection qConnect = null;
-
- private transient Queue bmtQ = null;
-
- private transient QueueSession qSession = null;
-
- private transient QueueConnectionFactory qFactory = null;
-
- private transient QueueSender qSender = null;
-
- private transient QueueReceiver qReceiver = null;
-
- private transient Topic bmtT = null;
-
- private transient TopicConnection tConnect = null;
-
- private transient TopicSession tSession = null;
-
- private transient TopicConnectionFactory tFactory = null;
-
- private transient TopicPublisher tPublisher = null;
-
- private transient TopicSubscriber tSub = null;
-
- private transient TextMessage msg = null;
-
- private transient UserTransaction ut = null;
-
- private boolean transacted = true;
-
- private boolean queueTest = false;
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- TransactionTests theTests = new TransactionTests();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * Individual tests create a temporary Queue
- *
- * @class.setup_props: jms_timeout; user; password;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- jmsUser = p.getProperty("user");
- jmsPassword = p.getProperty("password");
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception("'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (jmsUser == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (jmsPassword == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
-
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- bmtQ = (Queue) context.lookup("java:comp/env/jms/QUEUE_BMT");
-
- tFactory = (TopicConnectionFactory) context
- .lookup("java:comp/env/jms/MyTopicConnectionFactory");
- bmtT = (Topic) context.lookup("java:comp/env/jms/TOPIC_BMT");
-
- ut = (UserTransaction) context.lookup("java:comp/UserTransaction");
- TestUtil.logTrace("in client setup");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * Closes the default connections that are created by setup(). Any separate
- * connections made by individual tests should be closed by that test.
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- logTrace("Cleanup");
- try {
- if (ut != null && ut
- .getStatus() != jakarta.transaction.Status.STATUS_NO_TRANSACTION) {
- logTrace("Cleanup open transaction");
- printTxStatus();
- ut.commit();
- }
- } catch (Exception e) {
- logErr("Exception during cleanup of transaction", e);
- }
- try {
- if (queueTest) {
- logTrace("Cleanup of Queue and close receiver/sender");
- flushQueue(qSession, qReceiver, bmtQ);
- logTrace("Closing receiver and sender");
- if (qReceiver != null)
- qReceiver.close();
- if (qSender != null)
- qSender.close();
- qReceiver = null;
- qSender = null;
- } else {
- logTrace("Cleanup of Topic and close publisher");
- if (tPublisher != null)
- tPublisher.close();
- tPublisher = null;
- }
- } catch (Exception e) {
- if (queueTest)
- logErr("Exception during cleanup of Queue", e);
- else
- logErr("Exception during cleanup of Topic", e);
- }
- try {
- logTrace("Closing sessions");
- if (tSession != null)
- tSession.close();
- if (qSession != null)
- qSession.close();
- tSession = null;
- qSession = null;
- } catch (Exception e) {
- logErr("Exception during closing of sessions", e);
- }
- try {
- logTrace("Closing connections");
- if (tConnect != null)
- tConnect.close();
- if (qConnect != null)
- qConnect.close();
- tConnect = null;
- qConnect = null;
- } catch (Exception e) {
- logErr("Exception during closing of connections", e);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logErr("An error occurred while cleaning");
- throw new Exception("Cleanup failed!", e);
- }
- }
-
- /*
- * Cleanup method for tests that use durable subscriptions
- */
- private void cleanupSubscription(TopicSubscriber sub, TopicSession session,
- String subName) {
- if (sub != null) {
- try {
- TestUtil.logTrace("Closing durable subscriber: " + sub);
- sub.close();
- } catch (Exception e) {
- TestUtil.logErr("exception during close: ", e);
- }
- }
-
- if (session != null) {
- try {
- TestUtil.logTrace("Unsubscribing \"" + subName + "\"");
- session.unsubscribe(subName);
- } catch (Exception e) {
- TestUtil.logErr("exception during unsubscribe: ", e);
- }
- }
- }
-
- private void flushQueue(QueueSession qSession, QueueReceiver qReceiver,
- Queue queue) throws Exception {
- int numMsgsFlushed = 0;
- int numMsgs = 0;
- Enumeration msgs = null;
-
- try {
- TestUtil.logTrace("Flush Queue " + queue.getQueueName());
- QueueBrowser qBrowser = qSession.createBrowser(queue);
-
- // count the number of messages
- msgs = qBrowser.getEnumeration();
- while (msgs.hasMoreElements()) {
- msgs.nextElement();
- numMsgs++;
- }
- qBrowser.close();
-
- if (numMsgs == 0) {
- TestUtil.logTrace("No Messages left on Queue " + queue.getQueueName());
- } else {
- TestUtil.logTrace(
- numMsgs + " Messages left on Queue " + queue.getQueueName());
-
- // flush the queue
- Message msg = qReceiver.receiveNoWait();
- while (msg != null) {
- numMsgsFlushed++;
- msg = qReceiver.receiveNoWait();
- }
- if (numMsgsFlushed > 0) {
- TestUtil.logMsg("flush queue of " + numMsgsFlushed + " messages");
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void printTxStatus() {
- logTrace("Transaction Status: ");
- int status;
-
- try {
- status = ut.getStatus();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- logTrace("Unable to get transaction status");
- return;
- }
-
- switch (status) {
- case jakarta.transaction.Status.STATUS_ACTIVE:
- logTrace("==== A transaction is associated with"
- + " the target object and it is in the active state.");
- break;
-
- case jakarta.transaction.Status.STATUS_COMMITTED:
- logTrace("==== A transaction is associated with the target object"
- + " and it has been committed..");
- break;
- case jakarta.transaction.Status.STATUS_COMMITTING:
- logTrace("==== A transaction is associated with the target object"
- + " and it is in the process of committing.");
- break;
- case jakarta.transaction.Status.STATUS_MARKED_ROLLBACK:
- logTrace("==== A transaction is associated with the target object"
- + " and it has been marked forrollback, perhaps as a result of a setRollbackOnly operation. ");
- break;
- case jakarta.transaction.Status.STATUS_NO_TRANSACTION:
- logTrace(
- "==== No transaction is currently associated with the target object.");
- break;
- case jakarta.transaction.Status.STATUS_PREPARED:
- logTrace("====A transaction is associated with the target object"
- + " and it has been prepared, i.e. ");
- break;
- case jakarta.transaction.Status.STATUS_PREPARING:
- logTrace("==== A transaction is associated with the target object"
- + " and it is in the process of preparing. ");
- break;
-
- case jakarta.transaction.Status.STATUS_ROLLEDBACK:
- logTrace("==== A transaction is associated with the target object"
- + " and the outcome has been determined as rollback. ");
- break;
- case jakarta.transaction.Status.STATUS_ROLLING_BACK:
- logTrace("==== A transaction is associated with the target object"
- + " and it is in the process of rolling back.");
- break;
-
- case jakarta.transaction.Status.STATUS_UNKNOWN:
- logTrace("==== A transaction is associated with the target object"
- + " but its current status cannot be determined ");
- break;
-
- default:
- TestUtil.logTrace("??? jakarta.transaction.Status is " + status);
- break;
- }
- }
-
- private void createTestMessage(String TestCase, int num) throws Exception {
- logTrace("Invoked createTestMessage");
-
- String myMessage = "EjbWebTransaction tests";
- try {
- if (queueTest)
- msg = qSession.createTextMessage();
- else
- msg = tSession.createTextMessage();
- msg.setText(myMessage);
- msg.setIntProperty("TestCaseNum", num);
- msg.setStringProperty("COM_SUN_JMS_TESTNAME", TestCase);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Error in createTestMessage!");
- }
- }
-
- private void testInitForQ(String TestCase, int TestNum) throws Exception {
- try {
- logMsg("TestCase = " + TestCase);
- queueTest = true;
-
- // create QueueConnection, start user transaction, create QueueSession
- logMsg(
- "Create QueueConnection, start user transaction, create QueueSession");
- qConnect = qFactory.createQueueConnection(jmsUser, jmsPassword);
- qConnect.start();
- ut.begin();
- qSession = qConnect.createQueueSession(transacted, 0);
-
- // Create a receiver and a sender
- logMsg("Create receiver and sender");
- qReceiver = qSession.createReceiver(bmtQ);
- qSender = qSession.createSender(bmtQ);
-
- // construct a message for this test case
- logMsg("Construct a test message for this test case");
- createTestMessage(TestCase, TestNum);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Error in testInitForQ!");
- }
- }
-
- private void testInitForT(String TestCase, int TestNum) throws Exception {
- try {
- logMsg("TestCase = " + TestCase);
- queueTest = false;
-
- // create TopicConnection, start user transaction, create TopicSession
- logMsg(
- "Create TopicConnection, start user transaction, create TopicSession");
- tConnect = tFactory.createTopicConnection(jmsUser, jmsPassword);
- tConnect.start();
- ut.begin();
- tSession = tConnect.createTopicSession(transacted, 0);
-
- // Create subscriber and publisher with TestCase as subscription name
- logMsg(
- "Create subscriber and publisher with TestCase as subscription name");
- tSub = tSession.createDurableSubscriber(bmtT, TestCase);
- tPublisher = tSession.createPublisher(bmtT);
-
- // construct a message for this test case
- logMsg("Construct a test message for this test case");
- createTestMessage(TestCase, TestNum);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new Exception("Error in testInitForT!");
- }
- }
-
- /* Tests */
- /*
- * @testName: Test01
- *
- * @assertion_ids: JMS:SPEC:122; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
- *
- * @test_Strategy: Start a transaction. Send a message to Queue QUEUE_BMT.
- * Commit the transaction. Verify that you can receive the message.
- *
- */
- public void Test01() throws Exception {
- String TestCase = "Test01";
- int TestNum = 1;
- TextMessage msgRec;
- try {
- testInitForQ(TestCase, TestNum);
-
- // send the message
- logMsg("Begin TX: sending test message to Queue then: Commit TX");
- qSender.send(msg);
- // commit the transaction
- ut.commit();
-
- ut.begin();
- logMsg("Begin TX: receiving test message from Queue then: Commit TX");
- msgRec = (TextMessage) qReceiver.receive(timeout);
- ut.commit();
-
- logMsg("Verify message received");
- if (msgRec == null) {
- logMsg("Test " + TestNum + " Fail!");
- throw new Exception("Message was not received");
- } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
- logMsg("Test " + TestNum + " Pass!");
- } else {
- logMsg("Unknown Message was received in error");
- logMsg("msgRec.getIntProperty(\"TestCaseNum\")="
- + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
- throw new Exception("Unknown Message was received in error");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test02
- *
- * @assertion_ids: JMS:SPEC:123; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
- *
- * @test_Strategy: Start a transaction. Send a message to Queue QUEUE_BMT.
- * Rollback the transaction. Verify that you cannot receive the message.
- *
- */
- public void Test02() throws Exception {
- String TestCase = "Test02";
- int TestNum = 2;
- TextMessage msgRec;
- try {
- testInitForQ(TestCase, TestNum);
-
- logMsg("Begin TX: sending test message to Queue then: Rollback TX");
- qSender.send(msg);
- ut.rollback();
-
- ut.begin();
- logMsg("Begin TX: try receiving test message from Queue then: Commit TX");
- msgRec = (TextMessage) qReceiver.receive(timeout);
- ut.commit();
-
- logMsg("Verify no message received");
- if (msgRec == null) {
- logMsg("Test " + TestNum + " Pass!");
- } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
- logMsg("Test " + TestNum + " Fail!");
- throw new Exception("Message was received in error");
- } else {
- logMsg("Unknown Message was received in error");
- logMsg("msgRec.getIntProperty(\"TestCaseNum\")="
- + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
- throw new Exception("Unknown Message was received in error");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test03
- *
- * @assertion_ids: JMS:SPEC:122; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
- *
- * @test_Strategy: Send a message to Queue QUEUE_BMT. Start a transaction.
- * Receive the message for the queue Commit the transaction. Verify that you
- * cannot receive the message again.
- *
- */
- public void Test03() throws Exception {
- String TestCase = "Test03";
- int TestNum = 3;
- TextMessage msgRec;
- try {
- testInitForQ(TestCase, TestNum);
-
- logMsg("Begin TX: sending test message to Queue then: Commit TX");
- qSender.send(msg);
- ut.commit();
-
- ut.begin();
- logMsg("Begin TX: receiving test message from Queue then: Commit TX");
- msgRec = (TextMessage) qReceiver.receive(timeout);
- ut.commit();
- if (msgRec == null) {
- throw new Exception(
- "Unable to complete test! Did not receive a message");
- }
-
- ut.begin();
- logMsg(
- "Begin TX: receiving test message again from Queue then: Commit TX");
- msgRec = (TextMessage) qReceiver.receive(timeout);
- ut.commit();
-
- logMsg("Verify no message received");
- if (msgRec == null) {
- logMsg("Test " + TestNum + " Pass!");
- } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
- logMsg("Test " + TestNum + " Fail!");
- throw new Exception("Message was received in error");
- } else {
- logMsg("Unknown Message was received in error");
- logMsg("msgRec.getIntProperty(\"TestCaseNum\")="
- + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
- throw new Exception("Unknown Message was received in error");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test04
- *
- * @assertion_ids: JMS:SPEC:123; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
- *
- * @test_Strategy: Send a message to Queue QUEUE_BMT. Start a transaction.
- * Receive the message for the queue Rollback the transaction. Verify that you
- * can receive the message again.
- *
- */
- public void Test04() throws Exception {
- String TestCase = "Test04";
- int TestNum = 4;
- TextMessage msgRec;
- try {
- testInitForQ(TestCase, TestNum);
-
- logMsg("Begin TX: sending test message to Queue then: Commit TX");
- qSender.send(msg);
- ut.commit();
-
- // start a transaction
- ut.begin();
- logMsg("Begin TX: receiving test message from Queue then: Rollback TX");
- msgRec = (TextMessage) qReceiver.receive(timeout);
- ut.rollback();
-
- ut.begin();
- logMsg(
- "Begin TX: receiving test message again from Queue then: Commit TX");
- msgRec = (TextMessage) qReceiver.receive(timeout);
- ut.commit();
-
- logMsg("Verify message received");
- if (msgRec == null) {
- logMsg("Test " + TestNum + " Fail!");
- throw new Exception("Message was not received ");
- } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
- logMsg("Test " + TestNum + " Pass!");
- } else {
- logMsg("Unknown Message was received in error");
- logMsg("msgRec.getIntProperty(\"TestCaseNum\")="
- + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
- throw new Exception("Unknown Message was received in error");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test05
- *
- * @assertion_ids: JMS:SPEC:122; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
- *
- * @test_Strategy: Start a transaction. Send a message to Topic TOPIC_BMT.
- * Commit the transaction. Verify that you can receive the message.
- *
- */
- public void Test05() throws Exception {
- String TestCase = "Test05";
- int TestNum = 5;
- TextMessage msgRec;
- try {
- testInitForT(TestCase, TestNum);
-
- // send the message
- logMsg("Begin TX: sending test message to Topic then: Commit TX");
- tPublisher.publish(msg);
- ut.commit();
-
- ut.begin();
- logMsg("Begin TX: receiving test message from Topic then: Commit TX");
- msgRec = (TextMessage) tSub.receive(timeout);
- ut.commit();
-
- logMsg("Verify message received");
- if (msgRec == null) {
- logMsg("Test " + TestNum + " Fail!");
- throw new Exception("Message was not received");
- } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
- logMsg("Test " + TestNum + " Pass!");
- } else {
- logMsg("Unknown Message was received in error");
- logMsg("msgRec.getIntProperty(\"TestCaseNum\")="
- + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
- throw new Exception("Unknown Message was received in error");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- } finally {
- cleanupSubscription(tSub, tSession, TestCase);
- }
- }
-
- /*
- * @testName: Test06
- *
- * @assertion_ids: JMS:SPEC:123; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
- *
- * @test_Strategy: Start a transaction. Send a message to Topic TOPIC_BMT.
- * Rollback the transaction. Verify that you cannot receive the message.
- *
- */
- public void Test06() throws Exception {
- String TestCase = "Test06";
- int TestNum = 6;
- TextMessage msgRec;
- try {
- testInitForT(TestCase, TestNum);
-
- logMsg("Begin TX: sending test message to Topic then: Rollback TX");
- // send the message
- tPublisher.publish(msg);
- // rollback the transaction
- ut.rollback();
-
- ut.begin();
- logMsg("Begin TX: receiving test message from Topic then: Commit TX");
- msgRec = (TextMessage) tSub.receive(timeout);
- ut.commit();
-
- logMsg("Verify no message received");
- if (msgRec == null) {
- logMsg("Test " + TestNum + " Pass!");
- } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
- logMsg("Test " + TestNum + " Fail!");
- throw new Exception("Message was received in error");
- } else {
- logMsg("Unknown Message was received in error");
- logMsg("msgRec.getIntProperty(\"TestCaseNum\")="
- + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
- throw new Exception("Unknown Message was received in error");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- } finally {
- cleanupSubscription(tSub, tSession, TestCase);
- }
- }
-
- /*
- * @testName: Test07
- *
- * @assertion_ids: JMS:SPEC:122; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
- *
- * @test_Strategy: Send a message to Topic TOPIC_BMT. Start a transaction.
- * Receive the message for the topic Commit the transaction. Verify that you
- * cannot receive the message again.
- *
- */
- public void Test07() throws Exception {
- String TestCase = "Test07";
- int TestNum = 7;
- TextMessage msgRec;
- try {
- testInitForT(TestCase, TestNum);
-
- logMsg("Begin TX: sending test message to Topic then: Commit TX");
- // send the message
- tPublisher.publish(msg);
- ut.commit();
-
- ut.begin();
- logMsg("Begin TX: receiving test message from Topic then: Commit TX");
- msgRec = (TextMessage) tSub.receive(timeout);
- ut.commit();
- if (msgRec == null) {
- throw new Exception(
- "Unable to complete test! Did not receive a message");
- }
-
- ut.begin();
- logMsg(
- "Begin TX: receiving test message again from Topic then: Commit TX");
- msgRec = (TextMessage) tSub.receive(timeout);
- ut.commit();
-
- logMsg("Verify no message received");
- if (msgRec == null) {
- logMsg("Test " + TestNum + " Pass!");
- } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
- logMsg("Test " + TestNum + " Fail!");
- throw new Exception("Message was received in error");
- } else {
- logMsg("Unknown Message was received in error");
- logMsg("msgRec.getIntProperty(\"TestCaseNum\")="
- + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
- throw new Exception("Unknown Message was received in error");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- } finally {
- cleanupSubscription(tSub, tSession, TestCase);
- }
- }
-
- /*
- * @testName: Test08
- *
- * @assertion_ids: JMS:SPEC:123; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
- *
- * @test_Strategy: Send a message to Topic TOPIC_BMT. Start a transaction.
- * Receive the message for the topic Rollback the transaction. Verify that you
- * can receive the message again.
- *
- */
- public void Test08() throws Exception {
- String TestCase = "Test08";
- int TestNum = 8;
- TextMessage msgRec;
- try {
- testInitForT(TestCase, TestNum);
-
- logMsg("Begin TX: sending test message to Topic then: Commit TX");
- // send the message
- tPublisher.publish(msg);
- ut.commit();
-
- // start a transaction, receive a message, then rollback
- ut.begin();
- logMsg("Begin TX: receiving test message from Topic then: Rollback TX");
- msgRec = (TextMessage) tSub.receive(timeout);
- ut.rollback();
- if (msgRec == null) {
- throw new Exception(
- "Unable to complete test! Did not receive a message");
- }
-
- // start transaction, then try to receive again - should get a message.
- ut.begin();
- logMsg(
- "Begin TX: receiving test message again from Topic then: Commit TX");
- msgRec = (TextMessage) tSub.receive(timeout);
- ut.commit();
-
- logMsg("Verify message received");
- if (msgRec == null) {
- logMsg("Test " + TestNum + " Failed!");
- throw new Exception("Message was not received ");
- } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
- logMsg("Test " + TestNum + " Pass!");
- } else {
- logMsg("Unknown Test Message " + TestNum + " Fail!");
- logMsg("msgRec.getIntProperty(\"TestCaseNum\")="
- + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
- throw new Exception("Unknown Message was received in error");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- } finally {
- cleanupSubscription(tSub, tSession, TestCase);
- }
- }
-
- /*
- * @testName: Test09
- *
- * @assertion_ids: JMS:SPEC:122; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
- *
- * @test_Strategy: Start a transaction. Send message to Queue QUEUE_BMT.
- * Commit the transaction. Start another transaction. Send message again to
- * Queue QUEUE_BMT. Commit the transaction. Start a transaction. Receive
- * message from Queue QUEUE_BMT. Commit the transaction. Start a transaction.
- * Receive message from Queue QUEUE_BMT. Commit the transaction. Verify that
- * you can receive the message twice.
- */
- public void Test09() throws Exception {
- String TestCase = "Test09";
- int TestNum = 9;
- TextMessage msgRec;
- try {
- testInitForQ(TestCase, TestNum);
-
- // send the message
- logMsg("Begin TX: sending test message to Queue then: Commit TX");
- qSender.send(msg);
- // commit the transaction
- ut.commit();
-
- // send the message again
- ut.begin();
- logMsg("Begin TX: sending test message again to Queue then: Commit TX");
- qSender.send(msg);
- // commit the transaction
- ut.commit();
-
- for (int i = 0; i < 2; i++) {
- ut.begin();
- logMsg("Begin TX: receiving test message from Queue then: Commit TX");
- msgRec = (TextMessage) qReceiver.receive(timeout);
- ut.commit();
-
- logMsg("Verify message received");
- if (msgRec == null) {
- logMsg("Test " + TestNum + " Fail!");
- throw new Exception("Message was not received");
- } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
- logMsg("Test " + TestNum + " Pass!");
- } else {
- logMsg("Unknown Message was received in error");
- logMsg("msgRec.getIntProperty(\"TestCaseNum\")="
- + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
- throw new Exception("Unknown Message was received in error");
- }
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test10
- *
- * @assertion_ids: JMS:SPEC:122; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
- *
- * @test_Strategy: Start a transaction. Send message to Topic TOPIC_BMT.
- * Commit the transaction. Start another transaction. Send message again to
- * Topic TOPIC_BMT. Commit the transaction. Start a transaction. Receive
- * message from Topic TOPIC_BMT. Commit the transaction. Start a transaction.
- * Receive message from Topic TOPIC_BMT. Commit the transaction. Verify that
- * you can receive the message twice.
- */
- public void Test10() throws Exception {
- String TestCase = "Test10";
- int TestNum = 10;
- TextMessage msgRec;
- try {
- testInitForT(TestCase, TestNum);
-
- logMsg("Begin TX: sending test message to Topic then: Commit TX");
- // send the message
- tPublisher.publish(msg);
- // commit the transaction
- ut.commit();
-
- // send the message again
- ut.begin();
- logMsg("Begin TX: sending test message again to Topic then: Commit TX");
- tPublisher.publish(msg);
- // commit the transaction
- ut.commit();
-
- for (int i = 0; i < 2; i++) {
- ut.begin();
- logMsg("Begin TX: receiving test message from Queue then: Commit TX");
- msgRec = (TextMessage) tSub.receive(timeout);
- ut.commit();
-
- logMsg("Verify message received");
- if (msgRec == null) {
- logMsg("Test " + TestNum + " Fail!");
- throw new Exception("Message was not received");
- } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
- logMsg("Test " + TestNum + " Pass!");
- } else {
- logMsg("Unknown Message was received in error");
- logMsg("msgRec.getIntProperty(\"TestCaseNum\")="
- + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
- throw new Exception("Unknown Message was received in error");
- }
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- } finally {
- cleanupSubscription(tSub, tSession, TestCase);
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/ejbweb/xa/TransactionTestsIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/ejbweb/xa/TransactionTestsIT.java
new file mode 100644
index 0000000000..13b76f5f1c
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/ejbweb/xa/TransactionTestsIT.java
@@ -0,0 +1,926 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.ejbweb.xa;
+
+import java.lang.System.Logger;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TSNamingContext;
+import com.sun.ts.lib.util.TSNamingContextInterface;
+import com.sun.ts.lib.util.TestUtil;
+
+import jakarta.jms.Message;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueBrowser;
+import jakarta.jms.QueueConnection;
+import jakarta.jms.QueueConnectionFactory;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueSender;
+import jakarta.jms.QueueSession;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicConnection;
+import jakarta.jms.TopicConnectionFactory;
+import jakarta.jms.TopicPublisher;
+import jakarta.jms.TopicSession;
+import jakarta.jms.TopicSubscriber;
+import jakarta.transaction.UserTransaction;
+
+
+public class TransactionTestsIT {
+ private static final String testName = "com.sun.ts.tests.jms.ee.ejbweb.xa.TransactionTestsIT";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger logger = (Logger) System.getLogger(TransactionTestsIT.class.getName());
+
+ // Naming specific member variables
+ private TSNamingContextInterface context = null;
+
+ private Properties props = null;
+
+ private String jmsUser;
+
+ private String jmsPassword;
+
+ long timeout;
+
+ private transient QueueConnection qConnect = null;
+
+ private transient Queue bmtQ = null;
+
+ private transient QueueSession qSession = null;
+
+ private transient QueueConnectionFactory qFactory = null;
+
+ private transient QueueSender qSender = null;
+
+ private transient QueueReceiver qReceiver = null;
+
+ private transient Topic bmtT = null;
+
+ private transient TopicConnection tConnect = null;
+
+ private transient TopicSession tSession = null;
+
+ private transient TopicConnectionFactory tFactory = null;
+
+ private transient TopicPublisher tPublisher = null;
+
+ private transient TopicSubscriber tSub = null;
+
+ private transient TextMessage msg = null;
+
+ private transient UserTransaction ut = null;
+
+ private boolean transacted = true;
+
+ private boolean queueTest = false;
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * Individual tests create a temporary Queue
+ *
+ * @class.setup_props: jms_timeout; user; password;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (jmsUser == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (jmsPassword == null) {
+ throw new Exception("'password' is null ");
+ }
+
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ bmtQ = (Queue) context.lookup("java:comp/env/jms/QUEUE_BMT");
+
+ tFactory = (TopicConnectionFactory) context.lookup("java:comp/env/jms/MyTopicConnectionFactory");
+ bmtT = (Topic) context.lookup("java:comp/env/jms/TOPIC_BMT");
+
+ ut = (UserTransaction) context.lookup("java:comp/UserTransaction");
+ logger.log(Logger.Level.TRACE, "in client setup");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * Closes the default connections that are created by setup(). Any separate
+ * connections made by individual tests should be closed by that test.
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, "Cleanup");
+ try {
+ if (ut != null && ut.getStatus() != jakarta.transaction.Status.STATUS_NO_TRANSACTION) {
+ logger.log(Logger.Level.TRACE, "Cleanup open transaction");
+ printTxStatus();
+ ut.commit();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception during cleanup of transaction", e);
+ }
+ try {
+ if (queueTest) {
+ logger.log(Logger.Level.TRACE, "Cleanup of Queue and close receiver/sender");
+ flushQueue(qSession, qReceiver, bmtQ);
+ logger.log(Logger.Level.TRACE, "Closing receiver and sender");
+ if (qReceiver != null)
+ qReceiver.close();
+ if (qSender != null)
+ qSender.close();
+ qReceiver = null;
+ qSender = null;
+ } else {
+ logger.log(Logger.Level.TRACE, "Cleanup of Topic and close publisher");
+ if (tPublisher != null)
+ tPublisher.close();
+ tPublisher = null;
+ }
+ } catch (Exception e) {
+ if (queueTest)
+ logger.log(Logger.Level.ERROR, "Exception during cleanup of Queue", e);
+ else
+ logger.log(Logger.Level.ERROR, "Exception during cleanup of Topic", e);
+ }
+ try {
+ logger.log(Logger.Level.TRACE, "Closing sessions");
+ if (tSession != null)
+ tSession.close();
+ if (qSession != null)
+ qSession.close();
+ tSession = null;
+ qSession = null;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception during closing of sessions", e);
+ }
+ try {
+ logger.log(Logger.Level.TRACE, "Closing connections");
+ if (tConnect != null)
+ tConnect.close();
+ if (qConnect != null)
+ qConnect.close();
+ tConnect = null;
+ qConnect = null;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception during closing of connections", e);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "An error occurred while cleaning");
+ throw new Exception("Cleanup failed!", e);
+ }
+ }
+
+ /*
+ * Cleanup method for tests that use durable subscriptions
+ */
+ private void cleanupSubscription(TopicSubscriber sub, TopicSession session, String subName) {
+ if (sub != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Closing durable subscriber: " + sub);
+ sub.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "exception during close: ", e);
+ }
+ }
+
+ if (session != null) {
+ try {
+ logger.log(Logger.Level.TRACE, "Unsubscribing \"" + subName + "\"");
+ session.unsubscribe(subName);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "exception during unsubscribe: ", e);
+ }
+ }
+ }
+
+ private void flushQueue(QueueSession qSession, QueueReceiver qReceiver, Queue queue) throws Exception {
+ int numMsgsFlushed = 0;
+ int numMsgs = 0;
+ Enumeration msgs = null;
+
+ try {
+ logger.log(Logger.Level.TRACE, "Flush Queue " + queue.getQueueName());
+ QueueBrowser qBrowser = qSession.createBrowser(queue);
+
+ // count the number of messages
+ msgs = qBrowser.getEnumeration();
+ while (msgs.hasMoreElements()) {
+ msgs.nextElement();
+ numMsgs++;
+ }
+ qBrowser.close();
+
+ if (numMsgs == 0) {
+ logger.log(Logger.Level.TRACE, "No Messages left on Queue " + queue.getQueueName());
+ } else {
+ logger.log(Logger.Level.TRACE, numMsgs + " Messages left on Queue " + queue.getQueueName());
+
+ // flush the queue
+ Message msg = qReceiver.receiveNoWait();
+ while (msg != null) {
+ numMsgsFlushed++;
+ msg = qReceiver.receiveNoWait();
+ }
+ if (numMsgsFlushed > 0) {
+ logger.log(Logger.Level.INFO, "flush queue of " + numMsgsFlushed + " messages");
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void printTxStatus() {
+ logger.log(Logger.Level.TRACE, "Transaction Status: ");
+ int status;
+
+ try {
+ status = ut.getStatus();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Unable to get transaction status");
+ return;
+ }
+
+ switch (status) {
+ case jakarta.transaction.Status.STATUS_ACTIVE:
+ logger.log(Logger.Level.TRACE,
+ "==== A transaction is associated with" + " the target object and it is in the active state.");
+ break;
+
+ case jakarta.transaction.Status.STATUS_COMMITTED:
+ logger.log(Logger.Level.TRACE,
+ "==== A transaction is associated with the target object" + " and it has been committed..");
+ break;
+ case jakarta.transaction.Status.STATUS_COMMITTING:
+ logger.log(Logger.Level.TRACE, "==== A transaction is associated with the target object"
+ + " and it is in the process of committing.");
+ break;
+ case jakarta.transaction.Status.STATUS_MARKED_ROLLBACK:
+ logger.log(Logger.Level.TRACE, "==== A transaction is associated with the target object"
+ + " and it has been marked forrollback, perhaps as a result of a setRollbackOnly operation. ");
+ break;
+ case jakarta.transaction.Status.STATUS_NO_TRANSACTION:
+ logger.log(Logger.Level.TRACE, "==== No transaction is currently associated with the target object.");
+ break;
+ case jakarta.transaction.Status.STATUS_PREPARED:
+ logger.log(Logger.Level.TRACE,
+ "====A transaction is associated with the target object" + " and it has been prepared, i.e. ");
+ break;
+ case jakarta.transaction.Status.STATUS_PREPARING:
+ logger.log(Logger.Level.TRACE, "==== A transaction is associated with the target object"
+ + " and it is in the process of preparing. ");
+ break;
+
+ case jakarta.transaction.Status.STATUS_ROLLEDBACK:
+ logger.log(Logger.Level.TRACE, "==== A transaction is associated with the target object"
+ + " and the outcome has been determined as rollback. ");
+ break;
+ case jakarta.transaction.Status.STATUS_ROLLING_BACK:
+ logger.log(Logger.Level.TRACE, "==== A transaction is associated with the target object"
+ + " and it is in the process of rolling back.");
+ break;
+
+ case jakarta.transaction.Status.STATUS_UNKNOWN:
+ logger.log(Logger.Level.TRACE, "==== A transaction is associated with the target object"
+ + " but its current status cannot be determined ");
+ break;
+
+ default:
+ logger.log(Logger.Level.TRACE, "??? jakarta.transaction.Status is " + status);
+ break;
+ }
+ }
+
+ private void createTestMessage(String TestCase, int num) throws Exception {
+ logger.log(Logger.Level.TRACE, "Invoked createTestMessage");
+
+ String myMessage = "EjbWebTransaction tests";
+ try {
+ if (queueTest)
+ msg = qSession.createTextMessage();
+ else
+ msg = tSession.createTextMessage();
+ msg.setText(myMessage);
+ msg.setIntProperty("TestCaseNum", num);
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", TestCase);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Error in createTestMessage!");
+ }
+ }
+
+ private void testInitForQ(String TestCase, int TestNum) throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "TestCase = " + TestCase);
+ queueTest = true;
+
+ // create QueueConnection, start user transaction, create QueueSession
+ logger.log(Logger.Level.INFO, "Create QueueConnection, start user transaction, create QueueSession");
+ qConnect = qFactory.createQueueConnection(jmsUser, jmsPassword);
+ qConnect.start();
+ ut.begin();
+ qSession = qConnect.createQueueSession(transacted, 0);
+
+ // Create a receiver and a sender
+ logger.log(Logger.Level.INFO, "Create receiver and sender");
+ qReceiver = qSession.createReceiver(bmtQ);
+ qSender = qSession.createSender(bmtQ);
+
+ // construct a message for this test case
+ logger.log(Logger.Level.INFO, "Construct a test message for this test case");
+ createTestMessage(TestCase, TestNum);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Error in testInitForQ!");
+ }
+ }
+
+ private void testInitForT(String TestCase, int TestNum) throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "TestCase = " + TestCase);
+ queueTest = false;
+
+ // create TopicConnection, start user transaction, create TopicSession
+ logger.log(Logger.Level.INFO, "Create TopicConnection, start user transaction, create TopicSession");
+ tConnect = tFactory.createTopicConnection(jmsUser, jmsPassword);
+ tConnect.start();
+ ut.begin();
+ tSession = tConnect.createTopicSession(transacted, 0);
+
+ // Create subscriber and publisher with TestCase as subscription name
+ logger.log(Logger.Level.INFO, "Create subscriber and publisher with TestCase as subscription name");
+ tSub = tSession.createDurableSubscriber(bmtT, TestCase);
+ tPublisher = tSession.createPublisher(bmtT);
+
+ // construct a message for this test case
+ logger.log(Logger.Level.INFO, "Construct a test message for this test case");
+ createTestMessage(TestCase, TestNum);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new Exception("Error in testInitForT!");
+ }
+ }
+
+ /* Tests */
+ /*
+ * @testName: Test01
+ *
+ * @assertion_ids: JMS:SPEC:122; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
+ *
+ * @test_Strategy: Start a transaction. Send a message to Queue QUEUE_BMT.
+ * Commit the transaction. Verify that you can receive the message.
+ *
+ */
+ @Test
+ public void Test01() throws Exception {
+ String TestCase = "Test01";
+ int TestNum = 1;
+ TextMessage msgRec;
+ try {
+ testInitForQ(TestCase, TestNum);
+
+ // send the message
+ logger.log(Logger.Level.INFO, "Begin TX: sending test message to Queue then: Commit TX");
+ qSender.send(msg);
+ // commit the transaction
+ ut.commit();
+
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message from Queue then: Commit TX");
+ msgRec = (TextMessage) qReceiver.receive(timeout);
+ ut.commit();
+
+ logger.log(Logger.Level.INFO, "Verify message received");
+ if (msgRec == null) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Fail!");
+ throw new Exception("Message was not received");
+ } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Pass!");
+ } else {
+ logger.log(Logger.Level.INFO, "Unknown Message was received in error");
+ logger.log(Logger.Level.INFO, "msgRec.getIntProperty(\"TestCaseNum\")="
+ + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
+ throw new Exception("Unknown Message was received in error");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test02
+ *
+ * @assertion_ids: JMS:SPEC:123; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
+ *
+ * @test_Strategy: Start a transaction. Send a message to Queue QUEUE_BMT.
+ * Rollback the transaction. Verify that you cannot receive the message.
+ *
+ */
+ @Test
+ public void Test02() throws Exception {
+ String TestCase = "Test02";
+ int TestNum = 2;
+ TextMessage msgRec;
+ try {
+ testInitForQ(TestCase, TestNum);
+
+ logger.log(Logger.Level.INFO, "Begin TX: sending test message to Queue then: Rollback TX");
+ qSender.send(msg);
+ ut.rollback();
+
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: try receiving test message from Queue then: Commit TX");
+ msgRec = (TextMessage) qReceiver.receive(timeout);
+ ut.commit();
+
+ logger.log(Logger.Level.INFO, "Verify no message received");
+ if (msgRec == null) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Pass!");
+ } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Fail!");
+ throw new Exception("Message was received in error");
+ } else {
+ logger.log(Logger.Level.INFO, "Unknown Message was received in error");
+ logger.log(Logger.Level.INFO, "msgRec.getIntProperty(\"TestCaseNum\")="
+ + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
+ throw new Exception("Unknown Message was received in error");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test03
+ *
+ * @assertion_ids: JMS:SPEC:122; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
+ *
+ * @test_Strategy: Send a message to Queue QUEUE_BMT. Start a transaction.
+ * Receive the message for the queue Commit the transaction. Verify that you
+ * cannot receive the message again.
+ *
+ */
+ @Test
+ public void Test03() throws Exception {
+ String TestCase = "Test03";
+ int TestNum = 3;
+ TextMessage msgRec;
+ try {
+ testInitForQ(TestCase, TestNum);
+
+ logger.log(Logger.Level.INFO, "Begin TX: sending test message to Queue then: Commit TX");
+ qSender.send(msg);
+ ut.commit();
+
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message from Queue then: Commit TX");
+ msgRec = (TextMessage) qReceiver.receive(timeout);
+ ut.commit();
+ if (msgRec == null) {
+ throw new Exception("Unable to complete test! Did not receive a message");
+ }
+
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message again from Queue then: Commit TX");
+ msgRec = (TextMessage) qReceiver.receive(timeout);
+ ut.commit();
+
+ logger.log(Logger.Level.INFO, "Verify no message received");
+ if (msgRec == null) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Pass!");
+ } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Fail!");
+ throw new Exception("Message was received in error");
+ } else {
+ logger.log(Logger.Level.INFO, "Unknown Message was received in error");
+ logger.log(Logger.Level.INFO, "msgRec.getIntProperty(\"TestCaseNum\")="
+ + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
+ throw new Exception("Unknown Message was received in error");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test04
+ *
+ * @assertion_ids: JMS:SPEC:123; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
+ *
+ * @test_Strategy: Send a message to Queue QUEUE_BMT. Start a transaction.
+ * Receive the message for the queue Rollback the transaction. Verify that you
+ * can receive the message again.
+ *
+ */
+ @Test
+ public void Test04() throws Exception {
+ String TestCase = "Test04";
+ int TestNum = 4;
+ TextMessage msgRec;
+ try {
+ testInitForQ(TestCase, TestNum);
+
+ logger.log(Logger.Level.INFO, "Begin TX: sending test message to Queue then: Commit TX");
+ qSender.send(msg);
+ ut.commit();
+
+ // start a transaction
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message from Queue then: Rollback TX");
+ msgRec = (TextMessage) qReceiver.receive(timeout);
+ ut.rollback();
+
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message again from Queue then: Commit TX");
+ msgRec = (TextMessage) qReceiver.receive(timeout);
+ ut.commit();
+
+ logger.log(Logger.Level.INFO, "Verify message received");
+ if (msgRec == null) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Fail!");
+ throw new Exception("Message was not received ");
+ } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Pass!");
+ } else {
+ logger.log(Logger.Level.INFO, "Unknown Message was received in error");
+ logger.log(Logger.Level.INFO, "msgRec.getIntProperty(\"TestCaseNum\")="
+ + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
+ throw new Exception("Unknown Message was received in error");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test05
+ *
+ * @assertion_ids: JMS:SPEC:122; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
+ *
+ * @test_Strategy: Start a transaction. Send a message to Topic TOPIC_BMT.
+ * Commit the transaction. Verify that you can receive the message.
+ *
+ */
+ @Test
+ public void Test05() throws Exception {
+ String TestCase = "Test05";
+ int TestNum = 5;
+ TextMessage msgRec;
+ try {
+ testInitForT(TestCase, TestNum);
+
+ // send the message
+ logger.log(Logger.Level.INFO, "Begin TX: sending test message to Topic then: Commit TX");
+ tPublisher.publish(msg);
+ ut.commit();
+
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message from Topic then: Commit TX");
+ msgRec = (TextMessage) tSub.receive(timeout);
+ ut.commit();
+
+ logger.log(Logger.Level.INFO, "Verify message received");
+ if (msgRec == null) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Fail!");
+ throw new Exception("Message was not received");
+ } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Pass!");
+ } else {
+ logger.log(Logger.Level.INFO, "Unknown Message was received in error");
+ logger.log(Logger.Level.INFO, "msgRec.getIntProperty(\"TestCaseNum\")="
+ + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
+ throw new Exception("Unknown Message was received in error");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ } finally {
+ cleanupSubscription(tSub, tSession, TestCase);
+ }
+ }
+
+ /*
+ * @testName: Test06
+ *
+ * @assertion_ids: JMS:SPEC:123; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
+ *
+ * @test_Strategy: Start a transaction. Send a message to Topic TOPIC_BMT.
+ * Rollback the transaction. Verify that you cannot receive the message.
+ *
+ */
+ @Test
+ public void Test06() throws Exception {
+ String TestCase = "Test06";
+ int TestNum = 6;
+ TextMessage msgRec;
+ try {
+ testInitForT(TestCase, TestNum);
+
+ logger.log(Logger.Level.INFO, "Begin TX: sending test message to Topic then: Rollback TX");
+ // send the message
+ tPublisher.publish(msg);
+ // rollback the transaction
+ ut.rollback();
+
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message from Topic then: Commit TX");
+ msgRec = (TextMessage) tSub.receive(timeout);
+ ut.commit();
+
+ logger.log(Logger.Level.INFO, "Verify no message received");
+ if (msgRec == null) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Pass!");
+ } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Fail!");
+ throw new Exception("Message was received in error");
+ } else {
+ logger.log(Logger.Level.INFO, "Unknown Message was received in error");
+ logger.log(Logger.Level.INFO, "msgRec.getIntProperty(\"TestCaseNum\")="
+ + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
+ throw new Exception("Unknown Message was received in error");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ } finally {
+ cleanupSubscription(tSub, tSession, TestCase);
+ }
+ }
+
+ /*
+ * @testName: Test07
+ *
+ * @assertion_ids: JMS:SPEC:122; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
+ *
+ * @test_Strategy: Send a message to Topic TOPIC_BMT. Start a transaction.
+ * Receive the message for the topic Commit the transaction. Verify that you
+ * cannot receive the message again.
+ *
+ */
+ @Test
+ public void Test07() throws Exception {
+ String TestCase = "Test07";
+ int TestNum = 7;
+ TextMessage msgRec;
+ try {
+ testInitForT(TestCase, TestNum);
+
+ logger.log(Logger.Level.INFO, "Begin TX: sending test message to Topic then: Commit TX");
+ // send the message
+ tPublisher.publish(msg);
+ ut.commit();
+
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message from Topic then: Commit TX");
+ msgRec = (TextMessage) tSub.receive(timeout);
+ ut.commit();
+ if (msgRec == null) {
+ throw new Exception("Unable to complete test! Did not receive a message");
+ }
+
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message again from Topic then: Commit TX");
+ msgRec = (TextMessage) tSub.receive(timeout);
+ ut.commit();
+
+ logger.log(Logger.Level.INFO, "Verify no message received");
+ if (msgRec == null) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Pass!");
+ } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Fail!");
+ throw new Exception("Message was received in error");
+ } else {
+ logger.log(Logger.Level.INFO, "Unknown Message was received in error");
+ logger.log(Logger.Level.INFO, "msgRec.getIntProperty(\"TestCaseNum\")="
+ + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
+ throw new Exception("Unknown Message was received in error");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ } finally {
+ cleanupSubscription(tSub, tSession, TestCase);
+ }
+ }
+
+ /*
+ * @testName: Test08
+ *
+ * @assertion_ids: JMS:SPEC:123; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
+ *
+ * @test_Strategy: Send a message to Topic TOPIC_BMT. Start a transaction.
+ * Receive the message for the topic Rollback the transaction. Verify that you
+ * can receive the message again.
+ *
+ */
+ @Test
+ public void Test08() throws Exception {
+ String TestCase = "Test08";
+ int TestNum = 8;
+ TextMessage msgRec;
+ try {
+ testInitForT(TestCase, TestNum);
+
+ logger.log(Logger.Level.INFO, "Begin TX: sending test message to Topic then: Commit TX");
+ // send the message
+ tPublisher.publish(msg);
+ ut.commit();
+
+ // start a transaction, receive a message, then rollback
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message from Topic then: Rollback TX");
+ msgRec = (TextMessage) tSub.receive(timeout);
+ ut.rollback();
+ if (msgRec == null) {
+ throw new Exception("Unable to complete test! Did not receive a message");
+ }
+
+ // start transaction, then try to receive again - should get a message.
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message again from Topic then: Commit TX");
+ msgRec = (TextMessage) tSub.receive(timeout);
+ ut.commit();
+
+ logger.log(Logger.Level.INFO, "Verify message received");
+ if (msgRec == null) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Failed!");
+ throw new Exception("Message was not received ");
+ } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Pass!");
+ } else {
+ logger.log(Logger.Level.INFO, "Unknown Test Message " + TestNum + " Fail!");
+ logger.log(Logger.Level.INFO, "msgRec.getIntProperty(\"TestCaseNum\")="
+ + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
+ throw new Exception("Unknown Message was received in error");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ } finally {
+ cleanupSubscription(tSub, tSession, TestCase);
+ }
+ }
+
+ /*
+ * @testName: Test09
+ *
+ * @assertion_ids: JMS:SPEC:122; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
+ *
+ * @test_Strategy: Start a transaction. Send message to Queue QUEUE_BMT. Commit
+ * the transaction. Start another transaction. Send message again to Queue
+ * QUEUE_BMT. Commit the transaction. Start a transaction. Receive message from
+ * Queue QUEUE_BMT. Commit the transaction. Start a transaction. Receive message
+ * from Queue QUEUE_BMT. Commit the transaction. Verify that you can receive the
+ * message twice.
+ */
+ @Test
+ public void Test09() throws Exception {
+ String TestCase = "Test09";
+ int TestNum = 9;
+ TextMessage msgRec;
+ try {
+ testInitForQ(TestCase, TestNum);
+
+ // send the message
+ logger.log(Logger.Level.INFO, "Begin TX: sending test message to Queue then: Commit TX");
+ qSender.send(msg);
+ // commit the transaction
+ ut.commit();
+
+ // send the message again
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: sending test message again to Queue then: Commit TX");
+ qSender.send(msg);
+ // commit the transaction
+ ut.commit();
+
+ for (int i = 0; i < 2; i++) {
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message from Queue then: Commit TX");
+ msgRec = (TextMessage) qReceiver.receive(timeout);
+ ut.commit();
+
+ logger.log(Logger.Level.INFO, "Verify message received");
+ if (msgRec == null) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Fail!");
+ throw new Exception("Message was not received");
+ } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Pass!");
+ } else {
+ logger.log(Logger.Level.INFO, "Unknown Message was received in error");
+ logger.log(Logger.Level.INFO, "msgRec.getIntProperty(\"TestCaseNum\")="
+ + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
+ throw new Exception("Unknown Message was received in error");
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test10
+ *
+ * @assertion_ids: JMS:SPEC:122; JavaEE:SPEC:72; JMS:SPEC:265; JMS:SPEC:265.1;
+ *
+ * @test_Strategy: Start a transaction. Send message to Topic TOPIC_BMT. Commit
+ * the transaction. Start another transaction. Send message again to Topic
+ * TOPIC_BMT. Commit the transaction. Start a transaction. Receive message from
+ * Topic TOPIC_BMT. Commit the transaction. Start a transaction. Receive message
+ * from Topic TOPIC_BMT. Commit the transaction. Verify that you can receive the
+ * message twice.
+ */
+ @Test
+ public void Test10() throws Exception {
+ String TestCase = "Test10";
+ int TestNum = 10;
+ TextMessage msgRec;
+ try {
+ testInitForT(TestCase, TestNum);
+
+ logger.log(Logger.Level.INFO, "Begin TX: sending test message to Topic then: Commit TX");
+ // send the message
+ tPublisher.publish(msg);
+ // commit the transaction
+ ut.commit();
+
+ // send the message again
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: sending test message again to Topic then: Commit TX");
+ tPublisher.publish(msg);
+ // commit the transaction
+ ut.commit();
+
+ for (int i = 0; i < 2; i++) {
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Begin TX: receiving test message from Queue then: Commit TX");
+ msgRec = (TextMessage) tSub.receive(timeout);
+ ut.commit();
+
+ logger.log(Logger.Level.INFO, "Verify message received");
+ if (msgRec == null) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Fail!");
+ throw new Exception("Message was not received");
+ } else if (msgRec.getIntProperty("TestCaseNum") == TestNum) {
+ logger.log(Logger.Level.INFO, "Test " + TestNum + " Pass!");
+ } else {
+ logger.log(Logger.Level.INFO, "Unknown Message was received in error");
+ logger.log(Logger.Level.INFO, "msgRec.getIntProperty(\"TestCaseNum\")="
+ + msgRec.getIntProperty("TestCaseNum") + " expected " + TestNum);
+ throw new Exception("Unknown Message was received in error");
+ }
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ } finally {
+ cleanupSubscription(tSub, tSession, TestCase);
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptQ/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptQ/MDBClient.java
deleted file mode 100644
index c7a71360b5..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptQ/MDBClient.java
+++ /dev/null
@@ -1,394 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_exceptQ;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.tests.jms.commonee.Client;
-
-import jakarta.jms.Queue;
-
-public class MDBClient extends Client {
-
- // Naming specific member variables
- private Queue cmtQ;
-
- private Queue cmtQTXNS;
-
- private Queue bmtQ;
-
- /* Run test in standalone mode */
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * Test setup:
- *
- * @class.setup_props: jms_timeout, in milliseconds - how long to wait on
- * synchronous receive; user;password;
- *
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- super.setup(args, p);
- try {
- cmtQ = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_CMT");
- cmtQTXNS = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUETXNS_CMT");
- bmtQ = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_BMT");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
-
- /*
- * @testName: Test1
- *
- * @assertion_ids: EJB:SPEC:529; EJB:SPEC:530; EJB:SPEC:547; EJB:SPEC:580;
- *
- * @test_Strategy: Invoke an bmt mdb by writing to MDB_QUEUE_BMT. The mdb
- * begins a jakarta.transaction.UserTransaction, then attempts a
- * MessageDrivenContext getRollBackOnly() method. Return verification message
- * that a java.lang.IllegalStateException was thrown.
- */
- public void Test1() throws Exception {
- String TestCase = "expTest1";
- int TestNum = 1;
- try {
- qSender = session.createSender(bmtQ);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test1 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test2
- *
- * @assertion_ids: EJB:SPEC:529; EJB:SPEC:530; EJB:SPEC:547; EJB:SPEC:580;
- *
- * @test_Strategy: Invoke an bmt mdb by writing to MDB_QUEUE_BMT. The mdb
- * begins a jakarta.transaction.UserTransaction, then attempts a
- * MessageDrivenContext setRollBackOnly() method. Return verification message
- * that a java.lang.IllegalStateException was thrown.
- *
- */
- public void Test2() throws Exception {
- String TestCase = "expTest2";
- int TestNum = 2;
- try {
-
- qSender = session.createSender(bmtQ);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test2 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test3
- *
- * @assertion_ids: EJB:SPEC:592; EJB:SPEC:602;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUETXNS_CMT. The mdb
- * attempts a MessageDrivenContext setRollBackOnly() method. Return
- * verification message that a java.lang.IllegalStateException was thrown.
- *
- */
- public void Test3() throws Exception {
- String TestCase = "expTest3";
- int TestNum = 3;
- try {
- qSender = session.createSender(cmtQTXNS);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test3 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test4
- *
- * @assertion_ids: EJB:SPEC:592; EJB:SPEC:602;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUETXNS_CMT. The mdb
- * attempts a MessageDrivenContext getRollBackOnly() method. Return
- * verification message that a java.lang.IllegalStateException was thrown.
- *
- */
- public void Test4() throws Exception {
- String TestCase = "expTest4";
- int TestNum = 4;
- try {
-
- qSender = session.createSender(cmtQTXNS);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test4 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test5
- *
- * @assertion_ids: EJB:SPEC:593; EJB:SPEC:603;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUETXNS_CMT The mdb
- * attempts a EJBContext getUserTransaction() method. Return verification
- * message that a java.lang.IllegalStateException was thrown.
- *
- */
- public void Test5() throws Exception {
- String TestCase = "expTest5";
- int TestNum = 5;
- try {
-
- qSender = session.createSender(cmtQTXNS);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test5 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test6
- *
- * @assertion_ids: EJB:SPEC:593; EJB:SPEC:603;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUE_CMT The mdb
- * attempts a EJBContext getUserTransaction() method. Return verification
- * message that a java.lang.IllegalStateException was thrown.
- *
- */
- public void Test6() throws Exception {
- String TestCase = "expTest6";
- int TestNum = 6;
- try {
-
- qSender = session.createSender(cmtQ);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test6 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test7
- *
- * @assertion_ids: EJB:SPEC:513;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUE_CMT. The mdb
- * attempts a EJBContext getCallerPrincipal() method.
- */
- public void Test7() throws Exception {
- String TestCase = "expTest7";
- int TestNum = 7;
- try {
-
- qSender = session.createSender(cmtQ);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test7 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test8
- *
- * @assertion_ids: EJB:SPEC:513;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUETXNS_CMT. The mdb
- * attempts a EJBContext getCallerPrincipal() method.
- */
- public void Test8() throws Exception {
- String TestCase = "expTest8";
- int TestNum = 8;
- try {
-
- qSender = session.createSender(cmtQTXNS);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test8 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test11
- *
- * @assertion_ids: EJB:SPEC:515; EJB:SPEC:531;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUE_CMT. The mdb
- * attempts a EJBContext getEJBHome() method. Return verification message that
- * a java.lang.IllegalStateException was thrown.
- *
- */
- public void Test11() throws Exception {
- String TestCase = "expTest11";
- int TestNum = 11;
- try {
-
- qSender = session.createSender(cmtQ);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test11 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test12
- *
- * @assertion_ids: EJB:SPEC:515; EJB:SPEC:531;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUETXNS_CMT. The mdb
- * attempts a EJBContext getEJBHome() method. Return verification message that
- * a java.lang.IllegalStateException was thrown.
- *
- */
- public void Test12() throws Exception {
- String TestCase = "expTest12";
- int TestNum = 12;
- try {
-
- qSender = session.createSender(cmtQTXNS);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test12 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test15
- *
- * @assertion_ids: EJB:SPEC:579;
- *
- * @test_Strategy: Invoke an bmt mdb by writing to MDB_QUEUE_BMT. The mdb
- * begins a jakarta.transaction.UserTransaction. The mdb begins another
- * jakarta.transaction.UserTransaction Verify that the container throws a
- * jakarta.transaction.NotSupportedException
- *
- */
- public void Test15() throws Exception {
- String TestCase = "expTest15";
- int TestNum = 15;
- try {
-
- qSender = session.createSender(bmtQ);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test15 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- use super cleanup */
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptQ/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptQ/MDBClientIT.java
new file mode 100644
index 0000000000..8ed7615742
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptQ/MDBClientIT.java
@@ -0,0 +1,403 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_exceptQ;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.tests.jms.commonee.Client;
+
+import jakarta.jms.Queue;
+
+
+public class MDBClientIT extends Client {
+
+ // Naming specific member variables
+ private Queue cmtQ;
+
+ private Queue cmtQTXNS;
+
+ private Queue bmtQ;
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /*
+ * Test setup:
+ *
+ * @class.setup_props: jms_timeout, in milliseconds - how long to wait on
+ * synchronous receive; user;password;
+ *
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ // super.setup();
+ try {
+ cmtQ = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_CMT");
+ cmtQTXNS = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUETXNS_CMT");
+ bmtQ = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_BMT");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+
+ /*
+ * @testName: Test1
+ *
+ * @assertion_ids: EJB:SPEC:529; EJB:SPEC:530; EJB:SPEC:547; EJB:SPEC:580;
+ *
+ * @test_Strategy: Invoke an bmt mdb by writing to MDB_QUEUE_BMT. The mdb begins
+ * a jakarta.transaction.UserTransaction, then attempts a MessageDrivenContext
+ * getRollBackOnly() method. Return verification message that a
+ * java.lang.IllegalStateException was thrown.
+ */
+ @Test
+ public void Test1() throws Exception {
+ String TestCase = "expTest1";
+ int TestNum = 1;
+ try {
+ qSender = session.createSender(bmtQ);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test1 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test2
+ *
+ * @assertion_ids: EJB:SPEC:529; EJB:SPEC:530; EJB:SPEC:547; EJB:SPEC:580;
+ *
+ * @test_Strategy: Invoke an bmt mdb by writing to MDB_QUEUE_BMT. The mdb begins
+ * a jakarta.transaction.UserTransaction, then attempts a MessageDrivenContext
+ * setRollBackOnly() method. Return verification message that a
+ * java.lang.IllegalStateException was thrown.
+ *
+ */
+ @Test
+ public void Test2() throws Exception {
+ String TestCase = "expTest2";
+ int TestNum = 2;
+ try {
+
+ qSender = session.createSender(bmtQ);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test2 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test3
+ *
+ * @assertion_ids: EJB:SPEC:592; EJB:SPEC:602;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUETXNS_CMT. The mdb
+ * attempts a MessageDrivenContext setRollBackOnly() method. Return verification
+ * message that a java.lang.IllegalStateException was thrown.
+ *
+ */
+ @Test
+ public void Test3() throws Exception {
+ String TestCase = "expTest3";
+ int TestNum = 3;
+ try {
+ qSender = session.createSender(cmtQTXNS);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test3 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test4
+ *
+ * @assertion_ids: EJB:SPEC:592; EJB:SPEC:602;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUETXNS_CMT. The mdb
+ * attempts a MessageDrivenContext getRollBackOnly() method. Return verification
+ * message that a java.lang.IllegalStateException was thrown.
+ *
+ */
+ @Test
+ public void Test4() throws Exception {
+ String TestCase = "expTest4";
+ int TestNum = 4;
+ try {
+
+ qSender = session.createSender(cmtQTXNS);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test4 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test5
+ *
+ * @assertion_ids: EJB:SPEC:593; EJB:SPEC:603;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUETXNS_CMT The mdb
+ * attempts a EJBContext getUserTransaction() method. Return verification
+ * message that a java.lang.IllegalStateException was thrown.
+ *
+ */
+ @Test
+ public void Test5() throws Exception {
+ String TestCase = "expTest5";
+ int TestNum = 5;
+ try {
+
+ qSender = session.createSender(cmtQTXNS);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test5 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test6
+ *
+ * @assertion_ids: EJB:SPEC:593; EJB:SPEC:603;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUE_CMT The mdb
+ * attempts a EJBContext getUserTransaction() method. Return verification
+ * message that a java.lang.IllegalStateException was thrown.
+ *
+ */
+ @Test
+ public void Test6() throws Exception {
+ String TestCase = "expTest6";
+ int TestNum = 6;
+ try {
+
+ qSender = session.createSender(cmtQ);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test6 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test7
+ *
+ * @assertion_ids: EJB:SPEC:513;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUE_CMT. The mdb
+ * attempts a EJBContext getCallerPrincipal() method.
+ */
+ @Test
+ public void Test7() throws Exception {
+ String TestCase = "expTest7";
+ int TestNum = 7;
+ try {
+
+ qSender = session.createSender(cmtQ);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test7 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test8
+ *
+ * @assertion_ids: EJB:SPEC:513;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUETXNS_CMT. The mdb
+ * attempts a EJBContext getCallerPrincipal() method.
+ */
+ @Test
+ public void Test8() throws Exception {
+ String TestCase = "expTest8";
+ int TestNum = 8;
+ try {
+
+ qSender = session.createSender(cmtQTXNS);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test8 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test11
+ *
+ * @assertion_ids: EJB:SPEC:515; EJB:SPEC:531;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUE_CMT. The mdb
+ * attempts a EJBContext getEJBHome() method. Return verification message that a
+ * java.lang.IllegalStateException was thrown.
+ *
+ */
+ @Test
+ public void Test11() throws Exception {
+ String TestCase = "expTest11";
+ int TestNum = 11;
+ try {
+
+ qSender = session.createSender(cmtQ);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test11 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test12
+ *
+ * @assertion_ids: EJB:SPEC:515; EJB:SPEC:531;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_QUEUETXNS_CMT. The mdb
+ * attempts a EJBContext getEJBHome() method. Return verification message that a
+ * java.lang.IllegalStateException was thrown.
+ *
+ */
+ @Test
+ public void Test12() throws Exception {
+ String TestCase = "expTest12";
+ int TestNum = 12;
+ try {
+
+ qSender = session.createSender(cmtQTXNS);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test12 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test15
+ *
+ * @assertion_ids: EJB:SPEC:579;
+ *
+ * @test_Strategy: Invoke an bmt mdb by writing to MDB_QUEUE_BMT. The mdb begins
+ * a jakarta.transaction.UserTransaction. The mdb begins another
+ * jakarta.transaction.UserTransaction Verify that the container throws a
+ * jakarta.transaction.NotSupportedException
+ *
+ */
+ @Test
+ public void Test15() throws Exception {
+ String TestCase = "expTest15";
+ int TestNum = 15;
+ try {
+
+ qSender = session.createSender(bmtQ);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test15 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- use super cleanup */
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptQ/MsgBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptQ/MsgBean.java
index 9be015e9a6..1c3974d945 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptQ/MsgBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptQ/MsgBean.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_exceptQ;
+import java.lang.System.Logger;
import java.security.Principal;
import com.sun.ts.lib.util.TestUtil;
@@ -33,242 +34,235 @@
public class MsgBean extends ParentMsgBeanNoTx {
- protected void runTests(Message msg, QueueSession qSession, String testName,
- java.util.Properties p) {
- try {
- // test to see if this is the first message
- if (msg.getIntProperty("TestCaseNum") > 0) {
-
- switch (msg.getIntProperty("TestCaseNum")) {
-
- case 1: // MDB Queue w/ BMT demarcation
- runGetRollbackOnlyBMT(msg, qSession, testName);
- break;
-
- case 2: // MDB Queue w/ BMT demarcation
- runSetRollbackOnlyBMT(msg, qSession, testName);
- break;
-
- case 3: // MDB Queue w/CMT - TX_NOT_SUPPORTED
- runSetRollbackOnlyCMT(msg, qSession, testName);
- break;
-
- case 4: // MDB Queue w/CMT - TX_NOT_SUPPORTED
- runGetRollbackOnlyCMT(msg, qSession, testName);
- break;
-
- case 5: // MDB Queue w/CMT - TX_NOT_SUPPORTED
- case 6: // MDB Queue w/CMT
- runGetUserTransaction(msg, qSession, testName);
- break;
-
- case 7: // MDB Queue w/CMT
- case 8: // MDB Queue w/CMT - TX_NOT_SUPPORTED
- runGetCallerPrincipal(msg, qSession, testName);
- break;
-
- case 11: // MDB Queue w/CMT
- case 12: // MDB Queue w/CMT - TX_NOT_SUPPORTED
- runGetEJBHome(msg, qSession, testName);
- break;
-
- case 15: // MDB Queue w/ BMT demarcation
- runBeginAgain(msg, qSession, testName);
- break;
-
- default:
- TestUtil.logErr("Error in mdb - ");
- TestUtil.logErr("No test match for TestCaseNum: "
- + msg.getIntProperty("TestCaseNum"));
- break;
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }// runTests
-
- // MDB_QUEUE_BMT getRollbackOnly
- public void runGetRollbackOnlyBMT(Message msg, QueueSession qSession,
- String testName) {
-
- result = false;
-
- try {
-
- // get beanManagedTx
- UserTransaction ut = mdc.getUserTransaction();
- ut.begin();
-
- // this should throw an exception
- try {
- mdc.getRollbackOnly();
-
- TestUtil.logErr("BMT MDB getRollbackOnly() Test Failed!");
- } catch (java.lang.IllegalStateException e) {
- result = true;
- TestUtil.logTrace("BMT MDB getRollbackOnly() Test Succeeded!");
- TestUtil.logTrace("Got expected IllegalStateException");
- }
-
- ut.rollback();
-
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception: ", e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- // MDB_QUEUE_BMT setRollbackOnly
- public void runSetRollbackOnlyBMT(Message msg, QueueSession qSession,
- String testName) {
- result = false;
- try {
-
- // get beanManagedTx
- UserTransaction ut = mdc.getUserTransaction();
-
- ut.begin();
-
- // this should throw an exception
- try {
- mdc.setRollbackOnly();
-
- TestUtil.logErr("BMT MDB setRollbackOnly() Test Failed!");
- // send a message to MDB_QUEUE_REPLY.
- } catch (java.lang.IllegalStateException e) {
- TestUtil.logTrace("BMT MDB setRollbackOnly() Test Succeeded!");
- TestUtil.logTrace("Got expected IllegalStateException");
- result = true;
- }
- ut.rollback();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception: ", e);
- }
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- // MDB_NSTX_CMT setRollbackOnly
- public void runSetRollbackOnlyCMT(Message msg, QueueSession qSession,
- String testName) {
-
- result = false;
-
- // this should throw an exception
- try {
- mdc.setRollbackOnly();
-
- TestUtil.logErr("CMT MDB setRollbackOnly() Test Failed!");
- } catch (java.lang.IllegalStateException e) {
- TestUtil.logTrace("CMT MDB setRollbackOnly() Test Succeeded!");
- TestUtil.logTrace("Got expected IllegalStateException");
- result = true;
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception: ", e);
- }
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- public void runGetRollbackOnlyCMT(Message msg, QueueSession qSession,
- String testName) {
- result = false;
-
- // this should throw an exception
- try {
- mdc.getRollbackOnly();
-
- TestUtil.logErr("CMT MDB getRollbackOnly() Test Failed!");
- } catch (java.lang.IllegalStateException e) {
- TestUtil.logTrace("CMT MDB getRollbackOnly() Test Succeeded!");
- TestUtil.logTrace("Got expected IllegalStateException");
- result = true;
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception: ", e);
- }
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- // MDB_NSTX_CMT getUserTransaction
- public void runGetUserTransaction(Message msg, QueueSession qSession,
- String testName) {
- result = false;
-
- // this should throw an exception
- try {
- UserTransaction ut = mdc.getUserTransaction();
-
- TestUtil.logErr("CMT MDB getUserTransaction() Test Failed!");
- } catch (java.lang.IllegalStateException e) {
- TestUtil.logTrace("CMT MDB getUserTransaction() Test Succeeded!");
- TestUtil.logTrace("Got expected IllegalStateException");
- result = true;
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception: ", e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- public void runGetCallerPrincipal(Message msg, QueueSession qSession,
- String testName) {
- result = false;
-
- try {
- Principal cp = mdc.getCallerPrincipal();
- TestUtil.logTrace("CMT MDB getCallerPrincipal() Test Succeeded!");
- result = true;
- } catch (Exception e) {
- TestUtil.logErr("CMT MDB getCallerPrincipal() Test Failed!", e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- public void runGetEJBHome(Message msg, QueueSession qSession,
- String testName) {
- result = false;
-
- // this should throw an exception
- try {
- EJBHome home = mdc.getEJBHome();
-
- TestUtil.logErr("CMT MDB getEJBHome() Test Failed!");
- } catch (java.lang.IllegalStateException e) {
- TestUtil.logTrace("CMT MDB getEJBHome() Test Succeeded!");
- TestUtil.logTrace("Got expected IllegalStateException");
- result = true;
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception: ", e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- public void runBeginAgain(Message msg, QueueSession qSession,
- String testName) {
- try {
-
- // get beanManagedTx
- UserTransaction ut = mdc.getUserTransaction();
-
- ut.begin();
-
- // this should throw an exception
- try {
- ut.begin();
- TestUtil.logErr("BMT MDB getBeginAgain() Test Failed!");
- } catch (jakarta.transaction.NotSupportedException e) {
- TestUtil.logTrace("BMT MDB getBeginAgain() Test Succeeded!");
- TestUtil.logTrace("Got expected NotSupportedException");
- result = true;
- }
- ut.rollback();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception: ", e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
+ private static final Logger logger = (Logger) System.getLogger(MsgBean.class.getName());
+
+ protected void runTests(Message msg, QueueSession qSession, String testName, java.util.Properties p) {
+ try {
+ // test to see if this is the first message
+ if (msg.getIntProperty("TestCaseNum") > 0) {
+
+ switch (msg.getIntProperty("TestCaseNum")) {
+
+ case 1: // MDB Queue w/ BMT demarcation
+ runGetRollbackOnlyBMT(msg, qSession, testName);
+ break;
+
+ case 2: // MDB Queue w/ BMT demarcation
+ runSetRollbackOnlyBMT(msg, qSession, testName);
+ break;
+
+ case 3: // MDB Queue w/CMT - TX_NOT_SUPPORTED
+ runSetRollbackOnlyCMT(msg, qSession, testName);
+ break;
+
+ case 4: // MDB Queue w/CMT - TX_NOT_SUPPORTED
+ runGetRollbackOnlyCMT(msg, qSession, testName);
+ break;
+
+ case 5: // MDB Queue w/CMT - TX_NOT_SUPPORTED
+ case 6: // MDB Queue w/CMT
+ runGetUserTransaction(msg, qSession, testName);
+ break;
+
+ case 7: // MDB Queue w/CMT
+ case 8: // MDB Queue w/CMT - TX_NOT_SUPPORTED
+ runGetCallerPrincipal(msg, qSession, testName);
+ break;
+
+ case 11: // MDB Queue w/CMT
+ case 12: // MDB Queue w/CMT - TX_NOT_SUPPORTED
+ runGetEJBHome(msg, qSession, testName);
+ break;
+
+ case 15: // MDB Queue w/ BMT demarcation
+ runBeginAgain(msg, qSession, testName);
+ break;
+
+ default:
+ logger.log(Logger.Level.ERROR, "Error in mdb - ");
+ logger.log(Logger.Level.ERROR,
+ "No test match for TestCaseNum: " + msg.getIntProperty("TestCaseNum"));
+ break;
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }// runTests
+
+ // MDB_QUEUE_BMT getRollbackOnly
+ public void runGetRollbackOnlyBMT(Message msg, QueueSession qSession, String testName) {
+
+ result = false;
+
+ try {
+
+ // get beanManagedTx
+ UserTransaction ut = mdc.getUserTransaction();
+ ut.begin();
+
+ // this should throw an exception
+ try {
+ mdc.getRollbackOnly();
+
+ logger.log(Logger.Level.ERROR, "BMT MDB getRollbackOnly() Test Failed!");
+ } catch (java.lang.IllegalStateException e) {
+ result = true;
+ logger.log(Logger.Level.TRACE, "BMT MDB getRollbackOnly() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected IllegalStateException");
+ }
+
+ ut.rollback();
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception: ", e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ // MDB_QUEUE_BMT setRollbackOnly
+ public void runSetRollbackOnlyBMT(Message msg, QueueSession qSession, String testName) {
+ result = false;
+ try {
+
+ // get beanManagedTx
+ UserTransaction ut = mdc.getUserTransaction();
+
+ ut.begin();
+
+ // this should throw an exception
+ try {
+ mdc.setRollbackOnly();
+
+ logger.log(Logger.Level.ERROR, "BMT MDB setRollbackOnly() Test Failed!");
+ // send a message to MDB_QUEUE_REPLY.
+ } catch (java.lang.IllegalStateException e) {
+ logger.log(Logger.Level.TRACE, "BMT MDB setRollbackOnly() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected IllegalStateException");
+ result = true;
+ }
+ ut.rollback();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception: ", e);
+ }
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ // MDB_NSTX_CMT setRollbackOnly
+ public void runSetRollbackOnlyCMT(Message msg, QueueSession qSession, String testName) {
+
+ result = false;
+
+ // this should throw an exception
+ try {
+ mdc.setRollbackOnly();
+
+ logger.log(Logger.Level.ERROR, "CMT MDB setRollbackOnly() Test Failed!");
+ } catch (java.lang.IllegalStateException e) {
+ logger.log(Logger.Level.TRACE, "CMT MDB setRollbackOnly() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected IllegalStateException");
+ result = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception: ", e);
+ }
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ public void runGetRollbackOnlyCMT(Message msg, QueueSession qSession, String testName) {
+ result = false;
+
+ // this should throw an exception
+ try {
+ mdc.getRollbackOnly();
+
+ logger.log(Logger.Level.ERROR, "CMT MDB getRollbackOnly() Test Failed!");
+ } catch (java.lang.IllegalStateException e) {
+ logger.log(Logger.Level.TRACE, "CMT MDB getRollbackOnly() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected IllegalStateException");
+ result = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception: ", e);
+ }
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ // MDB_NSTX_CMT getUserTransaction
+ public void runGetUserTransaction(Message msg, QueueSession qSession, String testName) {
+ result = false;
+
+ // this should throw an exception
+ try {
+ UserTransaction ut = mdc.getUserTransaction();
+
+ logger.log(Logger.Level.ERROR, "CMT MDB getUserTransaction() Test Failed!");
+ } catch (java.lang.IllegalStateException e) {
+ logger.log(Logger.Level.TRACE, "CMT MDB getUserTransaction() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected IllegalStateException");
+ result = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception: ", e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ public void runGetCallerPrincipal(Message msg, QueueSession qSession, String testName) {
+ result = false;
+
+ try {
+ Principal cp = mdc.getCallerPrincipal();
+ logger.log(Logger.Level.TRACE, "CMT MDB getCallerPrincipal() Test Succeeded!");
+ result = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CMT MDB getCallerPrincipal() Test Failed!", e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ public void runGetEJBHome(Message msg, QueueSession qSession, String testName) {
+ result = false;
+
+ // this should throw an exception
+ try {
+ EJBHome home = mdc.getEJBHome();
+
+ logger.log(Logger.Level.ERROR, "CMT MDB getEJBHome() Test Failed!");
+ } catch (java.lang.IllegalStateException e) {
+ logger.log(Logger.Level.TRACE, "CMT MDB getEJBHome() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected IllegalStateException");
+ result = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception: ", e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ public void runBeginAgain(Message msg, QueueSession qSession, String testName) {
+ try {
+
+ // get beanManagedTx
+ UserTransaction ut = mdc.getUserTransaction();
+
+ ut.begin();
+
+ // this should throw an exception
+ try {
+ ut.begin();
+ logger.log(Logger.Level.ERROR, "BMT MDB getBeginAgain() Test Failed!");
+ } catch (jakarta.transaction.NotSupportedException e) {
+ logger.log(Logger.Level.TRACE, "BMT MDB getBeginAgain() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected NotSupportedException");
+ result = true;
+ }
+ ut.rollback();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception: ", e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptT/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptT/MDBClient.java
deleted file mode 100644
index c20b63c90f..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptT/MDBClient.java
+++ /dev/null
@@ -1,386 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_exceptT;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.tests.jms.commonee.Client;
-
-import jakarta.jms.Topic;
-
-public class MDBClient extends Client {
-
- private Topic bmtT;
-
- private Topic cmtTTXNS;
-
- private Topic cmtT;
-
- /* Run test in standalone mode */
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout, in milliseconds - how long to wait on
- * synchronous receive; user;password;
- *
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- super.setup(args, p);
- try {
- bmtT = (Topic) context.lookup("java:comp/env/jms/MDB_DURABLE_BMT");
- cmtTTXNS = (Topic) context
- .lookup("java:comp/env/jms/MDB_DURABLETXNS_CMT");
- cmtT = (Topic) context.lookup("java:comp/env/jms/MDB_DURABLE_CMT");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
- /*
- * @testName: Test1
- *
- * @assertion_ids: EJB:SPEC:529; EJB:SPEC:530; EJB:SPEC:547; EJB:SPEC:580;
- *
- * @test_Strategy: Invoke an bmt mdb by writing to MDB_DURABLE_BMT. The mdb
- * begins a jakarta.transaction.UserTransaction, then attempts a
- * MessageDrivenContext getRollBackOnly() method. Return verification message
- * that a java.lang.IllegalStateException was thrown.
- */
- public void Test1() throws Exception {
- String TestCase = "expTest1";
- int TestNum = 1;
- try {
- tPub = tSession.createPublisher(bmtT);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test1 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test2
- *
- * @assertion_ids: EJB:SPEC:529; EJB:SPEC:530; EJB:SPEC:547; EJB:SPEC:580;
- *
- * @test_Strategy: Invoke an bmt mdb by writing to MDB_DURABLE_BMT. The mdb
- * begins a jakarta.transaction.UserTransaction, then attempts a
- * MessageDrivenContext setRollBackOnly() method. Return verification message
- * that a java.lang.IllegalStateException was thrown.
- *
- */
- public void Test2() throws Exception {
- String TestCase = "expTest2";
- int TestNum = 2;
- try {
- tPub = tSession.createPublisher(bmtT);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test2 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test3
- *
- * @assertion_ids: EJB:SPEC:592; EJB:SPEC:602;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLETXNS_CMT The mdb
- * attempts a MessageDrivenContext setRollBackOnly() method. Return
- * verification message that a java.lang.IllegalStateException was thrown.
- *
- */
- public void Test3() throws Exception {
- String TestCase = "expTest3";
- int TestNum = 3;
- try {
- tPub = tSession.createPublisher(cmtTTXNS);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test3 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test4
- *
- * @assertion_ids: EJB:SPEC:592; EJB:SPEC:602;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLETXNS_CMT. The
- * mdb attempts a MessageDrivenContext setRollBackOnly() method. Return
- * verification message that a java.lang.IllegalStateException was thrown.
- *
- */
- public void Test4() throws Exception {
- String TestCase = "expTest4";
- int TestNum = 4;
- try {
- tPub = tSession.createPublisher(cmtTTXNS);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test4 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test5
- *
- * @assertion_ids: EJB:SPEC:593; EJB:SPEC:603;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLETXNS_CMT The mdb
- * attempts a EJBContext getUserTransaction() method. Return verification
- * message that a java.lang.IllegalStateException was thrown.
- *
- */
- public void Test5() throws Exception {
- String TestCase = "expTest5";
- int TestNum = 5;
- try {
- tPub = tSession.createPublisher(cmtTTXNS);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test5 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test6
- *
- * @assertion_ids: EJB:SPEC:593; EJB:SPEC:603;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLE_CMT The mdb
- * attempts a EJBContext getUserTransaction() method. Return verification
- * message that a java.lang.IllegalStateException was thrown.
- */
- public void Test6() throws Exception {
- String TestCase = "expTest6";
- int TestNum = 6;
- try {
-
- tPub = tSession.createPublisher(cmtT);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test6 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test7
- *
- * @assertion_ids: EJB:SPEC:513;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLE_CMT The mdb
- * attempts a EJBContext getCallerPrincipal() method.
- */
- public void Test7() throws Exception {
- String TestCase = "expTest7";
- int TestNum = 7;
- try {
-
- tPub = tSession.createPublisher(cmtT);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test7 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test8
- *
- * @assertion_ids: EJB:SPEC:513;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLETXNS_CMT The mdb
- * attempts a EJBContext getCallerPrincipal() method.
- */
- public void Test8() throws Exception {
- String TestCase = "expTest8";
- int TestNum = 8;
- try {
-
- tPub = tSession.createPublisher(cmtTTXNS);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test8 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test11
- *
- * @assertion_ids: EJB:SPEC:515; EJB:SPEC:531;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLE_CMT The mdb
- * attempts a EJBContext getEJBHome() method. Return verification message that
- * a java.lang.IllegalStateException was thrown.
- */
-
- public void Test11() throws Exception {
- String TestCase = "expTest11";
- int TestNum = 11;
- try {
-
- tPub = tSession.createPublisher(cmtT);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test11 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test12
- *
- * @assertion_ids: EJB:SPEC:515; EJB:SPEC:531;
- *
- * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLETXNS_CMT The mdb
- * attempts a EJBContext getEJBHome() method. Return verification message that
- * a java.lang.IllegalStateException was thrown.
- */
-
- public void Test12() throws Exception {
- String TestCase = "expTest12";
- int TestNum = 12;
- try {
- tPub = tSession.createPublisher(cmtTTXNS);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test12 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test13
- *
- * @assertion_ids: EJB:SPEC:579;
- *
- * @test_Strategy: Invoke an bmt mdb by writing to MDB_DURABLE_BMT. The mdb
- * begins a jakarta.transaction.UserTransaction. The mdb begins another
- * jakarta.transaction.UserTransaction Verify that the container throws a
- * jakarta.transaction.NotSupportedException
- */
- public void Test13() throws Exception {
- String TestCase = "expTest13";
- int TestNum = 13;
- try {
-
- tPub = tSession.createPublisher(bmtT);
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test13 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- use super cleanup */
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptT/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptT/MDBClientIT.java
new file mode 100644
index 0000000000..ceab4ca9d9
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptT/MDBClientIT.java
@@ -0,0 +1,391 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_exceptT;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.tests.jms.commonee.Client;
+
+import jakarta.jms.Topic;
+
+
+public class MDBClientIT extends Client {
+
+ private Topic bmtT;
+
+ private Topic cmtTTXNS;
+
+ private Topic cmtT;
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout, in milliseconds - how long to wait on
+ * synchronous receive; user;password;
+ *
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ bmtT = (Topic) context.lookup("java:comp/env/jms/MDB_DURABLE_BMT");
+ cmtTTXNS = (Topic) context.lookup("java:comp/env/jms/MDB_DURABLETXNS_CMT");
+ cmtT = (Topic) context.lookup("java:comp/env/jms/MDB_DURABLE_CMT");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+ /*
+ * @testName: Test1
+ *
+ * @assertion_ids: EJB:SPEC:529; EJB:SPEC:530; EJB:SPEC:547; EJB:SPEC:580;
+ *
+ * @test_Strategy: Invoke an bmt mdb by writing to MDB_DURABLE_BMT. The mdb
+ * begins a jakarta.transaction.UserTransaction, then attempts a
+ * MessageDrivenContext getRollBackOnly() method. Return verification message
+ * that a java.lang.IllegalStateException was thrown.
+ */
+ @Test
+ public void Test1() throws Exception {
+ String TestCase = "expTest1";
+ int TestNum = 1;
+ try {
+ tPub = tSession.createPublisher(bmtT);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test1 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test2
+ *
+ * @assertion_ids: EJB:SPEC:529; EJB:SPEC:530; EJB:SPEC:547; EJB:SPEC:580;
+ *
+ * @test_Strategy: Invoke an bmt mdb by writing to MDB_DURABLE_BMT. The mdb
+ * begins a jakarta.transaction.UserTransaction, then attempts a
+ * MessageDrivenContext setRollBackOnly() method. Return verification message
+ * that a java.lang.IllegalStateException was thrown.
+ *
+ */
+ @Test
+ public void Test2() throws Exception {
+ String TestCase = "expTest2";
+ int TestNum = 2;
+ try {
+ tPub = tSession.createPublisher(bmtT);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test2 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test3
+ *
+ * @assertion_ids: EJB:SPEC:592; EJB:SPEC:602;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLETXNS_CMT The mdb
+ * attempts a MessageDrivenContext setRollBackOnly() method. Return verification
+ * message that a java.lang.IllegalStateException was thrown.
+ *
+ */
+ @Test
+ public void Test3() throws Exception {
+ String TestCase = "expTest3";
+ int TestNum = 3;
+ try {
+ tPub = tSession.createPublisher(cmtTTXNS);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test3 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test4
+ *
+ * @assertion_ids: EJB:SPEC:592; EJB:SPEC:602;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLETXNS_CMT. The mdb
+ * attempts a MessageDrivenContext setRollBackOnly() method. Return verification
+ * message that a java.lang.IllegalStateException was thrown.
+ *
+ */
+ @Test
+ public void Test4() throws Exception {
+ String TestCase = "expTest4";
+ int TestNum = 4;
+ try {
+ tPub = tSession.createPublisher(cmtTTXNS);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test4 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test5
+ *
+ * @assertion_ids: EJB:SPEC:593; EJB:SPEC:603;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLETXNS_CMT The mdb
+ * attempts a EJBContext getUserTransaction() method. Return verification
+ * message that a java.lang.IllegalStateException was thrown.
+ *
+ */
+ @Test
+ public void Test5() throws Exception {
+ String TestCase = "expTest5";
+ int TestNum = 5;
+ try {
+ tPub = tSession.createPublisher(cmtTTXNS);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test5 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test6
+ *
+ * @assertion_ids: EJB:SPEC:593; EJB:SPEC:603;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLE_CMT The mdb
+ * attempts a EJBContext getUserTransaction() method. Return verification
+ * message that a java.lang.IllegalStateException was thrown.
+ */
+ @Test
+ public void Test6() throws Exception {
+ String TestCase = "expTest6";
+ int TestNum = 6;
+ try {
+
+ tPub = tSession.createPublisher(cmtT);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test6 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test7
+ *
+ * @assertion_ids: EJB:SPEC:513;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLE_CMT The mdb
+ * attempts a EJBContext getCallerPrincipal() method.
+ */
+ @Test
+ public void Test7() throws Exception {
+ String TestCase = "expTest7";
+ int TestNum = 7;
+ try {
+
+ tPub = tSession.createPublisher(cmtT);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test7 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test8
+ *
+ * @assertion_ids: EJB:SPEC:513;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLETXNS_CMT The mdb
+ * attempts a EJBContext getCallerPrincipal() method.
+ */
+ @Test
+ public void Test8() throws Exception {
+ String TestCase = "expTest8";
+ int TestNum = 8;
+ try {
+
+ tPub = tSession.createPublisher(cmtTTXNS);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test8 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test11
+ *
+ * @assertion_ids: EJB:SPEC:515; EJB:SPEC:531;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLE_CMT The mdb
+ * attempts a EJBContext getEJBHome() method. Return verification message that a
+ * java.lang.IllegalStateException was thrown.
+ */
+ @Test
+ public void Test11() throws Exception {
+ String TestCase = "expTest11";
+ int TestNum = 11;
+ try {
+
+ tPub = tSession.createPublisher(cmtT);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test11 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test12
+ *
+ * @assertion_ids: EJB:SPEC:515; EJB:SPEC:531;
+ *
+ * @test_Strategy: Invoke an cmt mdb by writing to MDB_DURABLETXNS_CMT The mdb
+ * attempts a EJBContext getEJBHome() method. Return verification message that a
+ * java.lang.IllegalStateException was thrown.
+ */
+ @Test
+ public void Test12() throws Exception {
+ String TestCase = "expTest12";
+ int TestNum = 12;
+ try {
+ tPub = tSession.createPublisher(cmtTTXNS);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test12 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test13
+ *
+ * @assertion_ids: EJB:SPEC:579;
+ *
+ * @test_Strategy: Invoke an bmt mdb by writing to MDB_DURABLE_BMT. The mdb
+ * begins a jakarta.transaction.UserTransaction. The mdb begins another
+ * jakarta.transaction.UserTransaction Verify that the container throws a
+ * jakarta.transaction.NotSupportedException
+ */
+ @Test
+ public void Test13() throws Exception {
+ String TestCase = "expTest13";
+ int TestNum = 13;
+ try {
+
+ tPub = tSession.createPublisher(bmtT);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test13 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- use super cleanup */
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptT/MsgBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptT/MsgBean.java
index b3c394bb0a..0e2c918302 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptT/MsgBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_exceptT/MsgBean.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_exceptT;
+import java.lang.System.Logger;
import java.security.Principal;
import com.sun.ts.lib.util.TestUtil;
@@ -33,243 +34,236 @@
public class MsgBean extends ParentMsgBeanNoTx {
- protected void runTests(Message msg, QueueSession qSession, String testName,
- java.util.Properties p) {
-
- try {
- // test to see if this is the first message
- if (msg.getIntProperty("TestCaseNum") > 0) {
-
- switch (msg.getIntProperty("TestCaseNum")) {
-
- case 1: // MDB Durable Topic w/BMT demarcation
- runGetRollbackOnlyBMT(msg, qSession, testName);
- break;
-
- case 2: // MDB Durable Topic w/BMT demarcation
- runSetRollbackOnlyBMT(msg, qSession, testName);
- break;
-
- case 3: // MDB Durable Topic w/CMT - TX_NOT_SUPPORTED
- runSetRollbackOnlyCMT(msg, qSession, testName);
- break;
-
- case 4: // MDB Durable Topic w/CMT - TX_NOT_SUPPORTED
- runGetRollbackOnlyCMT(msg, qSession, testName);
- break;
-
- case 5: // MDB Durable Topic w/CMT - TX_NOT_SUPPORTED
- case 6: // MDB Durable Topic w/CMT
- runGetUserTransaction(msg, qSession, testName);
- break;
-
- case 7: // MDB Durable Topic w/CMT
- case 8: // MDB Durable Topic w/CMT - TX_NOT_SUPPORTED
- runGetCallerPrincipal(msg, qSession, testName);
- break;
-
- case 11: // MDB Durable Topic w/CMT
- case 12: // MDB Durable Topic w/CMT - TX_NOT_SUPPORTED
- runGetEJBHome(msg, qSession, testName);
- break;
-
- case 13: // MDB Durable Topic w/BMT demarcation
- runBeginAgain(msg, qSession, testName);
- break;
-
- default:
- TestUtil.logTrace("Error in mdb - ");
- TestUtil.logTrace("No test match for TestCaseNum: "
- + msg.getIntProperty("TestCaseNum"));
- break;
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }// runTests
-
- // MDB_QUEUE_BMT getRollbackOnly
- public void runGetRollbackOnlyBMT(Message msg, QueueSession qSession,
- String testName) {
- result = false;
- try {
-
- // get beanManagedTx
- UserTransaction ut = mdc.getUserTransaction();
-
- ut.begin();
-
- // this should throw an exception
- try {
- mdc.getRollbackOnly();
- TestUtil.logErr("BMT MDB getRollbackOnly() Test Failed!");
- } catch (java.lang.IllegalStateException e) {
- TestUtil.logTrace("BMT MDB getRollbackOnly() Test Succeeded!");
- TestUtil.logTrace("Got expected IllegalStateException!");
- result = true;
- }
- ut.rollback();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected Exception: ", e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- // MDB_QUEUE_BMT setRollbackOnly
- public void runSetRollbackOnlyBMT(Message msg, QueueSession qSession,
- String testName) {
-
- result = false;
-
- try {
-
- // get beanManagedTx
- UserTransaction ut = mdc.getUserTransaction();
-
- ut.begin();
-
- // this should throw an exception
- try {
- mdc.setRollbackOnly();
-
- TestUtil.logErr("BMT MDB setRollbackOnly() Test Failed!");
- } catch (java.lang.IllegalStateException e) {
- TestUtil.logTrace("BMT MDB setRollbackOnly() Test Succeeded!");
- TestUtil.logTrace("Got expected IllegalStateException!");
- result = true;
- }
- ut.rollback();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected Exception: ", e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- // MDB_NSTX_CMT setRollbackOnly
- public void runSetRollbackOnlyCMT(Message msg, QueueSession qSession,
- String testName) {
- result = false;
-
- // this should throw an exception
- try {
- mdc.setRollbackOnly();
-
- TestUtil.logErr("CMT MDB setRollbackOnly() Test Failed!");
- } catch (java.lang.IllegalStateException e) {
- TestUtil.logTrace("CMT MDB setRollbackOnly() Test Succeeded!");
- TestUtil.logTrace("Got expected IllegalStateException!");
- result = true;
- } catch (Exception e) {
- TestUtil.logErr("Unexpected Exception: ", e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- public void runGetRollbackOnlyCMT(Message msg, QueueSession qSession,
- String testName) {
-
- // this should throw an exception
- try {
- mdc.getRollbackOnly();
-
- TestUtil.logErr("CMT MDB getRollbackOnly() Test Failed!");
- } catch (java.lang.IllegalStateException e) {
- TestUtil.logTrace("CMT MDB getRollbackOnly() Test Succeeded!");
- TestUtil.logTrace("Got expected IllegalStateException!");
- result = true;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- // MDB_NSTX_CMT getUserTransaction
- public void runGetUserTransaction(Message msg, QueueSession qSession,
- String testName) {
-
- result = false;
- // this should throw an exception
- try {
- UserTransaction ut = mdc.getUserTransaction();
-
- TestUtil.logErr("CMT MDB getUserTransaction() Test Failed!");
- } catch (java.lang.IllegalStateException e) {
- TestUtil.logTrace("CMT MDB getUserTransaction() Test Succeeded!");
- TestUtil.logTrace("Got expected IllegalStateException!");
- result = true;
- } catch (Exception e) {
- TestUtil.logErr("Unexpected Exception: ", e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- public void runGetCallerPrincipal(Message msg, QueueSession qSession,
- String testName) {
- result = false;
-
- try {
- Principal cp = mdc.getCallerPrincipal();
- TestUtil.logTrace("CMT MDB getCallerPrincipal() Test Succeeded!");
- result = true;
- } catch (Exception e) {
- TestUtil.logErr("CMT MDB getCallerPrincipal() Test Failed!", e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- public void runGetEJBHome(Message msg, QueueSession qSession,
- String testName) {
- result = false;
-
- // this should throw an exception
- try {
- EJBHome home = mdc.getEJBHome();
-
- TestUtil.logErr("CMT MDB getEJBHome() Test Failed!");
- // rollback the message
- } catch (java.lang.IllegalStateException e) {
- TestUtil.logTrace("CMT MDB getEJBHome() Test Succeeded!");
- TestUtil.logTrace("Got expected IllegalStateException!");
- result = true;
- } catch (Exception e) {
- TestUtil.logErr("Unexpected Exception: ", e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
-
- public void runBeginAgain(Message msg, QueueSession qSession,
- String testName) {
- result = false;
- try {
-
- // get beanManagedTx
- UserTransaction ut = mdc.getUserTransaction();
-
- ut.begin();
-
- // this should throw an exception
- try {
- ut.begin();
- TestUtil.logErr("BMT MDB getRollbackOnly() Test Failed!");
- } catch (jakarta.transaction.NotSupportedException e) {
- TestUtil.logTrace("BMT MDB getRollbackOnly() Test Succeeded!");
- TestUtil.logTrace("Got expected NotSupportedException!");
- result = true;
- }
- ut.rollback();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected Exception: ", e);
- }
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults(testName, result, qSession, queueR);
- }
+ private static final Logger logger = (Logger) System.getLogger(MsgBean.class.getName());
+
+ protected void runTests(Message msg, QueueSession qSession, String testName, java.util.Properties p) {
+
+ try {
+ // test to see if this is the first message
+ if (msg.getIntProperty("TestCaseNum") > 0) {
+
+ switch (msg.getIntProperty("TestCaseNum")) {
+
+ case 1: // MDB Durable Topic w/BMT demarcation
+ runGetRollbackOnlyBMT(msg, qSession, testName);
+ break;
+
+ case 2: // MDB Durable Topic w/BMT demarcation
+ runSetRollbackOnlyBMT(msg, qSession, testName);
+ break;
+
+ case 3: // MDB Durable Topic w/CMT - TX_NOT_SUPPORTED
+ runSetRollbackOnlyCMT(msg, qSession, testName);
+ break;
+
+ case 4: // MDB Durable Topic w/CMT - TX_NOT_SUPPORTED
+ runGetRollbackOnlyCMT(msg, qSession, testName);
+ break;
+
+ case 5: // MDB Durable Topic w/CMT - TX_NOT_SUPPORTED
+ case 6: // MDB Durable Topic w/CMT
+ runGetUserTransaction(msg, qSession, testName);
+ break;
+
+ case 7: // MDB Durable Topic w/CMT
+ case 8: // MDB Durable Topic w/CMT - TX_NOT_SUPPORTED
+ runGetCallerPrincipal(msg, qSession, testName);
+ break;
+
+ case 11: // MDB Durable Topic w/CMT
+ case 12: // MDB Durable Topic w/CMT - TX_NOT_SUPPORTED
+ runGetEJBHome(msg, qSession, testName);
+ break;
+
+ case 13: // MDB Durable Topic w/BMT demarcation
+ runBeginAgain(msg, qSession, testName);
+ break;
+
+ default:
+ logger.log(Logger.Level.TRACE, "Error in mdb - ");
+ logger.log(Logger.Level.TRACE,
+ "No test match for TestCaseNum: " + msg.getIntProperty("TestCaseNum"));
+ break;
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }// runTests
+
+ // MDB_QUEUE_BMT getRollbackOnly
+ public void runGetRollbackOnlyBMT(Message msg, QueueSession qSession, String testName) {
+ result = false;
+ try {
+
+ // get beanManagedTx
+ UserTransaction ut = mdc.getUserTransaction();
+
+ ut.begin();
+
+ // this should throw an exception
+ try {
+ mdc.getRollbackOnly();
+ logger.log(Logger.Level.ERROR, "BMT MDB getRollbackOnly() Test Failed!");
+ } catch (java.lang.IllegalStateException e) {
+ logger.log(Logger.Level.TRACE, "BMT MDB getRollbackOnly() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected IllegalStateException!");
+ result = true;
+ }
+ ut.rollback();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected Exception: ", e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ // MDB_QUEUE_BMT setRollbackOnly
+ public void runSetRollbackOnlyBMT(Message msg, QueueSession qSession, String testName) {
+
+ result = false;
+
+ try {
+
+ // get beanManagedTx
+ UserTransaction ut = mdc.getUserTransaction();
+
+ ut.begin();
+
+ // this should throw an exception
+ try {
+ mdc.setRollbackOnly();
+
+ logger.log(Logger.Level.ERROR, "BMT MDB setRollbackOnly() Test Failed!");
+ } catch (java.lang.IllegalStateException e) {
+ logger.log(Logger.Level.TRACE, "BMT MDB setRollbackOnly() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected IllegalStateException!");
+ result = true;
+ }
+ ut.rollback();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected Exception: ", e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ // MDB_NSTX_CMT setRollbackOnly
+ public void runSetRollbackOnlyCMT(Message msg, QueueSession qSession, String testName) {
+ result = false;
+
+ // this should throw an exception
+ try {
+ mdc.setRollbackOnly();
+
+ logger.log(Logger.Level.ERROR, "CMT MDB setRollbackOnly() Test Failed!");
+ } catch (java.lang.IllegalStateException e) {
+ logger.log(Logger.Level.TRACE, "CMT MDB setRollbackOnly() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected IllegalStateException!");
+ result = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected Exception: ", e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ public void runGetRollbackOnlyCMT(Message msg, QueueSession qSession, String testName) {
+
+ // this should throw an exception
+ try {
+ mdc.getRollbackOnly();
+
+ logger.log(Logger.Level.ERROR, "CMT MDB getRollbackOnly() Test Failed!");
+ } catch (java.lang.IllegalStateException e) {
+ logger.log(Logger.Level.TRACE, "CMT MDB getRollbackOnly() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected IllegalStateException!");
+ result = true;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ // MDB_NSTX_CMT getUserTransaction
+ public void runGetUserTransaction(Message msg, QueueSession qSession, String testName) {
+
+ result = false;
+ // this should throw an exception
+ try {
+ UserTransaction ut = mdc.getUserTransaction();
+
+ logger.log(Logger.Level.ERROR, "CMT MDB getUserTransaction() Test Failed!");
+ } catch (java.lang.IllegalStateException e) {
+ logger.log(Logger.Level.TRACE, "CMT MDB getUserTransaction() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected IllegalStateException!");
+ result = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected Exception: ", e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ public void runGetCallerPrincipal(Message msg, QueueSession qSession, String testName) {
+ result = false;
+
+ try {
+ Principal cp = mdc.getCallerPrincipal();
+ logger.log(Logger.Level.TRACE, "CMT MDB getCallerPrincipal() Test Succeeded!");
+ result = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CMT MDB getCallerPrincipal() Test Failed!", e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ public void runGetEJBHome(Message msg, QueueSession qSession, String testName) {
+ result = false;
+
+ // this should throw an exception
+ try {
+ EJBHome home = mdc.getEJBHome();
+
+ logger.log(Logger.Level.ERROR, "CMT MDB getEJBHome() Test Failed!");
+ // rollback the message
+ } catch (java.lang.IllegalStateException e) {
+ logger.log(Logger.Level.TRACE, "CMT MDB getEJBHome() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected IllegalStateException!");
+ result = true;
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected Exception: ", e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
+
+ public void runBeginAgain(Message msg, QueueSession qSession, String testName) {
+ result = false;
+ try {
+
+ // get beanManagedTx
+ UserTransaction ut = mdc.getUserTransaction();
+
+ ut.begin();
+
+ // this should throw an exception
+ try {
+ ut.begin();
+ logger.log(Logger.Level.ERROR, "BMT MDB getRollbackOnly() Test Failed!");
+ } catch (jakarta.transaction.NotSupportedException e) {
+ logger.log(Logger.Level.TRACE, "BMT MDB getRollbackOnly() Test Succeeded!");
+ logger.log(Logger.Level.TRACE, "Got expected NotSupportedException!");
+ result = true;
+ }
+ ut.rollback();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected Exception: ", e);
+ }
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults(testName, result, qSession, queueR);
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrQ/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrQ/MDBClient.java
deleted file mode 100644
index 4a094dbbc1..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrQ/MDBClient.java
+++ /dev/null
@@ -1,470 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_msgHdrQ;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.MDB_Q_Test;
-
-import jakarta.ejb.EJB;
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_MSGHdrQ_Test")
- private static MDB_Q_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.port;
- * harness.log.traceflag;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
- //
- /*
- * @testName: mdbMsgHdrTimeStampQTest
- *
- * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347;
- *
- * @test_Strategy: With a queue destination Invoke a session bean, have the
- * bean request an mdb for a queue
- *
- * to send a single Text, map, bytes, stream, and object message check time of
- * send against time send returns JMSTimeStamp should be between these two
- * Have the mdb send the test results to MDB_QUEUE_REPLY
- */
- public void mdbMsgHdrTimeStampQTest() throws Exception {
- String testCase = "msgHdrTimeStampQTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil
- .logTrace("Call bean - have it tell mdb to run msgHdrTimeStampQTest");
- hr.askMDBToRunATest(testCase);
- if (!hr.checkOnResponse(testCase)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrTimeStampQTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrCorlIdQTextTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
- * queue to send a text message to a Queue with CorrelationID set. Receive msg
- * and verify the correlationid is as set by client Have the mdb send the test
- * results to MDB_QUEUE_REPLY
- *
- */
- public void mdbMsgHdrCorlIdQTextTest() throws Exception {
- String testCase1 = "msgHdrCorlIdQTextTestCreate";
- String testCase2 = "msgHdrCorlIdQTextTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrCorlIdQTextTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrCorlIdQTextTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrCorlIdQBytesTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
- * queue to send a Bytes message to a Queue with CorrelationID set. Receive
- * msg and verify the correlationid is as set by client Have the mdb send the
- * test results to MDB_QUEUE_REPLY
- *
- */
- public void mdbMsgHdrCorlIdQBytesTest() throws Exception {
- String testCase1 = "msgHdrCorlIdQBytesTestCreate";
- String testCase2 = "msgHdrCorlIdQBytesTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrCorlIdQBytesTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrCorlIdQBytesTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrCorlIdQMapTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
- * queue to send a map message to a Queue with CorrelationID set. Receive msg
- * and verify the correlationid is as set by client Have the mdb send the test
- * results to MDB_QUEUE_REPLY
- *
- */
- public void mdbMsgHdrCorlIdQMapTest() throws Exception {
- String testCase1 = "msgHdrCorlIdQMapTestCreate";
- String testCase2 = "msgHdrCorlIdQMapTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrCorlIdQMapTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrCorlIdQMapTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrCorlIdQStreamTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
- * queue to send a stream message to a Queue with CorrelationID set. Receive
- * msg and verify the correlationid is as set by client Have the mdb send the
- * test results to MDB_QUEUE_REPLY
- *
- */
- public void mdbMsgHdrCorlIdQStreamTest() throws Exception {
- String testCase1 = "msgHdrCorlIdQStreamTestCreate";
- String testCase2 = "msgHdrCorlIdQStreamTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrCorlIdQStreamTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrCorlIdQStreamTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrCorlIdQObjectTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- *
- * @test_Strategy: Send an Object message to a Queue with CorrelationID set.
- * Receive msg and verify the correlationid is as set by client Have the mdb
- * send the test results to MDB_QUEUE_REPLY
- *
- */
- public void mdbMsgHdrCorlIdQObjectTest() throws Exception {
- String testCase1 = "msgHdrCorlIdQObjectTestCreate";
- String testCase2 = "msgHdrCorlIdQObjectTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrCorlIdQObjectTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrCorlIdQObjectTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrReplyToQTest
- *
- * @assertion_ids: JMS:SPEC:12; JMS:SPEC:246.8; JMS:JAVADOC:359;
- * JMS:JAVADOC:361; JMS:JAVADOC:286; JMS:JAVADOC:562; JMS:JAVADOC:166;
- *
- *
- * @test_Strategy: Invoke a session bean. Have the session bean request an mdb
- * to send a message to a Queue with ReplyTo set to a destination. Have the
- * mdb verify on receive. Have the mdb send the test results to
- * MDB_QUEUE_REPLY
- *
- */
- public void mdbMsgHdrReplyToQTest() throws Exception {
- String testCase1 = "msgHdrReplyToQTestCreate";
- String testCase2 = "msgHdrReplyToQTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrReplyToQTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrReplyToQTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrJMSTypeQTest
- *
- * @assertion_ids: JMS:SPEC:246.9; JMS:JAVADOC:375; JMS:JAVADOC:377;
- *
- * @test_Strategy: Invoke a session bean. Have the session bean request an mdb
- * to send a message to a Queue with JMSType set to TESTMSG verify on receive.
- * Have the mdb send the test results to MDB_QUEUE_REPLY
- *
- */
- public void mdbMsgHdrJMSTypeQTest() throws Exception {
- String testCase1 = "msgHdrJMSTypeQTestCreate";
- String testCase2 = "msgHdrJMSTypeQTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrJMSTypeQTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrJMSTypeQTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrJMSPriorityQTest
- *
- * @assertion_ids: JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140; JMS:JAVADOC:305;
- * JMS:JAVADOC:383;
- *
- * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
- * queue to send a message to a Queue with JMSPriority set to 2 test with
- * Text, map, object, byte, and stream messages verify on receive. Have the
- * mdb send the test results to MDB_QUEUE_REPLY
- *
- */
- public void mdbMsgHdrJMSPriorityQTest() throws Exception {
- String testCase1 = "msgHdrJMSPriorityQTestCreate";
- String testCase2 = "msgHdrJMSPriorityQTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run mdbMsgHdrJMSTypeQTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbMsgHdrJMSTypeQTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrJMSExpirationQueueTest
- *
- * @assertion_ids: JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140;
- * JMS:JAVADOC:309; JMS:JAVADOC:379;
- *
- * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
- * queue to send a message to a Queue with time to live set to 0 Verify that
- * JMSExpiration gets set to 0 test with Text, map, object, byte, and stream
- * messages verify on receive. Have the mdb send the test results to
- * MDB_QUEUE_REPLY
- *
- */
- public void mdbMsgHdrJMSExpirationQueueTest() throws Exception {
- String testCase1 = "msgHdrJMSExpirationQueueTestCreate";
- String testCase2 = "msgHdrJMSExpirationQueueTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrJMSExpirationQueueTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrJMSExpirationQueueTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrJMSDestinationQTest
- *
- * @assertion_ids: JMS:SPEC:2; JMS:JAVADOC:363; JMS:JAVADOC:286;
- *
- * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
- * queue to create and send a message set to the default Queue. Receive msg
- * and verify that JMSDestination is set to the default Queue test with Text,
- * map, object, byte, and stream messages Have the mdb send the test results
- * to MDB_QUEUE_REPLY
- */
- public void mdbMsgHdrJMSDestinationQTest() throws Exception {
- String testCase1 = "msgHdrJMSDestinationQTestCreate";
- String testCase2 = "msgHdrJMSDestinationQTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrJMSDestinationQTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrJMSDestinationQTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrJMSDeliveryModeQTest
- *
- * @assertion_ids: JMS:SPEC:246.2; JMS:SPEC:3; JMS:SPEC:140; JMS:JAVADOC:367;
- * JMS:JAVADOC:301;
- *
- * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
- * queue to create and send a message. Receive the msg and verify that
- * JMSDeliveryMode is set the default delivery mode of persistent. Create and
- * test another message with a nonpersistent delivery mode. test with Text,
- * map, object, byte, and stream messages Have the mdb send the test results
- * to MDB_QUEUE_REPLY
- */
- public void mdbMsgHdrJMSDeliveryModeQTest() throws Exception {
- String testCase1 = "msgHdrJMSDeliveryModeQTestCreate";
- String testCase2 = "msgHdrJMSDeliveryModeQTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrJMSDeliveryModeQTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrJMSDeliveryModeQTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrIDQTest
- *
- * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343;
- *
- * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
- * queue to send and receive single Text, map, bytes, stream, and object
- * message call getJMSMessageID and verify that it starts with ID: 3.4.3 Have
- * the mdb send the test results to MDB_QUEUE_REPLY
- */
- public void mdbMsgHdrIDQTest() throws Exception {
-
- String testCase1 = "msgHdrIDQTestCreate";
- String testCase2 = "msgHdrIDQTest";
- try {
- // Have the EJB invoke the MDB
-
- TestUtil
- .logTrace("Call bean - have it tell mdb to run msgHdrIDQTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrIDQTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- ;
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrQ/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrQ/MDBClientIT.java
new file mode 100644
index 0000000000..4d8c87180b
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrQ/MDBClientIT.java
@@ -0,0 +1,473 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_msgHdrQ;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.commonee.MDB_Q_Test;
+
+import jakarta.ejb.EJB;
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_MSGHdrQ_Test")
+ private static MDB_Q_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ try {
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ hr.setup(props);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+ //
+ /*
+ * @testName: mdbMsgHdrTimeStampQTest
+ *
+ * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347;
+ *
+ * @test_Strategy: With a queue destination Invoke a session bean, have the bean
+ * request an mdb for a queue
+ *
+ * to send a single Text, map, bytes, stream, and object message check time of
+ * send against time send returns JMSTimeStamp should be between these two Have
+ * the mdb send the test results to MDB_QUEUE_REPLY
+ */
+ @Test
+ public void mdbMsgHdrTimeStampQTest() throws Exception {
+ String testCase = "msgHdrTimeStampQTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrTimeStampQTest");
+ hr.askMDBToRunATest(testCase);
+ if (!hr.checkOnResponse(testCase)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrTimeStampQTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrCorlIdQTextTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
+ * queue to send a text message to a Queue with CorrelationID set. Receive msg
+ * and verify the correlationid is as set by client Have the mdb send the test
+ * results to MDB_QUEUE_REPLY
+ *
+ */
+ @Test
+ public void mdbMsgHdrCorlIdQTextTest() throws Exception {
+ String testCase1 = "msgHdrCorlIdQTextTestCreate";
+ String testCase2 = "msgHdrCorlIdQTextTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrCorlIdQTextTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrCorlIdQTextTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrCorlIdQBytesTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
+ * queue to send a Bytes message to a Queue with CorrelationID set. Receive msg
+ * and verify the correlationid is as set by client Have the mdb send the test
+ * results to MDB_QUEUE_REPLY
+ *
+ */
+ @Test
+ public void mdbMsgHdrCorlIdQBytesTest() throws Exception {
+ String testCase1 = "msgHdrCorlIdQBytesTestCreate";
+ String testCase2 = "msgHdrCorlIdQBytesTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrCorlIdQBytesTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrCorlIdQBytesTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrCorlIdQMapTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
+ * queue to send a map message to a Queue with CorrelationID set. Receive msg
+ * and verify the correlationid is as set by client Have the mdb send the test
+ * results to MDB_QUEUE_REPLY
+ *
+ */
+ @Test
+ public void mdbMsgHdrCorlIdQMapTest() throws Exception {
+ String testCase1 = "msgHdrCorlIdQMapTestCreate";
+ String testCase2 = "msgHdrCorlIdQMapTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrCorlIdQMapTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrCorlIdQMapTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrCorlIdQStreamTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
+ * queue to send a stream message to a Queue with CorrelationID set. Receive msg
+ * and verify the correlationid is as set by client Have the mdb send the test
+ * results to MDB_QUEUE_REPLY
+ *
+ */
+ @Test
+ public void mdbMsgHdrCorlIdQStreamTest() throws Exception {
+ String testCase1 = "msgHdrCorlIdQStreamTestCreate";
+ String testCase2 = "msgHdrCorlIdQStreamTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrCorlIdQStreamTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrCorlIdQStreamTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrCorlIdQObjectTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ *
+ * @test_Strategy: Send an Object message to a Queue with CorrelationID set.
+ * Receive msg and verify the correlationid is as set by client Have the mdb
+ * send the test results to MDB_QUEUE_REPLY
+ *
+ */
+ @Test
+ public void mdbMsgHdrCorlIdQObjectTest() throws Exception {
+ String testCase1 = "msgHdrCorlIdQObjectTestCreate";
+ String testCase2 = "msgHdrCorlIdQObjectTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrCorlIdQObjectTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrCorlIdQObjectTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrReplyToQTest
+ *
+ * @assertion_ids: JMS:SPEC:12; JMS:SPEC:246.8; JMS:JAVADOC:359;
+ * JMS:JAVADOC:361; JMS:JAVADOC:286; JMS:JAVADOC:562; JMS:JAVADOC:166;
+ *
+ *
+ * @test_Strategy: Invoke a session bean. Have the session bean request an mdb
+ * to send a message to a Queue with ReplyTo set to a destination. Have the mdb
+ * verify on receive. Have the mdb send the test results to MDB_QUEUE_REPLY
+ *
+ */
+ @Test
+ public void mdbMsgHdrReplyToQTest() throws Exception {
+ String testCase1 = "msgHdrReplyToQTestCreate";
+ String testCase2 = "msgHdrReplyToQTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrReplyToQTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrReplyToQTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrJMSTypeQTest
+ *
+ * @assertion_ids: JMS:SPEC:246.9; JMS:JAVADOC:375; JMS:JAVADOC:377;
+ *
+ * @test_Strategy: Invoke a session bean. Have the session bean request an mdb
+ * to send a message to a Queue with JMSType set to TESTMSG verify on receive.
+ * Have the mdb send the test results to MDB_QUEUE_REPLY
+ *
+ */
+ @Test
+ public void mdbMsgHdrJMSTypeQTest() throws Exception {
+ String testCase1 = "msgHdrJMSTypeQTestCreate";
+ String testCase2 = "msgHdrJMSTypeQTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrJMSTypeQTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrJMSTypeQTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrJMSPriorityQTest
+ *
+ * @assertion_ids: JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140; JMS:JAVADOC:305;
+ * JMS:JAVADOC:383;
+ *
+ * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
+ * queue to send a message to a Queue with JMSPriority set to 2 test with Text,
+ * map, object, byte, and stream messages verify on receive. Have the mdb send
+ * the test results to MDB_QUEUE_REPLY
+ *
+ */
+ @Test
+ public void mdbMsgHdrJMSPriorityQTest() throws Exception {
+ String testCase1 = "msgHdrJMSPriorityQTestCreate";
+ String testCase2 = "msgHdrJMSPriorityQTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run mdbMsgHdrJMSTypeQTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbMsgHdrJMSTypeQTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrJMSExpirationQueueTest
+ *
+ * @assertion_ids: JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140; JMS:JAVADOC:309;
+ * JMS:JAVADOC:379;
+ *
+ * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
+ * queue to send a message to a Queue with time to live set to 0 Verify that
+ * JMSExpiration gets set to 0 test with Text, map, object, byte, and stream
+ * messages verify on receive. Have the mdb send the test results to
+ * MDB_QUEUE_REPLY
+ *
+ */
+ @Test
+ public void mdbMsgHdrJMSExpirationQueueTest() throws Exception {
+ String testCase1 = "msgHdrJMSExpirationQueueTestCreate";
+ String testCase2 = "msgHdrJMSExpirationQueueTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrJMSExpirationQueueTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrJMSExpirationQueueTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrJMSDestinationQTest
+ *
+ * @assertion_ids: JMS:SPEC:2; JMS:JAVADOC:363; JMS:JAVADOC:286;
+ *
+ * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
+ * queue to create and send a message set to the default Queue. Receive msg and
+ * verify that JMSDestination is set to the default Queue test with Text, map,
+ * object, byte, and stream messages Have the mdb send the test results to
+ * MDB_QUEUE_REPLY
+ */
+ @Test
+ public void mdbMsgHdrJMSDestinationQTest() throws Exception {
+ String testCase1 = "msgHdrJMSDestinationQTestCreate";
+ String testCase2 = "msgHdrJMSDestinationQTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrJMSDestinationQTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrJMSDestinationQTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrJMSDeliveryModeQTest
+ *
+ * @assertion_ids: JMS:SPEC:246.2; JMS:SPEC:3; JMS:SPEC:140; JMS:JAVADOC:367;
+ * JMS:JAVADOC:301;
+ *
+ * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
+ * queue to create and send a message. Receive the msg and verify that
+ * JMSDeliveryMode is set the default delivery mode of persistent. Create and
+ * test another message with a nonpersistent delivery mode. test with Text, map,
+ * object, byte, and stream messages Have the mdb send the test results to
+ * MDB_QUEUE_REPLY
+ */
+ @Test
+ public void mdbMsgHdrJMSDeliveryModeQTest() throws Exception {
+ String testCase1 = "msgHdrJMSDeliveryModeQTestCreate";
+ String testCase2 = "msgHdrJMSDeliveryModeQTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrJMSDeliveryModeQTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrJMSDeliveryModeQTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrIDQTest
+ *
+ * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343;
+ *
+ * @test_Strategy: Invoke a session bean, have the bean request an mdb for a
+ * queue to send and receive single Text, map, bytes, stream, and object message
+ * call getJMSMessageID and verify that it starts with ID: 3.4.3 Have the mdb
+ * send the test results to MDB_QUEUE_REPLY
+ */
+ @Test
+ public void mdbMsgHdrIDQTest() throws Exception {
+
+ String testCase1 = "msgHdrIDQTestCreate";
+ String testCase2 = "msgHdrIDQTest";
+ try {
+ // Have the EJB invoke the MDB
+
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrIDQTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrIDQTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ ;
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrQ/MsgBeanMsgTestHdrQ.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrQ/MsgBeanMsgTestHdrQ.java
index 14dfe944ec..aefe46152d 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrQ/MsgBeanMsgTestHdrQ.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrQ/MsgBeanMsgTestHdrQ.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_msgHdrQ;
+import java.lang.System.Logger;
import java.util.Enumeration;
import java.util.Properties;
import java.util.Vector;
@@ -48,818 +49,775 @@
public class MsgBeanMsgTestHdrQ implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties p = null;
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
- private TSNamingContext context = null;
+ private TSNamingContext context = null;
- private MessageDrivenContext mdc = null;
+ private MessageDrivenContext mdc = null;
- // JMS
- private QueueConnectionFactory qFactory = null;
+ // JMS
+ private QueueConnectionFactory qFactory = null;
- private QueueConnection qConnection = null;
+ private QueueConnection qConnection = null;
- private Queue queueR = null;
-
- private Queue queue = null;
-
- private QueueSender mSender = null;
-
- private QueueSession qSession = null;
-
- private TextMessage messageSent = null;
-
- private StreamMessage messageSentStreamMessage = null;
-
- private BytesMessage messageSentBytesMessage = null;
-
- private MapMessage messageSentMapMessage = null;
-
- private ObjectMessage messageSentObjectMessage = null;
-
- public MsgBeanMsgTestHdrQ() {
- TestUtil.logTrace("@MsgBeanMsgTestHdrQ()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgHdrQ - @MsgBeanMsgTestHdrQ-ejbCreate() !!");
- try {
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- if (qFactory == null) {
- TestUtil.logTrace("qFactory error");
- }
-
- queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- if (queueR == null) {
- TestUtil.logTrace("queueR error");
- }
- queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
-
- try {
- p = new Properties();
- JmsUtil.initHarnessProps(msg, p);
-
- TestUtil.logTrace("from jms.ee.mdb.mdb_msgHdrQ @onMessage!" + msg);
-
- TestUtil.logTrace(
- "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null) {
- throw new Exception("Null QueueConnection created");
- }
- qConnection.start();
-
- qSession = qConnection.createQueueSession(true, 0);
-
- // create testmessages
- Vector mVec = new Vector();
- messageSent = qSession.createTextMessage();
- mVec.addElement(messageSent);
- messageSentStreamMessage = qSession.createStreamMessage();
- mVec.addElement(messageSentStreamMessage);
- messageSentBytesMessage = qSession.createBytesMessage();
- mVec.addElement(messageSentBytesMessage);
- messageSentMapMessage = qSession.createMapMessage();
- mVec.addElement(messageSentMapMessage);
- messageSentObjectMessage = qSession.createObjectMessage();
- mVec.addElement(messageSentObjectMessage);
-
- // for each message addPropsToMessage
- Enumeration vNum = mVec.elements();
- while (vNum.hasMoreElements()) {
- JmsUtil.addPropsToMessage((Message) vNum.nextElement(), p);
- }
-
- // myTestUtil.logTrace - for trace logging messages
-
- if (msg.getStringProperty("TestCase").equals("msgHdrTimeStampQTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgHdrTimeStampQTest - create the message");
- msgHdrTimeStampQTest();
- } else if (msg.getStringProperty("TestCase").equals("dummy")) {
- TestUtil.logTrace("@onMessage - ignore this!");
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdQTextTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdQTextTestCreate!");
- msgHdrCorlIdQTextTestCreate();
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdQTextTest")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdQTextTest!");
- msgHdrCorlIdQTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdQBytesTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdQBytesTestCreate!");
- msgHdrCorlIdQBytesTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdQBytesTest")) {
- TestUtil.logTrace("@onMessage -msgHdrCorlIdQBytesTest!");
- msgHdrCorlIdQTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdQMapTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdQMapTestCreate!");
- msgHdrCorlIdQMapTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdQMapTest")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdQMapTest!");
- msgHdrCorlIdQTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdQStreamTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdQStreamTestCreate!");
- msgHdrCorlIdQStreamTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdQStreamTest")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdQStreamTest!");
- msgHdrCorlIdQTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdQObjectTestCreate")) {
- TestUtil.logTrace("@onMessage -msgHdrCorlIdQObjectTestCreate!");
- msgHdrCorlIdQObjectTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdQObjectTest")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdQObjectTest!");
- msgHdrCorlIdQTest(msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("msgHdrReplyToQTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrReplyToQTestCreate!");
- msgHdrReplyToQTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrReplyToQTest")) {
- TestUtil.logTrace("@onMessage - msgHdrReplyToQTest!");
- msgHdrReplyToQTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSTypeQTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSTypeQTestCreate!");
- msgHdrJMSTypeQTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSTypeQTest")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSTypeQTest!");
- msgHdrJMSTypeQTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSPriorityQTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSPriorityQTestCreate!");
- msgHdrJMSPriorityQTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSPriorityQTest")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSPriorityQTest!");
- msgHdrJMSPriorityQTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSExpirationQueueTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSExpirationQueueTestCreate!");
- msgHdrJMSExpirationQueueTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSExpirationQueueTest")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSExpirationQueueTest!");
- msgHdrJMSExpirationQueueTest(msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSDestinationQTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSDestinationQTestCreate!");
- msgHdrJMSDestinationQTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSDestinationQTest")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSDestinationQTest!");
- msgHdrJMSDestinationQTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSDeliveryModeQTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSDeliveryModeQTestCreate!");
- msgHdrJMSDeliveryModeQTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSDeliveryModeQTest")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSDeliveryModeQTest!");
- msgHdrJMSDeliveryModeQTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrIDQTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrIDQTestCreate!");
- msgHdrIDQTestCreate();
- } else if (msg.getStringProperty("TestCase").equals("msgHdrIDQTest")) {
- TestUtil.logTrace("@onMessage - msgHdrIDQTest!");
- msgHdrIDQTest(msg);
- }
-
- else {
- TestUtil.logTrace(
- "@onMessage - invalid message type found in StringProperty");
- TestUtil.logTrace("Do not have a method for this testcase: "
- + msg.getStringProperty("TestCase"));
- }
-
- TestUtil.logTrace("@onMessage - Finished for this test!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
-
- }
-
- /*
- * Description: Send a single Text, map, bytes, stream, and object message
- * check time of send against time send returns JMSTimeStamp should be between
- * these two
- */
- public void msgHdrTimeStampQTest() {
- boolean pass = true;
- long timeBeforeSend;
- long timeAfterSend;
- byte bValue = 127;
- String id = null;
- String testCase = "msgHdrTimeStampQTest";
- try {
-
- // send Object message
- TestUtil.logTrace("Send ObjectMessage to Queue.");
- messageSentObjectMessage
- .setObject("msgHdrTimeStampQTest for Object Message");
- messageSentObjectMessage.setStringProperty("TestCase", "dummy");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- mSender = qSession.createSender(queue);
- mSender.send(messageSentObjectMessage);
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
- TestUtil.logTrace(" getJMSTimestamp");
- TestUtil.logTrace(" " + messageSentObjectMessage.getJMSTimestamp());
- TestUtil.logTrace("Time at send is: " + timeBeforeSend);
- TestUtil.logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentObjectMessage.getJMSTimestamp())
- && (timeAfterSend >= messageSentObjectMessage.getJMSTimestamp())) {
- TestUtil.logTrace("Object Message TimeStamp pass");
- } else {
- TestUtil.logMsg("Error: invalid timestamp from ObjectMessage");
- pass = false;
- }
-
- // send map message to Queue
- TestUtil.logTrace("Send MapMessage to Queue.");
-
- messageSentMapMessage.setStringProperty("TestCase", "dummy");
- messageSentMapMessage.setString("aString", "value");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- mSender.send(messageSentMapMessage);
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
-
- TestUtil.logTrace(" getJMSTimestamp");
- TestUtil.logTrace(" " + messageSentMapMessage.getJMSTimestamp());
- TestUtil.logTrace("Time at send is: " + timeBeforeSend);
- TestUtil.logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentMapMessage.getJMSTimestamp())
- && (timeAfterSend >= messageSentMapMessage.getJMSTimestamp())) {
- TestUtil.logTrace("MapMessage TimeStamp pass");
- } else {
- TestUtil.logMsg("Error: invalid timestamp from MapMessage");
- pass = false;
- }
-
- // send bytes message
-
- TestUtil.logTrace("Send BytesMessage to Queue.");
-
- messageSentBytesMessage.setStringProperty("TestCase", "dummy");
-
- messageSentBytesMessage.writeByte(bValue);
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- mSender.send(messageSentBytesMessage);
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
-
- TestUtil.logTrace(" getJMSTimestamp");
- TestUtil.logTrace(" " + messageSentBytesMessage.getJMSTimestamp());
- TestUtil.logTrace("Time at send is: " + timeBeforeSend);
- TestUtil.logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentBytesMessage.getJMSTimestamp())
- && (timeAfterSend >= messageSentBytesMessage.getJMSTimestamp())) {
- TestUtil.logTrace("BytesMessage TimeStamp pass");
- } else {
- TestUtil.logMsg("Error: invalid timestamp from BytesMessage");
- pass = false;
- }
-
- // Send a StreamMessage
- TestUtil.logTrace("sending a Stream message");
-
- messageSentStreamMessage.setStringProperty("TestCase", "dummy");
-
- messageSentStreamMessage.writeString("Testing...");
- TestUtil.logTrace("Sending message");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- mSender.send(messageSentStreamMessage);
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
-
- TestUtil.logTrace(" getJMSTimestamp");
- TestUtil.logTrace(" " + messageSentStreamMessage.getJMSTimestamp());
- TestUtil.logTrace("Time at send is: " + timeBeforeSend);
- TestUtil.logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSentStreamMessage.getJMSTimestamp())
- && (timeAfterSend >= messageSentStreamMessage.getJMSTimestamp())) {
- TestUtil.logTrace("StreamMessage TimeStamp pass");
- } else {
- TestUtil.logMsg("Error: invalid timestamp from StreamMessage");
- pass = false;
- }
-
- // Text Message
-
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("TestCase", "dummy");
-
- TestUtil.logTrace("sending a Text message");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- mSender.send(messageSent);
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
-
- TestUtil.logTrace(" getJMSTimestamp");
- TestUtil.logTrace(" " + messageSent.getJMSTimestamp());
- TestUtil.logTrace("Time at send is: " + timeBeforeSend);
- TestUtil.logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSent.getJMSTimestamp())
- && (timeAfterSend >= messageSent.getJMSTimestamp())) {
- TestUtil.logTrace("TextMessage TimeStamp pass");
- } else {
- TestUtil.logMsg("Error: invalid timestamp from TextMessage");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: create a text msg, set correlation id
- */
- private void msgHdrCorlIdQTextTestCreate() {
-
- String jmsCorrelationID = "test Correlation id";
- try {
-
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrCorlIdQTextTest");
-
- TestUtil.logTrace("Send Text Message to Queue.");
- messageSent.setJMSCorrelationID(jmsCorrelationID);
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create a stream msg, set correlation id
- */
- private void msgHdrCorlIdQStreamTestCreate() {
-
- String jmsCorrelationID = "test Correlation id";
- try {
-
- messageSentStreamMessage.setStringProperty("TestCase",
- "msgHdrCorlIdQStreamTest");
- messageSentStreamMessage.setJMSCorrelationID(jmsCorrelationID);
- messageSentStreamMessage.writeString("Testing...");
- TestUtil.logTrace("Sending Stream message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSentStreamMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create a bytes msg, set correlation id
- */
- private void msgHdrCorlIdQBytesTestCreate() {
- byte bValue = 127;
-
- String jmsCorrelationID = "test Correlation id";
- try {
-
- TestUtil.logTrace("Send BytesMessage to Queue.");
-
- messageSentBytesMessage.setStringProperty("TestCase",
- "msgHdrCorlIdQBytesTest");
- messageSentBytesMessage.setJMSCorrelationID(jmsCorrelationID);
- messageSentBytesMessage.writeByte(bValue);
-
- mSender = qSession.createSender(queue);
- mSender.send(messageSentBytesMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create a mao msg, set correlation id
- */
- private void msgHdrCorlIdQMapTestCreate() {
-
- String jmsCorrelationID = "test Correlation id";
- try {
-
- TestUtil.logTrace("Send MapMessage to Queue.");
-
- messageSentMapMessage.setStringProperty("TestCase",
- "msgHdrCorlIdQMapTest");
- messageSentMapMessage.setJMSCorrelationID(jmsCorrelationID);
- messageSentMapMessage.setString("aString", "value");
-
- mSender = qSession.createSender(queue);
- mSender.send(messageSentMapMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create an object msg, set correlation id
- */
- private void msgHdrCorlIdQObjectTestCreate() {
-
- String jmsCorrelationID = "test Correlation id";
- try {
- TestUtil.logTrace("Send ObjectMessage to Queue.");
-
- messageSentObjectMessage
- .setObject("msgHdrIDQObjectTest for Object Message");
- messageSentObjectMessage.setStringProperty("TestCase",
- "msgHdrCorlIdQObjectTest");
- messageSentObjectMessage.setJMSCorrelationID(jmsCorrelationID);
-
- mSender = qSession.createSender(queue);
- mSender.send(messageSentObjectMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
-
- }
-
- public void msgHdrCorlIdQTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- String jmsCorrelationID = "test Correlation id";
- try {
- TestUtil.logTrace(
- "jmsCorrelationID: " + messageReceived.getJMSCorrelationID());
- if (messageReceived.getJMSCorrelationID() == null) {
- pass = false;
- TestUtil
- .logMsg("Text Message Error: JMSCorrelationID returned a null");
- } else if (messageReceived.getJMSCorrelationID()
- .equals(jmsCorrelationID)) {
- TestUtil.logTrace("pass");
- } else {
- pass = false;
- TestUtil.logMsg("Text Message Error: JMSCorrelationID is incorrect");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- try {
- sendTestResults(messageReceived.getStringProperty("TestCase"), pass);
- } catch (Exception j) {
- TestUtil.printStackTrace(j);
- }
- }
- }
-
- /*
- *
- */
- public void msgHdrReplyToQTestCreate() {
- Queue replyQueue = null;
- try {
-
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrReplyToQTest");
- messageSent.setJMSReplyTo(queue);
-
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrReplyToQTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- Queue replyQueue = null;
- String testCase = "msgHdrReplyToQTest";
- try {
- replyQueue = (Queue) messageReceived.getJMSReplyTo();
- TestUtil.logTrace("Queue name is " + replyQueue.getQueueName());
- if (replyQueue.getQueueName().equals(queue.getQueueName())) {
- TestUtil.logTrace("Pass ");
- } else {
- TestUtil.logMsg("ReplyTo Failed");
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- public void msgHdrJMSTypeQTestCreate() {
- boolean pass = true;
- byte bValue = 127;
- String type = "TESTMSG";
- try {
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrJMSTypeQTest");
- TestUtil.logTrace("JMSType test - Send a Text message");
- messageSent.setJMSType(type);
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrJMSTypeQTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- String type = "TESTMSG";
- String testCase = "msgHdrJMSTypeQTest";
- try {
-
- TestUtil.logTrace("JMSType is " + (String) messageReceived.getJMSType());
- if (messageReceived.getJMSType().equals(type)) {
- TestUtil.logTrace("Pass");
- } else {
- TestUtil.logMsg("Text Message Failed");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- public void msgHdrJMSPriorityQTestCreate() {
- boolean pass = true;
- byte bValue = 127;
- int priority = 2;
- try {
-
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrJMSPriorityQTest");
- TestUtil.logTrace("JMSPriority test - Send a Text message");
- mSender = qSession.createSender(queue);
- mSender.setPriority(priority);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrJMSPriorityQTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- int priority = 2;
- String testCase = "msgHdrJMSPriorityQTest";
- try {
- TestUtil.logTrace("JMSPriority is " + messageReceived.getJMSPriority());
- if (messageReceived.getJMSPriority() == priority) {
- TestUtil.logTrace("Pass ");
- } else {
- TestUtil.logMsg("JMSPriority test Failed");
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- public void msgHdrJMSExpirationQueueTestCreate() {
- boolean pass = true;
- long forever = 0;
- try {
-
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrJMSExpirationQueueTest");
- TestUtil.logTrace("JMSExpiration test - Send a Text message");
-
- mSender = qSession.createSender(queue);
- mSender.setTimeToLive(forever);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrJMSExpirationQueueTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- long forever = 0;
- String testCase = "msgHdrJMSExpirationQueueTest";
- try {
-
- TestUtil
- .logTrace("JMSExpiration is " + messageReceived.getJMSExpiration());
- if (messageReceived.getJMSExpiration() == forever) {
- TestUtil.logTrace("Pass ");
- } else {
- TestUtil.logMsg("Text Message Failed");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- public void msgHdrJMSDestinationQTestCreate() {
- Queue replyDestination = null;
- try {
-
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrJMSDestinationQTest");
- TestUtil.logTrace("send msg for JMSDestination test.");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrJMSDestinationQTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- Queue replyDestination = null;
- String testCase = "msgHdrJMSDestinationQTest";
-
- try {
- TestUtil
- .logTrace("JMSDestination: " + messageReceived.getJMSDestination());
- replyDestination = (Queue) messageReceived.getJMSDestination();
- if (replyDestination != null)
- TestUtil.logTrace("Queue name is " + replyDestination.getQueueName());
-
- if (replyDestination == null) {
- pass = false;
- TestUtil.logMsg("Text Message Error: JMSDestination returned a null");
- } else if (replyDestination.getQueueName().equals(queue.getQueueName())) {
- TestUtil.logTrace("Pass ");
- } else {
- TestUtil.logMsg("Text Message Failed");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr(
- "Unexpected Exception thrown in msgHdrJMSDestinationQTest:", e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- public void msgHdrJMSDeliveryModeQTestCreate() {
- try {
-
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrJMSDeliveryModeQTest");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrJMSDeliveryModeQTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- String testCase = "msgHdrJMSDeliveryModeQTest";
- try {
-
- TestUtil.logTrace(
- "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- TestUtil.logMsg(
- "Error: JMSDeliveryMode should be set to persistent as default");
- } else {
- TestUtil.logTrace("Pass: Default delivery mode is persistent");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- public void msgHdrIDQTestCreate() {
- String id = null;
- try {
-
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("TestCase", "msgHdrIDQTest");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrIDQTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- String id = null;
- String testCase = "msgHdrIDQTest";
- try {
-
- TestUtil.logTrace("getJMSMessageID ");
- TestUtil.logTrace(" " + messageReceived.getJMSMessageID());
- id = messageReceived.getJMSMessageID();
-
- if (id.startsWith("ID:")) {
- TestUtil.logTrace("Pass: JMSMessageID start with ID:");
- } else {
- TestUtil.logMsg("Error: JMSMessageID does not start with ID:");
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: send test results to response queue (MDB_QUEUE_REPLY) for
- * verification
- */
- private void sendTestResults(String testCase, boolean results) {
- TextMessage msg = null;
-
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- msg.setStringProperty("TestCase", testCase);
- msg.setText(testCase);
- if (results)
- msg.setStringProperty("Status", "Pass");
- else
- msg.setStringProperty("Status", "Fail");
-
- mSender.send(msg);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- System.out.println("Error: " + je.getClass().getName() + " was thrown");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- System.out.println("Error: " + ee.getClass().getName() + " was thrown");
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgHdrQ In MsgBeanMsgTestHdrQ::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil
- .logTrace("jms.ee.mdb.mdb_msgHdrQ In MsgBeanMsgTestHdrQ::remove()!!");
- }
+ private Queue queueR = null;
+
+ private Queue queue = null;
+
+ private QueueSender mSender = null;
+
+ private QueueSession qSession = null;
+
+ private TextMessage messageSent = null;
+
+ private StreamMessage messageSentStreamMessage = null;
+
+ private BytesMessage messageSentBytesMessage = null;
+
+ private MapMessage messageSentMapMessage = null;
+
+ private ObjectMessage messageSentObjectMessage = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanMsgTestHdrQ.class.getName());
+
+ public MsgBeanMsgTestHdrQ() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanMsgTestHdrQ()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgHdrQ - @MsgBeanMsgTestHdrQ-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ if (qFactory == null) {
+ logger.log(Logger.Level.TRACE, "qFactory error");
+ }
+
+ queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ if (queueR == null) {
+ logger.log(Logger.Level.TRACE, "queueR error");
+ }
+ queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+
+ try {
+ p = new Properties();
+ JmsUtil.initHarnessProps(msg, p);
+
+ logger.log(Logger.Level.TRACE, "from jms.ee.mdb.mdb_msgHdrQ @onMessage!" + msg);
+
+ logger.log(Logger.Level.TRACE, "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null) {
+ throw new Exception("Null QueueConnection created");
+ }
+ qConnection.start();
+
+ qSession = qConnection.createQueueSession(true, 0);
+
+ // create testmessages
+ Vector mVec = new Vector();
+ messageSent = qSession.createTextMessage();
+ mVec.addElement(messageSent);
+ messageSentStreamMessage = qSession.createStreamMessage();
+ mVec.addElement(messageSentStreamMessage);
+ messageSentBytesMessage = qSession.createBytesMessage();
+ mVec.addElement(messageSentBytesMessage);
+ messageSentMapMessage = qSession.createMapMessage();
+ mVec.addElement(messageSentMapMessage);
+ messageSentObjectMessage = qSession.createObjectMessage();
+ mVec.addElement(messageSentObjectMessage);
+
+ // for each message addPropsToMessage
+ Enumeration vNum = mVec.elements();
+ while (vNum.hasMoreElements()) {
+ JmsUtil.addPropsToMessage((Message) vNum.nextElement(), p);
+ }
+
+ // myTestUtil.logTrace - for trace logging messages
+
+ if (msg.getStringProperty("TestCase").equals("msgHdrTimeStampQTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - running msgHdrTimeStampQTest - create the message");
+ msgHdrTimeStampQTest();
+ } else if (msg.getStringProperty("TestCase").equals("dummy")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - ignore this!");
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdQTextTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdQTextTestCreate!");
+ msgHdrCorlIdQTextTestCreate();
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdQTextTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdQTextTest!");
+ msgHdrCorlIdQTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdQBytesTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdQBytesTestCreate!");
+ msgHdrCorlIdQBytesTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdQBytesTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage -msgHdrCorlIdQBytesTest!");
+ msgHdrCorlIdQTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdQMapTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdQMapTestCreate!");
+ msgHdrCorlIdQMapTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdQMapTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdQMapTest!");
+ msgHdrCorlIdQTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdQStreamTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdQStreamTestCreate!");
+ msgHdrCorlIdQStreamTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdQStreamTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdQStreamTest!");
+ msgHdrCorlIdQTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdQObjectTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage -msgHdrCorlIdQObjectTestCreate!");
+ msgHdrCorlIdQObjectTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdQObjectTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdQObjectTest!");
+ msgHdrCorlIdQTest(msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("msgHdrReplyToQTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrReplyToQTestCreate!");
+ msgHdrReplyToQTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrReplyToQTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrReplyToQTest!");
+ msgHdrReplyToQTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSTypeQTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSTypeQTestCreate!");
+ msgHdrJMSTypeQTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSTypeQTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSTypeQTest!");
+ msgHdrJMSTypeQTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSPriorityQTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSPriorityQTestCreate!");
+ msgHdrJMSPriorityQTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSPriorityQTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSPriorityQTest!");
+ msgHdrJMSPriorityQTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSExpirationQueueTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSExpirationQueueTestCreate!");
+ msgHdrJMSExpirationQueueTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSExpirationQueueTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSExpirationQueueTest!");
+ msgHdrJMSExpirationQueueTest(msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("msgHdrJMSDestinationQTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSDestinationQTestCreate!");
+ msgHdrJMSDestinationQTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSDestinationQTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSDestinationQTest!");
+ msgHdrJMSDestinationQTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSDeliveryModeQTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSDeliveryModeQTestCreate!");
+ msgHdrJMSDeliveryModeQTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSDeliveryModeQTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSDeliveryModeQTest!");
+ msgHdrJMSDeliveryModeQTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrIDQTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrIDQTestCreate!");
+ msgHdrIDQTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrIDQTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrIDQTest!");
+ msgHdrIDQTest(msg);
+ }
+
+ else {
+ logger.log(Logger.Level.TRACE, "@onMessage - invalid message type found in StringProperty");
+ logger.log(Logger.Level.TRACE,
+ "Do not have a method for this testcase: " + msg.getStringProperty("TestCase"));
+ }
+
+ logger.log(Logger.Level.TRACE, "@onMessage - Finished for this test!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+
+ }
+
+ /*
+ * Description: Send a single Text, map, bytes, stream, and object message check
+ * time of send against time send returns JMSTimeStamp should be between these
+ * two
+ */
+ public void msgHdrTimeStampQTest() {
+ boolean pass = true;
+ long timeBeforeSend;
+ long timeAfterSend;
+ byte bValue = 127;
+ String id = null;
+ String testCase = "msgHdrTimeStampQTest";
+ try {
+
+ // send Object message
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Queue.");
+ messageSentObjectMessage.setObject("msgHdrTimeStampQTest for Object Message");
+ messageSentObjectMessage.setStringProperty("TestCase", "dummy");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSentObjectMessage);
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSentObjectMessage.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentObjectMessage.getJMSTimestamp())
+ && (timeAfterSend >= messageSentObjectMessage.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "Object Message TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from ObjectMessage");
+ pass = false;
+ }
+
+ // send map message to Queue
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Queue.");
+
+ messageSentMapMessage.setStringProperty("TestCase", "dummy");
+ messageSentMapMessage.setString("aString", "value");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ mSender.send(messageSentMapMessage);
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSentMapMessage.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentMapMessage.getJMSTimestamp())
+ && (timeAfterSend >= messageSentMapMessage.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "MapMessage TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from MapMessage");
+ pass = false;
+ }
+
+ // send bytes message
+
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Queue.");
+
+ messageSentBytesMessage.setStringProperty("TestCase", "dummy");
+
+ messageSentBytesMessage.writeByte(bValue);
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ mSender.send(messageSentBytesMessage);
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSentBytesMessage.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentBytesMessage.getJMSTimestamp())
+ && (timeAfterSend >= messageSentBytesMessage.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "BytesMessage TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from BytesMessage");
+ pass = false;
+ }
+
+ // Send a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a Stream message");
+
+ messageSentStreamMessage.setStringProperty("TestCase", "dummy");
+
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending message");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ mSender.send(messageSentStreamMessage);
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSentStreamMessage.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSentStreamMessage.getJMSTimestamp())
+ && (timeAfterSend >= messageSentStreamMessage.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "StreamMessage TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from StreamMessage");
+ pass = false;
+ }
+
+ // Text Message
+
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("TestCase", "dummy");
+
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ mSender.send(messageSent);
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSent.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSent.getJMSTimestamp()) && (timeAfterSend >= messageSent.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "TextMessage TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from TextMessage");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: create a text msg, set correlation id
+ */
+ private void msgHdrCorlIdQTextTestCreate() {
+
+ String jmsCorrelationID = "test Correlation id";
+ try {
+
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrCorlIdQTextTest");
+
+ logger.log(Logger.Level.TRACE, "Send Text Message to Queue.");
+ messageSent.setJMSCorrelationID(jmsCorrelationID);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create a stream msg, set correlation id
+ */
+ private void msgHdrCorlIdQStreamTestCreate() {
+
+ String jmsCorrelationID = "test Correlation id";
+ try {
+
+ messageSentStreamMessage.setStringProperty("TestCase", "msgHdrCorlIdQStreamTest");
+ messageSentStreamMessage.setJMSCorrelationID(jmsCorrelationID);
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending Stream message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSentStreamMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create a bytes msg, set correlation id
+ */
+ private void msgHdrCorlIdQBytesTestCreate() {
+ byte bValue = 127;
+
+ String jmsCorrelationID = "test Correlation id";
+ try {
+
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Queue.");
+
+ messageSentBytesMessage.setStringProperty("TestCase", "msgHdrCorlIdQBytesTest");
+ messageSentBytesMessage.setJMSCorrelationID(jmsCorrelationID);
+ messageSentBytesMessage.writeByte(bValue);
+
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSentBytesMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create a mao msg, set correlation id
+ */
+ private void msgHdrCorlIdQMapTestCreate() {
+
+ String jmsCorrelationID = "test Correlation id";
+ try {
+
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Queue.");
+
+ messageSentMapMessage.setStringProperty("TestCase", "msgHdrCorlIdQMapTest");
+ messageSentMapMessage.setJMSCorrelationID(jmsCorrelationID);
+ messageSentMapMessage.setString("aString", "value");
+
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSentMapMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create an object msg, set correlation id
+ */
+ private void msgHdrCorlIdQObjectTestCreate() {
+
+ String jmsCorrelationID = "test Correlation id";
+ try {
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Queue.");
+
+ messageSentObjectMessage.setObject("msgHdrIDQObjectTest for Object Message");
+ messageSentObjectMessage.setStringProperty("TestCase", "msgHdrCorlIdQObjectTest");
+ messageSentObjectMessage.setJMSCorrelationID(jmsCorrelationID);
+
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSentObjectMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+
+ }
+
+ public void msgHdrCorlIdQTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ String jmsCorrelationID = "test Correlation id";
+ try {
+ logger.log(Logger.Level.TRACE, "jmsCorrelationID: " + messageReceived.getJMSCorrelationID());
+ if (messageReceived.getJMSCorrelationID() == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Text Message Error: JMSCorrelationID returned a null");
+ } else if (messageReceived.getJMSCorrelationID().equals(jmsCorrelationID)) {
+ logger.log(Logger.Level.TRACE, "pass");
+ } else {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Text Message Error: JMSCorrelationID is incorrect");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ try {
+ sendTestResults(messageReceived.getStringProperty("TestCase"), pass);
+ } catch (Exception j) {
+ TestUtil.printStackTrace(j);
+ }
+ }
+ }
+
+ /*
+ *
+ */
+ public void msgHdrReplyToQTestCreate() {
+ Queue replyQueue = null;
+ try {
+
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrReplyToQTest");
+ messageSent.setJMSReplyTo(queue);
+
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrReplyToQTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ Queue replyQueue = null;
+ String testCase = "msgHdrReplyToQTest";
+ try {
+ replyQueue = (Queue) messageReceived.getJMSReplyTo();
+ logger.log(Logger.Level.TRACE, "Queue name is " + replyQueue.getQueueName());
+ if (replyQueue.getQueueName().equals(queue.getQueueName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "ReplyTo Failed");
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ public void msgHdrJMSTypeQTestCreate() {
+ boolean pass = true;
+ byte bValue = 127;
+ String type = "TESTMSG";
+ try {
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrJMSTypeQTest");
+ logger.log(Logger.Level.TRACE, "JMSType test - Send a Text message");
+ messageSent.setJMSType(type);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrJMSTypeQTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ String type = "TESTMSG";
+ String testCase = "msgHdrJMSTypeQTest";
+ try {
+
+ logger.log(Logger.Level.TRACE, "JMSType is " + (String) messageReceived.getJMSType());
+ if (messageReceived.getJMSType().equals(type)) {
+ logger.log(Logger.Level.TRACE, "Pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Text Message Failed");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ public void msgHdrJMSPriorityQTestCreate() {
+ boolean pass = true;
+ byte bValue = 127;
+ int priority = 2;
+ try {
+
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrJMSPriorityQTest");
+ logger.log(Logger.Level.TRACE, "JMSPriority test - Send a Text message");
+ mSender = qSession.createSender(queue);
+ mSender.setPriority(priority);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrJMSPriorityQTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ int priority = 2;
+ String testCase = "msgHdrJMSPriorityQTest";
+ try {
+ logger.log(Logger.Level.TRACE, "JMSPriority is " + messageReceived.getJMSPriority());
+ if (messageReceived.getJMSPriority() == priority) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "JMSPriority test Failed");
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ public void msgHdrJMSExpirationQueueTestCreate() {
+ boolean pass = true;
+ long forever = 0;
+ try {
+
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrJMSExpirationQueueTest");
+ logger.log(Logger.Level.TRACE, "JMSExpiration test - Send a Text message");
+
+ mSender = qSession.createSender(queue);
+ mSender.setTimeToLive(forever);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrJMSExpirationQueueTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ long forever = 0;
+ String testCase = "msgHdrJMSExpirationQueueTest";
+ try {
+
+ logger.log(Logger.Level.TRACE, "JMSExpiration is " + messageReceived.getJMSExpiration());
+ if (messageReceived.getJMSExpiration() == forever) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Text Message Failed");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ public void msgHdrJMSDestinationQTestCreate() {
+ Queue replyDestination = null;
+ try {
+
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrJMSDestinationQTest");
+ logger.log(Logger.Level.TRACE, "send msg for JMSDestination test.");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrJMSDestinationQTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ Queue replyDestination = null;
+ String testCase = "msgHdrJMSDestinationQTest";
+
+ try {
+ logger.log(Logger.Level.TRACE, "JMSDestination: " + messageReceived.getJMSDestination());
+ replyDestination = (Queue) messageReceived.getJMSDestination();
+ if (replyDestination != null)
+ logger.log(Logger.Level.TRACE, "Queue name is " + replyDestination.getQueueName());
+
+ if (replyDestination == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Text Message Error: JMSDestination returned a null");
+ } else if (replyDestination.getQueueName().equals(queue.getQueueName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Text Message Failed");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected Exception thrown in msgHdrJMSDestinationQTest:", e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ public void msgHdrJMSDeliveryModeQTestCreate() {
+ try {
+
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrJMSDeliveryModeQTest");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrJMSDeliveryModeQTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ String testCase = "msgHdrJMSDeliveryModeQTest";
+ try {
+
+ logger.log(Logger.Level.TRACE, "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Error: JMSDeliveryMode should be set to persistent as default");
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: Default delivery mode is persistent");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ public void msgHdrIDQTestCreate() {
+ String id = null;
+ try {
+
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("TestCase", "msgHdrIDQTest");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrIDQTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ String id = null;
+ String testCase = "msgHdrIDQTest";
+ try {
+
+ logger.log(Logger.Level.TRACE, "getJMSMessageID ");
+ logger.log(Logger.Level.TRACE, " " + messageReceived.getJMSMessageID());
+ id = messageReceived.getJMSMessageID();
+
+ if (id.startsWith("ID:")) {
+ logger.log(Logger.Level.TRACE, "Pass: JMSMessageID start with ID:");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: JMSMessageID does not start with ID:");
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: send test results to response queue (MDB_QUEUE_REPLY) for
+ * verification
+ */
+ private void sendTestResults(String testCase, boolean results) {
+ TextMessage msg = null;
+
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ msg.setStringProperty("TestCase", testCase);
+ msg.setText(testCase);
+ if (results)
+ msg.setStringProperty("Status", "Pass");
+ else
+ msg.setStringProperty("Status", "Fail");
+
+ mSender.send(msg);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ System.out.println("Error: " + je.getClass().getName() + " was thrown");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ System.out.println("Error: " + ee.getClass().getName() + " was thrown");
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgHdrQ In MsgBeanMsgTestHdrQ::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgHdrQ In MsgBeanMsgTestHdrQ::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrT/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrT/MDBClient.java
deleted file mode 100644
index 568dc478ec..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrT/MDBClient.java
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_msgHdrT;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.MDB_T_Test;
-
-import jakarta.ejb.EJB;
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_MSGHdrT_Test")
- private static MDB_T_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.port;
- * harness.log.traceflag;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrTimeStampTTest
- *
- * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347;
- *
- * @test_Strategy: Invoke a stateful session bean have the session bean call
- * an mdb to Send a single Text, map, bytes, stream, and object message check
- * time of send against time send returns JMSTimeStamp should be between these
- * two Send Pass/Fail message to MDB_QUEUE_REPLY Have session bean check the
- * queue for pass/fail results
- */
- public void mdbMsgHdrTimeStampTTest() throws Exception {
- String testCase = "msgHdrTimeStampTTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil
- .logTrace("Call bean - have it tell mdb to run msgHdrTimeStampTTest");
- hr.askMDBToRunATest(testCase);
- if (!hr.checkOnResponse(testCase)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrTimeStampTTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrCorlIdTTextTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- * @test_Strategy: Invoke a stateful session bean have the session bean call
- * an mdb to Send a text message to a Topic with CorrelationID set. Receive
- * msg and verify the correlationid is as set by client Send Pass/Fail message
- * to MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
- *
- */
- public void mdbMsgHdrCorlIdTTextTest() throws Exception {
- String testCase1 = "msgHdrCorlIdTTextTestCreate";
- String testCase2 = "msgHdrCorlIdTTextTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrCorlIdTTextTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrCorlIdTTextTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrCorlIdTBytesTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- * @test_Strategy: Invoke a stateful session bean have the session bean call
- * an mdb to send a Bytes message to a Topic with CorrelationID set. Receive
- * msg and verify the correlationid is as set by client Send Pass/Fail message
- * to MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
- */
- public void mdbMsgHdrCorlIdTBytesTest() throws Exception {
- String testCase1 = "msgHdrCorlIdTBytesTestCreate";
- String testCase2 = "msgHdrCorlIdTBytesTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrCorlIdTBytesTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrCorlIdTBytesTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrCorlIdTMapTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- * @test_Strategy: Invoke a stateful session bean have the session bean call
- * an mdb to send a map message to a Topic with CorrelationID set. Receive msg
- * and verify the correlationid is as set by client Send Pass/Fail message to
- * MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
- *
- */
- public void mdbMsgHdrCorlIdTMapTest() throws Exception {
- String testCase1 = "msgHdrCorlIdTMapTestCreate";
- String testCase2 = "msgHdrCorlIdTMapTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrCorlIdTMapTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrCorlIdTMapTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrCorlIdTStreamTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:119; JMS:SPEC:12;
- * JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- * @test_Strategy: Invoke a stateful session bean have the session bean call
- * an mdb to send a stream message to a Topic with CorrelationID set. Receive
- * msg and verify the correlationid is as set by client Send Pass/Fail message
- * to MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
- *
- */
- public void mdbMsgHdrCorlIdTStreamTest() throws Exception {
- String testCase1 = "msgHdrCorlIdTStreamTestCreate";
- String testCase2 = "msgHdrCorlIdTStreamTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrCorlIdTStreamTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrCorlIdTStreamTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrCorlIdTObjectTest
- *
- * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:119; JMS:SPEC:12;
- * JMS:JAVADOC:355; JMS:JAVADOC:357;
- *
- * @test_Strategy: Invoke a stateful session bean have the session bean call
- * an mdb to send a stream message to a Topic with CorrelationID set. Receive
- * msg and verify the correlationid is as set by client Send Pass/Fail message
- * to MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
- *
- */
- public void mdbMsgHdrCorlIdTObjectTest() throws Exception {
- String testCase1 = "msgHdrCorlIdTObjectTestCreate";
- String testCase2 = "msgHdrCorlIdTObjectTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrCorlIdTObjectTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrCorlIdTObjectTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrReplyToTTest
- *
- * @assertion_ids: JMS:SPEC:12; JMS:JAVADOC:359; JMS:JAVADOC:361;
- * JMS:JAVADOC:286; JMS:JAVADOC:289; JMS:JAVADOC:562; JMS:JAVADOC:166;
- * JMS:SPEC:246.8;
- *
- * @test_Strategy: Invoke a session bean. Have the session bean request an mdb
- * to send a message to a Topic with ReplyTo set to a destination. Have the
- * mdb verify on receive. Send Pass/Fail message to MDB_QUEUE_REPLY Have
- * session bean check the queue for pass/fail results
- *
- */
- public void mdbMsgHdrReplyToTTest() throws Exception {
- String testCase1 = "msgHdrReplyToTTestCreate";
- String testCase2 = "msgHdrReplyToTTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrReplyToTTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrReplyToTTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrJMSTypeTTest
- *
- * @assertion_ids: JMS:SPEC:246.9; JMS:JAVADOC:375; JMS:JAVADOC:377;
- *
- * @test_Strategy: Invoke a session bean. Have the session bean request an mdb
- * to send a message to a Topic with JMSType set to TESTMSG verify on receive.
- * Send Pass/Fail message to MDB_QUEUE_REPLY Have session bean check the queue
- * for pass/fail results
- *
- */
- public void mdbMsgHdrJMSTypeTTest() throws Exception {
- String testCase1 = "msgHdrJMSTypeTTestCreate";
- String testCase2 = "msgHdrJMSTypeTTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrJMSTypeTTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrJMSTypeTTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrJMSPriorityTTest
- *
- * @assertion_ids: JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140; JMS:JAVADOC:305;
- * JMS:JAVADOC:383;
- *
- * @test_Strategy: Invoke a stateful session bean have the session bean call
- * an mdb to send a message to a Topic with JMSPriority set to 2 test with
- * Text, map, object, byte, and stream messages Send Pass/Fail message to
- * MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
- *
- */
- public void mdbMsgHdrJMSPriorityTTest() throws Exception {
- String testCase1 = "msgHdrJMSPriorityTTestCreate";
- String testCase2 = "msgHdrJMSPriorityTTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run mdbMsgHdrJMSTypeTTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbMsgHdrJMSTypeTTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrJMSExpirationTopicTest
- *
- * @assertion_ids: JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140;
- * JMS:JAVADOC:309; JMS:JAVADOC:379;
- *
- * @test_Strategy: Invoke a stateful session bean have the session bean call
- * an mdb to send a message to a Topic with time to live set to 0 Verify that
- * JMSExpiration gets set to 0 test with Text, map, object, byte, and stream
- * messages Send Pass/Fail message to MDB_QUEUE_REPLY Have session bean check
- * the queue for pass/fail results
- *
- */
- public void mdbMsgHdrJMSExpirationTopicTest() throws Exception {
- String testCase1 = "msgHdrJMSExpirationTopicTestCreate";
- String testCase2 = "msgHdrJMSExpirationTopicTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrJMSExpirationTopicTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrJMSExpirationTopicTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrJMSDestinationTTest
- *
- * @assertion_ids: JMS:SPEC:2; JMS:JAVADOC:363; JMS:JAVADOC:286;
- *
- * @test_Strategy: Invoke a stateful session bean have the session bean call
- * an mdb to create and send a message to the mdb Topic. Receive msg and
- * verify that JMSDestination is set as expected test with Text, map, object,
- * byte, and stream messages Send Pass/Fail message to MDB_QUEUE_REPLY Have
- * session bean check the queue for pass/fail results
- */
- public void mdbMsgHdrJMSDestinationTTest() throws Exception {
- String testCase1 = "msgHdrJMSDestinationTTestCreate";
- String testCase2 = "msgHdrJMSDestinationTTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrJMSDestinationTTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrJMSDestinationTTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrJMSDeliveryModeTTest
- *
- * @assertion_ids: JMS:SPEC:3; JMS:SPEC:140; JMS:JAVADOC:367; JMS:SPEC:246.2;
- * JMS:JAVADOC:301;
- *
- * @test_Strategy: Invoke a stateful session bean have the session bean call
- * an mdb to create and send a message to the default Topic. Receive the msg
- * and verify that JMSDeliveryMode is set the default delivery mode of
- * persistent. Create and test another message with a nonpersistent delivery
- * mode. test with Text, map, object, byte, and stream messages Send Pass/Fail
- * message to MDB_QUEUE_REPLY Have session bean check the queue for pass/fail
- * results
- */
- public void mdbMsgHdrJMSDeliveryModeTTest() throws Exception {
- String testCase1 = "msgHdrJMSDeliveryModeTTestCreate";
- String testCase2 = "msgHdrJMSDeliveryModeTTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgHdrJMSDeliveryModeTTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrJMSDeliveryModeTTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgHdrIDTTest
- *
- * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343;
- *
- * @test_Strategy: Invoke a stateful session bean have the session bean call
- * an mdb to send and receive single Text, map, bytes, stream, and object
- * message call getJMSMessageID and verify that it starts with ID: Send
- * Pass/Fail message to MDB_QUEUE_REPLY Have session bean check the queue for
- * pass/fail results
- */
- public void mdbMsgHdrIDTTest() throws Exception {
-
- String testCase1 = "msgHdrIDTTestCreate";
- String testCase2 = "msgHdrIDTTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil
- .logTrace("Call bean - have it tell mdb to run msgHdrIDTTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgHdrIDTTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- ;
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrT/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrT/MDBClientIT.java
new file mode 100644
index 0000000000..685e7a020e
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrT/MDBClientIT.java
@@ -0,0 +1,473 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_msgHdrT;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.commonee.MDB_T_Test;
+
+import jakarta.ejb.EJB;
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_MSGHdrT_Test")
+ private static MDB_T_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password; harness.log.port;
+ * harness.log.traceflag;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ hr.setup(props);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrTimeStampTTest
+ *
+ * @assertion_ids: JMS:SPEC:7; JMS:JAVADOC:347;
+ *
+ * @test_Strategy: Invoke a stateful session bean have the session bean call an
+ * mdb to Send a single Text, map, bytes, stream, and object message check time
+ * of send against time send returns JMSTimeStamp should be between these two
+ * Send Pass/Fail message to MDB_QUEUE_REPLY Have session bean check the queue
+ * for pass/fail results
+ */
+ @Test
+ public void mdbMsgHdrTimeStampTTest() throws Exception {
+ String testCase = "msgHdrTimeStampTTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrTimeStampTTest");
+ hr.askMDBToRunATest(testCase);
+ if (!hr.checkOnResponse(testCase)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrTimeStampTTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrCorlIdTTextTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ * @test_Strategy: Invoke a stateful session bean have the session bean call an
+ * mdb to Send a text message to a Topic with CorrelationID set. Receive msg and
+ * verify the correlationid is as set by client Send Pass/Fail message to
+ * MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
+ *
+ */
+ @Test
+ public void mdbMsgHdrCorlIdTTextTest() throws Exception {
+ String testCase1 = "msgHdrCorlIdTTextTestCreate";
+ String testCase2 = "msgHdrCorlIdTTextTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrCorlIdTTextTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrCorlIdTTextTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrCorlIdTBytesTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ * @test_Strategy: Invoke a stateful session bean have the session bean call an
+ * mdb to send a Bytes message to a Topic with CorrelationID set. Receive msg
+ * and verify the correlationid is as set by client Send Pass/Fail message to
+ * MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
+ */
+ @Test
+ public void mdbMsgHdrCorlIdTBytesTest() throws Exception {
+ String testCase1 = "msgHdrCorlIdTBytesTestCreate";
+ String testCase2 = "msgHdrCorlIdTBytesTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrCorlIdTBytesTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrCorlIdTBytesTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrCorlIdTMapTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ * @test_Strategy: Invoke a stateful session bean have the session bean call an
+ * mdb to send a map message to a Topic with CorrelationID set. Receive msg and
+ * verify the correlationid is as set by client Send Pass/Fail message to
+ * MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
+ *
+ */
+ @Test
+ public void mdbMsgHdrCorlIdTMapTest() throws Exception {
+ String testCase1 = "msgHdrCorlIdTMapTestCreate";
+ String testCase2 = "msgHdrCorlIdTMapTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrCorlIdTMapTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrCorlIdTMapTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrCorlIdTStreamTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:119; JMS:SPEC:12;
+ * JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ * @test_Strategy: Invoke a stateful session bean have the session bean call an
+ * mdb to send a stream message to a Topic with CorrelationID set. Receive msg
+ * and verify the correlationid is as set by client Send Pass/Fail message to
+ * MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
+ *
+ */
+ @Test
+ public void mdbMsgHdrCorlIdTStreamTest() throws Exception {
+ String testCase1 = "msgHdrCorlIdTStreamTestCreate";
+ String testCase2 = "msgHdrCorlIdTStreamTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrCorlIdTStreamTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrCorlIdTStreamTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrCorlIdTObjectTest
+ *
+ * @assertion_ids: JMS:SPEC:246.7; JMS:JAVADOC:119; JMS:SPEC:12;
+ * JMS:JAVADOC:355; JMS:JAVADOC:357;
+ *
+ * @test_Strategy: Invoke a stateful session bean have the session bean call an
+ * mdb to send a stream message to a Topic with CorrelationID set. Receive msg
+ * and verify the correlationid is as set by client Send Pass/Fail message to
+ * MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
+ *
+ */
+ @Test
+ public void mdbMsgHdrCorlIdTObjectTest() throws Exception {
+ String testCase1 = "msgHdrCorlIdTObjectTestCreate";
+ String testCase2 = "msgHdrCorlIdTObjectTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrCorlIdTObjectTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrCorlIdTObjectTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrReplyToTTest
+ *
+ * @assertion_ids: JMS:SPEC:12; JMS:JAVADOC:359; JMS:JAVADOC:361;
+ * JMS:JAVADOC:286; JMS:JAVADOC:289; JMS:JAVADOC:562; JMS:JAVADOC:166;
+ * JMS:SPEC:246.8;
+ *
+ * @test_Strategy: Invoke a session bean. Have the session bean request an mdb
+ * to send a message to a Topic with ReplyTo set to a destination. Have the mdb
+ * verify on receive. Send Pass/Fail message to MDB_QUEUE_REPLY Have session
+ * bean check the queue for pass/fail results
+ *
+ */
+ @Test
+ public void mdbMsgHdrReplyToTTest() throws Exception {
+ String testCase1 = "msgHdrReplyToTTestCreate";
+ String testCase2 = "msgHdrReplyToTTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrReplyToTTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrReplyToTTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrJMSTypeTTest
+ *
+ * @assertion_ids: JMS:SPEC:246.9; JMS:JAVADOC:375; JMS:JAVADOC:377;
+ *
+ * @test_Strategy: Invoke a session bean. Have the session bean request an mdb
+ * to send a message to a Topic with JMSType set to TESTMSG verify on receive.
+ * Send Pass/Fail message to MDB_QUEUE_REPLY Have session bean check the queue
+ * for pass/fail results
+ *
+ */
+ @Test
+ public void mdbMsgHdrJMSTypeTTest() throws Exception {
+ String testCase1 = "msgHdrJMSTypeTTestCreate";
+ String testCase2 = "msgHdrJMSTypeTTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrJMSTypeTTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrJMSTypeTTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrJMSPriorityTTest
+ *
+ * @assertion_ids: JMS:SPEC:16; JMS:SPEC:18; JMS:SPEC:140; JMS:JAVADOC:305;
+ * JMS:JAVADOC:383;
+ *
+ * @test_Strategy: Invoke a stateful session bean have the session bean call an
+ * mdb to send a message to a Topic with JMSPriority set to 2 test with Text,
+ * map, object, byte, and stream messages Send Pass/Fail message to
+ * MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
+ *
+ */
+ @Test
+ public void mdbMsgHdrJMSPriorityTTest() throws Exception {
+ String testCase1 = "msgHdrJMSPriorityTTestCreate";
+ String testCase2 = "msgHdrJMSPriorityTTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run mdbMsgHdrJMSTypeTTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbMsgHdrJMSTypeTTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrJMSExpirationTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:15.2; JMS:SPEC:15.3; JMS:SPEC:140; JMS:JAVADOC:309;
+ * JMS:JAVADOC:379;
+ *
+ * @test_Strategy: Invoke a stateful session bean have the session bean call an
+ * mdb to send a message to a Topic with time to live set to 0 Verify that
+ * JMSExpiration gets set to 0 test with Text, map, object, byte, and stream
+ * messages Send Pass/Fail message to MDB_QUEUE_REPLY Have session bean check
+ * the queue for pass/fail results
+ *
+ */
+ @Test
+ public void mdbMsgHdrJMSExpirationTopicTest() throws Exception {
+ String testCase1 = "msgHdrJMSExpirationTopicTestCreate";
+ String testCase2 = "msgHdrJMSExpirationTopicTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrJMSExpirationTopicTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrJMSExpirationTopicTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrJMSDestinationTTest
+ *
+ * @assertion_ids: JMS:SPEC:2; JMS:JAVADOC:363; JMS:JAVADOC:286;
+ *
+ * @test_Strategy: Invoke a stateful session bean have the session bean call an
+ * mdb to create and send a message to the mdb Topic. Receive msg and verify
+ * that JMSDestination is set as expected test with Text, map, object, byte, and
+ * stream messages Send Pass/Fail message to MDB_QUEUE_REPLY Have session bean
+ * check the queue for pass/fail results
+ */
+ @Test
+ public void mdbMsgHdrJMSDestinationTTest() throws Exception {
+ String testCase1 = "msgHdrJMSDestinationTTestCreate";
+ String testCase2 = "msgHdrJMSDestinationTTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrJMSDestinationTTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrJMSDestinationTTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrJMSDeliveryModeTTest
+ *
+ * @assertion_ids: JMS:SPEC:3; JMS:SPEC:140; JMS:JAVADOC:367; JMS:SPEC:246.2;
+ * JMS:JAVADOC:301;
+ *
+ * @test_Strategy: Invoke a stateful session bean have the session bean call an
+ * mdb to create and send a message to the default Topic. Receive the msg and
+ * verify that JMSDeliveryMode is set the default delivery mode of persistent.
+ * Create and test another message with a nonpersistent delivery mode. test with
+ * Text, map, object, byte, and stream messages Send Pass/Fail message to
+ * MDB_QUEUE_REPLY Have session bean check the queue for pass/fail results
+ */
+ @Test
+ public void mdbMsgHdrJMSDeliveryModeTTest() throws Exception {
+ String testCase1 = "msgHdrJMSDeliveryModeTTestCreate";
+ String testCase2 = "msgHdrJMSDeliveryModeTTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrJMSDeliveryModeTTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrJMSDeliveryModeTTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgHdrIDTTest
+ *
+ * @assertion_ids: JMS:SPEC:4; JMS:JAVADOC:343;
+ *
+ * @test_Strategy: Invoke a stateful session bean have the session bean call an
+ * mdb to send and receive single Text, map, bytes, stream, and object message
+ * call getJMSMessageID and verify that it starts with ID: Send Pass/Fail
+ * message to MDB_QUEUE_REPLY Have session bean check the queue for pass/fail
+ * results
+ */
+ @Test
+ public void mdbMsgHdrIDTTest() throws Exception {
+
+ String testCase1 = "msgHdrIDTTestCreate";
+ String testCase2 = "msgHdrIDTTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgHdrIDTTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgHdrIDTTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ ;
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrT/MsgBeanMsgTestHdrT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrT/MsgBeanMsgTestHdrT.java
index 96310486fd..e7830c74f4 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrT/MsgBeanMsgTestHdrT.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgHdrT/MsgBeanMsgTestHdrT.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_msgHdrT;
+import java.lang.System.Logger;
import java.util.Enumeration;
import java.util.Vector;
@@ -52,744 +53,702 @@
public class MsgBeanMsgTestHdrT implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties props = null;
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties props = null;
- private TSNamingContext context = null;
+ private TSNamingContext context = null;
- private MessageDrivenContext mdc = null;
+ private MessageDrivenContext mdc = null;
- // JMS
- private QueueConnectionFactory qFactory = null;
+ // JMS
+ private QueueConnectionFactory qFactory = null;
- private QueueConnection qConnection = null;
+ private QueueConnection qConnection = null;
- private Queue queueR = null;
+ private Queue queueR = null;
- private QueueSession qSession = null;
+ private QueueSession qSession = null;
- private QueueSender mSender;
+ private QueueSender mSender;
- private Topic topic;
+ private Topic topic;
- private TopicConnection tConnection;
+ private TopicConnection tConnection;
- private TopicSession tSession;
+ private TopicSession tSession;
- private TopicConnectionFactory tFactory;
+ private TopicConnectionFactory tFactory;
- private TopicPublisher tSender;
+ private TopicPublisher tSender;
- private TextMessage messageSent = null;
+ private TextMessage messageSent = null;
- private StreamMessage messageSentStreamMessage = null;
+ private StreamMessage messageSentStreamMessage = null;
- private BytesMessage messageSentBytesMessage = null;
-
- private MapMessage messageSentMapMessage = null;
-
- private ObjectMessage messageSentObjectMsg = null;
-
- public MsgBeanMsgTestHdrT() {
- TestUtil.logTrace("@MsgBeanMsgTestHdrT()!");
- };
-
- public void ejbCreate() {
- props = new java.util.Properties();
-
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgHdrT - @MsgBeanMsgTestHdrT-ejbCreate() !!");
- try {
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- if (qFactory == null) {
- TestUtil.logTrace("qFactory error");
- }
- TestUtil.logTrace("got a qFactory !!");
- queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- if (queueR == null) {
- TestUtil.logTrace("queueR error");
- }
-
- tFactory = (TopicConnectionFactory) context
- .lookup("java:comp/env/jms/MyTopicConnectionFactory");
- topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
-
- TestUtil.logTrace("from jms.ee.mdb.mdb_msgHdrT @onMessage!" + msg);
-
- try {
- JmsUtil.initHarnessProps(msg, props);
- TestUtil.logTrace("from jms.ee.mdb.mdb_msgHdrT @onMessage!" + msg);
-
- TestUtil.logTrace(
- "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
- tConnection = tFactory.createTopicConnection();
- if (tConnection == null) {
- TestUtil.logTrace("connection error");
- } else {
- tConnection.start();
- tSession = tConnection.createTopicSession(true, 0);
- }
-
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null) {
- System.out.println("connection error");
- } else {
- qConnection.start();
- qSession = qConnection.createQueueSession(true, 0);
- }
-
- // Send a message back to acknowledge that the mdb received the message.
-
- // create testmessages
- Vector mVec = new Vector();
- messageSent = tSession.createTextMessage();
- mVec.addElement(messageSent);
- messageSentStreamMessage = tSession.createStreamMessage();
- mVec.addElement(messageSentStreamMessage);
- messageSentBytesMessage = tSession.createBytesMessage();
- mVec.addElement(messageSentBytesMessage);
- messageSentMapMessage = tSession.createMapMessage();
- mVec.addElement(messageSentMapMessage);
- messageSentObjectMsg = tSession.createObjectMessage();
- mVec.addElement(messageSentObjectMsg);
-
- // for each message addPropsToMessage
- Enumeration vNum = mVec.elements();
- while (vNum.hasMoreElements()) {
- JmsUtil.addPropsToMessage((Message) vNum.nextElement(), props);
- }
-
- if (msg.getStringProperty("TestCase").equals("msgHdrTimeStampTTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgHdrTimeStampTTest - create the message");
- msgHdrTimeStampTTest();
- } else if (msg.getStringProperty("TestCase").equals("dummy")) {
- TestUtil.logTrace("@onMessage - ignore this!");
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdTTextTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdTTextTestCreate!");
- msgHdrCorlIdTTextTestCreate();
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdTTextTest")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdTTextTest!");
- msgHdrCorlIdTTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdTBytesTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdTBytesTestCreate!");
- msgHdrCorlIdTBytesTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdTBytesTest")) {
- TestUtil.logTrace("@onMessage -msgHdrCorlIdTBytesTest!");
- msgHdrCorlIdTTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdTMapTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdTMapTestCreate!");
- msgHdrCorlIdTMapTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdTMapTest")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdTMapTest!");
- msgHdrCorlIdTTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdTStreamTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdTStreamTestCreate!");
- msgHdrCorlIdTStreamTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdTStreamTest")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdTStreamTest!");
- msgHdrCorlIdTTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdTObjectTestCreate")) {
- TestUtil.logTrace("@onMessage -msgHdrCorlIdTObjectTestCreate!");
- msgHdrCorlIdTObjectTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrCorlIdTObjectTest")) {
- TestUtil.logTrace("@onMessage - msgHdrCorlIdTObjectTest!");
- msgHdrCorlIdTTest(msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("msgHdrReplyToTTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrReplyToTTestCreate!");
- msgHdrReplyToTTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrReplyToTTest")) {
- TestUtil.logTrace("@onMessage - msgHdrReplyToTTest!");
- msgHdrReplyToTTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSTypeTTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSTypeTTestCreate!");
- msgHdrJMSTypeTTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSTypeTTest")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSTypeTTest!");
- msgHdrJMSTypeTTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSPriorityTTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSPriorityTTestCreate!");
- msgHdrJMSPriorityTTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSPriorityTTest")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSPriorityTTest!");
- msgHdrJMSPriorityTTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSExpirationTopicTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSExpirationTopicTestCreate!");
- msgHdrJMSExpirationTopicTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSExpirationTopicTest")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSExpirationTopicTest!");
- msgHdrJMSExpirationTopicTest(msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSDestinationTTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSDestinationTTestCreate!");
- msgHdrJMSDestinationTTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSDestinationTTest")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSDestinationTTest!");
- msgHdrJMSDestinationTTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSDeliveryModeTTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSDeliveryModeTTestCreate!");
- msgHdrJMSDeliveryModeTTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrJMSDeliveryModeTTest")) {
- TestUtil.logTrace("@onMessage - msgHdrJMSDeliveryModeTTest!");
- msgHdrJMSDeliveryModeTTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgHdrIDTTestCreate")) {
- TestUtil.logTrace("@onMessage - msgHdrIDTTestCreate!");
- msgHdrIDTTestCreate();
- } else if (msg.getStringProperty("TestCase").equals("msgHdrIDTTest")) {
- TestUtil.logTrace("@onMessage - msgHdrIDTTest!");
- msgHdrIDTTest(msg);
- }
-
- else {
- TestUtil.logTrace(
- "@onMessage - invalid message type found in StringProperty");
- TestUtil.logTrace("Do not have a method for this testcase: "
- + msg.getStringProperty("TestCase"));
- }
- TestUtil.logTrace("@onMessage - Finished for this test!");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- if (tConnection != null) {
- try {
- tConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
- }
-
- /*
- * Description: Send a single Text message check time of send against time
- * send returns JMSTimeStamp should be between these two
- */
- public void msgHdrTimeStampTTest() {
- boolean pass = true;
- long timeBeforeSend;
- long timeAfterSend;
- byte bValue = 127;
- String id = null;
- String testCase = "msgHdrTimeStampTTest";
- try {
-
- // Text Message
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("TestCase", "dummy");
- TestUtil.logTrace("sending a Text message");
-
- // get the current time in milliseconds - before and after the send
- timeBeforeSend = System.currentTimeMillis();
- tSender = tSession.createPublisher(topic);
- tSender.publish(messageSent);
- // message has been sent
- timeAfterSend = System.currentTimeMillis();
-
- TestUtil.logTrace(" getJMSTimestamp");
- TestUtil.logTrace(" " + messageSent.getJMSTimestamp());
- TestUtil.logTrace("Time at send is: " + timeBeforeSend);
- TestUtil.logTrace("Time after return fromsend is:" + timeAfterSend);
- if ((timeBeforeSend <= messageSent.getJMSTimestamp())
- && (timeAfterSend >= messageSent.getJMSTimestamp())) {
- TestUtil.logTrace("TextMessage TimeStamp pass");
- } else {
- TestUtil.logMsg("Error: invalid timestamp from TextMessage");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: create a text msg, set correlation id
- */
- private void msgHdrCorlIdTTextTestCreate() {
-
- String jmsCorrelationID = "test Correlation id";
- try {
-
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrCorlIdTTextTest");
-
- TestUtil.logTrace("Send Text Message to Topic.");
- messageSent.setJMSCorrelationID(jmsCorrelationID);
- tSender = tSession.createPublisher(topic);
- tSender.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create a stream msg, set correlation id
- */
- private void msgHdrCorlIdTStreamTestCreate() {
-
- String jmsCorrelationID = "test Correlation id";
- try {
-
- messageSentStreamMessage.setStringProperty("TestCase",
- "msgHdrCorlIdTStreamTest");
- messageSentStreamMessage.setJMSCorrelationID(jmsCorrelationID);
- messageSentStreamMessage.writeString("Testing...");
- TestUtil.logTrace("Sending Stream message");
- tSender = tSession.createPublisher(topic);
- tSender.publish(messageSentStreamMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create a bytes msg, set correlation id
- */
- private void msgHdrCorlIdTBytesTestCreate() {
- byte bValue = 127;
-
- String jmsCorrelationID = "test Correlation id";
- try {
-
- TestUtil.logTrace("Send BytesMessage to Topic.");
- messageSentBytesMessage.setStringProperty("TestCase",
- "msgHdrCorlIdTBytesTest");
- messageSentBytesMessage.setJMSCorrelationID(jmsCorrelationID);
- messageSentBytesMessage.writeByte(bValue);
-
- tSender = tSession.createPublisher(topic);
- tSender.publish(messageSentBytesMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create a mao msg, set correlation id
- */
- private void msgHdrCorlIdTMapTestCreate() {
-
- String jmsCorrelationID = "test Correlation id";
- try {
-
- TestUtil.logTrace("Send MapMessage to Topic.");
-
- messageSentMapMessage.setStringProperty("TestCase",
- "msgHdrCorlIdTMapTest");
- messageSentMapMessage.setJMSCorrelationID(jmsCorrelationID);
- messageSentMapMessage.setString("aString", "value");
-
- tSender = tSession.createPublisher(topic);
- tSender.publish(messageSentMapMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create an object msg, set correlation id
- */
- private void msgHdrCorlIdTObjectTestCreate() {
-
- String jmsCorrelationID = "test Correlation id";
- try {
-
- TestUtil.logTrace("Send ObjectMessage to Topic.");
-
- messageSentObjectMsg.setObject("msgHdrIDTObjectTest for Object Message");
- messageSentObjectMsg.setStringProperty("TestCase",
- "msgHdrCorlIdTObjectTest");
- messageSentObjectMsg.setJMSCorrelationID(jmsCorrelationID);
-
- tSender = tSession.createPublisher(topic);
- tSender.publish(messageSentObjectMsg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
-
- }
-
- public void msgHdrCorlIdTTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- String jmsCorrelationID = "test Correlation id";
- try {
- TestUtil.logTrace(
- "jmsCorrelationID: " + messageReceived.getJMSCorrelationID());
- if (messageReceived.getJMSCorrelationID() == null) {
- pass = false;
- TestUtil
- .logMsg("Text Message Error: JMSCorrelationID returned a null");
- } else if (messageReceived.getJMSCorrelationID()
- .equals(jmsCorrelationID)) {
- TestUtil.logTrace("pass");
- } else {
- pass = false;
- TestUtil.logMsg("Text Message Error: JMSCorrelationID is incorrect");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- try {
- sendTestResults(messageReceived.getStringProperty("TestCase"), pass);
- } catch (Exception j) {
- TestUtil.printStackTrace(j);
- }
- }
- }
-
- /*
- *
- */
- public void msgHdrReplyToTTestCreate() {
- Topic replyTopic = null;
- try {
-
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrReplyToTTest");
- messageSent.setJMSReplyTo(topic);
-
- tSender = tSession.createPublisher(topic);
- tSender.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrReplyToTTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- Topic replyTopic = null;
- String testCase = "msgHdrReplyToTTest";
- try {
- replyTopic = (Topic) messageReceived.getJMSReplyTo();
- TestUtil.logTrace("Topic name is " + replyTopic.getTopicName());
- if (replyTopic.getTopicName().equals(topic.getTopicName())) {
- TestUtil.logTrace("Pass ");
- } else {
- TestUtil.logMsg("ReplyTo Failed");
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- public void msgHdrJMSTypeTTestCreate() {
- boolean pass = true;
- byte bValue = 127;
- String type = "TESTMSG";
- try {
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrJMSTypeTTest");
- TestUtil.logTrace("JMSType test - Send a Text message");
- messageSent.setJMSType(type);
- tSender = tSession.createPublisher(topic);
- tSender.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrJMSTypeTTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- String type = "TESTMSG";
- String testCase = "msgHdrJMSTypeTTest";
- try {
-
- TestUtil.logTrace("JMSType is " + (String) messageReceived.getJMSType());
- if (messageReceived.getJMSType().equals(type)) {
- TestUtil.logTrace("Pass");
- } else {
- TestUtil.logMsg("Text Message Failed");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- public void msgHdrJMSPriorityTTestCreate() {
- boolean pass = true;
- byte bValue = 127;
- int priority = 2;
- try {
-
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrJMSPriorityTTest");
- TestUtil.logTrace("JMSPriority test - Send a Text message");
- tSender = tSession.createPublisher(topic);
- tSender.setPriority(priority);
- tSender.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrJMSPriorityTTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- int priority = 2;
- String testCase = "msgHdrJMSPriorityTTest";
- try {
- TestUtil.logTrace("JMSPriority is " + messageReceived.getJMSPriority());
- if (messageReceived.getJMSPriority() == priority) {
- TestUtil.logTrace("Pass ");
- } else {
- TestUtil.logMsg("JMSPriority test Failed");
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- public void msgHdrJMSExpirationTopicTestCreate() {
- boolean pass = true;
- long forever = 0;
- try {
-
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrJMSExpirationTopicTest");
- TestUtil.logTrace("JMSExpiration test - Send a Text message");
-
- tSender = tSession.createPublisher(topic);
- tSender.setTimeToLive(forever);
- tSender.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrJMSExpirationTopicTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- long forever = 0;
- String testCase = "msgHdrJMSExpirationTopicTest";
- try {
-
- TestUtil
- .logTrace("JMSExpiration is " + messageReceived.getJMSExpiration());
- if (messageReceived.getJMSExpiration() == forever) {
- TestUtil.logTrace("Pass ");
- } else {
- TestUtil.logMsg("Text Message Failed");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- public void msgHdrJMSDestinationTTestCreate() {
- Topic replyDestination = null;
- try {
-
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrJMSDestinationTTest");
- TestUtil.logTrace("send msg for JMSDestination test.");
- tSender = tSession.createPublisher(topic);
- tSender.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrJMSDestinationTTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- Topic replyDestination = null;
- String testCase = "msgHdrJMSDestinationTTest";
-
- try {
- TestUtil
- .logTrace("JMSDestination: " + messageReceived.getJMSDestination());
- replyDestination = (Topic) messageReceived.getJMSDestination();
-
- if (replyDestination != null)
- TestUtil.logTrace("Topic name is " + replyDestination.getTopicName());
-
- if (replyDestination == null) {
- pass = false;
- TestUtil.logMsg("Text Message Error: JMSDestination returned a null");
- } else if (replyDestination.getTopicName().equals(topic.getTopicName())) {
- TestUtil.logTrace("Pass ");
- } else {
- TestUtil.logMsg("Text Message Failed");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Unexpected Exception in msgHdrJMSDestinationTTest:", e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- public void msgHdrJMSDeliveryModeTTestCreate() {
- try {
-
- messageSent.setText("sending a message");
- messageSent.setStringProperty("TestCase", "msgHdrJMSDeliveryModeTTest");
- tSender = tSession.createPublisher(topic);
- tSender.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrJMSDeliveryModeTTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- String testCase = "msgHdrJMSDeliveryModeTTest";
- try {
-
- TestUtil.logTrace(
- "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
- if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
- pass = false;
- TestUtil.logMsg(
- "Error: JMSDeliveryMode should be set to persistent as default");
- } else {
- TestUtil.logTrace("Pass: Default delivery mode is persistent");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- public void msgHdrIDTTestCreate() {
- String id = null;
- try {
-
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("TestCase", "msgHdrIDTTest");
- tSender = tSession.createPublisher(topic);
- tSender.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void msgHdrIDTTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- String id = null;
- String testCase = "msgHdrIDTTest";
- try {
-
- TestUtil.logTrace("getJMSMessageID ");
- TestUtil.logTrace(" " + messageReceived.getJMSMessageID());
- id = messageReceived.getJMSMessageID();
-
- if (id.startsWith("ID:")) {
- TestUtil.logTrace("Pass: JMSMessageID start with ID:");
- } else {
- TestUtil.logMsg("Error: JMSMessageID does not start with ID:");
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: send test results to response queue (MDB_QUEUE_REPLY) for
- * verification
- */
- private void sendTestResults(String testCase, boolean results) {
- TextMessage msg = null;
-
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- msg.setStringProperty("TestCase", testCase);
- msg.setText(testCase);
- if (results)
- msg.setStringProperty("Status", "Pass");
- else
- msg.setStringProperty("Status", "Fail");
-
- TestUtil.logTrace("Sending response message");
- TestUtil.logTrace(
- "==================================Test Results from: " + testCase);
- TestUtil.logTrace("==================================Status: " + results);
- mSender.send(msg);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- TestUtil.logTrace("Error: " + je.getClass().getName() + " was thrown");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logTrace("Error: " + ee.getClass().getName() + " was thrown");
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgHdrT In MsgBeanMsgTestHdrT::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil
- .logTrace("jms.ee.mdb.mdb_msgHdrT In MsgBeanMsgTestHdrT::remove()!!");
- }
+ private BytesMessage messageSentBytesMessage = null;
+
+ private MapMessage messageSentMapMessage = null;
+
+ private ObjectMessage messageSentObjectMsg = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanMsgTestHdrT.class.getName());
+
+ public MsgBeanMsgTestHdrT() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanMsgTestHdrT()!");
+ };
+
+ public void ejbCreate() {
+ props = new java.util.Properties();
+
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgHdrT - @MsgBeanMsgTestHdrT-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ if (qFactory == null) {
+ logger.log(Logger.Level.TRACE, "qFactory error");
+ }
+ logger.log(Logger.Level.TRACE, "got a qFactory !!");
+ queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ if (queueR == null) {
+ logger.log(Logger.Level.TRACE, "queueR error");
+ }
+
+ tFactory = (TopicConnectionFactory) context.lookup("java:comp/env/jms/MyTopicConnectionFactory");
+ topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+
+ logger.log(Logger.Level.TRACE, "from jms.ee.mdb.mdb_msgHdrT @onMessage!" + msg);
+
+ try {
+ JmsUtil.initHarnessProps(msg, props);
+ logger.log(Logger.Level.TRACE, "from jms.ee.mdb.mdb_msgHdrT @onMessage!" + msg);
+
+ logger.log(Logger.Level.TRACE, "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
+ tConnection = tFactory.createTopicConnection();
+ if (tConnection == null) {
+ logger.log(Logger.Level.TRACE, "connection error");
+ } else {
+ tConnection.start();
+ tSession = tConnection.createTopicSession(true, 0);
+ }
+
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null) {
+ System.out.println("connection error");
+ } else {
+ qConnection.start();
+ qSession = qConnection.createQueueSession(true, 0);
+ }
+
+ // Send a message back to acknowledge that the mdb received the message.
+
+ // create testmessages
+ Vector mVec = new Vector();
+ messageSent = tSession.createTextMessage();
+ mVec.addElement(messageSent);
+ messageSentStreamMessage = tSession.createStreamMessage();
+ mVec.addElement(messageSentStreamMessage);
+ messageSentBytesMessage = tSession.createBytesMessage();
+ mVec.addElement(messageSentBytesMessage);
+ messageSentMapMessage = tSession.createMapMessage();
+ mVec.addElement(messageSentMapMessage);
+ messageSentObjectMsg = tSession.createObjectMessage();
+ mVec.addElement(messageSentObjectMsg);
+
+ // for each message addPropsToMessage
+ Enumeration vNum = mVec.elements();
+ while (vNum.hasMoreElements()) {
+ JmsUtil.addPropsToMessage((Message) vNum.nextElement(), props);
+ }
+
+ if (msg.getStringProperty("TestCase").equals("msgHdrTimeStampTTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - running msgHdrTimeStampTTest - create the message");
+ msgHdrTimeStampTTest();
+ } else if (msg.getStringProperty("TestCase").equals("dummy")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - ignore this!");
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdTTextTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdTTextTestCreate!");
+ msgHdrCorlIdTTextTestCreate();
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdTTextTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdTTextTest!");
+ msgHdrCorlIdTTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdTBytesTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdTBytesTestCreate!");
+ msgHdrCorlIdTBytesTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdTBytesTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage -msgHdrCorlIdTBytesTest!");
+ msgHdrCorlIdTTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdTMapTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdTMapTestCreate!");
+ msgHdrCorlIdTMapTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdTMapTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdTMapTest!");
+ msgHdrCorlIdTTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdTStreamTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdTStreamTestCreate!");
+ msgHdrCorlIdTStreamTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdTStreamTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdTStreamTest!");
+ msgHdrCorlIdTTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdTObjectTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage -msgHdrCorlIdTObjectTestCreate!");
+ msgHdrCorlIdTObjectTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrCorlIdTObjectTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrCorlIdTObjectTest!");
+ msgHdrCorlIdTTest(msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("msgHdrReplyToTTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrReplyToTTestCreate!");
+ msgHdrReplyToTTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrReplyToTTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrReplyToTTest!");
+ msgHdrReplyToTTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSTypeTTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSTypeTTestCreate!");
+ msgHdrJMSTypeTTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSTypeTTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSTypeTTest!");
+ msgHdrJMSTypeTTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSPriorityTTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSPriorityTTestCreate!");
+ msgHdrJMSPriorityTTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSPriorityTTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSPriorityTTest!");
+ msgHdrJMSPriorityTTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSExpirationTopicTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSExpirationTopicTestCreate!");
+ msgHdrJMSExpirationTopicTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSExpirationTopicTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSExpirationTopicTest!");
+ msgHdrJMSExpirationTopicTest(msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("msgHdrJMSDestinationTTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSDestinationTTestCreate!");
+ msgHdrJMSDestinationTTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSDestinationTTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSDestinationTTest!");
+ msgHdrJMSDestinationTTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSDeliveryModeTTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSDeliveryModeTTestCreate!");
+ msgHdrJMSDeliveryModeTTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrJMSDeliveryModeTTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrJMSDeliveryModeTTest!");
+ msgHdrJMSDeliveryModeTTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrIDTTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrIDTTestCreate!");
+ msgHdrIDTTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgHdrIDTTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgHdrIDTTest!");
+ msgHdrIDTTest(msg);
+ }
+
+ else {
+ logger.log(Logger.Level.TRACE, "@onMessage - invalid message type found in StringProperty");
+ logger.log(Logger.Level.TRACE,
+ "Do not have a method for this testcase: " + msg.getStringProperty("TestCase"));
+ }
+ logger.log(Logger.Level.TRACE, "@onMessage - Finished for this test!");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ if (tConnection != null) {
+ try {
+ tConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+ }
+
+ /*
+ * Description: Send a single Text message check time of send against time send
+ * returns JMSTimeStamp should be between these two
+ */
+ public void msgHdrTimeStampTTest() {
+ boolean pass = true;
+ long timeBeforeSend;
+ long timeAfterSend;
+ byte bValue = 127;
+ String id = null;
+ String testCase = "msgHdrTimeStampTTest";
+ try {
+
+ // Text Message
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("TestCase", "dummy");
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+
+ // get the current time in milliseconds - before and after the send
+ timeBeforeSend = System.currentTimeMillis();
+ tSender = tSession.createPublisher(topic);
+ tSender.publish(messageSent);
+ // message has been sent
+ timeAfterSend = System.currentTimeMillis();
+
+ logger.log(Logger.Level.TRACE, " getJMSTimestamp");
+ logger.log(Logger.Level.TRACE, " " + messageSent.getJMSTimestamp());
+ logger.log(Logger.Level.TRACE, "Time at send is: " + timeBeforeSend);
+ logger.log(Logger.Level.TRACE, "Time after return fromsend is:" + timeAfterSend);
+ if ((timeBeforeSend <= messageSent.getJMSTimestamp()) && (timeAfterSend >= messageSent.getJMSTimestamp())) {
+ logger.log(Logger.Level.TRACE, "TextMessage TimeStamp pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: invalid timestamp from TextMessage");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: create a text msg, set correlation id
+ */
+ private void msgHdrCorlIdTTextTestCreate() {
+
+ String jmsCorrelationID = "test Correlation id";
+ try {
+
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrCorlIdTTextTest");
+
+ logger.log(Logger.Level.TRACE, "Send Text Message to Topic.");
+ messageSent.setJMSCorrelationID(jmsCorrelationID);
+ tSender = tSession.createPublisher(topic);
+ tSender.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create a stream msg, set correlation id
+ */
+ private void msgHdrCorlIdTStreamTestCreate() {
+
+ String jmsCorrelationID = "test Correlation id";
+ try {
+
+ messageSentStreamMessage.setStringProperty("TestCase", "msgHdrCorlIdTStreamTest");
+ messageSentStreamMessage.setJMSCorrelationID(jmsCorrelationID);
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending Stream message");
+ tSender = tSession.createPublisher(topic);
+ tSender.publish(messageSentStreamMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create a bytes msg, set correlation id
+ */
+ private void msgHdrCorlIdTBytesTestCreate() {
+ byte bValue = 127;
+
+ String jmsCorrelationID = "test Correlation id";
+ try {
+
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Topic.");
+ messageSentBytesMessage.setStringProperty("TestCase", "msgHdrCorlIdTBytesTest");
+ messageSentBytesMessage.setJMSCorrelationID(jmsCorrelationID);
+ messageSentBytesMessage.writeByte(bValue);
+
+ tSender = tSession.createPublisher(topic);
+ tSender.publish(messageSentBytesMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create a mao msg, set correlation id
+ */
+ private void msgHdrCorlIdTMapTestCreate() {
+
+ String jmsCorrelationID = "test Correlation id";
+ try {
+
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Topic.");
+
+ messageSentMapMessage.setStringProperty("TestCase", "msgHdrCorlIdTMapTest");
+ messageSentMapMessage.setJMSCorrelationID(jmsCorrelationID);
+ messageSentMapMessage.setString("aString", "value");
+
+ tSender = tSession.createPublisher(topic);
+ tSender.publish(messageSentMapMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create an object msg, set correlation id
+ */
+ private void msgHdrCorlIdTObjectTestCreate() {
+
+ String jmsCorrelationID = "test Correlation id";
+ try {
+
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Topic.");
+
+ messageSentObjectMsg.setObject("msgHdrIDTObjectTest for Object Message");
+ messageSentObjectMsg.setStringProperty("TestCase", "msgHdrCorlIdTObjectTest");
+ messageSentObjectMsg.setJMSCorrelationID(jmsCorrelationID);
+
+ tSender = tSession.createPublisher(topic);
+ tSender.publish(messageSentObjectMsg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+
+ }
+
+ public void msgHdrCorlIdTTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ String jmsCorrelationID = "test Correlation id";
+ try {
+ logger.log(Logger.Level.TRACE, "jmsCorrelationID: " + messageReceived.getJMSCorrelationID());
+ if (messageReceived.getJMSCorrelationID() == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Text Message Error: JMSCorrelationID returned a null");
+ } else if (messageReceived.getJMSCorrelationID().equals(jmsCorrelationID)) {
+ logger.log(Logger.Level.TRACE, "pass");
+ } else {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Text Message Error: JMSCorrelationID is incorrect");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ try {
+ sendTestResults(messageReceived.getStringProperty("TestCase"), pass);
+ } catch (Exception j) {
+ TestUtil.printStackTrace(j);
+ }
+ }
+ }
+
+ /*
+ *
+ */
+ public void msgHdrReplyToTTestCreate() {
+ Topic replyTopic = null;
+ try {
+
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrReplyToTTest");
+ messageSent.setJMSReplyTo(topic);
+
+ tSender = tSession.createPublisher(topic);
+ tSender.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrReplyToTTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ Topic replyTopic = null;
+ String testCase = "msgHdrReplyToTTest";
+ try {
+ replyTopic = (Topic) messageReceived.getJMSReplyTo();
+ logger.log(Logger.Level.TRACE, "Topic name is " + replyTopic.getTopicName());
+ if (replyTopic.getTopicName().equals(topic.getTopicName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "ReplyTo Failed");
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ public void msgHdrJMSTypeTTestCreate() {
+ boolean pass = true;
+ byte bValue = 127;
+ String type = "TESTMSG";
+ try {
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrJMSTypeTTest");
+ logger.log(Logger.Level.TRACE, "JMSType test - Send a Text message");
+ messageSent.setJMSType(type);
+ tSender = tSession.createPublisher(topic);
+ tSender.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrJMSTypeTTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ String type = "TESTMSG";
+ String testCase = "msgHdrJMSTypeTTest";
+ try {
+
+ logger.log(Logger.Level.TRACE, "JMSType is " + (String) messageReceived.getJMSType());
+ if (messageReceived.getJMSType().equals(type)) {
+ logger.log(Logger.Level.TRACE, "Pass");
+ } else {
+ logger.log(Logger.Level.INFO, "Text Message Failed");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ public void msgHdrJMSPriorityTTestCreate() {
+ boolean pass = true;
+ byte bValue = 127;
+ int priority = 2;
+ try {
+
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrJMSPriorityTTest");
+ logger.log(Logger.Level.TRACE, "JMSPriority test - Send a Text message");
+ tSender = tSession.createPublisher(topic);
+ tSender.setPriority(priority);
+ tSender.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrJMSPriorityTTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ int priority = 2;
+ String testCase = "msgHdrJMSPriorityTTest";
+ try {
+ logger.log(Logger.Level.TRACE, "JMSPriority is " + messageReceived.getJMSPriority());
+ if (messageReceived.getJMSPriority() == priority) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "JMSPriority test Failed");
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ public void msgHdrJMSExpirationTopicTestCreate() {
+ boolean pass = true;
+ long forever = 0;
+ try {
+
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrJMSExpirationTopicTest");
+ logger.log(Logger.Level.TRACE, "JMSExpiration test - Send a Text message");
+
+ tSender = tSession.createPublisher(topic);
+ tSender.setTimeToLive(forever);
+ tSender.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrJMSExpirationTopicTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ long forever = 0;
+ String testCase = "msgHdrJMSExpirationTopicTest";
+ try {
+
+ logger.log(Logger.Level.TRACE, "JMSExpiration is " + messageReceived.getJMSExpiration());
+ if (messageReceived.getJMSExpiration() == forever) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Text Message Failed");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ public void msgHdrJMSDestinationTTestCreate() {
+ Topic replyDestination = null;
+ try {
+
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrJMSDestinationTTest");
+ logger.log(Logger.Level.TRACE, "send msg for JMSDestination test.");
+ tSender = tSession.createPublisher(topic);
+ tSender.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrJMSDestinationTTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ Topic replyDestination = null;
+ String testCase = "msgHdrJMSDestinationTTest";
+
+ try {
+ logger.log(Logger.Level.TRACE, "JMSDestination: " + messageReceived.getJMSDestination());
+ replyDestination = (Topic) messageReceived.getJMSDestination();
+
+ if (replyDestination != null)
+ logger.log(Logger.Level.TRACE, "Topic name is " + replyDestination.getTopicName());
+
+ if (replyDestination == null) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Text Message Error: JMSDestination returned a null");
+ } else if (replyDestination.getTopicName().equals(topic.getTopicName())) {
+ logger.log(Logger.Level.TRACE, "Pass ");
+ } else {
+ logger.log(Logger.Level.INFO, "Text Message Failed");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected Exception in msgHdrJMSDestinationTTest:", e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ public void msgHdrJMSDeliveryModeTTestCreate() {
+ try {
+
+ messageSent.setText("sending a message");
+ messageSent.setStringProperty("TestCase", "msgHdrJMSDeliveryModeTTest");
+ tSender = tSession.createPublisher(topic);
+ tSender.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrJMSDeliveryModeTTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ String testCase = "msgHdrJMSDeliveryModeTTest";
+ try {
+
+ logger.log(Logger.Level.TRACE, "JMSDeliveryMode: " + messageReceived.getJMSDeliveryMode());
+ if (messageReceived.getJMSDeliveryMode() != DeliveryMode.PERSISTENT) {
+ pass = false;
+ logger.log(Logger.Level.INFO, "Error: JMSDeliveryMode should be set to persistent as default");
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: Default delivery mode is persistent");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ public void msgHdrIDTTestCreate() {
+ String id = null;
+ try {
+
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("TestCase", "msgHdrIDTTest");
+ tSender = tSession.createPublisher(topic);
+ tSender.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void msgHdrIDTTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ String id = null;
+ String testCase = "msgHdrIDTTest";
+ try {
+
+ logger.log(Logger.Level.TRACE, "getJMSMessageID ");
+ logger.log(Logger.Level.TRACE, " " + messageReceived.getJMSMessageID());
+ id = messageReceived.getJMSMessageID();
+
+ if (id.startsWith("ID:")) {
+ logger.log(Logger.Level.TRACE, "Pass: JMSMessageID start with ID:");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: JMSMessageID does not start with ID:");
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: send test results to response queue (MDB_QUEUE_REPLY) for
+ * verification
+ */
+ private void sendTestResults(String testCase, boolean results) {
+ TextMessage msg = null;
+
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ msg.setStringProperty("TestCase", testCase);
+ msg.setText(testCase);
+ if (results)
+ msg.setStringProperty("Status", "Pass");
+ else
+ msg.setStringProperty("Status", "Fail");
+
+ logger.log(Logger.Level.TRACE, "Sending response message");
+ logger.log(Logger.Level.TRACE, "==================================Test Results from: " + testCase);
+ logger.log(Logger.Level.TRACE, "==================================Status: " + results);
+ mSender.send(msg);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ logger.log(Logger.Level.TRACE, "Error: " + je.getClass().getName() + " was thrown");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.TRACE, "Error: " + ee.getClass().getName() + " was thrown");
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgHdrT In MsgBeanMsgTestHdrT::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgHdrT In MsgBeanMsgTestHdrT::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsQ/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsQ/MDBClient.java
deleted file mode 100644
index 511bbae0d2..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsQ/MDBClient.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_msgPropsQ;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.MDB_Q_Test;
-
-import jakarta.ejb.EJB;
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_MSGPropsQ_Test")
- private static MDB_Q_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
- /* Run tests */
-
- /*
- * @testName: mdbMsgPropertiesQTest
- *
- * @assertion_ids: JMS:SPEC:20.1; JMS:SPEC:20.2; JMS:SPEC:20.3; JMS:SPEC:20.4;
- * JMS:SPEC:20.5; JMS:SPEC:20.6; JMS:SPEC:20.7; JMS:SPEC:20.8; JMS:SPEC:21;
- * JMS:SPEC:23; JMS:SPEC:24; JMS:SPEC:25; JMS:SPEC:26; JMS:SPEC:10;
- * JMS:SPEC:27; JMS:SPEC:28; JMS:SPEC:29; JMS:SPEC:31; JMS:SPEC:32;
- * JMS:JAVADOC:411; JMS:JAVADOC:413; JMS:JAVADOC:415; JMS:JAVADOC:417;
- * JMS:JAVADOC:419; JMS:JAVADOC:421; JMS:JAVADOC:423; JMS:JAVADOC:425;
- * JMS:JAVADOC:427; JMS:JAVADOC:409; JMS:JAVADOC:391; JMS:JAVADOC:393;
- * JMS:JAVADOC:395; JMS:JAVADOC:397; JMS:JAVADOC:399; JMS:JAVADOC:401;
- * JMS:JAVADOC:403; JMS:JAVADOC:405; JMS:JAVADOC:407; JMS:JAVADOC:500;
- * JMS:JAVADOC:516; JMS:JAVADOC:387;
- *
- * @test_Strategy: create a session bean. Have the session bean send a message
- * to the mdb. The mdb will create a test message and send the test message to
- * the Queue for which it is a message listener. It will then verify the
- * results. pass or fail results are sent to the MDB_REPLY_QUEUE The session
- * bean checks MDB_QUEUE_REPLY for the results. Specifics: set and read
- * properties for boolean, byte, short, int, long, float, double, and String.
- * Verify expected results set and read properties for Boolean, Byte, Short,
- * Int, Long, Float, Double, and String. Verify expected results.
- *
- * When a client receives a message it is in read-only mode. Send a message
- * and have the client attempt modify the properties. Verify that a
- * MessageNotWriteableException is thrown. Call setObject property with an
- * invalid object and verify that a MessageFormatException is thrown
- *
- * call property get methods( other than getStringProperty and
- * getObjectProperty) for non-existent properties and verify that a null
- * pointer exception is returned. call getStringProperty and getObjectProperty
- * for non-existent properties and verify that a null is returned.
- *
- * set object properties and verify the correct value is returned with the
- * getObjectProperty method.
- *
- * call the clearProperties method on the received message and verify that the
- * messages properties were deleted. Test that getObjectProperty returns a
- * null and the getShortProperty throws a null pointer exception. Verify that
- * after clearing properties, you will be able to set and get properties.
- *
- * After clearing the message properties, call getText and verify that the
- * message body has not been cleared.
- *
- * call getJMSXPropertyNames() and verify that the names of the required JMSX
- * properties for JMSXGroupID and JMSXGroupSeq are returned.
- */
- public void mdbMsgPropertiesQTest() throws Exception {
- String testCase1 = "msgPropertiesQTestCreate";
- String testCase2 = "msgPropertiesQTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgPropertiesQTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgPropertiesQTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgPropertiesConversionQTest
- *
- * @assertion_ids: JMS:SPEC:22.1; JMS:SPEC:22.2; JMS:SPEC:22.3; JMS:SPEC:22.4;
- * JMS:SPEC:22.5; JMS:SPEC:22.6; JMS:SPEC:22.7; JMS:SPEC:22.8; JMS:SPEC:22.9;
- * JMS:SPEC:22.10; JMS:SPEC:22.11; JMS:SPEC:22.12; JMS:SPEC:22.13;
- * JMS:SPEC:22.14; JMS:SPEC:22.15; JMS:SPEC:22.16;
- *
- * @test_Strategy: create a session bean. have the session bean create a
- * message and send to mdb. THe mdb will create a message, set properties for
- * all of the primitive types, send that message to the Queue that it is a
- * listener for and then verify the conversion by getting the properties. pass
- * or fail results are then sent to the MDB_REPLY_QUEUE The session bean
- * checks MDB_QUEUE_REPLY for the results.
- */
- public void mdbMsgPropertiesConversionQTest() throws Exception {
- String testCase1 = "msgPropertiesConversionQTestCreate";
- String testCase2 = "msgPropertiesConversionQTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgPropertiesConversionQTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgPropertiesConversionQTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- ;
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsQ/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsQ/MDBClientIT.java
new file mode 100644
index 0000000000..2f98d78ee7
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsQ/MDBClientIT.java
@@ -0,0 +1,187 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_msgPropsQ;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.commonee.MDB_Q_Test;
+
+import jakarta.ejb.EJB;
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_MSGPropsQ_Test")
+ private static MDB_Q_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ hr.setup(props);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+ /* Run tests */
+
+ /*
+ * @testName: mdbMsgPropertiesQTest
+ *
+ * @assertion_ids: JMS:SPEC:20.1; JMS:SPEC:20.2; JMS:SPEC:20.3; JMS:SPEC:20.4;
+ * JMS:SPEC:20.5; JMS:SPEC:20.6; JMS:SPEC:20.7; JMS:SPEC:20.8; JMS:SPEC:21;
+ * JMS:SPEC:23; JMS:SPEC:24; JMS:SPEC:25; JMS:SPEC:26; JMS:SPEC:10; JMS:SPEC:27;
+ * JMS:SPEC:28; JMS:SPEC:29; JMS:SPEC:31; JMS:SPEC:32; JMS:JAVADOC:411;
+ * JMS:JAVADOC:413; JMS:JAVADOC:415; JMS:JAVADOC:417; JMS:JAVADOC:419;
+ * JMS:JAVADOC:421; JMS:JAVADOC:423; JMS:JAVADOC:425; JMS:JAVADOC:427;
+ * JMS:JAVADOC:409; JMS:JAVADOC:391; JMS:JAVADOC:393; JMS:JAVADOC:395;
+ * JMS:JAVADOC:397; JMS:JAVADOC:399; JMS:JAVADOC:401; JMS:JAVADOC:403;
+ * JMS:JAVADOC:405; JMS:JAVADOC:407; JMS:JAVADOC:500; JMS:JAVADOC:516;
+ * JMS:JAVADOC:387;
+ *
+ * @test_Strategy: create a session bean. Have the session bean send a message
+ * to the mdb. The mdb will create a test message and send the test message to
+ * the Queue for which it is a message listener. It will then verify the
+ * results. pass or fail results are sent to the MDB_REPLY_QUEUE The session
+ * bean checks MDB_QUEUE_REPLY for the results. Specifics: set and read
+ * properties for boolean, byte, short, int, long, float, double, and String.
+ * Verify expected results set and read properties for Boolean, Byte, Short,
+ * Int, Long, Float, Double, and String. Verify expected results.
+ *
+ * When a client receives a message it is in read-only mode. Send a message and
+ * have the client attempt modify the properties. Verify that a
+ * MessageNotWriteableException is thrown. Call setObject property with an
+ * invalid object and verify that a MessageFormatException is thrown
+ *
+ * call property get methods( other than getStringProperty and
+ * getObjectProperty) for non-existent properties and verify that a null pointer
+ * exception is returned. call getStringProperty and getObjectProperty for
+ * non-existent properties and verify that a null is returned.
+ *
+ * set object properties and verify the correct value is returned with the
+ * getObjectProperty method.
+ *
+ * call the clearProperties method on the received message and verify that the
+ * messages properties were deleted. Test that getObjectProperty returns a null
+ * and the getShortProperty throws a null pointer exception. Verify that after
+ * clearing properties, you will be able to set and get properties.
+ *
+ * After clearing the message properties, call getText and verify that the
+ * message body has not been cleared.
+ *
+ * call getJMSXPropertyNames() and verify that the names of the required JMSX
+ * properties for JMSXGroupID and JMSXGroupSeq are returned.
+ */
+ @Test
+ public void mdbMsgPropertiesQTest() throws Exception {
+ String testCase1 = "msgPropertiesQTestCreate";
+ String testCase2 = "msgPropertiesQTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgPropertiesQTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgPropertiesQTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgPropertiesConversionQTest
+ *
+ * @assertion_ids: JMS:SPEC:22.1; JMS:SPEC:22.2; JMS:SPEC:22.3; JMS:SPEC:22.4;
+ * JMS:SPEC:22.5; JMS:SPEC:22.6; JMS:SPEC:22.7; JMS:SPEC:22.8; JMS:SPEC:22.9;
+ * JMS:SPEC:22.10; JMS:SPEC:22.11; JMS:SPEC:22.12; JMS:SPEC:22.13;
+ * JMS:SPEC:22.14; JMS:SPEC:22.15; JMS:SPEC:22.16;
+ *
+ * @test_Strategy: create a session bean. have the session bean create a message
+ * and send to mdb. THe mdb will create a message, set properties for all of the
+ * primitive types, send that message to the Queue that it is a listener for and
+ * then verify the conversion by getting the properties. pass or fail results
+ * are then sent to the MDB_REPLY_QUEUE The session bean checks MDB_QUEUE_REPLY
+ * for the results.
+ */
+ @Test
+ public void mdbMsgPropertiesConversionQTest() throws Exception {
+ String testCase1 = "msgPropertiesConversionQTestCreate";
+ String testCase2 = "msgPropertiesConversionQTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgPropertiesConversionQTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgPropertiesConversionQTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ ;
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsQ/MsgBeanMsgTestPropsQ.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsQ/MsgBeanMsgTestPropsQ.java
index 39dbfeea48..16ae8d5919 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsQ/MsgBeanMsgTestPropsQ.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsQ/MsgBeanMsgTestPropsQ.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_msgPropsQ;
+import java.lang.System.Logger;
import java.util.Enumeration;
import java.util.Properties;
@@ -43,1663 +44,1526 @@
import jakarta.jms.QueueSession;
import jakarta.jms.TextMessage;
-public class MsgBeanMsgTestPropsQ
- implements MessageDrivenBean, MessageListener {
-
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- private MessageDrivenContext mdc = null;
-
- // JMS
- private QueueConnectionFactory qFactory = null;
-
- private QueueConnection qConnection = null;
-
- private Queue queueR = null;
-
- private Queue queue = null;
-
- private QueueSender mSender = null;
-
- private QueueSession qSession = null;
-
- private TextMessage messageSent = null;
-
- public MsgBeanMsgTestPropsQ() {
- System.out.println("@MsgBeanMsgTestPropsQ()!");
- };
-
- public void ejbCreate() {
- System.out.println(
- "jms.ee.mdb.mdb_msgPropsQ - @MsgBeanMsgTestPropsQ-ejbCreate() !!");
- try {
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- if (qFactory == null) {
- System.out.println("qFactory error");
- }
- System.out.println("got a qFactory !!");
-
- queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- if (queueR == null) {
- System.out.println("queueR error");
- }
- queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
-
- // Properties
- p = new Properties();
-
- }
-
- public void onMessage(Message msg) {
- System.out.println("from jms.ee.mdb.mdb_msgPropsQ @onMessage!" + msg);
-
- try {
- JmsUtil.initHarnessProps(msg, p);
-
- System.out.println(
- "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null) {
- System.out.println("connection error");
- } else {
- qConnection.start();
- qSession = qConnection.createQueueSession(true, 0);
- }
-
- messageSent = qSession.createTextMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
-
- if (msg.getStringProperty("TestCase")
- .equals("msgPropertiesQTestCreate")) {
- System.out.println(
- "@onMessage - running msgPropertiesQTestCreate - create the message");
- msgPropertiesQTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgPropertiesQTest")) {
- System.out.println("@onMessage - msgPropertiesQTest!");
- msgPropertiesQTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgPropertiesConversionQTestCreate")) {
- System.out.println("@onMessage - msgPropertiesConversionQTestCreate!");
- msgPropertiesConversionQTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgPropertiesConversionQTest")) {
- System.out.println("@onMessage - msgPropertiesConversionQTest!");
- msgPropertiesConversionQTest(msg);
- }
-
- else {
- System.out.println(
- "@onMessage - invalid message type found in StringProperty");
- System.out.println("Do not have a method for this testcase: "
- + msg.getStringProperty("TestCase"));
- }
-
- System.out.println("@onMessage - Finished for this test!");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
-
- }
-
- /*
- *
- */
-
- private void msgPropertiesQTestCreate() {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- Enumeration propertyNames = null;
- Enumeration jmsxDefined = null;
-
- int NUMPROPS = 0;
- String testMessageBody = "Testing...";
-
- JmsUtil.addPropsToMessage(messageSent, p);
- try {
-
- messageSent.setText(testMessageBody);
- // ------------------------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- messageSent.setBooleanProperty("TESTBOOLEAN", bool);
- messageSent.setByteProperty("TESTBYTE", bValue);
- messageSent.setShortProperty("TESTSHORT", nShort);
- messageSent.setIntProperty("TESTINT", nInt);
- messageSent.setFloatProperty("TESTFLOAT", nFloat);
- messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
- messageSent.setStringProperty("TESTSTRING", "test");
- messageSent.setLongProperty("TESTLONG", nLong);
-
- // ------------------------------------------------------------------------------
- // set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
- // String.
- // ------------------------------------------------------------------------------
-
- messageSent.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
- messageSent.setObjectProperty("OBJTESTBYTE", Byte.valueOf(bValue));
- messageSent.setObjectProperty("OBJTESTSHORT", Short.valueOf(nShort));
- messageSent.setObjectProperty("OBJTESTINT", Integer.valueOf(nInt));
- messageSent.setObjectProperty("OBJTESTFLOAT", new Float(nFloat));
- messageSent.setObjectProperty("OBJTESTDOUBLE", new Double(nDouble));
- messageSent.setObjectProperty("OBJTESTSTRING", "test");
- messageSent.setObjectProperty("OBJTESTLONG", new Long(nLong));
-
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesQTest");
- messageSent.setStringProperty("TestCase", "msgPropertiesQTest");
-
- // count total properties in messageSent
-
- Enumeration e = messageSent.getPropertyNames();
- String key = null;
- int i = 0;
- while (e.hasMoreElements()) {
- key = (String) e.nextElement();
- TestUtil.logTrace("+++++++ Property Name is: " + key);
- if (key.indexOf("JMS") != 0)
- i++;
- }
-
- // set Count for properties to pass + 1 for count itself
- i++;
- messageSent.setIntProperty("NUMPROPS", i);
-
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- // ------------------------------------------------------------------------------
- // An attempt to use any other class than Boolean, Byte, Short, Int, Long,
- // Float,
- // Double, and Stringmust throw a JMS MessageFormatException.
- // ------------------------------------------------------------------------------
- try {
- messageSent.setObjectProperty("OBJTESTLONG", new Object());
- TestUtil.logMsg("Error: expected MessageFormatException from invalid ");
- TestUtil.logMsg("call to setObjectProperty did not occur!");
- pass = false;
- } catch (MessageFormatException fe) {
- TestUtil.logTrace("Pass: ");
- TestUtil.logTrace(
- " MessageFormatException as expected from invalid setObjectProperty call");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg("from call to setObjectProperty!");
- TestUtil.logMsg(ee.getMessage());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void msgPropertiesQTest(jakarta.jms.Message msg) {
-
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- Enumeration propertyNames = null;
- Enumeration jmsxDefined = null;
-
- String testCase = "msgPropertiesQTest";
- String testMessageBody = "Testing...";
- TextMessage messageReceived = (TextMessage) msg;
- try {
- // -------------------------------------------------------------------------
- // Received message should be read-only - verify proper exception is
- // thrown
- // when trying to modify msg properties.
- // ------------------------------------------------------------------------
- try {
- messageReceived.setBooleanProperty("TESTBOOLEAN", bool);
- TestUtil.logMsg(
- "Error: exception should have occurred for setBooleanProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil
- .logTrace("Pass: exception as expected for setBooleanProperty ");
- }
-
- try {
- messageReceived.setByteProperty("TESTBYTE", bValue);
- TestUtil.logMsg(
- "Error: exception should have occurred for setByteProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setByteProperty ");
- }
-
- try {
- messageReceived.setShortProperty("TESTSHORT", nShort);
- pass = false;
- TestUtil.logMsg(
- "Error: exception should have occurred for setShortProperty");
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setShortProperty ");
- }
-
- try {
- messageReceived.setIntProperty("TESTINT", nInt);
- TestUtil
- .logMsg("Error: exception should have occurred for setIntProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setIntProperty ");
- }
-
- try {
- messageReceived.setFloatProperty("TESTFLOAT", nFloat);
- TestUtil.logMsg(
- "Error: exception should have occurred for setFloatProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setFloatProperty ");
- }
-
- try {
- messageReceived.setDoubleProperty("TESTDOUBLE", nDouble);
- TestUtil.logMsg(
- "Error: exception should have occurred for setDoubleProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setDoubleProperty ");
- }
-
- try {
- messageReceived.setStringProperty("TESTSTRING", testString);
- TestUtil.logMsg(
- "Error: exception should have occurred for setStringProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setStringProperty ");
- }
-
- try {
- messageReceived.setLongProperty("TESTLONG", nLong);
- TestUtil.logMsg(
- "Error: exception should have occurred for setLongProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setLongProperty ");
- }
-
- try {
- messageReceived.setObjectProperty("OBJTESTBOOLEAN",
- Boolean.valueOf(bool));
- TestUtil.logMsg(
- "Error: exception should have occurred for setObjectProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setObjectProperty ");
- }
-
- int numPropertyNames = (int) messageReceived.getIntProperty("NUMPROPS");
- // iterate thru the property names
- int i = 0;
- propertyNames = messageReceived.getPropertyNames();
- do {
- String tmp = (String) propertyNames.nextElement();
- TestUtil.logTrace("+++++++ Property Name is: " + tmp);
- if (tmp.indexOf("JMS") != 0)
- i++;
- } while (propertyNames.hasMoreElements());
-
- if (i == numPropertyNames) {
- TestUtil.logTrace(
- "Pass: # of properties is " + numPropertyNames + " as expected");
- } else {
- TestUtil
- .logMsg("Error: expected " + numPropertyNames + "property names");
- TestUtil.logMsg(" But " + i + " returned");
- pass = false;
- }
-
- // --------------------------------------------------------------------------------
- // read and verify the property values for primitive types in the received
- // message
- // --------------------------------------------------------------------------------
- if (messageReceived.getBooleanProperty("TESTBOOLEAN") == bool) {
- TestUtil.logTrace("Pass: getBooleanProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getBooleanProperty");
- pass = false;
- }
-
- if (messageReceived.getByteProperty("TESTBYTE") == bValue) {
- TestUtil.logTrace("Pass: getByteProperty returned correct value");
- } else {
- TestUtil.logMsg("Error: incorrect value returned from getByteProperty");
- pass = false;
- }
-
- if (messageReceived.getLongProperty("TESTLONG") == nLong) {
- TestUtil.logTrace("Pass: getLongProperty returned correct value");
- } else {
- TestUtil.logMsg("Error: incorrect value returned from getLongProperty");
- pass = false;
- }
-
- if (messageReceived.getStringProperty("TESTSTRING").equals(testString)) {
- TestUtil.logTrace("Pass: getStringProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getStringProperty");
- pass = false;
- }
-
- if (messageReceived.getDoubleProperty("TESTDOUBLE") == nDouble) {
- TestUtil.logTrace("Pass: getDoubleProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getDoubleProperty");
- pass = false;
- }
-
- if (messageReceived.getFloatProperty("TESTFLOAT") == nFloat) {
- TestUtil.logTrace("Pass: getFloatProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getFloatProperty");
- pass = false;
- }
-
- if (messageReceived.getIntProperty("TESTINT") == nInt) {
- TestUtil.logTrace("Pass: getIntProperty returned correct value");
- } else {
- TestUtil.logMsg("Error: incorrect value returned from getIntProperty");
- pass = false;
- }
-
- if (messageReceived.getShortProperty("TESTSHORT") == nShort) {
- TestUtil.logTrace("Pass: getShortProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getShortProperty");
- pass = false;
- }
- // --------------------------------------------------------------------------------
- // The other property get methods ( other than getStringProperty and
- // getObjectProperty) must throw a java.lang.NullPointerException if
- // they are used to get a non-existent property.
- // --------------------------------------------------------------------------------
- /*
- * ifc try { boolean value =
- * messageReceived.getBooleanProperty("TESTDUMMY"); TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getBooleanProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- *
- * try { byte value = messageReceived.getByteProperty("TESTDUMMY");
- * TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getByteProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- *
- * try { short value = messageReceived.getShortProperty("TESTDUMMY");
- * TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getShortProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- *
- * try { int value = messageReceived.getIntProperty("TESTDUMMY");
- * TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getIntProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- *
- * try { long value = messageReceived.getLongProperty("TESTDUMMY");
- * TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getLongProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- *
- * try { float value = messageReceived.getFloatProperty("TESTDUMMY");
- * TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getFloatProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- *
- * try { double value = messageReceived.getDoubleProperty("TESTDUMMY");
- * TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getDoubleProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- */
-
- // --------------------------------------------------------------------------------
- // Getting a property value for a name which has not been set returns a
- // null value.
- // (For getStringProperty and getObjectProperty)
- // --------------------------------------------------------------------------------
- String value = messageReceived.getStringProperty("TESTDUMMY");
- if (value == null) {
- TestUtil.logTrace("Pass: getStringProperty returned correct value");
- } else {
- TestUtil.logMsg(
- "Error: expected a null return from getStringProperty for invalid property");
- pass = false;
- }
-
- Boolean aBool = (Boolean) messageReceived.getObjectProperty("TESTDUMMY");
- if (aBool == null) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Boolean");
- } else {
- TestUtil.logMsg(
- "Error: expected a null return from getObjectProperty for invalid property");
- pass = false;
- }
-
- // --------------------------------------------------------------------------------
- // read and verify the property values for getObject in the received
- // message
- // --------------------------------------------------------------------------------
-
- Boolean boolValue = (Boolean) messageReceived
- .getObjectProperty("OBJTESTBOOLEAN");
- if (boolValue.booleanValue() == bool) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Boolean");
- } else {
- TestUtil.logMsg("Error: incorrect value returned for Boolean");
- pass = false;
- }
-
- Byte byteValue = (Byte) messageReceived.getObjectProperty("OBJTESTBYTE");
- if (byteValue.byteValue() == bValue) {
- TestUtil
- .logTrace("Pass: getObjectProperty returned correct Byte value");
- } else {
- TestUtil.logMsg("Error: incorrect value returned from Byte");
- pass = false;
- }
-
- Long lValue = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
- if (lValue.longValue() == nLong) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Long");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value returned for Long");
- pass = false;
- }
-
- // String value =
- // (String)messageReceived.getObjectProperty("OBJTESTSTRING");
- if (messageReceived.getObjectProperty("OBJTESTSTRING")
- .equals(testString)) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for String");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for String");
- pass = false;
- }
-
- Double dValue = (Double) messageReceived
- .getObjectProperty("OBJTESTDOUBLE");
- if (dValue.doubleValue() == nDouble) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Double");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for Double");
- pass = false;
- }
-
- Float fValue = (Float) messageReceived.getObjectProperty("OBJTESTFLOAT");
- if (fValue.floatValue() == nFloat) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Float");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for Float");
- pass = false;
- }
-
- Integer iValue = (Integer) messageReceived
- .getObjectProperty("OBJTESTINT");
- if (iValue.intValue() == nInt) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Integer");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for Integer");
- pass = false;
- }
-
- Short sValue = (Short) messageReceived.getObjectProperty("OBJTESTSHORT");
- if (sValue.shortValue() == nShort) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Short");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for Short");
- pass = false;
- }
-
- // clear message properties
- messageReceived.clearProperties();
-
- // -------------------------------------------------------------------
- // A message?s properties are deleted by the clearProperties method.
- // This leaves the message with an empty set of properties.
- // -------------------------------------------------------------------
-
- Long aLong = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
- if (aLong == null) {
- TestUtil.logTrace("Pass: property was cleared");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty should have returned null for cleared property");
- pass = false;
- }
- try {
- short aShort = messageReceived.getShortProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: NullPointerException should have occurred for getShortProperty");
- TestUtil.logMsg("Properties have been cleared!");
- pass = false;
- } catch (java.lang.NullPointerException np) {
- TestUtil.printStackTrace(np);
- TestUtil.logTrace("Pass: NullPointerException");
- } catch (java.lang.NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException as expected ");
- }
-
- // -------------------------------------------------------------------
- // A message's properties are deleted by the clearProperties method.
- // This leaves the message with an empty set of properties.
- // New property entries can then be both created and read.
- // -------------------------------------------------------------------
- try {
- String newEntry = "new entry";
- TestUtil
- .logTrace("Verify that you can set a property after clearProperty");
- messageReceived.setStringProperty("TESTSTRING", "new entry");
- if (messageReceived.getStringProperty("TESTSTRING").equals(newEntry)) {
- TestUtil.logTrace("Pass: able to set a cleared property");
- } else {
- TestUtil.logTrace(
- "Error: was not able to new property setting after clearProperty");
- pass = false;
- }
- } catch (Exception ex) {
- TestUtil.logTrace(
- "Unexpected Exception caught while testing set after clearProperty");
- pass = false;
- TestUtil.printStackTrace(ex);
- }
-
- // -------------------------------------------------------------------
- // clearing the message property should not effect the message body.
- // -------------------------------------------------------------------
- TestUtil.logMsg("Message body is : " + messageReceived.getText());
- if (messageReceived.getText().equals(testMessageBody)) {
- TestUtil
- .logTrace("Pass: able to read message body after clearProperties");
- } else {
- TestUtil
- .logMsg("Error: unable to read message body after clearProperties");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // ConnectionMetaData.getJMSXPropertyNames() method returns the
- // names of the JMSX properties supported by a connection.
- // -------------------------------------------------------------------
- try {
- ConnectionMetaData data = qConnection.getMetaData();
- Enumeration cmd = data.getJMSXPropertyNames();
- String propName;
- if (cmd == null) {
- TestUtil.logMsg("Error: no JMSX property names were returned!");
- TestUtil
- .logMsg("expected JMSXGroupID and JMSXGroupSeq at a miniumum");
- pass = false;
- } else {
- int iCount = 0;
- do {
- propName = (String) cmd.nextElement();
- TestUtil.logTrace(propName);
- if (propName.equals("JMSXGroupID")
- || propName.equals("JMSXGroupSeq")) {
- iCount++;
- }
- } while (cmd.hasMoreElements());
- if (iCount > 1) {
- TestUtil.logTrace("Pass:");
- } else {
- TestUtil.logMsg("Error: Expected property names not returned");
- pass = false;
- }
- }
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg("attempting to read JMSX property names.");
- TestUtil.logMsg("Error: unexpected exception: "
- + ee.getClass().getName() + " was thrown");
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- private void msgPropertiesConversionQTestCreate() {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- String testMessageBody = "Testing...";
- int ntest = 0;
- try {
- messageSent.setText(testMessageBody);
- // ------------------------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- messageSent.setBooleanProperty("TESTBOOLEAN", bool);
- messageSent.setByteProperty("TESTBYTE", bValue);
- messageSent.setShortProperty("TESTSHORT", nShort);
- messageSent.setIntProperty("TESTINT", nInt);
- messageSent.setFloatProperty("TESTFLOAT", nFloat);
- messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
- messageSent.setStringProperty("TESTSTRING", "test");
- messageSent.setLongProperty("TESTLONG", nLong);
- messageSent.setStringProperty("TESTSTRINGTRUE", "true");
- messageSent.setStringProperty("TESTSTRINGFALSE", "false");
- messageSent.setStringProperty("TESTSTRING1", "1");
-
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesConversionQTest");
- messageSent.setStringProperty("TestCase", "msgPropertiesConversionQTest");
- TestUtil.logTrace("Sending message");
-
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- // ------------------------------------------------------------------------------
- // An attempt to use any other class than Boolean, Byte, Short, Int, Long,
- // Float,
- // Double, and Stringmust throw a JMS MessageFormatException.
- // ------------------------------------------------------------------------------
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void msgPropertiesConversionQTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- String testMessageBody = "Testing...";
- int ntest = 0;
- String testCase = "msgPropertiesConversionQTest";
- try {
-
- // -------------------------------------------------------------------
- // test conversions for property values
- // -------------------------------------------------------------------
-
- // property set as boolean can be read only as string or boolean
- // -------------------------------------------------------------------
- // valid - boolean to string
-
- String myBool = messageReceived.getStringProperty("TESTBOOLEAN");
- if (Boolean.valueOf(myBool).booleanValue() == bool) {
- TestUtil.logTrace("Pass: conversion from boolean to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from boolean to string failed");
- pass = false;
- }
-
- // invalid - boolean to byte
- try {
- messageReceived.getByteProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- // TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- // + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- boolean to byte");
- pass = false;
- }
-
- // invalid - boolean to short
- try {
- messageReceived.getShortProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- boolean to short");
- pass = false;
- }
-
- // invalid - boolean to int
- try {
- messageReceived.getIntProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to int ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception --boolean to int ");
- pass = false;
- }
- // invalid - boolean to long
- try {
- messageReceived.getLongProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to long ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- boolean to long");
- pass = false;
- }
-
- // invalid - boolean to float
- try {
- messageReceived.getFloatProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- boolean to float");
- pass = false;
- }
-
- // invalid - boolean to double
- try {
- messageReceived.getDoubleProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- boolean to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as byte can be read as a byte,short,int,long or string
-
- // valid - byte to string
- String myByte = messageReceived.getStringProperty("TESTBYTE");
- if (Byte.valueOf(myByte).byteValue() == bValue) {
- TestUtil.logTrace("Pass: conversion from byte to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from byte to string failed");
- pass = false;
- }
- // valid - byte to short
- if (messageReceived.getShortProperty("TESTBYTE") == bValue) {
- TestUtil.logTrace("Pass: conversion from byte to short - ok");
- } else {
- TestUtil.logMsg("Error: conversion from byte to short failed");
- pass = false;
- }
- // valid - byte to int
- if (messageReceived.getIntProperty("TESTBYTE") == bValue) {
- TestUtil.logTrace("Pass: conversion from byte to int - ok");
- } else {
- TestUtil.logMsg("Error: conversion from byte to int failed");
- pass = false;
- }
- // valid - byte to long
-
- if (messageReceived.getLongProperty("TESTBYTE") == bValue) {
- TestUtil.logTrace("Pass: conversion from byte to long - ok");
- } else {
- TestUtil.logMsg("Error: conversion from byte to long failed");
- pass = false;
- }
- // invalid - byte to boolean
- try {
- messageReceived.getBooleanProperty("TESTBYTE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: byte to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- byte to boolean");
- pass = false;
- }
-
- // invalid - byte to float
- try {
- messageReceived.getFloatProperty("TESTBYTE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: byte to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception --byte to float ");
- pass = false;
- }
-
- // invalid - byte to double
- try {
- messageReceived.getDoubleProperty("TESTBYTE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: byte to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- byte to double");
- pass = false;
- }
-
- // -------------------------------------------------
- // property set as short can be read as short,int,long or string
-
- // valid - short to string
- String myshort = messageReceived.getStringProperty("TESTSHORT");
- if (Short.valueOf(myshort).shortValue() == nShort) {
- TestUtil.logTrace("Pass: conversion from short to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from short to string failed");
- pass = false;
- }
-
- // valid - short to int
- if (messageReceived.getIntProperty("TESTSHORT") == nShort) {
- TestUtil.logTrace("Pass: conversion from short to int - ok");
- } else {
- TestUtil.logMsg("Error: conversion from short to int failed");
- pass = false;
- }
- // valid - short to long
- if (messageReceived.getLongProperty("TESTSHORT") == nShort) {
- TestUtil.logTrace("Pass: conversion from short to long - ok");
- } else {
- TestUtil.logMsg("Error: conversion from short to long failed");
- pass = false;
- }
-
- // invalid - short to boolean
- try {
- messageReceived.getBooleanProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: short to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- short to boolean");
- pass = false;
- }
-
- // invalid - short to byte
- try {
- messageReceived.getByteProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: short to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- short to byte");
- pass = false;
- }
-
- // invalid - short to float
- try {
- messageReceived.getFloatProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: short to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- short to float");
- pass = false;
- }
-
- // invalid - short to double
- try {
- messageReceived.getDoubleProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: short to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- short to double");
- pass = false;
- }
-
- // -------------------------------------------------
- // property set as int can be read only as int, long or string
-
- // valid - int to string
- if (Integer.valueOf(messageReceived.getStringProperty("TESTINT"))
- .intValue() == nInt) {
- TestUtil.logTrace("Pass: conversion from int to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from int to string failed");
- pass = false;
- }
-
- // valid - int to long
- if (messageReceived.getLongProperty("TESTINT") == nInt) {
- TestUtil.logTrace("Pass: conversion from int to long - ok");
- } else {
- TestUtil.logMsg("Error: conversion from int to long failed");
- pass = false;
- }
-
- // invalid - int to boolean
- try {
- messageReceived.getBooleanProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- int to boolean");
- pass = false;
- }
-
- // invalid - int to byte
- try {
- messageReceived.getByteProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- int to byte");
- pass = false;
- }
-
- // invalid - int to short
- try {
- messageReceived.getShortProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace(
- "Pass: MessageFormatException as expected -- int to short ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg("Error: did not catch expected Exception ");
- pass = false;
- }
-
- // invalid - int to float
- try {
- messageReceived.getFloatProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- int to float");
- pass = false;
- }
-
- // invalid - int to double
- try {
- messageReceived.getDoubleProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- int to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as long can be read only as long,or a string
-
- // valid - long to string
- if (Long.valueOf(messageReceived.getStringProperty("TESTLONG"))
- .longValue() == nLong) {
- TestUtil.logTrace("Pass: conversion from long to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from long to string failed");
- pass = false;
- }
-
- // invalid - long to boolean
- try {
- messageReceived.getBooleanProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- long to boolean");
- pass = false;
- }
-
- // invalid - long to byte
- try {
- messageReceived.getByteProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- long to byte");
- pass = false;
- }
- // invalid - long to short
- try {
- messageReceived.getShortProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- long to short ");
- pass = false;
- }
- // invalid - long to int
- try {
- messageReceived.getIntProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to int ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- long to int");
- pass = false;
- }
-
- // invalid - long to float
- try {
- messageReceived.getFloatProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- long to float");
- pass = false;
- }
-
- // invalid - long to double
- try {
- messageReceived.getDoubleProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- long to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as float can be read only as float,double or a string
-
- // valid - float to string
- if (Float.valueOf(messageReceived.getStringProperty("TESTFLOAT"))
- .floatValue() == nFloat) {
- TestUtil.logTrace("Pass: conversion from float to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from float to string failed");
- pass = false;
- }
- // valid - float to double
- if (messageReceived.getDoubleProperty("TESTFLOAT") == nFloat) {
- TestUtil.logTrace("Pass: conversion from long to double - ok");
- } else {
- TestUtil.logMsg("Error: conversion from long to double failed");
- pass = false;
- }
-
- // invalid - float to boolean
- try {
- messageReceived.getBooleanProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- float to boolean ");
- pass = false;
- }
-
- // invalid - float to byte
- try {
- messageReceived.getByteProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- float to byte");
- pass = false;
- }
- // invalid - float to short
- try {
- messageReceived.getShortProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception - float to short ");
- pass = false;
- }
- // invalid - float to int
- try {
- messageReceived.getIntProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to int ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception --- float to int");
- pass = false;
- }
-
- // invalid - float to long
- try {
- messageReceived.getLongProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to long ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- float to long");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as double can be read only as double or string
-
- // valid - double to string
- if (Double.valueOf(messageReceived.getStringProperty("TESTDOUBLE"))
- .doubleValue() == nDouble) {
- TestUtil.logTrace("Pass: conversion from double to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from double to string failed");
- pass = false;
- }
-
- // invalid - double to boolean
- try {
- messageReceived.getBooleanProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- double to boolean ");
- pass = false;
- }
-
- // invalid - double to byte
- try {
- messageReceived.getByteProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- double to byte ");
- pass = false;
- }
- // invalid - double to short
- try {
- messageReceived.getShortProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- double to short");
- pass = false;
- }
- // invalid - double to int
- try {
- messageReceived.getIntProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to int ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception --- double to int ");
- pass = false;
- }
-
- // invalid - double to long
- try {
- messageReceived.getLongProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to long ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- double to long");
- pass = false;
- }
-
- // invalid - double to float
- try {
- messageReceived.getFloatProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- double to float");
- pass = false;
- }
- // -------------------------------------------------------------------
- // property set as string can be read as boolean, byte, short,
- // int, long, float, double, and String.
-
- // valid - string to boolean
- if ((messageReceived.getBooleanProperty("TESTSTRINGTRUE")) == true) {
- TestUtil.logTrace(
- "Pass: conversion from string to boolean - expect true - ok");
- } else {
- TestUtil.logMsg(
- "Error: conversion from string to boolean - expect true - failed");
- pass = false;
- }
-
- if ((messageReceived.getBooleanProperty("TESTSTRINGFALSE")) == false) {
- TestUtil.logTrace(
- "Pass: conversion from string to boolean expect false - ok");
- } else {
- TestUtil.logMsg(
- "Error: conversion from string to boolean expect false - failed");
- pass = false;
- }
-
- // valid - string to byte
- if (messageReceived.getByteProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to byte - ok");
- } else {
- TestUtil.logMsg("Error: conversion from string to byte failed");
- pass = false;
- }
- // valid - string to short
- if (messageReceived.getShortProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to short - ok");
- } else {
- TestUtil.logMsg("Error: conversion from string to short failed");
- pass = false;
- }
- // valid - string to int
- if (messageReceived.getIntProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to int - ok");
- } else {
- TestUtil.logMsg("Error: conversion from string to int failed");
- pass = false;
- }
- // valid - string to long
- if (messageReceived.getLongProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to long - ok");
- } else {
- TestUtil.logMsg("Error: conversion from string to long failed");
- pass = false;
- }
-
- // valid - string to float
- if (messageReceived.getFloatProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to float - ok");
- } else {
- TestUtil.logMsg("Error: conversion from string to float failed");
- pass = false;
- }
- // valid - string to double
- if (messageReceived.getDoubleProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to double - ok");
- } else {
- TestUtil.logMsg("Error: conversion from string to double failed");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: send test results to response queue (MDB_QUEUE_REPLY) for
- * verification
- */
- private void sendTestResults(String testCase, boolean results) {
- TextMessage msg = null;
-
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- msg.setStringProperty("TestCase", testCase);
- msg.setText(testCase);
- if (results)
- msg.setStringProperty("Status", "Pass");
- else
- msg.setStringProperty("Status", "Fail");
-
- System.out.println("Sending response message");
- System.out.println(
- "==================================Test Results from: " + testCase);
- System.out
- .println("==================================Status: " + results);
- mSender.send(msg);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- System.out.println("Error: " + je.getClass().getName() + " was thrown");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- System.out.println("Error: " + ee.getClass().getName() + " was thrown");
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- System.out.println(
- "jms.ee.mdb.mdb_msgPropsQ In MsgBeanMsgTestPropsQ::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- System.out.println(
- "jms.ee.mdb.mdb_msgPropsQ In MsgBeanMsgTestPropsQ::remove()!!");
- }
+public class MsgBeanMsgTestPropsQ implements MessageDrivenBean, MessageListener {
+
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ private MessageDrivenContext mdc = null;
+
+ // JMS
+ private QueueConnectionFactory qFactory = null;
+
+ private QueueConnection qConnection = null;
+
+ private Queue queueR = null;
+
+ private Queue queue = null;
+
+ private QueueSender mSender = null;
+
+ private QueueSession qSession = null;
+
+ private TextMessage messageSent = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanMsgTestPropsQ.class.getName());
+
+ public MsgBeanMsgTestPropsQ() {
+ System.out.println("@MsgBeanMsgTestPropsQ()!");
+ };
+
+ public void ejbCreate() {
+ System.out.println("jms.ee.mdb.mdb_msgPropsQ - @MsgBeanMsgTestPropsQ-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ if (qFactory == null) {
+ System.out.println("qFactory error");
+ }
+ System.out.println("got a qFactory !!");
+
+ queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ if (queueR == null) {
+ System.out.println("queueR error");
+ }
+ queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+
+ // Properties
+ p = new Properties();
+
+ }
+
+ public void onMessage(Message msg) {
+ System.out.println("from jms.ee.mdb.mdb_msgPropsQ @onMessage!" + msg);
+
+ try {
+ JmsUtil.initHarnessProps(msg, p);
+
+ System.out.println("onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null) {
+ System.out.println("connection error");
+ } else {
+ qConnection.start();
+ qSession = qConnection.createQueueSession(true, 0);
+ }
+
+ messageSent = qSession.createTextMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+
+ if (msg.getStringProperty("TestCase").equals("msgPropertiesQTestCreate")) {
+ System.out.println("@onMessage - running msgPropertiesQTestCreate - create the message");
+ msgPropertiesQTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgPropertiesQTest")) {
+ System.out.println("@onMessage - msgPropertiesQTest!");
+ msgPropertiesQTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgPropertiesConversionQTestCreate")) {
+ System.out.println("@onMessage - msgPropertiesConversionQTestCreate!");
+ msgPropertiesConversionQTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgPropertiesConversionQTest")) {
+ System.out.println("@onMessage - msgPropertiesConversionQTest!");
+ msgPropertiesConversionQTest(msg);
+ }
+
+ else {
+ System.out.println("@onMessage - invalid message type found in StringProperty");
+ System.out.println("Do not have a method for this testcase: " + msg.getStringProperty("TestCase"));
+ }
+
+ System.out.println("@onMessage - Finished for this test!");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+
+ }
+
+ /*
+ *
+ */
+
+ private void msgPropertiesQTestCreate() {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ Enumeration propertyNames = null;
+ Enumeration jmsxDefined = null;
+
+ int NUMPROPS = 0;
+ String testMessageBody = "Testing...";
+
+ JmsUtil.addPropsToMessage(messageSent, p);
+ try {
+
+ messageSent.setText(testMessageBody);
+ // ------------------------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ messageSent.setBooleanProperty("TESTBOOLEAN", bool);
+ messageSent.setByteProperty("TESTBYTE", bValue);
+ messageSent.setShortProperty("TESTSHORT", nShort);
+ messageSent.setIntProperty("TESTINT", nInt);
+ messageSent.setFloatProperty("TESTFLOAT", nFloat);
+ messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
+ messageSent.setStringProperty("TESTSTRING", "test");
+ messageSent.setLongProperty("TESTLONG", nLong);
+
+ // ------------------------------------------------------------------------------
+ // set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
+ // String.
+ // ------------------------------------------------------------------------------
+
+ messageSent.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ messageSent.setObjectProperty("OBJTESTBYTE", Byte.valueOf(bValue));
+ messageSent.setObjectProperty("OBJTESTSHORT", Short.valueOf(nShort));
+ messageSent.setObjectProperty("OBJTESTINT", Integer.valueOf(nInt));
+ messageSent.setObjectProperty("OBJTESTFLOAT", new Float(nFloat));
+ messageSent.setObjectProperty("OBJTESTDOUBLE", new Double(nDouble));
+ messageSent.setObjectProperty("OBJTESTSTRING", "test");
+ messageSent.setObjectProperty("OBJTESTLONG", new Long(nLong));
+
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesQTest");
+ messageSent.setStringProperty("TestCase", "msgPropertiesQTest");
+
+ // count total properties in messageSent
+
+ Enumeration e = messageSent.getPropertyNames();
+ String key = null;
+ int i = 0;
+ while (e.hasMoreElements()) {
+ key = (String) e.nextElement();
+ logger.log(Logger.Level.TRACE, "+++++++ Property Name is: " + key);
+ if (key.indexOf("JMS") != 0)
+ i++;
+ }
+
+ // set Count for properties to pass + 1 for count itself
+ i++;
+ messageSent.setIntProperty("NUMPROPS", i);
+
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ // ------------------------------------------------------------------------------
+ // An attempt to use any other class than Boolean, Byte, Short, Int, Long,
+ // Float,
+ // Double, and Stringmust throw a JMS MessageFormatException.
+ // ------------------------------------------------------------------------------
+ try {
+ messageSent.setObjectProperty("OBJTESTLONG", new Object());
+ logger.log(Logger.Level.INFO, "Error: expected MessageFormatException from invalid ");
+ logger.log(Logger.Level.INFO, "call to setObjectProperty did not occur!");
+ pass = false;
+ } catch (MessageFormatException fe) {
+ logger.log(Logger.Level.TRACE, "Pass: ");
+ logger.log(Logger.Level.TRACE,
+ " MessageFormatException as expected from invalid setObjectProperty call");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "from call to setObjectProperty!");
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void msgPropertiesQTest(jakarta.jms.Message msg) {
+
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ Enumeration propertyNames = null;
+ Enumeration jmsxDefined = null;
+
+ String testCase = "msgPropertiesQTest";
+ String testMessageBody = "Testing...";
+ TextMessage messageReceived = (TextMessage) msg;
+ try {
+ // -------------------------------------------------------------------------
+ // Received message should be read-only - verify proper exception is
+ // thrown
+ // when trying to modify msg properties.
+ // ------------------------------------------------------------------------
+ try {
+ messageReceived.setBooleanProperty("TESTBOOLEAN", bool);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setBooleanProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setBooleanProperty ");
+ }
+
+ try {
+ messageReceived.setByteProperty("TESTBYTE", bValue);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setByteProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setByteProperty ");
+ }
+
+ try {
+ messageReceived.setShortProperty("TESTSHORT", nShort);
+ pass = false;
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setShortProperty");
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setShortProperty ");
+ }
+
+ try {
+ messageReceived.setIntProperty("TESTINT", nInt);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setIntProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setIntProperty ");
+ }
+
+ try {
+ messageReceived.setFloatProperty("TESTFLOAT", nFloat);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setFloatProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setFloatProperty ");
+ }
+
+ try {
+ messageReceived.setDoubleProperty("TESTDOUBLE", nDouble);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setDoubleProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setDoubleProperty ");
+ }
+
+ try {
+ messageReceived.setStringProperty("TESTSTRING", testString);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setStringProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setStringProperty ");
+ }
+
+ try {
+ messageReceived.setLongProperty("TESTLONG", nLong);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setLongProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setLongProperty ");
+ }
+
+ try {
+ messageReceived.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setObjectProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setObjectProperty ");
+ }
+
+ int numPropertyNames = (int) messageReceived.getIntProperty("NUMPROPS");
+ // iterate thru the property names
+ int i = 0;
+ propertyNames = messageReceived.getPropertyNames();
+ do {
+ String tmp = (String) propertyNames.nextElement();
+ logger.log(Logger.Level.TRACE, "+++++++ Property Name is: " + tmp);
+ if (tmp.indexOf("JMS") != 0)
+ i++;
+ } while (propertyNames.hasMoreElements());
+
+ if (i == numPropertyNames) {
+ logger.log(Logger.Level.TRACE, "Pass: # of properties is " + numPropertyNames + " as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: expected " + numPropertyNames + "property names");
+ logger.log(Logger.Level.INFO, " But " + i + " returned");
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------
+ // read and verify the property values for primitive types in the received
+ // message
+ // --------------------------------------------------------------------------------
+ if (messageReceived.getBooleanProperty("TESTBOOLEAN") == bool) {
+ logger.log(Logger.Level.TRACE, "Pass: getBooleanProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getBooleanProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getByteProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: getByteProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getByteProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getLongProperty("TESTLONG") == nLong) {
+ logger.log(Logger.Level.TRACE, "Pass: getLongProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getLongProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getStringProperty("TESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getStringProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getDoubleProperty("TESTDOUBLE") == nDouble) {
+ logger.log(Logger.Level.TRACE, "Pass: getDoubleProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getDoubleProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getFloatProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: getFloatProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getFloatProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getIntProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: getIntProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getIntProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getShortProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: getShortProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getShortProperty");
+ pass = false;
+ }
+ // --------------------------------------------------------------------------------
+ // The other property get methods ( other than getStringProperty and
+ // getObjectProperty) must throw a java.lang.NullPointerException if
+ // they are used to get a non-existent property.
+ // --------------------------------------------------------------------------------
+ /*
+ * ifc try { boolean value = messageReceived.getBooleanProperty("TESTDUMMY");
+ * TestUtil. logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getBooleanProperty"
+ * ); pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ *
+ * try { byte value = messageReceived.getByteProperty("TESTDUMMY"); TestUtil.
+ * logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getByteProperty"
+ * ); pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ *
+ * try { short value = messageReceived.getShortProperty("TESTDUMMY"); TestUtil.
+ * logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getShortProperty"
+ * ); pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ *
+ * try { int value = messageReceived.getIntProperty("TESTDUMMY"); TestUtil.
+ * logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getIntProperty" );
+ * pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ *
+ * try { long value = messageReceived.getLongProperty("TESTDUMMY"); TestUtil.
+ * logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getLongProperty"
+ * ); pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ *
+ * try { float value = messageReceived.getFloatProperty("TESTDUMMY"); TestUtil.
+ * logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getFloatProperty"
+ * ); pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ *
+ * try { double value = messageReceived.getDoubleProperty("TESTDUMMY");
+ * TestUtil. logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getDoubleProperty"
+ * ); pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ */
+
+ // --------------------------------------------------------------------------------
+ // Getting a property value for a name which has not been set returns a
+ // null value.
+ // (For getStringProperty and getObjectProperty)
+ // --------------------------------------------------------------------------------
+ String value = messageReceived.getStringProperty("TESTDUMMY");
+ if (value == null) {
+ logger.log(Logger.Level.TRACE, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: expected a null return from getStringProperty for invalid property");
+ pass = false;
+ }
+
+ Boolean aBool = (Boolean) messageReceived.getObjectProperty("TESTDUMMY");
+ if (aBool == null) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Boolean");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: expected a null return from getObjectProperty for invalid property");
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------
+ // read and verify the property values for getObject in the received
+ // message
+ // --------------------------------------------------------------------------------
+
+ Boolean boolValue = (Boolean) messageReceived.getObjectProperty("OBJTESTBOOLEAN");
+ if (boolValue.booleanValue() == bool) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Boolean");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned for Boolean");
+ pass = false;
+ }
+
+ Byte byteValue = (Byte) messageReceived.getObjectProperty("OBJTESTBYTE");
+ if (byteValue.byteValue() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct Byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from Byte");
+ pass = false;
+ }
+
+ Long lValue = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
+ if (lValue.longValue() == nLong) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Long");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value returned for Long");
+ pass = false;
+ }
+
+ // String value =
+ // (String)messageReceived.getObjectProperty("OBJTESTSTRING");
+ if (messageReceived.getObjectProperty("OBJTESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for String");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for String");
+ pass = false;
+ }
+
+ Double dValue = (Double) messageReceived.getObjectProperty("OBJTESTDOUBLE");
+ if (dValue.doubleValue() == nDouble) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Double");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Double");
+ pass = false;
+ }
+
+ Float fValue = (Float) messageReceived.getObjectProperty("OBJTESTFLOAT");
+ if (fValue.floatValue() == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Float");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Float");
+ pass = false;
+ }
+
+ Integer iValue = (Integer) messageReceived.getObjectProperty("OBJTESTINT");
+ if (iValue.intValue() == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Integer");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Integer");
+ pass = false;
+ }
+
+ Short sValue = (Short) messageReceived.getObjectProperty("OBJTESTSHORT");
+ if (sValue.shortValue() == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Short");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Short");
+ pass = false;
+ }
+
+ // clear message properties
+ messageReceived.clearProperties();
+
+ // -------------------------------------------------------------------
+ // A message?s properties are deleted by the clearProperties method.
+ // This leaves the message with an empty set of properties.
+ // -------------------------------------------------------------------
+
+ Long aLong = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
+ if (aLong == null) {
+ logger.log(Logger.Level.TRACE, "Pass: property was cleared");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: getObjectProperty should have returned null for cleared property");
+ pass = false;
+ }
+ try {
+ short aShort = messageReceived.getShortProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO, "Error: NullPointerException should have occurred for getShortProperty");
+ logger.log(Logger.Level.INFO, "Properties have been cleared!");
+ pass = false;
+ } catch (java.lang.NullPointerException np) {
+ TestUtil.printStackTrace(np);
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException");
+ } catch (java.lang.NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+
+ // -------------------------------------------------------------------
+ // A message's properties are deleted by the clearProperties method.
+ // This leaves the message with an empty set of properties.
+ // New property entries can then be both created and read.
+ // -------------------------------------------------------------------
+ try {
+ String newEntry = "new entry";
+ logger.log(Logger.Level.TRACE, "Verify that you can set a property after clearProperty");
+ messageReceived.setStringProperty("TESTSTRING", "new entry");
+ if (messageReceived.getStringProperty("TESTSTRING").equals(newEntry)) {
+ logger.log(Logger.Level.TRACE, "Pass: able to set a cleared property");
+ } else {
+ logger.log(Logger.Level.TRACE, "Error: was not able to new property setting after clearProperty");
+ pass = false;
+ }
+ } catch (Exception ex) {
+ logger.log(Logger.Level.TRACE, "Unexpected Exception caught while testing set after clearProperty");
+ pass = false;
+ TestUtil.printStackTrace(ex);
+ }
+
+ // -------------------------------------------------------------------
+ // clearing the message property should not effect the message body.
+ // -------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Message body is : " + messageReceived.getText());
+ if (messageReceived.getText().equals(testMessageBody)) {
+ logger.log(Logger.Level.TRACE, "Pass: able to read message body after clearProperties");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unable to read message body after clearProperties");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // ConnectionMetaData.getJMSXPropertyNames() method returns the
+ // names of the JMSX properties supported by a connection.
+ // -------------------------------------------------------------------
+ try {
+ ConnectionMetaData data = qConnection.getMetaData();
+ Enumeration cmd = data.getJMSXPropertyNames();
+ String propName;
+ if (cmd == null) {
+ logger.log(Logger.Level.INFO, "Error: no JMSX property names were returned!");
+ logger.log(Logger.Level.INFO, "expected JMSXGroupID and JMSXGroupSeq at a miniumum");
+ pass = false;
+ } else {
+ int iCount = 0;
+ do {
+ propName = (String) cmd.nextElement();
+ logger.log(Logger.Level.TRACE, propName);
+ if (propName.equals("JMSXGroupID") || propName.equals("JMSXGroupSeq")) {
+ iCount++;
+ }
+ } while (cmd.hasMoreElements());
+ if (iCount > 1) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: Expected property names not returned");
+ pass = false;
+ }
+ }
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, "attempting to read JMSX property names.");
+ logger.log(Logger.Level.INFO,
+ "Error: unexpected exception: " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ private void msgPropertiesConversionQTestCreate() {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ String testMessageBody = "Testing...";
+ int ntest = 0;
+ try {
+ messageSent.setText(testMessageBody);
+ // ------------------------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ messageSent.setBooleanProperty("TESTBOOLEAN", bool);
+ messageSent.setByteProperty("TESTBYTE", bValue);
+ messageSent.setShortProperty("TESTSHORT", nShort);
+ messageSent.setIntProperty("TESTINT", nInt);
+ messageSent.setFloatProperty("TESTFLOAT", nFloat);
+ messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
+ messageSent.setStringProperty("TESTSTRING", "test");
+ messageSent.setLongProperty("TESTLONG", nLong);
+ messageSent.setStringProperty("TESTSTRINGTRUE", "true");
+ messageSent.setStringProperty("TESTSTRINGFALSE", "false");
+ messageSent.setStringProperty("TESTSTRING1", "1");
+
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesConversionQTest");
+ messageSent.setStringProperty("TestCase", "msgPropertiesConversionQTest");
+ logger.log(Logger.Level.TRACE, "Sending message");
+
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ // ------------------------------------------------------------------------------
+ // An attempt to use any other class than Boolean, Byte, Short, Int, Long,
+ // Float,
+ // Double, and Stringmust throw a JMS MessageFormatException.
+ // ------------------------------------------------------------------------------
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void msgPropertiesConversionQTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ String testMessageBody = "Testing...";
+ int ntest = 0;
+ String testCase = "msgPropertiesConversionQTest";
+ try {
+
+ // -------------------------------------------------------------------
+ // test conversions for property values
+ // -------------------------------------------------------------------
+
+ // property set as boolean can be read only as string or boolean
+ // -------------------------------------------------------------------
+ // valid - boolean to string
+
+ String myBool = messageReceived.getStringProperty("TESTBOOLEAN");
+ if (Boolean.valueOf(myBool).booleanValue() == bool) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from boolean to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from boolean to string failed");
+ pass = false;
+ }
+
+ // invalid - boolean to byte
+ try {
+ messageReceived.getByteProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ // logger.log(Logger.Level.INFO,"Error: unexpected error " +
+ // ee.getClass().getName()
+ // + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to byte");
+ pass = false;
+ }
+
+ // invalid - boolean to short
+ try {
+ messageReceived.getShortProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to short");
+ pass = false;
+ }
+
+ // invalid - boolean to int
+ try {
+ messageReceived.getIntProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception --boolean to int ");
+ pass = false;
+ }
+ // invalid - boolean to long
+ try {
+ messageReceived.getLongProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to long ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to long");
+ pass = false;
+ }
+
+ // invalid - boolean to float
+ try {
+ messageReceived.getFloatProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to float");
+ pass = false;
+ }
+
+ // invalid - boolean to double
+ try {
+ messageReceived.getDoubleProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as byte can be read as a byte,short,int,long or string
+
+ // valid - byte to string
+ String myByte = messageReceived.getStringProperty("TESTBYTE");
+ if (Byte.valueOf(myByte).byteValue() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from byte to string failed");
+ pass = false;
+ }
+ // valid - byte to short
+ if (messageReceived.getShortProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to short - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from byte to short failed");
+ pass = false;
+ }
+ // valid - byte to int
+ if (messageReceived.getIntProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from byte to int failed");
+ pass = false;
+ }
+ // valid - byte to long
+
+ if (messageReceived.getLongProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from byte to long failed");
+ pass = false;
+ }
+ // invalid - byte to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: byte to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- byte to boolean");
+ pass = false;
+ }
+
+ // invalid - byte to float
+ try {
+ messageReceived.getFloatProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: byte to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception --byte to float ");
+ pass = false;
+ }
+
+ // invalid - byte to double
+ try {
+ messageReceived.getDoubleProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: byte to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- byte to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------
+ // property set as short can be read as short,int,long or string
+
+ // valid - short to string
+ String myshort = messageReceived.getStringProperty("TESTSHORT");
+ if (Short.valueOf(myshort).shortValue() == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from short to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from short to string failed");
+ pass = false;
+ }
+
+ // valid - short to int
+ if (messageReceived.getIntProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from short to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from short to int failed");
+ pass = false;
+ }
+ // valid - short to long
+ if (messageReceived.getLongProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from short to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from short to long failed");
+ pass = false;
+ }
+
+ // invalid - short to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- short to boolean");
+ pass = false;
+ }
+
+ // invalid - short to byte
+ try {
+ messageReceived.getByteProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- short to byte");
+ pass = false;
+ }
+
+ // invalid - short to float
+ try {
+ messageReceived.getFloatProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- short to float");
+ pass = false;
+ }
+
+ // invalid - short to double
+ try {
+ messageReceived.getDoubleProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- short to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------
+ // property set as int can be read only as int, long or string
+
+ // valid - int to string
+ if (Integer.valueOf(messageReceived.getStringProperty("TESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from int to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from int to string failed");
+ pass = false;
+ }
+
+ // valid - int to long
+ if (messageReceived.getLongProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from int to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from int to long failed");
+ pass = false;
+ }
+
+ // invalid - int to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- int to boolean");
+ pass = false;
+ }
+
+ // invalid - int to byte
+ try {
+ messageReceived.getByteProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- int to byte");
+ pass = false;
+ }
+
+ // invalid - int to short
+ try {
+ messageReceived.getShortProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected -- int to short ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception ");
+ pass = false;
+ }
+
+ // invalid - int to float
+ try {
+ messageReceived.getFloatProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- int to float");
+ pass = false;
+ }
+
+ // invalid - int to double
+ try {
+ messageReceived.getDoubleProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- int to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as long can be read only as long,or a string
+
+ // valid - long to string
+ if (Long.valueOf(messageReceived.getStringProperty("TESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from long to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from long to string failed");
+ pass = false;
+ }
+
+ // invalid - long to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to boolean");
+ pass = false;
+ }
+
+ // invalid - long to byte
+ try {
+ messageReceived.getByteProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to byte");
+ pass = false;
+ }
+ // invalid - long to short
+ try {
+ messageReceived.getShortProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to short ");
+ pass = false;
+ }
+ // invalid - long to int
+ try {
+ messageReceived.getIntProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to int");
+ pass = false;
+ }
+
+ // invalid - long to float
+ try {
+ messageReceived.getFloatProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to float");
+ pass = false;
+ }
+
+ // invalid - long to double
+ try {
+ messageReceived.getDoubleProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as float can be read only as float,double or a string
+
+ // valid - float to string
+ if (Float.valueOf(messageReceived.getStringProperty("TESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from float to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from float to string failed");
+ pass = false;
+ }
+ // valid - float to double
+ if (messageReceived.getDoubleProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from long to double - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from long to double failed");
+ pass = false;
+ }
+
+ // invalid - float to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- float to boolean ");
+ pass = false;
+ }
+
+ // invalid - float to byte
+ try {
+ messageReceived.getByteProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- float to byte");
+ pass = false;
+ }
+ // invalid - float to short
+ try {
+ messageReceived.getShortProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception - float to short ");
+ pass = false;
+ }
+ // invalid - float to int
+ try {
+ messageReceived.getIntProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception --- float to int");
+ pass = false;
+ }
+
+ // invalid - float to long
+ try {
+ messageReceived.getLongProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to long ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- float to long");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as double can be read only as double or string
+
+ // valid - double to string
+ if (Double.valueOf(messageReceived.getStringProperty("TESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from double to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from double to string failed");
+ pass = false;
+ }
+
+ // invalid - double to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to boolean ");
+ pass = false;
+ }
+
+ // invalid - double to byte
+ try {
+ messageReceived.getByteProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to byte ");
+ pass = false;
+ }
+ // invalid - double to short
+ try {
+ messageReceived.getShortProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to short");
+ pass = false;
+ }
+ // invalid - double to int
+ try {
+ messageReceived.getIntProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception --- double to int ");
+ pass = false;
+ }
+
+ // invalid - double to long
+ try {
+ messageReceived.getLongProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to long ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to long");
+ pass = false;
+ }
+
+ // invalid - double to float
+ try {
+ messageReceived.getFloatProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to float");
+ pass = false;
+ }
+ // -------------------------------------------------------------------
+ // property set as string can be read as boolean, byte, short,
+ // int, long, float, double, and String.
+
+ // valid - string to boolean
+ if ((messageReceived.getBooleanProperty("TESTSTRINGTRUE")) == true) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to boolean - expect true - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to boolean - expect true - failed");
+ pass = false;
+ }
+
+ if ((messageReceived.getBooleanProperty("TESTSTRINGFALSE")) == false) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to boolean expect false - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to boolean expect false - failed");
+ pass = false;
+ }
+
+ // valid - string to byte
+ if (messageReceived.getByteProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to byte - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to byte failed");
+ pass = false;
+ }
+ // valid - string to short
+ if (messageReceived.getShortProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to short - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to short failed");
+ pass = false;
+ }
+ // valid - string to int
+ if (messageReceived.getIntProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to int failed");
+ pass = false;
+ }
+ // valid - string to long
+ if (messageReceived.getLongProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to long failed");
+ pass = false;
+ }
+
+ // valid - string to float
+ if (messageReceived.getFloatProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to float - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to float failed");
+ pass = false;
+ }
+ // valid - string to double
+ if (messageReceived.getDoubleProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to double - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to double failed");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: send test results to response queue (MDB_QUEUE_REPLY) for
+ * verification
+ */
+ private void sendTestResults(String testCase, boolean results) {
+ TextMessage msg = null;
+
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ msg.setStringProperty("TestCase", testCase);
+ msg.setText(testCase);
+ if (results)
+ msg.setStringProperty("Status", "Pass");
+ else
+ msg.setStringProperty("Status", "Fail");
+
+ System.out.println("Sending response message");
+ System.out.println("==================================Test Results from: " + testCase);
+ System.out.println("==================================Status: " + results);
+ mSender.send(msg);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ System.out.println("Error: " + je.getClass().getName() + " was thrown");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ System.out.println("Error: " + ee.getClass().getName() + " was thrown");
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ System.out.println("jms.ee.mdb.mdb_msgPropsQ In MsgBeanMsgTestPropsQ::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ System.out.println("jms.ee.mdb.mdb_msgPropsQ In MsgBeanMsgTestPropsQ::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsT/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsT/MDBClient.java
deleted file mode 100644
index bc2a58e09a..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsT/MDBClient.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_msgPropsT;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.MDB_T_Test;
-
-import jakarta.ejb.EJB;
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_MSGPropsT_Test")
- private static MDB_T_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.port;
- * harness.log.traceflag;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
-
- /*
- * @testName: mdbMsgPropertiesTTest
- *
- * @assertion_ids: JMS:SPEC:20.1; JMS:SPEC:20.2; JMS:SPEC:20.3; JMS:SPEC:20.4;
- * JMS:SPEC:20.5; JMS:SPEC:20.6; JMS:SPEC:20.7; JMS:SPEC:20.8; JMS:SPEC:21;
- * JMS:SPEC:23; JMS:SPEC:24; JMS:SPEC:25; JMS:SPEC:26; JMS:SPEC:10;
- * JMS:SPEC:27; JMS:SPEC:28; JMS:SPEC:29; JMS:SPEC:31; JMS:SPEC:32;
- * JMS:JAVADOC:411; JMS:JAVADOC:413; JMS:JAVADOC:415; JMS:JAVADOC:417;
- * JMS:JAVADOC:419; JMS:JAVADOC:421; JMS:JAVADOC:423; JMS:JAVADOC:425;
- * JMS:JAVADOC:427; JMS:JAVADOC:409; JMS:JAVADOC:391; JMS:JAVADOC:393;
- * JMS:JAVADOC:395; JMS:JAVADOC:397; JMS:JAVADOC:399; JMS:JAVADOC:401;
- * JMS:JAVADOC:403; JMS:JAVADOC:405; JMS:JAVADOC:407; JMS:JAVADOC:500;
- * JMS:JAVADOC:516; JMS:JAVADOC:387;
- *
- * @test_Strategy: create a session bean. Have the session bean send a message
- * to the mdb. The mdb will create a test message and send the test message to
- * the Topic for which it is a message listener. It will then verify the
- * results. pass or fail results are sent to the MDB_REPLY_QUEUE The session
- * bean checks MDB_QUEUE_REPLY for the results. Specifics: set and read
- * properties for boolean, byte, short, int, long, float, double, and String.
- * Verify expected results set and read properties for Boolean, Byte, Short,
- * Int, Long, Float, Double, and String. Verify expected results.
- *
- * When a client receives a message it is in read-only mode. Send a message
- * and have the client attempt modify the properties. Verify that a
- * MessageNotWriteableException is thrown. Call setObject property with an
- * invalid object and verify that a MessageFormatException is thrown
- *
- * call property get methods( other than getStringProperty and
- * getObjectProperty) for non-existent properties and verify that a null
- * pointer exception is returned. call getStringProperty and getObjectProperty
- * for non-existent properties and verify that a null is returned.
- *
- * set object properties and verify the correct value is returned with the
- * getObjectProperty method.
- *
- * call the clearProperties method on the received message and verify that the
- * messages properties were deleted. Test that getObjectProperty returns a
- * null and the getShortProperty throws a null pointer exception. Verify that
- * after clearing properties, you will be able to set and get properties.
- *
- * After clearing the message properties, call getText and verify that the
- * message body has not been cleared.
- *
- * call getJMSXPropertyNames() and verify that the names of the required JMSX
- * properties for JMSXGroupID and JMSXGroupSeq are returned.
- */
- public void mdbMsgPropertiesTTest() throws Exception {
- String testCase1 = "msgPropertiesTTestCreate";
- String testCase2 = "msgPropertiesTTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgPropertiesTTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgPropertiesTTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgPropertiesConversionTTest
- *
- * @assertion_ids: JMS:SPEC:22.1; JMS:SPEC:22.2; JMS:SPEC:22.3; JMS:SPEC:22.4;
- * JMS:SPEC:22.5; JMS:SPEC:22.6; JMS:SPEC:22.7; JMS:SPEC:22.8; JMS:SPEC:22.9;
- * JMS:SPEC:22.10; JMS:SPEC:22.11; JMS:SPEC:22.12; JMS:SPEC:22.13;
- * JMS:SPEC:22.14; JMS:SPEC:22.15; JMS:SPEC:22.16;
- *
- * @test_Strategy: create a session bean. have the session bean create a
- * message and send to mdb. THe mdb will create a message, set properties for
- * all of the primitive types, send that message to the Topic that it is a
- * listener for and then verify the conversion by getting the properties. pass
- * or fail results are then sent to the MDB_REPLY_QUEUE The session bean
- * checks MDB_QUEUE_REPLY for the results.
- */
- public void mdbMsgPropertiesConversionTTest() throws Exception {
- String testCase1 = "msgPropertiesConversionTTestCreate";
- String testCase2 = "msgPropertiesConversionTTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run msgPropertiesConversionTTestCreate");
- hr.askMDBToRunATest(testCase1);
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgPropertiesConversionTTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- ;
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsT/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsT/MDBClientIT.java
new file mode 100644
index 0000000000..4c41ee21ea
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsT/MDBClientIT.java
@@ -0,0 +1,188 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_msgPropsT;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.commonee.MDB_T_Test;
+
+import jakarta.ejb.EJB;
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_MSGPropsT_Test")
+ private static MDB_T_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password; harness.log.port;
+ * harness.log.traceflag;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ hr.setup(props);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+
+ /*
+ * @testName: mdbMsgPropertiesTTest
+ *
+ * @assertion_ids: JMS:SPEC:20.1; JMS:SPEC:20.2; JMS:SPEC:20.3; JMS:SPEC:20.4;
+ * JMS:SPEC:20.5; JMS:SPEC:20.6; JMS:SPEC:20.7; JMS:SPEC:20.8; JMS:SPEC:21;
+ * JMS:SPEC:23; JMS:SPEC:24; JMS:SPEC:25; JMS:SPEC:26; JMS:SPEC:10; JMS:SPEC:27;
+ * JMS:SPEC:28; JMS:SPEC:29; JMS:SPEC:31; JMS:SPEC:32; JMS:JAVADOC:411;
+ * JMS:JAVADOC:413; JMS:JAVADOC:415; JMS:JAVADOC:417; JMS:JAVADOC:419;
+ * JMS:JAVADOC:421; JMS:JAVADOC:423; JMS:JAVADOC:425; JMS:JAVADOC:427;
+ * JMS:JAVADOC:409; JMS:JAVADOC:391; JMS:JAVADOC:393; JMS:JAVADOC:395;
+ * JMS:JAVADOC:397; JMS:JAVADOC:399; JMS:JAVADOC:401; JMS:JAVADOC:403;
+ * JMS:JAVADOC:405; JMS:JAVADOC:407; JMS:JAVADOC:500; JMS:JAVADOC:516;
+ * JMS:JAVADOC:387;
+ *
+ * @test_Strategy: create a session bean. Have the session bean send a message
+ * to the mdb. The mdb will create a test message and send the test message to
+ * the Topic for which it is a message listener. It will then verify the
+ * results. pass or fail results are sent to the MDB_REPLY_QUEUE The session
+ * bean checks MDB_QUEUE_REPLY for the results. Specifics: set and read
+ * properties for boolean, byte, short, int, long, float, double, and String.
+ * Verify expected results set and read properties for Boolean, Byte, Short,
+ * Int, Long, Float, Double, and String. Verify expected results.
+ *
+ * When a client receives a message it is in read-only mode. Send a message and
+ * have the client attempt modify the properties. Verify that a
+ * MessageNotWriteableException is thrown. Call setObject property with an
+ * invalid object and verify that a MessageFormatException is thrown
+ *
+ * call property get methods( other than getStringProperty and
+ * getObjectProperty) for non-existent properties and verify that a null pointer
+ * exception is returned. call getStringProperty and getObjectProperty for
+ * non-existent properties and verify that a null is returned.
+ *
+ * set object properties and verify the correct value is returned with the
+ * getObjectProperty method.
+ *
+ * call the clearProperties method on the received message and verify that the
+ * messages properties were deleted. Test that getObjectProperty returns a null
+ * and the getShortProperty throws a null pointer exception. Verify that after
+ * clearing properties, you will be able to set and get properties.
+ *
+ * After clearing the message properties, call getText and verify that the
+ * message body has not been cleared.
+ *
+ * call getJMSXPropertyNames() and verify that the names of the required JMSX
+ * properties for JMSXGroupID and JMSXGroupSeq are returned.
+ */
+ @Test
+ public void mdbMsgPropertiesTTest() throws Exception {
+ String testCase1 = "msgPropertiesTTestCreate";
+ String testCase2 = "msgPropertiesTTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgPropertiesTTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgPropertiesTTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgPropertiesConversionTTest
+ *
+ * @assertion_ids: JMS:SPEC:22.1; JMS:SPEC:22.2; JMS:SPEC:22.3; JMS:SPEC:22.4;
+ * JMS:SPEC:22.5; JMS:SPEC:22.6; JMS:SPEC:22.7; JMS:SPEC:22.8; JMS:SPEC:22.9;
+ * JMS:SPEC:22.10; JMS:SPEC:22.11; JMS:SPEC:22.12; JMS:SPEC:22.13;
+ * JMS:SPEC:22.14; JMS:SPEC:22.15; JMS:SPEC:22.16;
+ *
+ * @test_Strategy: create a session bean. have the session bean create a message
+ * and send to mdb. THe mdb will create a message, set properties for all of the
+ * primitive types, send that message to the Topic that it is a listener for and
+ * then verify the conversion by getting the properties. pass or fail results
+ * are then sent to the MDB_REPLY_QUEUE The session bean checks MDB_QUEUE_REPLY
+ * for the results.
+ */
+ @Test
+ public void mdbMsgPropertiesConversionTTest() throws Exception {
+ String testCase1 = "msgPropertiesConversionTTestCreate";
+ String testCase2 = "msgPropertiesConversionTTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run msgPropertiesConversionTTestCreate");
+ hr.askMDBToRunATest(testCase1);
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgPropertiesConversionTTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ ;
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsT/MsgBeanMsgTestPropsT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsT/MsgBeanMsgTestPropsT.java
index fe3f748cf0..f166bb68ce 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsT/MsgBeanMsgTestPropsT.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgPropsT/MsgBeanMsgTestPropsT.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_msgPropsT;
+import java.lang.System.Logger;
import java.util.Enumeration;
import java.util.Properties;
@@ -48,1697 +49,1562 @@
import jakarta.jms.TopicPublisher;
import jakarta.jms.TopicSession;
-public class MsgBeanMsgTestPropsT
- implements MessageDrivenBean, MessageListener {
+public class MsgBeanMsgTestPropsT implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- private MessageDrivenContext mdc = null;
-
- // JMS
- private QueueConnectionFactory qFactory = null;
-
- private QueueConnection qConnection = null;
-
- private Queue queueR = null;
-
- private QueueSender mSender = null;
-
- private QueueSession qSession = null;
-
- private TopicConnectionFactory tFactory = null;
-
- private TopicConnection tConnection = null;
-
- private Topic topic = null;
-
- private TopicPublisher tPublisher = null;
-
- private TopicSession tSession = null;
-
- private TextMessage messageSent = null;
-
- public MsgBeanMsgTestPropsT() {
- TestUtil.logTrace("@MsgBeanMsgTestPropsT()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgPropsT - @MsgBeanMsgTestPropsT-ejbCreate() !!");
- try {
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- if (qFactory == null) {
- TestUtil.logTrace("qFactory error");
- }
- TestUtil.logTrace("got a qFactory !!");
-
- queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- if (queueR == null) {
- TestUtil.logTrace("queueR error");
- }
-
- tFactory = (TopicConnectionFactory) context
- .lookup("java:comp/env/jms/MyTopicConnectionFactory");
- if (tFactory == null) {
- TestUtil.logTrace("tFactory error");
- }
- TestUtil.logTrace("got a tFactory !!");
-
- topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC");
- if (topic == null) {
- TestUtil.logTrace("topic error");
- }
-
- p = new Properties();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
-
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("from jms.ee.mdb.mdb_msgPropsT @onMessage!" + msg);
-
- try {
- TestUtil.logTrace(
- "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null) {
- TestUtil.logTrace("connection error");
- } else {
- qConnection.start();
- qSession = qConnection.createQueueSession(true, 0);
- }
- tConnection = tFactory.createTopicConnection();
- if (tConnection == null) {
- TestUtil.logTrace("connection error");
- } else {
- tConnection.start();
- tSession = tConnection.createTopicSession(true, 0);
- }
-
- messageSent = tSession.createTextMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
-
- if (msg.getStringProperty("TestCase")
- .equals("msgPropertiesTTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running msgPropertiesTTestCreate - create the message");
- msgPropertiesTTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgPropertiesTTest")) {
- TestUtil.logTrace("@onMessage - msgPropertiesTTest!");
- msgPropertiesTTest(msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgPropertiesConversionTTestCreate")) {
- TestUtil.logTrace("@onMessage - msgPropertiesConversionTTestCreate!");
- msgPropertiesConversionTTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgPropertiesConversionTTest")) {
- TestUtil.logTrace("@onMessage - msgPropertiesConversionTTest!");
- msgPropertiesConversionTTest(msg);
- }
-
- else {
- TestUtil.logTrace(
- "@onMessage - invalid message type found in StringProperty");
- TestUtil.logTrace("Do not have a method for this testcase: "
- + msg.getStringProperty("TestCase"));
- }
-
- TestUtil.logTrace("@onMessage - Finished for this test!");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- if (tConnection != null) {
- try {
- tConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
-
- }
-
- /*
- *
- */
-
- private void msgPropertiesTTestCreate() {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- Enumeration propertyNames = null;
- Enumeration jmsxDefined = null;
-
- String testMessageBody = "Testing...";
- int NUMPROPS = 0;
-
- JmsUtil.addPropsToMessage(messageSent, p);
-
- try {
-
- messageSent.setText(testMessageBody);
- // ------------------------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- messageSent.setBooleanProperty("TESTBOOLEAN", bool);
- messageSent.setByteProperty("TESTBYTE", bValue);
- messageSent.setShortProperty("TESTSHORT", nShort);
- messageSent.setIntProperty("TESTINT", nInt);
- messageSent.setFloatProperty("TESTFLOAT", nFloat);
- messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
- messageSent.setStringProperty("TESTSTRING", "test");
- messageSent.setLongProperty("TESTLONG", nLong);
-
- // ------------------------------------------------------------------------------
- // set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
- // String.
- // ------------------------------------------------------------------------------
-
- messageSent.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
- messageSent.setObjectProperty("OBJTESTBYTE", Byte.valueOf(bValue));
- messageSent.setObjectProperty("OBJTESTSHORT", Short.valueOf(nShort));
- messageSent.setObjectProperty("OBJTESTINT", Integer.valueOf(nInt));
- messageSent.setObjectProperty("OBJTESTFLOAT", new Float(nFloat));
- messageSent.setObjectProperty("OBJTESTDOUBLE", new Double(nDouble));
- messageSent.setObjectProperty("OBJTESTSTRING", "test");
- messageSent.setObjectProperty("OBJTESTLONG", new Long(nLong));
-
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesTTest");
- messageSent.setStringProperty("TestCase", "msgPropertiesTTest");
-
- // count total properties in messageSent
-
- Enumeration e = messageSent.getPropertyNames();
- String key = null;
- int i = 0;
- while (e.hasMoreElements()) {
- key = (String) e.nextElement();
- TestUtil.logTrace("+++++++ Property Name is: " + key);
- if (key.indexOf("JMS") != 0)
- i++;
- }
-
- // set Count for properties to pass + 1 for count itself
- i++;
- messageSent.setIntProperty("NUMPROPS", i);
-
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- // ------------------------------------------------------------------------------
- // An attempt to use any other class than Boolean, Byte, Short, Int, Long,
- // Float,
- // Double, and Stringmust throw a JMS MessageFormatException.
- // ------------------------------------------------------------------------------
- try {
- messageSent.setObjectProperty("OBJTESTLONG", new Object());
- TestUtil.logMsg("Error: expected MessageFormatException from invalid ");
- TestUtil.logMsg("call to setObjectProperty did not occur!");
- pass = false;
- } catch (MessageFormatException fe) {
- TestUtil.logTrace("Pass: ");
- TestUtil.logTrace(
- " MessageFormatException as expected from invalid setObjectProperty call");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg("from call to setObjectProperty!");
- TestUtil.logMsg(ee.getMessage());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void msgPropertiesTTest(jakarta.jms.Message msg) {
-
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- Enumeration propertyNames = null;
- Enumeration jmsxDefined = null;
-
- String testCase = "msgPropertiesTTest";
- String testMessageBody = "Testing...";
- TextMessage messageReceived = (TextMessage) msg;
- try {
- // -------------------------------------------------------------------------
- // Received message should be read-only - verify proper exception is
- // thrown
- // when trying to modify msg properties.
- // ------------------------------------------------------------------------
- try {
- messageReceived.setBooleanProperty("TESTBOOLEAN", bool);
- TestUtil.logMsg(
- "Error: exception should have occurred for setBooleanProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil
- .logTrace("Pass: exception as expected for setBooleanProperty ");
- }
-
- try {
- messageReceived.setByteProperty("TESTBYTE", bValue);
- TestUtil.logMsg(
- "Error: exception should have occurred for setByteProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setByteProperty ");
- }
-
- try {
- messageReceived.setShortProperty("TESTSHORT", nShort);
- pass = false;
- TestUtil.logMsg(
- "Error: exception should have occurred for setShortProperty");
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setShortProperty ");
- }
-
- try {
- messageReceived.setIntProperty("TESTINT", nInt);
- TestUtil
- .logMsg("Error: exception should have occurred for setIntProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setIntProperty ");
- }
-
- try {
- messageReceived.setFloatProperty("TESTFLOAT", nFloat);
- TestUtil.logMsg(
- "Error: exception should have occurred for setFloatProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setFloatProperty ");
- }
-
- try {
- messageReceived.setDoubleProperty("TESTDOUBLE", nDouble);
- TestUtil.logMsg(
- "Error: exception should have occurred for setDoubleProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setDoubleProperty ");
- }
-
- try {
- messageReceived.setStringProperty("TESTSTRING", testString);
- TestUtil.logMsg(
- "Error: exception should have occurred for setStringProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setStringProperty ");
- }
-
- try {
- messageReceived.setLongProperty("TESTLONG", nLong);
- TestUtil.logMsg(
- "Error: exception should have occurred for setLongProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setLongProperty ");
- }
-
- try {
- messageReceived.setObjectProperty("OBJTESTBOOLEAN",
- Boolean.valueOf(bool));
- TestUtil.logMsg(
- "Error: exception should have occurred for setObjectProperty");
- pass = false;
- } catch (MessageNotWriteableException aBool) {
- TestUtil.logTrace("Pass: exception as expected for setObjectProperty ");
- }
-
- int numPropertyNames = (int) messageReceived.getIntProperty("NUMPROPS");
- // iterate thru the property names
- int i = 0;
- propertyNames = messageReceived.getPropertyNames();
- do {
- String tmp = (String) propertyNames.nextElement();
- TestUtil.logTrace("+++++++ Property Name is: " + tmp);
- if (tmp.indexOf("JMS") != 0)
- i++;
- } while (propertyNames.hasMoreElements());
-
- if (i == numPropertyNames) {
- TestUtil.logTrace(
- "Pass: # of properties is " + numPropertyNames + " as expected");
- } else {
- TestUtil
- .logMsg("Error: expected " + numPropertyNames + "property names");
- TestUtil.logMsg(" But " + i + " returned");
- pass = false;
- }
-
- // --------------------------------------------------------------------------------
- // read and verify the property values for primitive types in the received
- // message
- // --------------------------------------------------------------------------------
- if (messageReceived.getBooleanProperty("TESTBOOLEAN") == bool) {
- TestUtil.logTrace("Pass: getBooleanProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getBooleanProperty");
- pass = false;
- }
-
- if (messageReceived.getByteProperty("TESTBYTE") == bValue) {
- TestUtil.logTrace("Pass: getByteProperty returned correct value");
- } else {
- TestUtil.logMsg("Error: incorrect value returned from getByteProperty");
- pass = false;
- }
-
- if (messageReceived.getLongProperty("TESTLONG") == nLong) {
- TestUtil.logTrace("Pass: getLongProperty returned correct value");
- } else {
- TestUtil.logMsg("Error: incorrect value returned from getLongProperty");
- pass = false;
- }
-
- if (messageReceived.getStringProperty("TESTSTRING").equals(testString)) {
- TestUtil.logTrace("Pass: getStringProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getStringProperty");
- pass = false;
- }
-
- if (messageReceived.getDoubleProperty("TESTDOUBLE") == nDouble) {
- TestUtil.logTrace("Pass: getDoubleProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getDoubleProperty");
- pass = false;
- }
-
- if (messageReceived.getFloatProperty("TESTFLOAT") == nFloat) {
- TestUtil.logTrace("Pass: getFloatProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getFloatProperty");
- pass = false;
- }
-
- if (messageReceived.getIntProperty("TESTINT") == nInt) {
- TestUtil.logTrace("Pass: getIntProperty returned correct value");
- } else {
- TestUtil.logMsg("Error: incorrect value returned from getIntProperty");
- pass = false;
- }
-
- if (messageReceived.getShortProperty("TESTSHORT") == nShort) {
- TestUtil.logTrace("Pass: getShortProperty returned correct value");
- } else {
- TestUtil
- .logMsg("Error: incorrect value returned from getShortProperty");
- pass = false;
- }
- // --------------------------------------------------------------------------------
- // The other property get methods ( other than getStringProperty and
- // getObjectProperty) must throw a java.lang.NullPointerException if
- // they are used to get a non-existent property.
- // --------------------------------------------------------------------------------
- boolean b = messageReceived.getBooleanProperty("TESTDUMMY");
- if (b != false) {
- TestUtil.logTrace(
- "Error: should havereceived false for getBooleanProperty");
- pass = false;
- }
- // try {
- // boolean value = messageReceived.getBooleanProperty("TESTDUMMY");
- // TestUtil.logMsg("Error: NullPointerException should have occurred for
- // getBooleanProperty");
- // pass = false;
- // } catch (java.lang.NullPointerException np) {
- // TestUtil.logTrace("Pass: NullPointerException as expected ");}
- /*
- * try { byte value = messageReceived.getByteProperty("TESTDUMMY");
- * TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getByteProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- *
- * try { short value = messageReceived.getShortProperty("TESTDUMMY");
- * TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getShortProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- *
- * try { int value = messageReceived.getIntProperty("TESTDUMMY");
- * TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getIntProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- *
- * try { long value = messageReceived.getLongProperty("TESTDUMMY");
- * TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getLongProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- *
- * try { float value = messageReceived.getFloatProperty("TESTDUMMY");
- * TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getFloatProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- *
- * try { double value = messageReceived.getDoubleProperty("TESTDUMMY");
- * TestUtil.
- * logMsg("Error: NullPointerException should have occurred for getDoubleProperty"
- * ); pass = false; } catch (java.lang.NullPointerException np) {
- * TestUtil.logTrace("Pass: NullPointerException as expected ");}
- *
- */
- // --------------------------------------------------------------------------------
- // Getting a property value for a name which has not been set returns a
- // null value.
- // (For getStringProperty and getObjectProperty)
- // --------------------------------------------------------------------------------
- String value = messageReceived.getStringProperty("TESTDUMMY");
- if (value == null) {
- TestUtil.logTrace("Pass: getStringProperty returned correct value");
- } else {
- TestUtil.logMsg(
- "Error: expected a null return from getStringProperty for invalid property");
- pass = false;
- }
-
- Boolean aBool = (Boolean) messageReceived.getObjectProperty("TESTDUMMY");
- if (aBool == null) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Boolean");
- } else {
- TestUtil.logMsg(
- "Error: expected a null return from getObjectProperty for invalid property");
- pass = false;
- }
-
- // --------------------------------------------------------------------------------
- // read and verify the property values for getObject in the received
- // message
- // --------------------------------------------------------------------------------
-
- Boolean boolValue = (Boolean) messageReceived
- .getObjectProperty("OBJTESTBOOLEAN");
- if (boolValue.booleanValue() == bool) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Boolean");
- } else {
- TestUtil.logMsg("Error: incorrect value returned for Boolean");
- pass = false;
- }
-
- Byte byteValue = (Byte) messageReceived.getObjectProperty("OBJTESTBYTE");
- if (byteValue.byteValue() == bValue) {
- TestUtil
- .logTrace("Pass: getObjectProperty returned correct Byte value");
- } else {
- TestUtil.logMsg("Error: incorrect value returned from Byte");
- pass = false;
- }
-
- Long lValue = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
- if (lValue.longValue() == nLong) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Long");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value returned for Long");
- pass = false;
- }
-
- // String value =
- // (String)messageReceived.getObjectProperty("OBJTESTSTRING");
- if (messageReceived.getObjectProperty("OBJTESTSTRING")
- .equals(testString)) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for String");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for String");
- pass = false;
- }
-
- Double dValue = (Double) messageReceived
- .getObjectProperty("OBJTESTDOUBLE");
- if (dValue.doubleValue() == nDouble) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Double");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for Double");
- pass = false;
- }
-
- Float fValue = (Float) messageReceived.getObjectProperty("OBJTESTFLOAT");
- if (fValue.floatValue() == nFloat) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Float");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for Float");
- pass = false;
- }
-
- Integer iValue = (Integer) messageReceived
- .getObjectProperty("OBJTESTINT");
- if (iValue.intValue() == nInt) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Integer");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for Integer");
- pass = false;
- }
-
- Short sValue = (Short) messageReceived.getObjectProperty("OBJTESTSHORT");
- if (sValue.shortValue() == nShort) {
- TestUtil.logTrace(
- "Pass: getObjectProperty returned correct value for Short");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty returned incorrect value for Short");
- pass = false;
- }
-
- // clear message properties
- messageReceived.clearProperties();
-
- // -------------------------------------------------------------------
- // A message?s properties are deleted by the clearProperties method.
- // This leaves the message with an empty set of properties.
- // -------------------------------------------------------------------
-
- Long aLong = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
- if (aLong == null) {
- TestUtil.logTrace("Pass: property was cleared");
- } else {
- TestUtil.logMsg(
- "Error: getObjectProperty should have returned null for cleared property");
- pass = false;
- }
-
- try {
- short aShort = messageReceived.getShortProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: NullPointerException should have occurred for getShortProperty");
- TestUtil.logMsg("Properties have been cleared!");
- pass = false;
- } catch (java.lang.NullPointerException np) {
- TestUtil.logTrace("Pass: NullPointerException as expected ");
- } catch (java.lang.NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException as expected ");
- }
-
- // -------------------------------------------------------------------
- // A message's properties are deleted by the clearProperties method.
- // This leaves the message with an empty set of properties.
- // New property entries can then be both created and read.
- // -------------------------------------------------------------------
- try {
- String newEntry = "new entry";
- TestUtil
- .logTrace("Verify that you can set a property after clearProperty");
- messageReceived.setStringProperty("TESTSTRING", "new entry");
- if (messageReceived.getStringProperty("TESTSTRING").equals(newEntry)) {
- TestUtil.logTrace("Pass: able to set a cleared property");
- } else {
- TestUtil.logTrace(
- "Error: was not able to new property setting after clearProperty");
- pass = false;
- }
- } catch (Exception exp) {
- TestUtil.logTrace(
- "Unexpected Exception caught while testing set after clearProperty");
- pass = false;
- TestUtil.printStackTrace(exp);
- }
-
- // -------------------------------------------------------------------
- // clearing the message property should not effect the message body.
- // -------------------------------------------------------------------
- TestUtil.logMsg("Message body is : " + messageReceived.getText());
- if (messageReceived.getText().equals(testMessageBody)) {
- TestUtil
- .logTrace("Pass: able to read message body after clearProperties");
- } else {
- TestUtil
- .logMsg("Error: unable to read message body after clearProperties");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // ConnectionMetaData.getJMSXPropertyNames() method returns the
- // names of the JMSX properties supported by a connection.
- // -------------------------------------------------------------------
- try {
- ConnectionMetaData data = qConnection.getMetaData();
- Enumeration cmd = data.getJMSXPropertyNames();
- String propName;
- if (cmd == null) {
- TestUtil.logMsg("Error: no JMSX property names were returned!");
- TestUtil
- .logMsg("expected JMSXGroupID and JMSXGroupSeq at a miniumum");
- pass = false;
- } else {
- int iCount = 0;
- while (cmd.hasMoreElements()) {
- propName = (String) cmd.nextElement();
- TestUtil.logTrace(propName);
- if (propName.equals("JMSXGroupID")
- || propName.equals("JMSXGroupSeq")) {
- iCount++;
- }
- }
- if (iCount == 2) {
- TestUtil.logTrace("Pass:");
- } else {
- TestUtil.logMsg("Error: Expected property names not returned");
- pass = false;
- }
- }
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg("attempting to read JMSX property names.");
- TestUtil.logMsg("Error: unexpected exception: "
- + ee.getClass().getName() + " was thrown");
- pass = false;
- }
-
- } catch (Exception ex) {
- TestUtil.printStackTrace(ex);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- private void msgPropertiesConversionTTestCreate() {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- String testMessageBody = "Testing...";
- int ntest = 0;
- try {
- messageSent.setText(testMessageBody);
- // ------------------------------------------------------------------------------
- // set properties for boolean, byte, short, int, long, float, double, and
- // String.
- // ------------------------------------------------------------------------------
- messageSent.setBooleanProperty("TESTBOOLEAN", bool);
- messageSent.setByteProperty("TESTBYTE", bValue);
- messageSent.setShortProperty("TESTSHORT", nShort);
- messageSent.setIntProperty("TESTINT", nInt);
- messageSent.setFloatProperty("TESTFLOAT", nFloat);
- messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
- messageSent.setStringProperty("TESTSTRING", "test");
- messageSent.setLongProperty("TESTLONG", nLong);
- messageSent.setStringProperty("TESTSTRINGTRUE", "true");
- messageSent.setStringProperty("TESTSTRINGFALSE", "false");
- messageSent.setStringProperty("TESTSTRING1", "1");
-
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgPropertiesConversionTTest");
- messageSent.setStringProperty("TestCase", "msgPropertiesConversionTTest");
- TestUtil.logTrace("Sending message");
-
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void msgPropertiesConversionTTest(jakarta.jms.Message messageReceived) {
- boolean pass = true;
- boolean bool = true;
- byte bValue = 127;
- short nShort = 10;
- int nInt = 5;
- long nLong = 333;
- float nFloat = 1;
- double nDouble = 100;
- String testString = "test";
- String testMessageBody = "Testing...";
- int ntest = 0;
- String testCase = "msgPropertiesConversionTTest";
- try {
-
- // -------------------------------------------------------------------
- // test conversions for property values
- // -------------------------------------------------------------------
-
- // property set as boolean can be read only as string or boolean
- // -------------------------------------------------------------------
- // valid - boolean to string
-
- String myBool = messageReceived.getStringProperty("TESTBOOLEAN");
- if (Boolean.valueOf(myBool).booleanValue() == bool) {
- TestUtil.logTrace("Pass: conversion from boolean to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from boolean to string failed");
- pass = false;
- }
-
- // invalid - boolean to byte
- try {
- messageReceived.getByteProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- // TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- // + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- boolean to byte");
- pass = false;
- }
-
- // invalid - boolean to short
- try {
- messageReceived.getShortProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- boolean to short");
- pass = false;
- }
-
- // invalid - boolean to int
- try {
- messageReceived.getIntProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to int ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception --boolean to int ");
- pass = false;
- }
- // invalid - boolean to long
- try {
- messageReceived.getLongProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to long ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- boolean to long");
- pass = false;
- }
-
- // invalid - boolean to float
- try {
- messageReceived.getFloatProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- boolean to float");
- pass = false;
- }
-
- // invalid - boolean to double
- try {
- messageReceived.getDoubleProperty("TESTBOOLEAN");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: boolean to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- boolean to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as byte can be read as a byte,short,int,long or string
-
- // valid - byte to string
- String myByte = messageReceived.getStringProperty("TESTBYTE");
- if (Byte.valueOf(myByte).byteValue() == bValue) {
- TestUtil.logTrace("Pass: conversion from byte to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from byte to string failed");
- pass = false;
- }
- // valid - byte to short
- if (messageReceived.getShortProperty("TESTBYTE") == bValue) {
- TestUtil.logTrace("Pass: conversion from byte to short - ok");
- } else {
- TestUtil.logMsg("Error: conversion from byte to short failed");
- pass = false;
- }
- // valid - byte to int
- if (messageReceived.getIntProperty("TESTBYTE") == bValue) {
- TestUtil.logTrace("Pass: conversion from byte to int - ok");
- } else {
- TestUtil.logMsg("Error: conversion from byte to int failed");
- pass = false;
- }
- // valid - byte to long
-
- if (messageReceived.getLongProperty("TESTBYTE") == bValue) {
- TestUtil.logTrace("Pass: conversion from byte to long - ok");
- } else {
- TestUtil.logMsg("Error: conversion from byte to long failed");
- pass = false;
- }
- // invalid - byte to boolean
- try {
- messageReceived.getBooleanProperty("TESTBYTE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: byte to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- byte to boolean");
- pass = false;
- }
-
- // invalid - byte to float
- try {
- messageReceived.getFloatProperty("TESTBYTE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: byte to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception --byte to float ");
- pass = false;
- }
-
- // invalid - byte to double
- try {
- messageReceived.getDoubleProperty("TESTBYTE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: byte to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- byte to double");
- pass = false;
- }
-
- // -------------------------------------------------
- // property set as short can be read as short,int,long or string
-
- // valid - short to string
- String myshort = messageReceived.getStringProperty("TESTSHORT");
- if (Short.valueOf(myshort).shortValue() == nShort) {
- TestUtil.logTrace("Pass: conversion from short to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from short to string failed");
- pass = false;
- }
-
- // valid - short to int
- if (messageReceived.getIntProperty("TESTSHORT") == nShort) {
- TestUtil.logTrace("Pass: conversion from short to int - ok");
- } else {
- TestUtil.logMsg("Error: conversion from short to int failed");
- pass = false;
- }
- // valid - short to long
- if (messageReceived.getLongProperty("TESTSHORT") == nShort) {
- TestUtil.logTrace("Pass: conversion from short to long - ok");
- } else {
- TestUtil.logMsg("Error: conversion from short to long failed");
- pass = false;
- }
-
- // invalid - short to boolean
- try {
- messageReceived.getBooleanProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: short to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- short to boolean");
- pass = false;
- }
-
- // invalid - short to byte
- try {
- messageReceived.getByteProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: short to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- short to byte");
- pass = false;
- }
-
- // invalid - short to float
- try {
- messageReceived.getFloatProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: short to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- short to float");
- pass = false;
- }
-
- // invalid - short to double
- try {
- messageReceived.getDoubleProperty("TESTSHORT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: short to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- short to double");
- pass = false;
- }
-
- // -------------------------------------------------
- // property set as int can be read only as int, long or string
-
- // valid - int to string
- if (Integer.valueOf(messageReceived.getStringProperty("TESTINT"))
- .intValue() == nInt) {
- TestUtil.logTrace("Pass: conversion from int to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from int to string failed");
- pass = false;
- }
-
- // valid - int to long
- if (messageReceived.getLongProperty("TESTINT") == nInt) {
- TestUtil.logTrace("Pass: conversion from int to long - ok");
- } else {
- TestUtil.logMsg("Error: conversion from int to long failed");
- pass = false;
- }
-
- // invalid - int to boolean
- try {
- messageReceived.getBooleanProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- int to boolean");
- pass = false;
- }
-
- // invalid - int to byte
- try {
- messageReceived.getByteProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- int to byte");
- pass = false;
- }
-
- // invalid - int to short
- try {
- messageReceived.getShortProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace(
- "Pass: MessageFormatException as expected -- int to short ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg("Error: did not catch expected Exception ");
- pass = false;
- }
-
- // invalid - int to float
- try {
- messageReceived.getFloatProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- int to float");
- pass = false;
- }
-
- // invalid - int to double
- try {
- messageReceived.getDoubleProperty("TESTINT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: int to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- int to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as long can be read only as long,or a string
-
- // valid - long to string
- if (Long.valueOf(messageReceived.getStringProperty("TESTLONG"))
- .longValue() == nLong) {
- TestUtil.logTrace("Pass: conversion from long to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from long to string failed");
- pass = false;
- }
-
- // invalid - long to boolean
- try {
- messageReceived.getBooleanProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- long to boolean");
- pass = false;
- }
-
- // invalid - long to byte
- try {
- messageReceived.getByteProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- long to byte");
- pass = false;
- }
- // invalid - long to short
- try {
- messageReceived.getShortProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- long to short ");
- pass = false;
- }
- // invalid - long to int
- try {
- messageReceived.getIntProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to int ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- long to int");
- pass = false;
- }
-
- // invalid - long to float
- try {
- messageReceived.getFloatProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- long to float");
- pass = false;
- }
-
- // invalid - long to double
- try {
- messageReceived.getDoubleProperty("TESTLONG");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: long to double ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- long to double");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as float can be read only as float,double or a string
-
- // valid - float to string
- if (Float.valueOf(messageReceived.getStringProperty("TESTFLOAT"))
- .floatValue() == nFloat) {
- TestUtil.logTrace("Pass: conversion from float to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from float to string failed");
- pass = false;
- }
- // valid - float to double
- if (messageReceived.getDoubleProperty("TESTFLOAT") == nFloat) {
- TestUtil.logTrace("Pass: conversion from long to double - ok");
- } else {
- TestUtil.logMsg("Error: conversion from long to double failed");
- pass = false;
- }
-
- // invalid - float to boolean
- try {
- messageReceived.getBooleanProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- float to boolean ");
- pass = false;
- }
-
- // invalid - float to byte
- try {
- messageReceived.getByteProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception -- float to byte");
- pass = false;
- }
- // invalid - float to short
- try {
- messageReceived.getShortProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception - float to short ");
- pass = false;
- }
- // invalid - float to int
- try {
- messageReceived.getIntProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to int ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil
- .logMsg("Error: did not catch expected Exception --- float to int");
- pass = false;
- }
-
- // invalid - float to long
- try {
- messageReceived.getLongProperty("TESTFLOAT");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: float to long ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- float to long");
- pass = false;
- }
-
- // -------------------------------------------------------------------
- // property set as double can be read only as double or string
-
- // valid - double to string
- if (Double.valueOf(messageReceived.getStringProperty("TESTDOUBLE"))
- .doubleValue() == nDouble) {
- TestUtil.logTrace("Pass: conversion from double to string - ok");
- } else {
- TestUtil.logMsg("Error: conversion from double to string failed");
- pass = false;
- }
-
- // invalid - double to boolean
- try {
- messageReceived.getBooleanProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to boolean ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- double to boolean ");
- pass = false;
- }
-
- // invalid - double to byte
- try {
- messageReceived.getByteProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to byte ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- double to byte ");
- pass = false;
- }
- // invalid - double to short
- try {
- messageReceived.getShortProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to short ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- double to short");
- pass = false;
- }
- // invalid - double to int
- try {
- messageReceived.getIntProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to int ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception --- double to int ");
- pass = false;
- }
-
- // invalid - double to long
- try {
- messageReceived.getLongProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to long ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- double to long");
- pass = false;
- }
-
- // invalid - double to float
- try {
- messageReceived.getFloatProperty("TESTDOUBLE");
- TestUtil.logMsg(
- "Error: MessageFormatException should have occurred for type conversion error");
- TestUtil.logMsg("unsupported conversion: double to float ");
- pass = false;
- } catch (MessageFormatException me) {
- TestUtil.logTrace("Pass: MessageFormatException as expected ");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logMsg(ee.getMessage());
- TestUtil.logMsg("Error: unexpected error " + ee.getClass().getName()
- + " was thrown");
- TestUtil.logMsg(
- "Error: did not catch expected Exception -- double to float");
- pass = false;
- }
- // -------------------------------------------------------------------
- // property set as string can be read as boolean, byte, short,
- // int, long, float, double, and String.
-
- // valid - string to boolean
- if ((messageReceived.getBooleanProperty("TESTSTRINGTRUE")) == true) {
- TestUtil.logTrace(
- "Pass: conversion from string to boolean - expect true - ok");
- } else {
- TestUtil.logMsg(
- "Error: conversion from string to boolean - expect true - failed");
- pass = false;
- }
-
- if ((messageReceived.getBooleanProperty("TESTSTRINGFALSE")) == false) {
- TestUtil.logTrace(
- "Pass: conversion from string to boolean expect false - ok");
- } else {
- TestUtil.logMsg(
- "Error: conversion from string to boolean expect false - failed");
- pass = false;
- }
-
- // valid - string to byte
- if (messageReceived.getByteProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to byte - ok");
- } else {
- TestUtil.logMsg("Error: conversion from string to byte failed");
- pass = false;
- }
- // valid - string to short
- if (messageReceived.getShortProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to short - ok");
- } else {
- TestUtil.logMsg("Error: conversion from string to short failed");
- pass = false;
- }
- // valid - string to int
- if (messageReceived.getIntProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to int - ok");
- } else {
- TestUtil.logMsg("Error: conversion from string to int failed");
- pass = false;
- }
- // valid - string to long
- if (messageReceived.getLongProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to long - ok");
- } else {
- TestUtil.logMsg("Error: conversion from string to long failed");
- pass = false;
- }
-
- // valid - string to float
- if (messageReceived.getFloatProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to float - ok");
- } else {
- TestUtil.logMsg("Error: conversion from string to float failed");
- pass = false;
- }
- // valid - string to double
- if (messageReceived.getDoubleProperty("TESTSTRING1") == 1) {
- TestUtil.logTrace("Pass: conversion from string to double - ok");
- } else {
- TestUtil.logMsg("Error: conversion from string to double failed");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: send test results to response queue (MDB_QUEUE_REPLY) for
- * verification
- */
- private void sendTestResults(String testCase, boolean results) {
- TextMessage msg = null;
-
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- msg.setStringProperty("TestCase", testCase);
- msg.setText(testCase);
- if (results)
- msg.setStringProperty("Status", "Pass");
- else
- msg.setStringProperty("Status", "Fail");
-
- TestUtil.logTrace("Sending response message");
- TestUtil.logTrace(
- "==================================Test Results from: " + testCase);
- TestUtil.logTrace("==================================Status: " + results);
- mSender.send(msg);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- TestUtil.logTrace("Error: " + je.getClass().getName() + " was thrown");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logTrace("Error: " + ee.getClass().getName() + " was thrown");
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgPropsT In MsgBeanMsgTestPropsT::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgPropsT In MsgBeanMsgTestPropsT::remove()!!");
- }
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ private MessageDrivenContext mdc = null;
+
+ // JMS
+ private QueueConnectionFactory qFactory = null;
+
+ private QueueConnection qConnection = null;
+
+ private Queue queueR = null;
+
+ private QueueSender mSender = null;
+
+ private QueueSession qSession = null;
+
+ private TopicConnectionFactory tFactory = null;
+
+ private TopicConnection tConnection = null;
+
+ private Topic topic = null;
+
+ private TopicPublisher tPublisher = null;
+
+ private TopicSession tSession = null;
+
+ private TextMessage messageSent = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanMsgTestPropsT.class.getName());
+
+ public MsgBeanMsgTestPropsT() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanMsgTestPropsT()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgPropsT - @MsgBeanMsgTestPropsT-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ if (qFactory == null) {
+ logger.log(Logger.Level.TRACE, "qFactory error");
+ }
+ logger.log(Logger.Level.TRACE, "got a qFactory !!");
+
+ queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ if (queueR == null) {
+ logger.log(Logger.Level.TRACE, "queueR error");
+ }
+
+ tFactory = (TopicConnectionFactory) context.lookup("java:comp/env/jms/MyTopicConnectionFactory");
+ if (tFactory == null) {
+ logger.log(Logger.Level.TRACE, "tFactory error");
+ }
+ logger.log(Logger.Level.TRACE, "got a tFactory !!");
+
+ topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC");
+ if (topic == null) {
+ logger.log(Logger.Level.TRACE, "topic error");
+ }
+
+ p = new Properties();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "from jms.ee.mdb.mdb_msgPropsT @onMessage!" + msg);
+
+ try {
+ logger.log(Logger.Level.TRACE, "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null) {
+ logger.log(Logger.Level.TRACE, "connection error");
+ } else {
+ qConnection.start();
+ qSession = qConnection.createQueueSession(true, 0);
+ }
+ tConnection = tFactory.createTopicConnection();
+ if (tConnection == null) {
+ logger.log(Logger.Level.TRACE, "connection error");
+ } else {
+ tConnection.start();
+ tSession = tConnection.createTopicSession(true, 0);
+ }
+
+ messageSent = tSession.createTextMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+
+ if (msg.getStringProperty("TestCase").equals("msgPropertiesTTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - running msgPropertiesTTestCreate - create the message");
+ msgPropertiesTTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgPropertiesTTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgPropertiesTTest!");
+ msgPropertiesTTest(msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgPropertiesConversionTTestCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgPropertiesConversionTTestCreate!");
+ msgPropertiesConversionTTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgPropertiesConversionTTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - msgPropertiesConversionTTest!");
+ msgPropertiesConversionTTest(msg);
+ }
+
+ else {
+ logger.log(Logger.Level.TRACE, "@onMessage - invalid message type found in StringProperty");
+ logger.log(Logger.Level.TRACE,
+ "Do not have a method for this testcase: " + msg.getStringProperty("TestCase"));
+ }
+
+ logger.log(Logger.Level.TRACE, "@onMessage - Finished for this test!");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ if (tConnection != null) {
+ try {
+ tConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+
+ }
+
+ /*
+ *
+ */
+
+ private void msgPropertiesTTestCreate() {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ Enumeration propertyNames = null;
+ Enumeration jmsxDefined = null;
+
+ String testMessageBody = "Testing...";
+ int NUMPROPS = 0;
+
+ JmsUtil.addPropsToMessage(messageSent, p);
+
+ try {
+
+ messageSent.setText(testMessageBody);
+ // ------------------------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ messageSent.setBooleanProperty("TESTBOOLEAN", bool);
+ messageSent.setByteProperty("TESTBYTE", bValue);
+ messageSent.setShortProperty("TESTSHORT", nShort);
+ messageSent.setIntProperty("TESTINT", nInt);
+ messageSent.setFloatProperty("TESTFLOAT", nFloat);
+ messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
+ messageSent.setStringProperty("TESTSTRING", "test");
+ messageSent.setLongProperty("TESTLONG", nLong);
+
+ // ------------------------------------------------------------------------------
+ // set properties for Boolean, Byte, Short, Int, Long, Float, Double, and
+ // String.
+ // ------------------------------------------------------------------------------
+
+ messageSent.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ messageSent.setObjectProperty("OBJTESTBYTE", Byte.valueOf(bValue));
+ messageSent.setObjectProperty("OBJTESTSHORT", Short.valueOf(nShort));
+ messageSent.setObjectProperty("OBJTESTINT", Integer.valueOf(nInt));
+ messageSent.setObjectProperty("OBJTESTFLOAT", new Float(nFloat));
+ messageSent.setObjectProperty("OBJTESTDOUBLE", new Double(nDouble));
+ messageSent.setObjectProperty("OBJTESTSTRING", "test");
+ messageSent.setObjectProperty("OBJTESTLONG", new Long(nLong));
+
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesTTest");
+ messageSent.setStringProperty("TestCase", "msgPropertiesTTest");
+
+ // count total properties in messageSent
+
+ Enumeration e = messageSent.getPropertyNames();
+ String key = null;
+ int i = 0;
+ while (e.hasMoreElements()) {
+ key = (String) e.nextElement();
+ logger.log(Logger.Level.TRACE, "+++++++ Property Name is: " + key);
+ if (key.indexOf("JMS") != 0)
+ i++;
+ }
+
+ // set Count for properties to pass + 1 for count itself
+ i++;
+ messageSent.setIntProperty("NUMPROPS", i);
+
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ // ------------------------------------------------------------------------------
+ // An attempt to use any other class than Boolean, Byte, Short, Int, Long,
+ // Float,
+ // Double, and Stringmust throw a JMS MessageFormatException.
+ // ------------------------------------------------------------------------------
+ try {
+ messageSent.setObjectProperty("OBJTESTLONG", new Object());
+ logger.log(Logger.Level.INFO, "Error: expected MessageFormatException from invalid ");
+ logger.log(Logger.Level.INFO, "call to setObjectProperty did not occur!");
+ pass = false;
+ } catch (MessageFormatException fe) {
+ logger.log(Logger.Level.TRACE, "Pass: ");
+ logger.log(Logger.Level.TRACE,
+ " MessageFormatException as expected from invalid setObjectProperty call");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "from call to setObjectProperty!");
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void msgPropertiesTTest(jakarta.jms.Message msg) {
+
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ Enumeration propertyNames = null;
+ Enumeration jmsxDefined = null;
+
+ String testCase = "msgPropertiesTTest";
+ String testMessageBody = "Testing...";
+ TextMessage messageReceived = (TextMessage) msg;
+ try {
+ // -------------------------------------------------------------------------
+ // Received message should be read-only - verify proper exception is
+ // thrown
+ // when trying to modify msg properties.
+ // ------------------------------------------------------------------------
+ try {
+ messageReceived.setBooleanProperty("TESTBOOLEAN", bool);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setBooleanProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setBooleanProperty ");
+ }
+
+ try {
+ messageReceived.setByteProperty("TESTBYTE", bValue);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setByteProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setByteProperty ");
+ }
+
+ try {
+ messageReceived.setShortProperty("TESTSHORT", nShort);
+ pass = false;
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setShortProperty");
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setShortProperty ");
+ }
+
+ try {
+ messageReceived.setIntProperty("TESTINT", nInt);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setIntProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setIntProperty ");
+ }
+
+ try {
+ messageReceived.setFloatProperty("TESTFLOAT", nFloat);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setFloatProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setFloatProperty ");
+ }
+
+ try {
+ messageReceived.setDoubleProperty("TESTDOUBLE", nDouble);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setDoubleProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setDoubleProperty ");
+ }
+
+ try {
+ messageReceived.setStringProperty("TESTSTRING", testString);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setStringProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setStringProperty ");
+ }
+
+ try {
+ messageReceived.setLongProperty("TESTLONG", nLong);
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setLongProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setLongProperty ");
+ }
+
+ try {
+ messageReceived.setObjectProperty("OBJTESTBOOLEAN", Boolean.valueOf(bool));
+ logger.log(Logger.Level.INFO, "Error: exception should have occurred for setObjectProperty");
+ pass = false;
+ } catch (MessageNotWriteableException aBool) {
+ logger.log(Logger.Level.TRACE, "Pass: exception as expected for setObjectProperty ");
+ }
+
+ int numPropertyNames = (int) messageReceived.getIntProperty("NUMPROPS");
+ // iterate thru the property names
+ int i = 0;
+ propertyNames = messageReceived.getPropertyNames();
+ do {
+ String tmp = (String) propertyNames.nextElement();
+ logger.log(Logger.Level.TRACE, "+++++++ Property Name is: " + tmp);
+ if (tmp.indexOf("JMS") != 0)
+ i++;
+ } while (propertyNames.hasMoreElements());
+
+ if (i == numPropertyNames) {
+ logger.log(Logger.Level.TRACE, "Pass: # of properties is " + numPropertyNames + " as expected");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: expected " + numPropertyNames + "property names");
+ logger.log(Logger.Level.INFO, " But " + i + " returned");
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------
+ // read and verify the property values for primitive types in the received
+ // message
+ // --------------------------------------------------------------------------------
+ if (messageReceived.getBooleanProperty("TESTBOOLEAN") == bool) {
+ logger.log(Logger.Level.TRACE, "Pass: getBooleanProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getBooleanProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getByteProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: getByteProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getByteProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getLongProperty("TESTLONG") == nLong) {
+ logger.log(Logger.Level.TRACE, "Pass: getLongProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getLongProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getStringProperty("TESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getStringProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getDoubleProperty("TESTDOUBLE") == nDouble) {
+ logger.log(Logger.Level.TRACE, "Pass: getDoubleProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getDoubleProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getFloatProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: getFloatProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getFloatProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getIntProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: getIntProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getIntProperty");
+ pass = false;
+ }
+
+ if (messageReceived.getShortProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: getShortProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from getShortProperty");
+ pass = false;
+ }
+ // --------------------------------------------------------------------------------
+ // The other property get methods ( other than getStringProperty and
+ // getObjectProperty) must throw a java.lang.NullPointerException if
+ // they are used to get a non-existent property.
+ // --------------------------------------------------------------------------------
+ boolean b = messageReceived.getBooleanProperty("TESTDUMMY");
+ if (b != false) {
+ logger.log(Logger.Level.TRACE, "Error: should havereceived false for getBooleanProperty");
+ pass = false;
+ }
+ // try {
+ // boolean value = messageReceived.getBooleanProperty("TESTDUMMY");
+ // logger.log(Logger.Level.INFO,"Error: NullPointerException should have
+ // occurred for
+ // getBooleanProperty");
+ // pass = false;
+ // } catch (java.lang.NullPointerException np) {
+ // logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ /*
+ * try { byte value = messageReceived.getByteProperty("TESTDUMMY"); TestUtil.
+ * logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getByteProperty"
+ * ); pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ *
+ * try { short value = messageReceived.getShortProperty("TESTDUMMY"); TestUtil.
+ * logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getShortProperty"
+ * ); pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ *
+ * try { int value = messageReceived.getIntProperty("TESTDUMMY"); TestUtil.
+ * logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getIntProperty" );
+ * pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ *
+ * try { long value = messageReceived.getLongProperty("TESTDUMMY"); TestUtil.
+ * logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getLongProperty"
+ * ); pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ *
+ * try { float value = messageReceived.getFloatProperty("TESTDUMMY"); TestUtil.
+ * logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getFloatProperty"
+ * ); pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ *
+ * try { double value = messageReceived.getDoubleProperty("TESTDUMMY");
+ * TestUtil. logger.log(Logger.Level.
+ * INFO,"Error: NullPointerException should have occurred for getDoubleProperty"
+ * ); pass = false; } catch (java.lang.NullPointerException np) {
+ * logger.log(Logger.Level.TRACE,"Pass: NullPointerException as expected ");}
+ *
+ */
+ // --------------------------------------------------------------------------------
+ // Getting a property value for a name which has not been set returns a
+ // null value.
+ // (For getStringProperty and getObjectProperty)
+ // --------------------------------------------------------------------------------
+ String value = messageReceived.getStringProperty("TESTDUMMY");
+ if (value == null) {
+ logger.log(Logger.Level.TRACE, "Pass: getStringProperty returned correct value");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: expected a null return from getStringProperty for invalid property");
+ pass = false;
+ }
+
+ Boolean aBool = (Boolean) messageReceived.getObjectProperty("TESTDUMMY");
+ if (aBool == null) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Boolean");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: expected a null return from getObjectProperty for invalid property");
+ pass = false;
+ }
+
+ // --------------------------------------------------------------------------------
+ // read and verify the property values for getObject in the received
+ // message
+ // --------------------------------------------------------------------------------
+
+ Boolean boolValue = (Boolean) messageReceived.getObjectProperty("OBJTESTBOOLEAN");
+ if (boolValue.booleanValue() == bool) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Boolean");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned for Boolean");
+ pass = false;
+ }
+
+ Byte byteValue = (Byte) messageReceived.getObjectProperty("OBJTESTBYTE");
+ if (byteValue.byteValue() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct Byte value");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: incorrect value returned from Byte");
+ pass = false;
+ }
+
+ Long lValue = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
+ if (lValue.longValue() == nLong) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Long");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value returned for Long");
+ pass = false;
+ }
+
+ // String value =
+ // (String)messageReceived.getObjectProperty("OBJTESTSTRING");
+ if (messageReceived.getObjectProperty("OBJTESTSTRING").equals(testString)) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for String");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for String");
+ pass = false;
+ }
+
+ Double dValue = (Double) messageReceived.getObjectProperty("OBJTESTDOUBLE");
+ if (dValue.doubleValue() == nDouble) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Double");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Double");
+ pass = false;
+ }
+
+ Float fValue = (Float) messageReceived.getObjectProperty("OBJTESTFLOAT");
+ if (fValue.floatValue() == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Float");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Float");
+ pass = false;
+ }
+
+ Integer iValue = (Integer) messageReceived.getObjectProperty("OBJTESTINT");
+ if (iValue.intValue() == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Integer");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Integer");
+ pass = false;
+ }
+
+ Short sValue = (Short) messageReceived.getObjectProperty("OBJTESTSHORT");
+ if (sValue.shortValue() == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: getObjectProperty returned correct value for Short");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: getObjectProperty returned incorrect value for Short");
+ pass = false;
+ }
+
+ // clear message properties
+ messageReceived.clearProperties();
+
+ // -------------------------------------------------------------------
+ // A message?s properties are deleted by the clearProperties method.
+ // This leaves the message with an empty set of properties.
+ // -------------------------------------------------------------------
+
+ Long aLong = (Long) messageReceived.getObjectProperty("OBJTESTLONG");
+ if (aLong == null) {
+ logger.log(Logger.Level.TRACE, "Pass: property was cleared");
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Error: getObjectProperty should have returned null for cleared property");
+ pass = false;
+ }
+
+ try {
+ short aShort = messageReceived.getShortProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO, "Error: NullPointerException should have occurred for getShortProperty");
+ logger.log(Logger.Level.INFO, "Properties have been cleared!");
+ pass = false;
+ } catch (java.lang.NullPointerException np) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException as expected ");
+ } catch (java.lang.NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException as expected ");
+ }
+
+ // -------------------------------------------------------------------
+ // A message's properties are deleted by the clearProperties method.
+ // This leaves the message with an empty set of properties.
+ // New property entries can then be both created and read.
+ // -------------------------------------------------------------------
+ try {
+ String newEntry = "new entry";
+ logger.log(Logger.Level.TRACE, "Verify that you can set a property after clearProperty");
+ messageReceived.setStringProperty("TESTSTRING", "new entry");
+ if (messageReceived.getStringProperty("TESTSTRING").equals(newEntry)) {
+ logger.log(Logger.Level.TRACE, "Pass: able to set a cleared property");
+ } else {
+ logger.log(Logger.Level.TRACE, "Error: was not able to new property setting after clearProperty");
+ pass = false;
+ }
+ } catch (Exception exp) {
+ logger.log(Logger.Level.TRACE, "Unexpected Exception caught while testing set after clearProperty");
+ pass = false;
+ TestUtil.printStackTrace(exp);
+ }
+
+ // -------------------------------------------------------------------
+ // clearing the message property should not effect the message body.
+ // -------------------------------------------------------------------
+ logger.log(Logger.Level.INFO, "Message body is : " + messageReceived.getText());
+ if (messageReceived.getText().equals(testMessageBody)) {
+ logger.log(Logger.Level.TRACE, "Pass: able to read message body after clearProperties");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: unable to read message body after clearProperties");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // ConnectionMetaData.getJMSXPropertyNames() method returns the
+ // names of the JMSX properties supported by a connection.
+ // -------------------------------------------------------------------
+ try {
+ ConnectionMetaData data = qConnection.getMetaData();
+ Enumeration cmd = data.getJMSXPropertyNames();
+ String propName;
+ if (cmd == null) {
+ logger.log(Logger.Level.INFO, "Error: no JMSX property names were returned!");
+ logger.log(Logger.Level.INFO, "expected JMSXGroupID and JMSXGroupSeq at a miniumum");
+ pass = false;
+ } else {
+ int iCount = 0;
+ while (cmd.hasMoreElements()) {
+ propName = (String) cmd.nextElement();
+ logger.log(Logger.Level.TRACE, propName);
+ if (propName.equals("JMSXGroupID") || propName.equals("JMSXGroupSeq")) {
+ iCount++;
+ }
+ }
+ if (iCount == 2) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: Expected property names not returned");
+ pass = false;
+ }
+ }
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, "attempting to read JMSX property names.");
+ logger.log(Logger.Level.INFO,
+ "Error: unexpected exception: " + ee.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ } catch (Exception ex) {
+ TestUtil.printStackTrace(ex);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ private void msgPropertiesConversionTTestCreate() {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ String testMessageBody = "Testing...";
+ int ntest = 0;
+ try {
+ messageSent.setText(testMessageBody);
+ // ------------------------------------------------------------------------------
+ // set properties for boolean, byte, short, int, long, float, double, and
+ // String.
+ // ------------------------------------------------------------------------------
+ messageSent.setBooleanProperty("TESTBOOLEAN", bool);
+ messageSent.setByteProperty("TESTBYTE", bValue);
+ messageSent.setShortProperty("TESTSHORT", nShort);
+ messageSent.setIntProperty("TESTINT", nInt);
+ messageSent.setFloatProperty("TESTFLOAT", nFloat);
+ messageSent.setDoubleProperty("TESTDOUBLE", nDouble);
+ messageSent.setStringProperty("TESTSTRING", "test");
+ messageSent.setLongProperty("TESTLONG", nLong);
+ messageSent.setStringProperty("TESTSTRINGTRUE", "true");
+ messageSent.setStringProperty("TESTSTRINGFALSE", "false");
+ messageSent.setStringProperty("TESTSTRING1", "1");
+
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "msgPropertiesConversionTTest");
+ messageSent.setStringProperty("TestCase", "msgPropertiesConversionTTest");
+ logger.log(Logger.Level.TRACE, "Sending message");
+
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void msgPropertiesConversionTTest(jakarta.jms.Message messageReceived) {
+ boolean pass = true;
+ boolean bool = true;
+ byte bValue = 127;
+ short nShort = 10;
+ int nInt = 5;
+ long nLong = 333;
+ float nFloat = 1;
+ double nDouble = 100;
+ String testString = "test";
+ String testMessageBody = "Testing...";
+ int ntest = 0;
+ String testCase = "msgPropertiesConversionTTest";
+ try {
+
+ // -------------------------------------------------------------------
+ // test conversions for property values
+ // -------------------------------------------------------------------
+
+ // property set as boolean can be read only as string or boolean
+ // -------------------------------------------------------------------
+ // valid - boolean to string
+
+ String myBool = messageReceived.getStringProperty("TESTBOOLEAN");
+ if (Boolean.valueOf(myBool).booleanValue() == bool) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from boolean to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from boolean to string failed");
+ pass = false;
+ }
+
+ // invalid - boolean to byte
+ try {
+ messageReceived.getByteProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ // logger.log(Logger.Level.INFO,"Error: unexpected error " +
+ // ee.getClass().getName()
+ // + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to byte");
+ pass = false;
+ }
+
+ // invalid - boolean to short
+ try {
+ messageReceived.getShortProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to short");
+ pass = false;
+ }
+
+ // invalid - boolean to int
+ try {
+ messageReceived.getIntProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception --boolean to int ");
+ pass = false;
+ }
+ // invalid - boolean to long
+ try {
+ messageReceived.getLongProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to long ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to long");
+ pass = false;
+ }
+
+ // invalid - boolean to float
+ try {
+ messageReceived.getFloatProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to float");
+ pass = false;
+ }
+
+ // invalid - boolean to double
+ try {
+ messageReceived.getDoubleProperty("TESTBOOLEAN");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: boolean to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- boolean to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as byte can be read as a byte,short,int,long or string
+
+ // valid - byte to string
+ String myByte = messageReceived.getStringProperty("TESTBYTE");
+ if (Byte.valueOf(myByte).byteValue() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from byte to string failed");
+ pass = false;
+ }
+ // valid - byte to short
+ if (messageReceived.getShortProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to short - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from byte to short failed");
+ pass = false;
+ }
+ // valid - byte to int
+ if (messageReceived.getIntProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from byte to int failed");
+ pass = false;
+ }
+ // valid - byte to long
+
+ if (messageReceived.getLongProperty("TESTBYTE") == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from byte to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from byte to long failed");
+ pass = false;
+ }
+ // invalid - byte to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: byte to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- byte to boolean");
+ pass = false;
+ }
+
+ // invalid - byte to float
+ try {
+ messageReceived.getFloatProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: byte to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception --byte to float ");
+ pass = false;
+ }
+
+ // invalid - byte to double
+ try {
+ messageReceived.getDoubleProperty("TESTBYTE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: byte to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- byte to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------
+ // property set as short can be read as short,int,long or string
+
+ // valid - short to string
+ String myshort = messageReceived.getStringProperty("TESTSHORT");
+ if (Short.valueOf(myshort).shortValue() == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from short to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from short to string failed");
+ pass = false;
+ }
+
+ // valid - short to int
+ if (messageReceived.getIntProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from short to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from short to int failed");
+ pass = false;
+ }
+ // valid - short to long
+ if (messageReceived.getLongProperty("TESTSHORT") == nShort) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from short to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from short to long failed");
+ pass = false;
+ }
+
+ // invalid - short to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- short to boolean");
+ pass = false;
+ }
+
+ // invalid - short to byte
+ try {
+ messageReceived.getByteProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- short to byte");
+ pass = false;
+ }
+
+ // invalid - short to float
+ try {
+ messageReceived.getFloatProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- short to float");
+ pass = false;
+ }
+
+ // invalid - short to double
+ try {
+ messageReceived.getDoubleProperty("TESTSHORT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: short to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- short to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------
+ // property set as int can be read only as int, long or string
+
+ // valid - int to string
+ if (Integer.valueOf(messageReceived.getStringProperty("TESTINT")).intValue() == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from int to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from int to string failed");
+ pass = false;
+ }
+
+ // valid - int to long
+ if (messageReceived.getLongProperty("TESTINT") == nInt) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from int to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from int to long failed");
+ pass = false;
+ }
+
+ // invalid - int to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- int to boolean");
+ pass = false;
+ }
+
+ // invalid - int to byte
+ try {
+ messageReceived.getByteProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- int to byte");
+ pass = false;
+ }
+
+ // invalid - int to short
+ try {
+ messageReceived.getShortProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected -- int to short ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception ");
+ pass = false;
+ }
+
+ // invalid - int to float
+ try {
+ messageReceived.getFloatProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- int to float");
+ pass = false;
+ }
+
+ // invalid - int to double
+ try {
+ messageReceived.getDoubleProperty("TESTINT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: int to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- int to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as long can be read only as long,or a string
+
+ // valid - long to string
+ if (Long.valueOf(messageReceived.getStringProperty("TESTLONG")).longValue() == nLong) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from long to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from long to string failed");
+ pass = false;
+ }
+
+ // invalid - long to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to boolean");
+ pass = false;
+ }
+
+ // invalid - long to byte
+ try {
+ messageReceived.getByteProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to byte");
+ pass = false;
+ }
+ // invalid - long to short
+ try {
+ messageReceived.getShortProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to short ");
+ pass = false;
+ }
+ // invalid - long to int
+ try {
+ messageReceived.getIntProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to int");
+ pass = false;
+ }
+
+ // invalid - long to float
+ try {
+ messageReceived.getFloatProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to float");
+ pass = false;
+ }
+
+ // invalid - long to double
+ try {
+ messageReceived.getDoubleProperty("TESTLONG");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: long to double ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- long to double");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as float can be read only as float,double or a string
+
+ // valid - float to string
+ if (Float.valueOf(messageReceived.getStringProperty("TESTFLOAT")).floatValue() == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from float to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from float to string failed");
+ pass = false;
+ }
+ // valid - float to double
+ if (messageReceived.getDoubleProperty("TESTFLOAT") == nFloat) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from long to double - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from long to double failed");
+ pass = false;
+ }
+
+ // invalid - float to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- float to boolean ");
+ pass = false;
+ }
+
+ // invalid - float to byte
+ try {
+ messageReceived.getByteProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- float to byte");
+ pass = false;
+ }
+ // invalid - float to short
+ try {
+ messageReceived.getShortProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception - float to short ");
+ pass = false;
+ }
+ // invalid - float to int
+ try {
+ messageReceived.getIntProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception --- float to int");
+ pass = false;
+ }
+
+ // invalid - float to long
+ try {
+ messageReceived.getLongProperty("TESTFLOAT");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: float to long ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- float to long");
+ pass = false;
+ }
+
+ // -------------------------------------------------------------------
+ // property set as double can be read only as double or string
+
+ // valid - double to string
+ if (Double.valueOf(messageReceived.getStringProperty("TESTDOUBLE")).doubleValue() == nDouble) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from double to string - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from double to string failed");
+ pass = false;
+ }
+
+ // invalid - double to boolean
+ try {
+ messageReceived.getBooleanProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to boolean ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to boolean ");
+ pass = false;
+ }
+
+ // invalid - double to byte
+ try {
+ messageReceived.getByteProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to byte ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to byte ");
+ pass = false;
+ }
+ // invalid - double to short
+ try {
+ messageReceived.getShortProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to short ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to short");
+ pass = false;
+ }
+ // invalid - double to int
+ try {
+ messageReceived.getIntProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to int ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception --- double to int ");
+ pass = false;
+ }
+
+ // invalid - double to long
+ try {
+ messageReceived.getLongProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to long ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to long");
+ pass = false;
+ }
+
+ // invalid - double to float
+ try {
+ messageReceived.getFloatProperty("TESTDOUBLE");
+ logger.log(Logger.Level.INFO,
+ "Error: MessageFormatException should have occurred for type conversion error");
+ logger.log(Logger.Level.INFO, "unsupported conversion: double to float ");
+ pass = false;
+ } catch (MessageFormatException me) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException as expected ");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.INFO, ee.getMessage());
+ logger.log(Logger.Level.INFO, "Error: unexpected error " + ee.getClass().getName() + " was thrown");
+ logger.log(Logger.Level.INFO, "Error: did not catch expected Exception -- double to float");
+ pass = false;
+ }
+ // -------------------------------------------------------------------
+ // property set as string can be read as boolean, byte, short,
+ // int, long, float, double, and String.
+
+ // valid - string to boolean
+ if ((messageReceived.getBooleanProperty("TESTSTRINGTRUE")) == true) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to boolean - expect true - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to boolean - expect true - failed");
+ pass = false;
+ }
+
+ if ((messageReceived.getBooleanProperty("TESTSTRINGFALSE")) == false) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to boolean expect false - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to boolean expect false - failed");
+ pass = false;
+ }
+
+ // valid - string to byte
+ if (messageReceived.getByteProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to byte - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to byte failed");
+ pass = false;
+ }
+ // valid - string to short
+ if (messageReceived.getShortProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to short - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to short failed");
+ pass = false;
+ }
+ // valid - string to int
+ if (messageReceived.getIntProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to int - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to int failed");
+ pass = false;
+ }
+ // valid - string to long
+ if (messageReceived.getLongProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to long - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to long failed");
+ pass = false;
+ }
+
+ // valid - string to float
+ if (messageReceived.getFloatProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to float - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to float failed");
+ pass = false;
+ }
+ // valid - string to double
+ if (messageReceived.getDoubleProperty("TESTSTRING1") == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: conversion from string to double - ok");
+ } else {
+ logger.log(Logger.Level.INFO, "Error: conversion from string to double failed");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: send test results to response queue (MDB_QUEUE_REPLY) for
+ * verification
+ */
+ private void sendTestResults(String testCase, boolean results) {
+ TextMessage msg = null;
+
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ msg.setStringProperty("TestCase", testCase);
+ msg.setText(testCase);
+ if (results)
+ msg.setStringProperty("Status", "Pass");
+ else
+ msg.setStringProperty("Status", "Fail");
+
+ logger.log(Logger.Level.TRACE, "Sending response message");
+ logger.log(Logger.Level.TRACE, "==================================Test Results from: " + testCase);
+ logger.log(Logger.Level.TRACE, "==================================Status: " + results);
+ mSender.send(msg);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ logger.log(Logger.Level.TRACE, "Error: " + je.getClass().getName() + " was thrown");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.TRACE, "Error: " + ee.getClass().getName() + " was thrown");
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE,
+ "jms.ee.mdb.mdb_msgPropsT In MsgBeanMsgTestPropsT::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgPropsT In MsgBeanMsgTestPropsT::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ1/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ1/MDBClient.java
deleted file mode 100644
index d0443a1101..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ1/MDBClient.java
+++ /dev/null
@@ -1,548 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesQ1;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.MDB_Q_Test;
-
-import jakarta.ejb.EJB;
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_MSGQ1_Test")
- private static MDB_Q_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
- //
- /*
- * @testName: mdbBytesMsgNullStreamQTest
- *
- * @assertion_ids: JMS:SPEC:86.1; JMS:JAVADOC:714;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a byte message. Use writeObject to write a null. verify a
- * java.lang.NullPointerException is thrown.
- *
- *
- */
- public void mdbBytesMsgNullStreamQTest() throws Exception {
- String testCase = "bytesMsgNullStreamQTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run bytesMsgNullStreamQTest");
- hr.askMDBToRunATest(testCase);
- if (!hr.checkOnResponse(testCase)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbBytesMsgNullStreamQTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbBytesMessageQTestsFullMsg
- *
- * @assertion_ids: JMS:JAVADOC:560; JMS:JAVADOC:562; JMS:JAVADOC:564;
- * JMS:JAVADOC:566; JMS:JAVADOC:568; JMS:JAVADOC:570; JMS:JAVADOC:572;
- * JMS:JAVADOC:574; JMS:JAVADOC:576; JMS:JAVADOC:578; JMS:JAVADOC:580;
- * JMS:JAVADOC:582; JMS:JAVADOC:534; JMS:JAVADOC:536; JMS:JAVADOC:540;
- * JMS:JAVADOC:544; JMS:JAVADOC:546; JMS:JAVADOC:548; JMS:JAVADOC:550;
- * JMS:JAVADOC:552; JMS:JAVADOC:554; JMS:JAVADOC:556; JMS:JAVADOC:558;
- * JMS:JAVADOC:538; JMS:JAVADOC:542; JMS:JAVADOC:532;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a BytesMessage -. write to the message using each type of method and
- * as an object. Send the message. Verify the data received was as sent.
- *
- */
-
- public void mdbBytesMessageQTestsFullMsg() throws Exception {
- String testCase1 = "bytesMessageQTestsFullMsgCreate";
- String testCase2 = "bytesMessageQTestsFullMsg";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase bytesMessageQTestsFullMsgCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- // System.out.println("client - run testcase2 bytesMessageQTestsFullMsg")
- // hr.askMDBToRunATest(testCase2) ; // read and verify message sent
- System.out.println(
- "client - Check for response from bytesMessageQTestsFullMsg");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: bytesMessageQTestsFullMsg failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageFullMsgQTest
- *
- * @assertion_ids: JMS:SPEC:74; JMS:JAVADOC:211; JMS:JAVADOC:457;
- * JMS:JAVADOC:459; JMS:JAVADOC:475; JMS:JAVADOC:477; JMS:JAVADOC:479;
- * JMS:JAVADOC:461; JMS:JAVADOC:463; JMS:JAVADOC:465; JMS:JAVADOC:467;
- * JMS:JAVADOC:469; JMS:JAVADOC:471; JMS:JAVADOC:473; JMS:JAVADOC:433;
- * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:439; JMS:JAVADOC:441;
- * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
- * JMS:JAVADOC:451; JMS:JAVADOC:453;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. write to the message using each type of method and
- * as an object. Send the message. Verify the data received was as sent.
- *
- */
- public void mdbMapMessageFullMsgQTest() throws Exception {
- String testCase1 = "mapMessageFullMsgQTestCreate";
- String testCase2 = "mapMessageFullMsgQTest";
- try {
- // Have the EJB invoke the MDB
- System.out.println("client - run testcase mapMessageFullMsgQTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out
- .println("client - Check for response from mapMessageFullMsgQTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageFullMsgQTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionQTestsBoolean
- *
- * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:457;
- * JMS:JAVADOC:433; JMS:JAVADOC:449; JMS:JAVADOC:796; JMS:JAVADOC:797;
- * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeBoolean to write a
- * boolean to the message. Verify the proper conversion support as in 3.11.3
- */
-
- public void mdbMapMessageConversionQTestsBoolean() throws Exception {
- String testCase1 = "mapMessageConversionQTestsBooleanCreate";
- String testCase2 = "mapMessageConversionQTestsBoolean";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionQTestsBooleanCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from mapMessageConversionQTestsBoolean");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionQTestsBoolean failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionQTestsByte
- *
- * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:459;
- * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443;
- * JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:798; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method setByte to write a byte.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionQTestsByte() throws Exception {
- String testCase1 = "mapMessageConversionQTestsByteCreate";
- String testCase2 = "mapMessageConversionQTestsByte";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionQTestsByteCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from mapMessageConversionQTestsByte");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionQTestsByte failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionQTestsShort
- *
- * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:461;
- * JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449;
- * JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:798; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeShort to write a short.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionQTestsShort() throws Exception {
- String testCase1 = "mapMessageConversionQTestsShortCreate";
- String testCase2 = "mapMessageConversionQTestsShort";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionQTestsShortCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from mapMessageConversionQTestsShort");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionQTestsShort failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionQTestsChar
- *
- * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:463;
- * JMS:JAVADOC:439; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeChar to write a Char.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionQTestsChar() throws Exception {
- String testCase1 = "mapMessageConversionQTestsCharCreate";
- String testCase2 = "mapMessageConversionQTestsChar";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionQTestsCharCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from mapMessageConversionQTestsChar");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionQTestsChar failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionQTestsInt
- *
- * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:465;
- * JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795;
- * JMS:JAVADOC:796; JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeInt to write a int.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionQTestsInt() throws Exception {
- String testCase1 = "mapMessageConversionQTestsIntCreate";
- String testCase2 = "mapMessageConversionQTestsInt";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase mapMessageConversionQTestsIntCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from mapMessageConversionQTestsInt");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionQTestsInt failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionQTestsLong
- *
- * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:467;
- * JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeLong to write a long.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionQTestsLong() throws Exception {
- String testCase1 = "mapMessageConversionQTestsLongCreate";
- String testCase2 = "mapMessageConversionQTestsLong";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionQTestsLongCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from mapMessageConversionQTestsLong");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionQTestsLong failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionQTestsFloat
- *
- * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:469;
- * JMS:JAVADOC:445; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeFloat to write a float.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionQTestsFloat() throws Exception {
- String testCase1 = "mapMessageConversionQTestsFloatCreate";
- String testCase2 = "mapMessageConversionQTestsFloat";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionQTestsFloatCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from mapMessageConversionQTestsFloat");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionQTestsFloat failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionQTestsDouble
- *
- * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:471;
- * JMS:JAVADOC:447; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
- * JMS:JAVADOC:801; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeDouble to write a double.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionQTestsDouble() throws Exception {
- String testCase1 = "mapMessageConversionQTestsDoubleCreate";
- String testCase2 = "mapMessageConversionQTestsDouble";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionQTestsDoubleCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from mapMessageConversionQTestsDouble");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionQTestsDouble failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionQTestsString
- *
- * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:JAVADOC:473;
- * JMS:JAVADOC:433; JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441;
- * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
- * JMS:JAVADOC:798; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeString to write a String.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionQTestsString() throws Exception {
- String testCase1 = "mapMessageConversionQTestsStringCreate";
- String testCase2 = "mapMessageConversionQTestsString";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionQTestsStringCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from mapMessageConversionQTestsString");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionQTestsString failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionQTestsBytes
- *
- * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:475;
- * JMS:JAVADOC:451; JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:797;
- * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:803;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeBytes to write a Bytes.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionQTestsBytes() throws Exception {
- String testCase1 = "mapMessageConversionQTestsBytesCreate";
- String testCase2 = "mapMessageConversionQTestsBytes";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionQTestsBytesCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from mapMessageConversionQTestsBytes");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionQTestsBytes failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionQTestsInvFormatString
- *
- * @assertion_ids: JMS:SPEC:76;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method setString to write a text
- * string of "mytest string". Verify NumberFormatException is thrown
- *
- */
- public void mdbMapMessageConversionQTestsInvFormatString() throws Exception {
- String testCase1 = "mapMessageConversionQTestsInvFormatStringCreate";
- String testCase2 = "mapMessageConversionQTestsInvFormatString";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionQTestsInvFormatStringCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from mapMessageConversionQTestsInvFormatString");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: mapMessageConversionQTestsInvFormatString failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- ;
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ1/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ1/MDBClientIT.java
new file mode 100644
index 0000000000..64aedc1f67
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ1/MDBClientIT.java
@@ -0,0 +1,538 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesQ1;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.commonee.MDB_Q_Test;
+
+import jakarta.ejb.EJB;
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_MSGQ1_Test")
+ private static MDB_Q_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ hr.setup(props);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+ //
+ /*
+ * @testName: mdbBytesMsgNullStreamQTest
+ *
+ * @assertion_ids: JMS:SPEC:86.1; JMS:JAVADOC:714;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a byte message. Use writeObject to write a null. verify a
+ * java.lang.NullPointerException is thrown.
+ *
+ *
+ */
+ @Test
+ public void mdbBytesMsgNullStreamQTest() throws Exception {
+ String testCase = "bytesMsgNullStreamQTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run bytesMsgNullStreamQTest");
+ hr.askMDBToRunATest(testCase);
+ if (!hr.checkOnResponse(testCase)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbBytesMsgNullStreamQTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbBytesMessageQTestsFullMsg
+ *
+ * @assertion_ids: JMS:JAVADOC:560; JMS:JAVADOC:562; JMS:JAVADOC:564;
+ * JMS:JAVADOC:566; JMS:JAVADOC:568; JMS:JAVADOC:570; JMS:JAVADOC:572;
+ * JMS:JAVADOC:574; JMS:JAVADOC:576; JMS:JAVADOC:578; JMS:JAVADOC:580;
+ * JMS:JAVADOC:582; JMS:JAVADOC:534; JMS:JAVADOC:536; JMS:JAVADOC:540;
+ * JMS:JAVADOC:544; JMS:JAVADOC:546; JMS:JAVADOC:548; JMS:JAVADOC:550;
+ * JMS:JAVADOC:552; JMS:JAVADOC:554; JMS:JAVADOC:556; JMS:JAVADOC:558;
+ * JMS:JAVADOC:538; JMS:JAVADOC:542; JMS:JAVADOC:532;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a BytesMessage -. write to the message using each type of method and
+ * as an object. Send the message. Verify the data received was as sent.
+ *
+ */
+ @Test
+ public void mdbBytesMessageQTestsFullMsg() throws Exception {
+ String testCase1 = "bytesMessageQTestsFullMsgCreate";
+ String testCase2 = "bytesMessageQTestsFullMsg";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase bytesMessageQTestsFullMsgCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ // System.out.println("client - run testcase2 bytesMessageQTestsFullMsg")
+ // hr.askMDBToRunATest(testCase2) ; // read and verify message sent
+ System.out.println("client - Check for response from bytesMessageQTestsFullMsg");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: bytesMessageQTestsFullMsg failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageFullMsgQTest
+ *
+ * @assertion_ids: JMS:SPEC:74; JMS:JAVADOC:211; JMS:JAVADOC:457;
+ * JMS:JAVADOC:459; JMS:JAVADOC:475; JMS:JAVADOC:477; JMS:JAVADOC:479;
+ * JMS:JAVADOC:461; JMS:JAVADOC:463; JMS:JAVADOC:465; JMS:JAVADOC:467;
+ * JMS:JAVADOC:469; JMS:JAVADOC:471; JMS:JAVADOC:473; JMS:JAVADOC:433;
+ * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:439; JMS:JAVADOC:441;
+ * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
+ * JMS:JAVADOC:451; JMS:JAVADOC:453;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. write to the message using each type of method and as
+ * an object. Send the message. Verify the data received was as sent.
+ *
+ */
+ @Test
+ public void mdbMapMessageFullMsgQTest() throws Exception {
+ String testCase1 = "mapMessageFullMsgQTestCreate";
+ String testCase2 = "mapMessageFullMsgQTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageFullMsgQTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from mapMessageFullMsgQTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageFullMsgQTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionQTestsBoolean
+ *
+ * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:457;
+ * JMS:JAVADOC:433; JMS:JAVADOC:449; JMS:JAVADOC:796; JMS:JAVADOC:797;
+ * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeBoolean to write a boolean
+ * to the message. Verify the proper conversion support as in 3.11.3
+ */
+ @Test
+ public void mdbMapMessageConversionQTestsBoolean() throws Exception {
+ String testCase1 = "mapMessageConversionQTestsBooleanCreate";
+ String testCase2 = "mapMessageConversionQTestsBoolean";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionQTestsBooleanCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from mapMessageConversionQTestsBoolean");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionQTestsBoolean failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionQTestsByte
+ *
+ * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:459;
+ * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443;
+ * JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:798; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method setByte to write a byte. Verify
+ * the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionQTestsByte() throws Exception {
+ String testCase1 = "mapMessageConversionQTestsByteCreate";
+ String testCase2 = "mapMessageConversionQTestsByte";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionQTestsByteCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from mapMessageConversionQTestsByte");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionQTestsByte failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionQTestsShort
+ *
+ * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:461;
+ * JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449;
+ * JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:798; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeShort to write a short.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionQTestsShort() throws Exception {
+ String testCase1 = "mapMessageConversionQTestsShortCreate";
+ String testCase2 = "mapMessageConversionQTestsShort";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionQTestsShortCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from mapMessageConversionQTestsShort");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionQTestsShort failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionQTestsChar
+ *
+ * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:463;
+ * JMS:JAVADOC:439; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeChar to write a Char.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionQTestsChar() throws Exception {
+ String testCase1 = "mapMessageConversionQTestsCharCreate";
+ String testCase2 = "mapMessageConversionQTestsChar";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionQTestsCharCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from mapMessageConversionQTestsChar");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionQTestsChar failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionQTestsInt
+ *
+ * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:465;
+ * JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795;
+ * JMS:JAVADOC:796; JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeInt to write a int. Verify
+ * the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionQTestsInt() throws Exception {
+ String testCase1 = "mapMessageConversionQTestsIntCreate";
+ String testCase2 = "mapMessageConversionQTestsInt";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionQTestsIntCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from mapMessageConversionQTestsInt");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionQTestsInt failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionQTestsLong
+ *
+ * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:467;
+ * JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeLong to write a long.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionQTestsLong() throws Exception {
+ String testCase1 = "mapMessageConversionQTestsLongCreate";
+ String testCase2 = "mapMessageConversionQTestsLong";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionQTestsLongCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from mapMessageConversionQTestsLong");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionQTestsLong failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionQTestsFloat
+ *
+ * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:469;
+ * JMS:JAVADOC:445; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeFloat to write a float.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionQTestsFloat() throws Exception {
+ String testCase1 = "mapMessageConversionQTestsFloatCreate";
+ String testCase2 = "mapMessageConversionQTestsFloat";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionQTestsFloatCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from mapMessageConversionQTestsFloat");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionQTestsFloat failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionQTestsDouble
+ *
+ * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:471;
+ * JMS:JAVADOC:447; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
+ * JMS:JAVADOC:801; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeDouble to write a double.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionQTestsDouble() throws Exception {
+ String testCase1 = "mapMessageConversionQTestsDoubleCreate";
+ String testCase2 = "mapMessageConversionQTestsDouble";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionQTestsDoubleCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from mapMessageConversionQTestsDouble");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionQTestsDouble failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionQTestsString
+ *
+ * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:JAVADOC:473;
+ * JMS:JAVADOC:433; JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441;
+ * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
+ * JMS:JAVADOC:798; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeString to write a String.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionQTestsString() throws Exception {
+ String testCase1 = "mapMessageConversionQTestsStringCreate";
+ String testCase2 = "mapMessageConversionQTestsString";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionQTestsStringCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from mapMessageConversionQTestsString");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionQTestsString failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionQTestsBytes
+ *
+ * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:475;
+ * JMS:JAVADOC:451; JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:797;
+ * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:803;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeBytes to write a Bytes.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionQTestsBytes() throws Exception {
+ String testCase1 = "mapMessageConversionQTestsBytesCreate";
+ String testCase2 = "mapMessageConversionQTestsBytes";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionQTestsBytesCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from mapMessageConversionQTestsBytes");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionQTestsBytes failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionQTestsInvFormatString
+ *
+ * @assertion_ids: JMS:SPEC:76;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method setString to write a text string
+ * of "mytest string". Verify NumberFormatException is thrown
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionQTestsInvFormatString() throws Exception {
+ String testCase1 = "mapMessageConversionQTestsInvFormatStringCreate";
+ String testCase2 = "mapMessageConversionQTestsInvFormatString";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionQTestsInvFormatStringCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from mapMessageConversionQTestsInvFormatString");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionQTestsInvFormatString failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ ;
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ1/MsgBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ1/MsgBean.java
index 90cd74b705..1cb689cf9b 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ1/MsgBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ1/MsgBean.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesQ1;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.TSNamingContext;
@@ -44,3414 +45,3174 @@
public class MsgBean implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- private MessageDrivenContext mdc = null;
-
- // JMS
- private QueueConnectionFactory qFactory = null;
-
- private QueueConnection qConnection = null;
-
- private Queue queueR = null;
-
- private Queue queue = null;
-
- private QueueSender mSender = null;
-
- private QueueSession qSession = null;
-
- public MsgBean() {
- TestUtil.logTrace("@MsgBean()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace("jms.ee.mdb.mdb_msgTypesQ1 - @MsgBean-ejbCreate() !!");
- try {
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- if (qFactory == null) {
- TestUtil.logTrace("qFactory error");
- }
- TestUtil.logTrace("got a qFactory !!");
-
- queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- if (queueR == null) {
- TestUtil.logTrace("queueR error");
- }
-
- queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
- if (queue == null) {
- TestUtil.logTrace("queue error");
- }
-
- p = new Properties();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("from jms.ee.mdb.mdb_msgTypesQ1 @onMessage!" + msg);
-
- try {
-
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null) {
- TestUtil.logTrace("connection error");
- } else {
- qConnection.start();
- qSession = qConnection.createQueueSession(true, 0);
- }
-
- if (msg.getStringProperty("TestCase").equals("bytesMsgNullStreamQTest")) {
- bytesMsgNullStreamQTest();
- } else if (msg.getStringProperty("TestCase")
- .equals("bytesMessageQTestsFullMsgCreate")) {
- TestUtil.logTrace(
- "@onMessage - running bytesMessageQTestsFullMsg1 - create the message");
- bytesMessageQTestsFullMsgCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("bytesMessageQTestsFullMsg")) {
- TestUtil.logTrace(
- "@onMessage - running bytesMessageQTestsFullMsg - read and verify the message");
- bytesMessageQTestsFullMsg((jakarta.jms.BytesMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageFullMsgQTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageFullMsgQTestCreate - read and verify the message");
- mapMessageFullMsgQTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageFullMsgQTest")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageFullMsgQTest - read and verify the message");
- mapMessageFullMsgQTest((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsBooleanCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsBooleanCreate - read and verify the message");
- mapMessageConversionQTestsBooleanCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsBoolean")) {
- TestUtil.logTrace(
- "@onMessage - running MapMessageConversionQTestsBoolean - read and verify the message");
- mapMessageConversionQTestsBoolean((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsByteCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsByteCreate - read and verify the message");
- mapMessageConversionQTestsByteCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsByte")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsByte - read and verify the message");
- mapMessageConversionQTestsByte((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsShortCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsShortCreate - read and verify the message");
- mapMessageConversionQTestsShortCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsShort")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsShort - read and verify the message");
- mapMessageConversionQTestsShort((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsCharCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsCharCreate - read and verify the message");
- mapMessageConversionQTestsCharCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsChar")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsChar - read and verify the message");
- mapMessageConversionQTestsChar((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsIntCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsIntCreate - read and verify the message");
- mapMessageConversionQTestsIntCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsInt")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsInt - read and verify the message");
- mapMessageConversionQTestsInt((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsLongCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsLongCreate - read and verify the message");
- mapMessageConversionQTestsLongCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsLong")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsLong - read and verify the message");
- mapMessageConversionQTestsLong((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsFloatCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsFloatCreate - read and verify the message");
- mapMessageConversionQTestsFloatCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsFloat")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsFloat - read and verify the message");
- mapMessageConversionQTestsFloat((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsDoubleCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsDoubleCreate - read and verify the message");
- mapMessageConversionQTestsDoubleCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsDouble")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsDouble - read and verify the message");
- mapMessageConversionQTestsDouble((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsStringCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsStringCreate - read and verify the message");
- mapMessageConversionQTestsStringCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsString")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsString - read and verify the message");
- mapMessageConversionQTestsString((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsBytesCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsBytesCreate - read and verify the message");
- mapMessageConversionQTestsBytesCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsBytes")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsBytes - read and verify the message");
- mapMessageConversionQTestsBytes((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsInvFormatStringCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsInvFormatStringCreate - read and verify the message");
- mapMessageConversionQTestsInvFormatStringCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionQTestsInvFormatString")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionQTestsInvFormatString - read and verify the message");
- mapMessageConversionQTestsInvFormatString((jakarta.jms.MapMessage) msg);
- }
-
- else {
- TestUtil.logTrace(
- "@onMessage - invalid message type found in StringProperty");
- TestUtil
- .logTrace("@onMessage - could not find method for this testcase: "
- + msg.getStringProperty("TestCase"));
- }
- TestUtil.logTrace("@onMessage - Finished for this test!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
-
- }
-
- /*
- * BytesMessage does not support the concept of a null stream and attempting
- * to write a null into it must throw java.lang.NullPointerException. Jms
- * Specification 1.0.2, Section 3.12
- *
- * create a byte message. Use writeObject to write a null. verify a
- * java.lang.NullPointerException is thrown.
- *
- */
- private void bytesMsgNullStreamQTest() {
- BytesMessage messageSentBytesMessage = null;
- boolean ok = true;
- TextMessage msg = null;
- TestUtil.logTrace("@bytesMsgNullStreamQTest");
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.setStringProperty("TestCase", "bytesMsgNullStreamQTest");
- msg.setText("bytesMsgNullStreamQTest");
-
- TestUtil.logTrace(
- "Writing a null stream to byte message should throw a NullPointerException");
- messageSentBytesMessage = qSession.createBytesMessage();
- JmsUtil.addPropsToMessage(messageSentBytesMessage, p);
- // write a null to the message
- messageSentBytesMessage.writeObject(null);
- TestUtil.logTrace(
- "Fail: message did not throw NullPointerException exception as expected");
- } catch (java.lang.NullPointerException np) {
- // this is what we want
- TestUtil.logTrace("Pass: NullPointerException thrown as expected");
- ok = true;
- } catch (JMSException jmsE) {
- TestUtil.printStackTrace(jmsE);
- // we did not get the anticipated exception
- TestUtil.logTrace("Error: " + jmsE.getClass().getName() + " was thrown");
- ok = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- // we did not get the anticipated exception here either!
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- ok = false;
- }
- try {
- if (ok)
- msg.setStringProperty("Status", "Pass");
- else
- msg.setStringProperty("Status", "Fail");
- TestUtil.logTrace("Sending response message");
- mSender.send(msg);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- TestUtil.logTrace("Error: " + je.getClass().getName() + " was thrown");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logTrace("Error: " + ee.getClass().getName() + " was thrown");
- }
- }
-
- /*
- * Description: Creates a BytesMessage -. writes to the message using each
- * type of method and as an object. Sends the message to MDB_QUEUE Msg
- * verified by ejb.
- *
- */
- private void bytesMessageQTestsFullMsgCreate() {
- mSender = null;
- TestUtil.logTrace("MsgBean - @bytesMessageQTestsFullMsgCreate");
- try {
- BytesMessage messageSent = null;
- boolean pass = true;
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- Integer nInteger = new Integer(-2147483648);
- short shortValue = -32768;
- String utfValue = "what";
- TestUtil.logTrace("Creating 1 message");
-
- messageSent = qSession.createBytesMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "bytesMessageQTestsFullMsg");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace("Writing one of each primitive type to the message");
- // -----------------------------------------------------------------------------
-
- messageSent.writeBoolean(booleanValue);
- messageSent.writeByte(byteValue);
- messageSent.writeChar(charValue);
- messageSent.writeDouble(doubleValue);
- messageSent.writeFloat(floatValue);
- messageSent.writeInt(intValue);
- messageSent.writeLong(longValue);
- messageSent.writeObject(nInteger);
- messageSent.writeShort(shortValue);
- messageSent.writeUTF(utfValue);
- messageSent.writeBytes(bytesValue);
- messageSent.writeBytes(bytesValue, 0, 1);
-
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase", "bytesMessageQTestsFullMsg");
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- // send the message to defaultQueue
-
- mSender = qSession.createSender(queue);
- // send the message to another mdb handled Queue
- mSender.send(messageSent);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: reads and verifies BytesMessage created by
- * bytesMessageQTestsFullMsgCreate
- */
- private void bytesMessageQTestsFullMsg(jakarta.jms.BytesMessage msg) {
- TestUtil.logTrace("MsgBean - @bytesMessageQTestsFullMsg");
- String testCase = "bytesMessageQTestsFullMsg";
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = msg;
- boolean pass = true;
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- byte[] bytesValueRecvd = { 0, 0, 0, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- Integer nInteger = new Integer(-2147483648);
- short shortValue = -32768;
- String utfValue = "what";
-
- TestUtil.logTrace("Starting tests in @bytesMessageQTestsFullMsg");
-
- try {
- if (messageReceived.readBoolean() == booleanValue) {
- TestUtil.logTrace("Pass: boolean returned ok");
- } else {
- TestUtil.logTrace("Fail: boolean not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readByte() == byteValue) {
- TestUtil.logTrace("Pass: Byte returned ok");
- } else {
- TestUtil.logTrace("Fail: Byte not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readChar() == charValue) {
- TestUtil.logTrace("Pass: correct char");
- } else {
- TestUtil.logTrace("Fail: char not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readDouble() == doubleValue) {
- TestUtil.logTrace("Pass: correct double");
- } else {
- TestUtil.logTrace("Fail: double not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readFloat() == floatValue) {
- TestUtil.logTrace("Pass: correct float");
- } else {
- TestUtil.logTrace("Fail: float not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readInt() == intValue) {
- TestUtil.logTrace("Pass: correct int");
- } else {
- TestUtil.logTrace("Fail: int not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readLong() == longValue) {
- TestUtil.logTrace("Pass: correct long");
- } else {
- TestUtil.logTrace("Fail: long not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readInt() == nInteger.intValue()) {
- TestUtil.logTrace("Pass: correct Integer returned");
- } else {
- TestUtil.logTrace("Fail: Integer not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readShort() == shortValue) {
- TestUtil.logTrace("Pass: correct short");
- } else {
- TestUtil.logTrace("Fail: short not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readUTF().equals(utfValue)) {
- TestUtil.logTrace("Pass: correct UTF");
- } else {
- TestUtil.logTrace("Fail: UTF not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- int nCount = messageReceived.readBytes(bytesValueRecvd);
- for (int i = 0; i < nCount; i++) {
- if (bytesValueRecvd[i] != bytesValue[i]) {
- TestUtil.logTrace("Fail: bytes value incorrect");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte value " + i + " ok");
- }
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- int nCount = messageReceived.readBytes(bytesValueRecvd);
- TestUtil.logTrace("count returned " + nCount);
- if (bytesValueRecvd[0] != bytesValue[0]) {
- TestUtil.logTrace("Fail: bytes value incorrect");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte value ok");
- }
- if (nCount == 1) {
- TestUtil.logTrace("Pass: correct count");
- } else {
- TestUtil.logTrace("Fail: count not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- */
- private void mapMessageFullMsgQTestCreate() {
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- short shortValue = 32767;
- String stringValue = "Map Message Test";
- Integer integerValue = Integer.valueOf(100);
- String initial = "spring is here!";
- try {
- MapMessage messageSentMapMessage = null;
-
- TestUtil.logTrace("Send MapMessage to Topic.");
- messageSentMapMessage = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSentMapMessage, p);
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageFullMsgQTestCreate");
-
- messageSentMapMessage.setBoolean("booleanValue", booleanValue);
- messageSentMapMessage.setByte("byteValue", byteValue);
- messageSentMapMessage.setBytes("bytesValue", bytesValue);
- messageSentMapMessage.setBytes("bytesValue2", bytesValue, 0, 1);
- messageSentMapMessage.setChar("charValue", charValue);
- messageSentMapMessage.setDouble("doubleValue", doubleValue);
- messageSentMapMessage.setFloat("floatValue", floatValue);
- messageSentMapMessage.setInt("intValue", intValue);
- messageSentMapMessage.setLong("longValue", longValue);
- messageSentMapMessage.setObject("integerValue", integerValue);
- messageSentMapMessage.setShort("shortValue", shortValue);
-
- messageSentMapMessage.setString("stringValue", stringValue);
- messageSentMapMessage.setString("nullTest", null);
- // set up testcase so onMessage invokes the correct method
- messageSentMapMessage.setStringProperty("TestCase",
- "mapMessageFullMsgQTest");
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- // send the message to defaultQueue
-
- mSender = qSession.createSender(queue);
- // send the message to another mdb handled Queue
- mSender.send(messageSentMapMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- */
- private void mapMessageFullMsgQTest(
- jakarta.jms.MapMessage messageReceivedMapMessage) {
- String testCase = "mapMessageFullMsgQTest";
- boolean pass = true;
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- short shortValue = 32767;
- String stringValue = "Map Message Test";
- Integer integerValue = Integer.valueOf(100);
- String initial = "spring is here!";
- try {
- try {
- if (messageReceivedMapMessage
- .getBoolean("booleanValue") == booleanValue) {
- TestUtil.logTrace("Pass: valid boolean returned");
- } else {
- TestUtil.logTrace("Fail: invalid boolean returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getByte("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: valid byte returned");
- } else {
- TestUtil.logTrace("Fail: invalid byte returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- byte[] b = messageReceivedMapMessage.getBytes("bytesValue");
- for (int i = 0; i < b.length; i++) {
- if (b[i] != bytesValue[i]) {
- TestUtil.logTrace("Fail: byte array " + i + " not valid");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte array " + i + " valid");
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- byte[] b = messageReceivedMapMessage.getBytes("bytesValue2");
- if (b[0] != bytesValue[0]) {
- TestUtil.logTrace("Fail: byte array not valid");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte array valid");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getChar("charValue") == charValue) {
- TestUtil.logTrace("Pass: valid char returned");
- } else {
- TestUtil.logTrace("Fail: invalid char returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getDouble("doubleValue") == doubleValue) {
- TestUtil.logTrace("Pass: valid double returned");
- } else {
- TestUtil.logTrace("Fail: invalid double returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getFloat("floatValue") == floatValue) {
- TestUtil.logTrace("Pass: valid float returned");
- } else {
- TestUtil.logTrace("Fail: invalid float returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getInt("intValue") == intValue) {
- TestUtil.logTrace("Pass: valid int returned");
- } else {
- TestUtil.logTrace("Fail: invalid int returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getLong("longValue") == longValue) {
- TestUtil.logTrace("Pass: valid long returned");
- } else {
- TestUtil.logTrace("Fail: invalid long returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
-
- if (messageReceivedMapMessage.getObject("integerValue").toString()
- .equals(integerValue.toString())) {
- TestUtil.logTrace("Pass: valid object returned");
- } else {
- TestUtil.logTrace("Fail: invalid object returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getShort("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: valid short returned");
- } else {
- TestUtil.logTrace("Fail: invalid short returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getString("stringValue")
- .equals(stringValue)) {
- TestUtil.logTrace("Pass: valid string returned");
- } else {
- TestUtil.logTrace("Fail: invalid string returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getString("nullTest") == null) {
- TestUtil.logTrace("Pass: null returned");
- } else {
-
- TestUtil.logTrace("Fail: null not returned from getString");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a MapMessage -. use MapMessage method writeBoolean to
- * write a boolean to the message.
- */
- private void mapMessageConversionQTestsBooleanCreate() {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- boolean booleanValue = true;
- boolean pass = true;
-
- // set up test tool for Queue
- TestUtil.logTrace("Creating 1 message");
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionQTestsBooleanCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionQTestsBoolean");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for boolean primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setBoolean("booleanValue", booleanValue);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Descripton: For MapMessages Verify the proper conversion support for
- * boolean as in 3.11.3
- */
- private void mapMessageConversionQTestsBoolean(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionQTestsBoolean";
- try {
- boolean booleanValue = true;
- boolean pass = true;
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for boolean primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- // now test conversions for boolean
- // -----------------------------------------------
- // boolean to boolean - valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a boolean");
- try {
- if (messageReceived.getBoolean("booleanValue") == booleanValue) {
- TestUtil.logTrace("Pass: boolean to boolean - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a boolean");
- try {
- if (messageReceived.getString("booleanValue")
- .equals((Boolean.valueOf(booleanValue)).toString())) {
- TestUtil.logTrace("Pass: boolean to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to byte[] invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read a boolean - expect MessageFormatException");
- int nCount = 0;
- try {
- byte[] b = messageReceived.getBytes("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
- // -----------------------------------------------
- // boolean to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readByte to read a boolean - expect MessageFormatException");
- try {
- byte b = messageReceived.getByte("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readShort to read a boolean - expect MessageFormatException");
- try {
- short s = messageReceived.getShort("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
-
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readChar to read a boolean - expect MessageFormatException");
- try {
- char c = messageReceived.getChar("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to int invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readInt to read a boolean - expect MessageFormatException");
- try {
- int i = messageReceived.getInt("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readLong to read a boolean - expect MessageFormatException");
- try {
- long l = messageReceived.getLong("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to float invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readFloat to read a boolean - expect MessageFormatException");
- try {
- float f = messageReceived.getFloat("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
-
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to double invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readDouble to read a boolean - expect MessageFormatException");
- try {
- double d = messageReceived.getDouble("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
-
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- */
- private void mapMessageConversionQTestsByteCreate() {
- MapMessage messageSent = null;
- byte byteValue = 127;
- boolean pass = true;
- try {
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionQTestsByteCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionQTestsByte");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setByte("byteValue", byteValue);
- // send the message and then get it back
-
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- */
- private void mapMessageConversionQTestsByte(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionQTestsByte";
- MapMessage messageSent = null;
- byte byteValue = 127;
- boolean pass = true;
- try {
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------
- // byte to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a byte - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("byteValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a byte");
- try {
- if (messageReceived.getString("byteValue")
- .equals(Byte.toString(byteValue))) {
- TestUtil.logTrace("Pass: byte to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getBytes[] to read a byte - expect MessageFormatException");
- int nCount = 0;
- try {
- byte[] b = messageReceived.getBytes("byteValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to byte valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a byte");
- try {
- if (messageReceived.getByte("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to byte - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to short valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a byte");
- try {
- if (messageReceived.getShort("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to short - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a boolean - this is not valid");
- try {
- char c = messageReceived.getChar("byteValue");
- pass = false;
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a byte");
- try {
- if (messageReceived.getInt("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to int - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a byte");
- try {
- if (messageReceived.getLong("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a boolean - this is not valid");
- try {
- float f = messageReceived.getFloat("byteValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a boolean - this is not valid");
- try {
- double d = messageReceived.getDouble("byteValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeShort to
- * write a short.
- */
- public void mapMessageConversionQTestsShortCreate() {
- try {
- MapMessage messageSent = null;
- short shortValue = 1;
- boolean pass = true;
-
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionQTestsShort");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionQTestsShort");
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setShort("shortValue", shortValue);
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: MapMessage -. Verify the proper conversion support as in
- * 3.11.3
- */
- private void mapMessageConversionQTestsShort(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionQTestsShort";
- try {
- short shortValue = 1;
- boolean pass = true;
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- // now test conversions for byte
- // -----------------------------------------------
- // short to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a short - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("shortValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a short");
- try {
- if (messageReceived.getString("shortValue")
- .equals(Short.toString(shortValue))) {
- TestUtil.logTrace("Pass: short to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getBytes[] to read a short - expect MessageFormatException");
- try {
- byte[] b = messageReceived.getBytes("shortValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a short - this is not valid");
- try {
- byte b = messageReceived.getByte("shortValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to short valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a short");
- try {
- if (messageReceived.getShort("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: short to short - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a short - this is not valid");
- try {
- char c = messageReceived.getChar("shortValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a short");
- try {
- if (messageReceived.getInt("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: short to int - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a short");
- try {
- if (messageReceived.getLong("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: short to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a short - this is not valid");
- try {
- float f = messageReceived.getFloat("shortValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a short - this is not valid");
- try {
- double d = messageReceived.getDouble("shortValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeChar to
- * write a char. Verify the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionQTestsCharCreate() {
- try {
- MapMessage messageSent = null;
- char charValue = 'a';
- boolean pass = true;
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionQTestsChar");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionQTestsChar");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- messageSent.setChar("charValue", charValue);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeInt to write
- * an int. Verify the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionQTestsIntCreate() {
- try {
- MapMessage messageSent = null;
- int intValue = 6;
- boolean pass = true;
-
- // set up test tool for Queue
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionQTestsIntCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionQTestsInt");
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setInt("intValue", intValue);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeLong to
- * write a long. Verify the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionQTestsLongCreate() {
- try {
- MapMessage messageSent = null;
- long longValue = 2;
- boolean pass = true;
-
- TestUtil.logTrace("Creating 1 message");
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionQTestsLongCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionQTestsLong");
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setLong("longValue", longValue);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeFloat to
- * write a float. Verify the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionQTestsFloatCreate() {
- try {
- MapMessage messageSent = null;
- float floatValue = 5;
- boolean pass = true;
-
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionQTestsFloatCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionQTestsFloat");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setFloat("floatValue", floatValue);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeDouble to
- * write a double. Verify the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionQTestsDoubleCreate() {
- try {
- MapMessage messageSent = null;
- double doubleValue = 3;
- boolean pass = true;
-
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionQTestsDoubleCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionQTestsDouble");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- messageSent.setDouble("doubleValue", doubleValue);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeString to
- * write a string. Verify the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionQTestsStringCreate() {
- try {
- MapMessage messageSent = null;
- boolean pass = true;
- String myString = "10";
- String myString2 = "true";
-
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionQTestsStringCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionQTestsString");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- messageSent.setString("myString", myString);
- messageSent.setString("myString2", myString2);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a MapMessage -. use MapMessage method writeBytes to
- * write a byte[] to the message. Verify the proper conversion support as in
- * 3.11.3
- */
- private void mapMessageConversionQTestsBytesCreate() {
- try {
- MapMessage messageSent = null;
- byte[] byteValues = { 1, 2, 3 };
- boolean pass = true;
-
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionQTestsBytesCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionQTestsBytes");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte[] primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setBytes("byteValues", byteValues);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a MapMessage -. use MapMessage method setString to
- * write a text string of "mytest string". Verify NumberFormatException is
- * thrown
- *
- */
- private void mapMessageConversionQTestsInvFormatStringCreate() {
- try {
- MapMessage messageSent = null;
- boolean pass = true;
- String myString = "mytest string";
-
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionQTestsInvFormatStringCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionQTestsInvFormatString");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setString("myString", myString);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeChar to write a char. Verify the
- * proper conversion support as in 3.11.3
- */
- private void mapMessageConversionQTestsChar(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionQTestsChar";
- try {
- char charValue = 'a';
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // char to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a char - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a char");
- try {
- if (messageReceived.getString("charValue")
- .equals(Character.valueOf(charValue).toString())) {
- TestUtil.logTrace("Pass: char to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getBytes[] to read a char - expect MessageFormatException");
- try {
- byte[] b = messageReceived.getBytes("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a char - this is not valid");
- try {
-
- byte b = messageReceived.getByte("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a char");
- try {
- short s = messageReceived.getShort("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to char valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a char ");
- try {
- if (messageReceived.getChar("charValue") == charValue) {
- TestUtil.logTrace("Pass: char to char - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to int invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a char ");
- try {
- int i = messageReceived.getInt("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a char");
- try {
- long l = messageReceived.getLong("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a char - this is not valid");
- try {
- float f = messageReceived.getFloat("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to double invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a char - this is not valid");
- try {
- double d = messageReceived.getDouble("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeInt to write an int. Verify the
- * proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionQTestsInt(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionQTestsInt";
- try {
-
- int intValue = 6;
- boolean pass = true;
- // now test conversions for byte
- // -----------------------------------------------
- // int to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read an int - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read an int");
- try {
- if (messageReceived.getString("intValue")
- .equals(Integer.toString(intValue))) {
- TestUtil.logTrace("Pass: int to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getBytes[] to read an int - expect MessageFormatException");
- int nCount = 0;
- try {
- byte[] b = messageReceived.getBytes("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read an int - this is not valid");
- try {
- byte b = messageReceived.getByte("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read an int");
- try {
- short s = messageReceived.getShort("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read an int - this is not valid");
- try {
- char c = messageReceived.getChar("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read an int");
- try {
- if (messageReceived.getInt("intValue") == intValue) {
- TestUtil.logTrace("Pass: int to int - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read an int");
- try {
- if (messageReceived.getLong("intValue") == intValue) {
- TestUtil.logTrace("Pass: int to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read an int - this is not valid");
- try {
- float f = messageReceived.getFloat("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read an int - this is not valid");
- try {
- double d = messageReceived.getDouble("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeLong to write a long. Verify the
- * proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionQTestsLong(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionQTestsLong";
- try {
-
- long longValue = 2;
- boolean pass = true;
- // now test conversions for byte
- // -----------------------------------------------
- // long to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a long - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a long");
- try {
- if (messageReceived.getString("longValue")
- .equals(Long.toString(longValue))) {
- TestUtil.logTrace("Pass: long to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getBytes[] to read a long - expect MessageFormatException");
- try {
- byte[] b = messageReceived.getBytes("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read an long - this is not valid");
- try {
- byte b = messageReceived.getByte("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a long");
- try {
- short s = messageReceived.getShort("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a long - this is not valid");
- try {
- char c = messageReceived.getChar("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a long");
- try {
- int i = messageReceived.getInt("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a long");
- try {
- if (messageReceived.getLong("longValue") == longValue) {
- TestUtil.logTrace("Pass: int to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a long - this is not valid");
- try {
- float f = messageReceived.getFloat("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a long ");
- try {
- double d = messageReceived.getDouble("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeFloat to write a float. Verify the
- * proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionQTestsFloat(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionQTestsFloat";
- try {
- float floatValue = 5;
- boolean pass = true;
- // now test conversions for byte
- // -----------------------------------------------
- // float to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a float ");
- try {
- boolean b = messageReceived.getBoolean("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a float");
- try {
- if (messageReceived.getString("floatValue")
- .equals(Float.toString(floatValue))) {
- TestUtil.logTrace("Pass: float to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBytes[] to read a float ");
- try {
- byte[] b = messageReceived.getBytes("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // float to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a float ");
- try {
- byte b = messageReceived.getByte("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a float");
- try {
- short s = messageReceived.getShort("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // float to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a long ");
- try {
- char c = messageReceived.getChar("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a float");
- try {
- int i = messageReceived.getInt("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a long");
- try {
- long l = messageReceived.getLong("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to float valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a float ");
- try {
- if (messageReceived.getFloat("floatValue") == floatValue) {
- TestUtil.logTrace("Pass: float to float - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to double valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a float ");
- try {
- if (messageReceived.getDouble("floatValue") == floatValue) {
- TestUtil.logTrace("Pass: float to double - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeDouble to write a double. Verify
- * the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionQTestsDouble(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionQTestsDouble";
-
- try {
-
- double doubleValue = 3;
- boolean pass = true;
- // now test conversions for byte
- // -----------------------------------------------
- // double to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a double ");
- try {
- boolean b = messageReceived.getBoolean("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a double");
- try {
- if (messageReceived.getString("doubleValue")
- .equals(Double.toString(doubleValue))) {
- TestUtil.logTrace("Pass: double to string");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBytes[] to read a double ");
- try {
- byte[] b = messageReceived.getBytes("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a double ");
- try {
- byte b = messageReceived.getByte("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a double");
- try {
- short s = messageReceived.getShort("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a double ");
- try {
- char c = messageReceived.getChar("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a double");
- try {
- int i = messageReceived.getInt("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a double");
- try {
- long l = messageReceived.getLong("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a double ");
- try {
- float f = messageReceived.getFloat("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to double valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read an float ");
- try {
- if (messageReceived.getDouble("doubleValue") == doubleValue) {
- TestUtil.logTrace("Pass: double to double ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeString to write a string. Verify
- * the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionQTestsString(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionQTestsString";
-
- try {
-
- boolean pass = true;
- String myString = "10";
- String myString2 = "true";
- // now test conversions for String
- // -----------------------------------------------
- // string to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a String");
- try {
- if (messageReceived.getString("myString").equals(myString)) {
- TestUtil.logTrace("Pass: string to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // string to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBytes[] to read a String");
- try {
- byte[] b = messageReceived.getBytes("myString");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to byte valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a String");
- try {
- if (messageReceived.getByte("myString") == Byte.parseByte(myString)) {
- TestUtil.logTrace("Pass: String to byte ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // string to short valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a string");
- try {
- if (messageReceived.getShort("myString") == Short
- .parseShort(myString)) {
- TestUtil.logTrace("Pass: String to short ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a String ");
- try {
- char c = messageReceived.getChar("myString");
- TestUtil.logTrace("getChar returned " + c);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // string to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a String");
- try {
- if (messageReceived.getInt("myString") == Integer.parseInt(myString)) {
- TestUtil.logTrace("Pass: String to int ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a String");
- try {
- if (messageReceived.getLong("myString") == Long.parseLong(myString)) {
- TestUtil.logTrace("Pass: String to long ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a String");
- try {
- if (messageReceived.getFloat("myString") == Float
- .parseFloat(myString)) {
- TestUtil.logTrace("Pass: String to float ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to double valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a String");
- try {
-
- if (messageReceived.getDouble("myString") == Double
- .parseDouble(myString)) {
- TestUtil.logTrace("Pass: String to double ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a string ");
- try {
- if (messageReceived.getBoolean("myString2") == Boolean
- .valueOf(myString2).booleanValue()) {
- TestUtil.logTrace("Pass: String to boolean ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a string that is not true");
- try {
- boolean b = messageReceived.getBoolean("myString");
- if (b != false) {
- TestUtil.logTrace("Fail: !true should have returned false");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: !true returned false");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeBytes to write a byte[] to the
- * message. Verify the proper conversion support as in 3.11.3
- */
- private void mapMessageConversionQTestsBytes(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionQTestsBytes";
-
- try {
-
- byte[] byteValues = { 1, 2, 3 };
- boolean pass = true;
-
- // now test conversions for boolean
- // -----------------------------------------------
- // byte[] to byte[] - valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBytes[] to read a byte[] ");
- try {
- byte[] b = messageReceived.getBytes("byteValues");
- for (int i = 0; i < b.length; i++) {
- if (b[i] != byteValues[i]) {
- TestUtil.logTrace("Fail: byte[] value returned is invalid");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte[] returned is valid");
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a byte[]");
- try {
- boolean b = messageReceived.getBoolean("byteValues");
- TestUtil.logTrace(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to string invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a byte[]");
- try {
- String s = messageReceived.getString("byteValues");
- TestUtil.logTrace(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getByte to read a byte[] - expect MessageFormatException");
- try {
- byte b = messageReceived.getByte("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getShort to read a byte[] - expect MessageFormatException");
- try {
- short s = messageReceived.getShort("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getChar to read a byte[] - expect MessageFormatException");
- try {
-
- char c = messageReceived.getChar("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to int invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getInt to read a byte[] - expect MessageFormatException");
- try {
- int i = messageReceived.getInt("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getLong to read a byte[] - expect MessageFormatException");
- try {
- long l = messageReceived.getLong("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getFloat to read a byte[] - expect MessageFormatException");
- try {
- float f = messageReceived.getFloat("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to double invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getDouble to read a byte[] - expect MessageFormatException");
- try {
- double d = messageReceived.getDouble("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method setString to write a text string of
- * "mytest string". Verify NumberFormatException is thrown
- *
- */
- private void mapMessageConversionQTestsInvFormatString(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionQTestsInvFormatString";
-
- try {
- boolean pass = true;
- String myString = "mytest string";
-
- // -----------------------------------------------
- // String to byte
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a String that is not valid ");
- try {
- byte b = messageReceived.getByte("myString");
- TestUtil.logTrace("Fail: java.lang.NumberFormatException expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // string to short
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a string that is not valid ");
- try {
- short s = messageReceived.getShort("myString");
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to int
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a String that is not valid ");
- try {
- int i = messageReceived.getInt("myString");
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a String that is not valid ");
- try {
- long l = messageReceived.getLong("myString");
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a String that is not valid ");
- try {
- float f = messageReceived.getFloat("myString");
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to double
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a String that is not valid ");
- try {
- double d = messageReceived.getDouble("myString");
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: send test results to response queue (MDB_QUEUE_REPLY) for
- * verification
- */
- private void sendTestResults(String testCase, boolean results) {
- TextMessage msg = null;
-
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- msg.setStringProperty("TestCase", testCase);
- msg.setText(testCase);
- if (results)
- msg.setStringProperty("Status", "Pass");
- else
- msg.setStringProperty("Status", "Fail");
-
- TestUtil.logTrace("Sending response message");
- TestUtil.logTrace(
- "==================================Test Results from: " + testCase);
- TestUtil.logTrace("==================================Status: " + results);
- mSender.send(msg);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- TestUtil.logTrace("Error: " + je.getClass().getName() + " was thrown");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logTrace("Error: " + ee.getClass().getName() + " was thrown");
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgTypesQ1 In MsgBean::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil.logTrace("jms.ee.mdb.mdb_msgTypesQ1 In MsgBean::remove()!!");
- }
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ private MessageDrivenContext mdc = null;
+
+ // JMS
+ private QueueConnectionFactory qFactory = null;
+
+ private QueueConnection qConnection = null;
+
+ private Queue queueR = null;
+
+ private Queue queue = null;
+
+ private QueueSender mSender = null;
+
+ private QueueSession qSession = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBean.class.getName());
+
+ public MsgBean() {
+ logger.log(Logger.Level.TRACE, "@MsgBean()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesQ1 - @MsgBean-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ if (qFactory == null) {
+ logger.log(Logger.Level.TRACE, "qFactory error");
+ }
+ logger.log(Logger.Level.TRACE, "got a qFactory !!");
+
+ queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ if (queueR == null) {
+ logger.log(Logger.Level.TRACE, "queueR error");
+ }
+
+ queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
+ if (queue == null) {
+ logger.log(Logger.Level.TRACE, "queue error");
+ }
+
+ p = new Properties();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "from jms.ee.mdb.mdb_msgTypesQ1 @onMessage!" + msg);
+
+ try {
+
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null) {
+ logger.log(Logger.Level.TRACE, "connection error");
+ } else {
+ qConnection.start();
+ qSession = qConnection.createQueueSession(true, 0);
+ }
+
+ if (msg.getStringProperty("TestCase").equals("bytesMsgNullStreamQTest")) {
+ bytesMsgNullStreamQTest();
+ } else if (msg.getStringProperty("TestCase").equals("bytesMessageQTestsFullMsgCreate")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - running bytesMessageQTestsFullMsg1 - create the message");
+ bytesMessageQTestsFullMsgCreate();
+ } else if (msg.getStringProperty("TestCase").equals("bytesMessageQTestsFullMsg")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running bytesMessageQTestsFullMsg - read and verify the message");
+ bytesMessageQTestsFullMsg((jakarta.jms.BytesMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageFullMsgQTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageFullMsgQTestCreate - read and verify the message");
+ mapMessageFullMsgQTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageFullMsgQTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageFullMsgQTest - read and verify the message");
+ mapMessageFullMsgQTest((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsBooleanCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsBooleanCreate - read and verify the message");
+ mapMessageConversionQTestsBooleanCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsBoolean")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running MapMessageConversionQTestsBoolean - read and verify the message");
+ mapMessageConversionQTestsBoolean((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsByteCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsByteCreate - read and verify the message");
+ mapMessageConversionQTestsByteCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsByte")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsByte - read and verify the message");
+ mapMessageConversionQTestsByte((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsShortCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsShortCreate - read and verify the message");
+ mapMessageConversionQTestsShortCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsShort")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsShort - read and verify the message");
+ mapMessageConversionQTestsShort((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsCharCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsCharCreate - read and verify the message");
+ mapMessageConversionQTestsCharCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsChar")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsChar - read and verify the message");
+ mapMessageConversionQTestsChar((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsIntCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsIntCreate - read and verify the message");
+ mapMessageConversionQTestsIntCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsInt")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsInt - read and verify the message");
+ mapMessageConversionQTestsInt((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsLongCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsLongCreate - read and verify the message");
+ mapMessageConversionQTestsLongCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsLong")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsLong - read and verify the message");
+ mapMessageConversionQTestsLong((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsFloatCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsFloatCreate - read and verify the message");
+ mapMessageConversionQTestsFloatCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsFloat")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsFloat - read and verify the message");
+ mapMessageConversionQTestsFloat((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsDoubleCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsDoubleCreate - read and verify the message");
+ mapMessageConversionQTestsDoubleCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsDouble")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsDouble - read and verify the message");
+ mapMessageConversionQTestsDouble((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsStringCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsStringCreate - read and verify the message");
+ mapMessageConversionQTestsStringCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsString")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsString - read and verify the message");
+ mapMessageConversionQTestsString((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsBytesCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsBytesCreate - read and verify the message");
+ mapMessageConversionQTestsBytesCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsBytes")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsBytes - read and verify the message");
+ mapMessageConversionQTestsBytes((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsInvFormatStringCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsInvFormatStringCreate - read and verify the message");
+ mapMessageConversionQTestsInvFormatStringCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionQTestsInvFormatString")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionQTestsInvFormatString - read and verify the message");
+ mapMessageConversionQTestsInvFormatString((jakarta.jms.MapMessage) msg);
+ }
+
+ else {
+ logger.log(Logger.Level.TRACE, "@onMessage - invalid message type found in StringProperty");
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - could not find method for this testcase: " + msg.getStringProperty("TestCase"));
+ }
+ logger.log(Logger.Level.TRACE, "@onMessage - Finished for this test!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+
+ }
+
+ /*
+ * BytesMessage does not support the concept of a null stream and attempting to
+ * write a null into it must throw java.lang.NullPointerException. Jms
+ * Specification 1.0.2, Section 3.12
+ *
+ * create a byte message. Use writeObject to write a null. verify a
+ * java.lang.NullPointerException is thrown.
+ *
+ */
+ private void bytesMsgNullStreamQTest() {
+ BytesMessage messageSentBytesMessage = null;
+ boolean ok = true;
+ TextMessage msg = null;
+ logger.log(Logger.Level.TRACE, "@bytesMsgNullStreamQTest");
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.setStringProperty("TestCase", "bytesMsgNullStreamQTest");
+ msg.setText("bytesMsgNullStreamQTest");
+
+ logger.log(Logger.Level.TRACE, "Writing a null stream to byte message should throw a NullPointerException");
+ messageSentBytesMessage = qSession.createBytesMessage();
+ JmsUtil.addPropsToMessage(messageSentBytesMessage, p);
+ // write a null to the message
+ messageSentBytesMessage.writeObject(null);
+ logger.log(Logger.Level.TRACE, "Fail: message did not throw NullPointerException exception as expected");
+ } catch (java.lang.NullPointerException np) {
+ // this is what we want
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException thrown as expected");
+ ok = true;
+ } catch (JMSException jmsE) {
+ TestUtil.printStackTrace(jmsE);
+ // we did not get the anticipated exception
+ logger.log(Logger.Level.TRACE, "Error: " + jmsE.getClass().getName() + " was thrown");
+ ok = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ // we did not get the anticipated exception here either!
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ ok = false;
+ }
+ try {
+ if (ok)
+ msg.setStringProperty("Status", "Pass");
+ else
+ msg.setStringProperty("Status", "Fail");
+ logger.log(Logger.Level.TRACE, "Sending response message");
+ mSender.send(msg);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ logger.log(Logger.Level.TRACE, "Error: " + je.getClass().getName() + " was thrown");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.TRACE, "Error: " + ee.getClass().getName() + " was thrown");
+ }
+ }
+
+ /*
+ * Description: Creates a BytesMessage -. writes to the message using each type
+ * of method and as an object. Sends the message to MDB_QUEUE Msg verified by
+ * ejb.
+ *
+ */
+ private void bytesMessageQTestsFullMsgCreate() {
+ mSender = null;
+ logger.log(Logger.Level.TRACE, "MsgBean - @bytesMessageQTestsFullMsgCreate");
+ try {
+ BytesMessage messageSent = null;
+ boolean pass = true;
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ Integer nInteger = new Integer(-2147483648);
+ short shortValue = -32768;
+ String utfValue = "what";
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+
+ messageSent = qSession.createBytesMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "bytesMessageQTestsFullMsg");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Writing one of each primitive type to the message");
+ // -----------------------------------------------------------------------------
+
+ messageSent.writeBoolean(booleanValue);
+ messageSent.writeByte(byteValue);
+ messageSent.writeChar(charValue);
+ messageSent.writeDouble(doubleValue);
+ messageSent.writeFloat(floatValue);
+ messageSent.writeInt(intValue);
+ messageSent.writeLong(longValue);
+ messageSent.writeObject(nInteger);
+ messageSent.writeShort(shortValue);
+ messageSent.writeUTF(utfValue);
+ messageSent.writeBytes(bytesValue);
+ messageSent.writeBytes(bytesValue, 0, 1);
+
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "bytesMessageQTestsFullMsg");
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ // send the message to defaultQueue
+
+ mSender = qSession.createSender(queue);
+ // send the message to another mdb handled Queue
+ mSender.send(messageSent);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: reads and verifies BytesMessage created by
+ * bytesMessageQTestsFullMsgCreate
+ */
+ private void bytesMessageQTestsFullMsg(jakarta.jms.BytesMessage msg) {
+ logger.log(Logger.Level.TRACE, "MsgBean - @bytesMessageQTestsFullMsg");
+ String testCase = "bytesMessageQTestsFullMsg";
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = msg;
+ boolean pass = true;
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ byte[] bytesValueRecvd = { 0, 0, 0, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ Integer nInteger = new Integer(-2147483648);
+ short shortValue = -32768;
+ String utfValue = "what";
+
+ logger.log(Logger.Level.TRACE, "Starting tests in @bytesMessageQTestsFullMsg");
+
+ try {
+ if (messageReceived.readBoolean() == booleanValue) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean returned ok");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: boolean not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readByte() == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: Byte returned ok");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Byte not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readChar() == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct char");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: char not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readDouble() == doubleValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct double");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: double not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readFloat() == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct float");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: float not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readInt() == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct int");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: int not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readLong() == longValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct long");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: long not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readInt() == nInteger.intValue()) {
+ logger.log(Logger.Level.TRACE, "Pass: correct Integer returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Integer not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readShort() == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct short");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: short not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readUTF().equals(utfValue)) {
+ logger.log(Logger.Level.TRACE, "Pass: correct UTF");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: UTF not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ int nCount = messageReceived.readBytes(bytesValueRecvd);
+ for (int i = 0; i < nCount; i++) {
+ if (bytesValueRecvd[i] != bytesValue[i]) {
+ logger.log(Logger.Level.TRACE, "Fail: bytes value incorrect");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte value " + i + " ok");
+ }
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ int nCount = messageReceived.readBytes(bytesValueRecvd);
+ logger.log(Logger.Level.TRACE, "count returned " + nCount);
+ if (bytesValueRecvd[0] != bytesValue[0]) {
+ logger.log(Logger.Level.TRACE, "Fail: bytes value incorrect");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte value ok");
+ }
+ if (nCount == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: correct count");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: count not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ */
+ private void mapMessageFullMsgQTestCreate() {
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ short shortValue = 32767;
+ String stringValue = "Map Message Test";
+ Integer integerValue = Integer.valueOf(100);
+ String initial = "spring is here!";
+ try {
+ MapMessage messageSentMapMessage = null;
+
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Topic.");
+ messageSentMapMessage = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSentMapMessage, p);
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageFullMsgQTestCreate");
+
+ messageSentMapMessage.setBoolean("booleanValue", booleanValue);
+ messageSentMapMessage.setByte("byteValue", byteValue);
+ messageSentMapMessage.setBytes("bytesValue", bytesValue);
+ messageSentMapMessage.setBytes("bytesValue2", bytesValue, 0, 1);
+ messageSentMapMessage.setChar("charValue", charValue);
+ messageSentMapMessage.setDouble("doubleValue", doubleValue);
+ messageSentMapMessage.setFloat("floatValue", floatValue);
+ messageSentMapMessage.setInt("intValue", intValue);
+ messageSentMapMessage.setLong("longValue", longValue);
+ messageSentMapMessage.setObject("integerValue", integerValue);
+ messageSentMapMessage.setShort("shortValue", shortValue);
+
+ messageSentMapMessage.setString("stringValue", stringValue);
+ messageSentMapMessage.setString("nullTest", null);
+ // set up testcase so onMessage invokes the correct method
+ messageSentMapMessage.setStringProperty("TestCase", "mapMessageFullMsgQTest");
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ // send the message to defaultQueue
+
+ mSender = qSession.createSender(queue);
+ // send the message to another mdb handled Queue
+ mSender.send(messageSentMapMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ */
+ private void mapMessageFullMsgQTest(jakarta.jms.MapMessage messageReceivedMapMessage) {
+ String testCase = "mapMessageFullMsgQTest";
+ boolean pass = true;
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ short shortValue = 32767;
+ String stringValue = "Map Message Test";
+ Integer integerValue = Integer.valueOf(100);
+ String initial = "spring is here!";
+ try {
+ try {
+ if (messageReceivedMapMessage.getBoolean("booleanValue") == booleanValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid boolean returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid boolean returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getByte("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid byte returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid byte returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ byte[] b = messageReceivedMapMessage.getBytes("bytesValue");
+ for (int i = 0; i < b.length; i++) {
+ if (b[i] != bytesValue[i]) {
+ logger.log(Logger.Level.TRACE, "Fail: byte array " + i + " not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte array " + i + " valid");
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ byte[] b = messageReceivedMapMessage.getBytes("bytesValue2");
+ if (b[0] != bytesValue[0]) {
+ logger.log(Logger.Level.TRACE, "Fail: byte array not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte array valid");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getChar("charValue") == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid char returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid char returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getDouble("doubleValue") == doubleValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid double returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid double returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getFloat("floatValue") == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid float returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid float returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getInt("intValue") == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid int returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid int returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getLong("longValue") == longValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid long returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid long returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+
+ if (messageReceivedMapMessage.getObject("integerValue").toString().equals(integerValue.toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: valid object returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid object returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getShort("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid short returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid short returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getString("stringValue").equals(stringValue)) {
+ logger.log(Logger.Level.TRACE, "Pass: valid string returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid string returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getString("nullTest") == null) {
+ logger.log(Logger.Level.TRACE, "Pass: null returned");
+ } else {
+
+ logger.log(Logger.Level.TRACE, "Fail: null not returned from getString");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a MapMessage -. use MapMessage method writeBoolean to
+ * write a boolean to the message.
+ */
+ private void mapMessageConversionQTestsBooleanCreate() {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ boolean booleanValue = true;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionQTestsBooleanCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionQTestsBoolean");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for boolean primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setBoolean("booleanValue", booleanValue);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Descripton: For MapMessages Verify the proper conversion support for boolean
+ * as in 3.11.3
+ */
+ private void mapMessageConversionQTestsBoolean(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionQTestsBoolean";
+ try {
+ boolean booleanValue = true;
+ boolean pass = true;
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for boolean primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // boolean to boolean - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a boolean");
+ try {
+ if (messageReceived.getBoolean("booleanValue") == booleanValue) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to boolean - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a boolean");
+ try {
+ if (messageReceived.getString("booleanValue").equals((Boolean.valueOf(booleanValue)).toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to byte[] invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a boolean - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ byte[] b = messageReceived.getBytes("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+ // -----------------------------------------------
+ // boolean to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a boolean - expect MessageFormatException");
+ try {
+ byte b = messageReceived.getByte("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a boolean - expect MessageFormatException");
+ try {
+ short s = messageReceived.getShort("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a boolean - expect MessageFormatException");
+ try {
+ char c = messageReceived.getChar("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a boolean - expect MessageFormatException");
+ try {
+ int i = messageReceived.getInt("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a boolean - expect MessageFormatException");
+ try {
+ long l = messageReceived.getLong("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to float invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a boolean - expect MessageFormatException");
+ try {
+ float f = messageReceived.getFloat("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a boolean - expect MessageFormatException");
+ try {
+ double d = messageReceived.getDouble("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ */
+ private void mapMessageConversionQTestsByteCreate() {
+ MapMessage messageSent = null;
+ byte byteValue = 127;
+ boolean pass = true;
+ try {
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionQTestsByteCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionQTestsByte");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setByte("byteValue", byteValue);
+ // send the message and then get it back
+
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ */
+ private void mapMessageConversionQTestsByte(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionQTestsByte";
+ MapMessage messageSent = null;
+ byte byteValue = 127;
+ boolean pass = true;
+ try {
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------
+ // byte to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a byte - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("byteValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a byte");
+ try {
+ if (messageReceived.getString("byteValue").equals(Byte.toString(byteValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a byte - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ byte[] b = messageReceived.getBytes("byteValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a byte");
+ try {
+ if (messageReceived.getByte("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to byte - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a byte");
+ try {
+ if (messageReceived.getShort("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to short - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a boolean - this is not valid");
+ try {
+ char c = messageReceived.getChar("byteValue");
+ pass = false;
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a byte");
+ try {
+ if (messageReceived.getInt("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to int - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a byte");
+ try {
+ if (messageReceived.getLong("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a boolean - this is not valid");
+ try {
+ float f = messageReceived.getFloat("byteValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a boolean - this is not valid");
+ try {
+ double d = messageReceived.getDouble("byteValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeShort to write
+ * a short.
+ */
+ public void mapMessageConversionQTestsShortCreate() {
+ try {
+ MapMessage messageSent = null;
+ short shortValue = 1;
+ boolean pass = true;
+
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionQTestsShort");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionQTestsShort");
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setShort("shortValue", shortValue);
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: MapMessage -. Verify the proper conversion support as in 3.11.3
+ */
+ private void mapMessageConversionQTestsShort(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionQTestsShort";
+ try {
+ short shortValue = 1;
+ boolean pass = true;
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // short to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a short - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("shortValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a short");
+ try {
+ if (messageReceived.getString("shortValue").equals(Short.toString(shortValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: short to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a short - expect MessageFormatException");
+ try {
+ byte[] b = messageReceived.getBytes("shortValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a short - this is not valid");
+ try {
+ byte b = messageReceived.getByte("shortValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a short");
+ try {
+ if (messageReceived.getShort("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to short - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a short - this is not valid");
+ try {
+ char c = messageReceived.getChar("shortValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a short");
+ try {
+ if (messageReceived.getInt("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to int - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a short");
+ try {
+ if (messageReceived.getLong("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a short - this is not valid");
+ try {
+ float f = messageReceived.getFloat("shortValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a short - this is not valid");
+ try {
+ double d = messageReceived.getDouble("shortValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeChar to write
+ * a char. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionQTestsCharCreate() {
+ try {
+ MapMessage messageSent = null;
+ char charValue = 'a';
+ boolean pass = true;
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionQTestsChar");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionQTestsChar");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ messageSent.setChar("charValue", charValue);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeInt to write
+ * an int. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionQTestsIntCreate() {
+ try {
+ MapMessage messageSent = null;
+ int intValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionQTestsIntCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionQTestsInt");
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setInt("intValue", intValue);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeLong to write
+ * a long. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionQTestsLongCreate() {
+ try {
+ MapMessage messageSent = null;
+ long longValue = 2;
+ boolean pass = true;
+
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionQTestsLongCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionQTestsLong");
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setLong("longValue", longValue);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeFloat to write
+ * a float. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionQTestsFloatCreate() {
+ try {
+ MapMessage messageSent = null;
+ float floatValue = 5;
+ boolean pass = true;
+
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionQTestsFloatCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionQTestsFloat");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setFloat("floatValue", floatValue);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeDouble to
+ * write a double. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionQTestsDoubleCreate() {
+ try {
+ MapMessage messageSent = null;
+ double doubleValue = 3;
+ boolean pass = true;
+
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionQTestsDoubleCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionQTestsDouble");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ messageSent.setDouble("doubleValue", doubleValue);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeString to
+ * write a string. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionQTestsStringCreate() {
+ try {
+ MapMessage messageSent = null;
+ boolean pass = true;
+ String myString = "10";
+ String myString2 = "true";
+
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionQTestsStringCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionQTestsString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ messageSent.setString("myString", myString);
+ messageSent.setString("myString2", myString2);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a MapMessage -. use MapMessage method writeBytes to write
+ * a byte[] to the message. Verify the proper conversion support as in 3.11.3
+ */
+ private void mapMessageConversionQTestsBytesCreate() {
+ try {
+ MapMessage messageSent = null;
+ byte[] byteValues = { 1, 2, 3 };
+ boolean pass = true;
+
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionQTestsBytesCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionQTestsBytes");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte[] primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setBytes("byteValues", byteValues);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a MapMessage -. use MapMessage method setString to write
+ * a text string of "mytest string". Verify NumberFormatException is thrown
+ *
+ */
+ private void mapMessageConversionQTestsInvFormatStringCreate() {
+ try {
+ MapMessage messageSent = null;
+ boolean pass = true;
+ String myString = "mytest string";
+
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionQTestsInvFormatStringCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionQTestsInvFormatString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setString("myString", myString);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeChar to write a char. Verify the
+ * proper conversion support as in 3.11.3
+ */
+ private void mapMessageConversionQTestsChar(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionQTestsChar";
+ try {
+ char charValue = 'a';
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // char to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a char - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a char");
+ try {
+ if (messageReceived.getString("charValue").equals(Character.valueOf(charValue).toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: char to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a char - expect MessageFormatException");
+ try {
+ byte[] b = messageReceived.getBytes("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a char - this is not valid");
+ try {
+
+ byte b = messageReceived.getByte("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a char");
+ try {
+ short s = messageReceived.getShort("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to char valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a char ");
+ try {
+ if (messageReceived.getChar("charValue") == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: char to char - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a char ");
+ try {
+ int i = messageReceived.getInt("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a char");
+ try {
+ long l = messageReceived.getLong("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a char - this is not valid");
+ try {
+ float f = messageReceived.getFloat("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a char - this is not valid");
+ try {
+ double d = messageReceived.getDouble("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeInt to write an int. Verify the
+ * proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionQTestsInt(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionQTestsInt";
+ try {
+
+ int intValue = 6;
+ boolean pass = true;
+ // now test conversions for byte
+ // -----------------------------------------------
+ // int to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read an int - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read an int");
+ try {
+ if (messageReceived.getString("intValue").equals(Integer.toString(intValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: int to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read an int - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ byte[] b = messageReceived.getBytes("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read an int - this is not valid");
+ try {
+ byte b = messageReceived.getByte("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read an int");
+ try {
+ short s = messageReceived.getShort("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read an int - this is not valid");
+ try {
+ char c = messageReceived.getChar("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read an int");
+ try {
+ if (messageReceived.getInt("intValue") == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to int - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read an int");
+ try {
+ if (messageReceived.getLong("intValue") == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read an int - this is not valid");
+ try {
+ float f = messageReceived.getFloat("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read an int - this is not valid");
+ try {
+ double d = messageReceived.getDouble("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeLong to write a long. Verify the
+ * proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionQTestsLong(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionQTestsLong";
+ try {
+
+ long longValue = 2;
+ boolean pass = true;
+ // now test conversions for byte
+ // -----------------------------------------------
+ // long to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a long - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a long");
+ try {
+ if (messageReceived.getString("longValue").equals(Long.toString(longValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: long to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a long - expect MessageFormatException");
+ try {
+ byte[] b = messageReceived.getBytes("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read an long - this is not valid");
+ try {
+ byte b = messageReceived.getByte("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a long");
+ try {
+ short s = messageReceived.getShort("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a long - this is not valid");
+ try {
+ char c = messageReceived.getChar("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a long");
+ try {
+ int i = messageReceived.getInt("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a long");
+ try {
+ if (messageReceived.getLong("longValue") == longValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a long - this is not valid");
+ try {
+ float f = messageReceived.getFloat("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a long ");
+ try {
+ double d = messageReceived.getDouble("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeFloat to write a float. Verify the
+ * proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionQTestsFloat(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionQTestsFloat";
+ try {
+ float floatValue = 5;
+ boolean pass = true;
+ // now test conversions for byte
+ // -----------------------------------------------
+ // float to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a float ");
+ try {
+ boolean b = messageReceived.getBoolean("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a float");
+ try {
+ if (messageReceived.getString("floatValue").equals(Float.toString(floatValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: float to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a float ");
+ try {
+ byte[] b = messageReceived.getBytes("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a float ");
+ try {
+ byte b = messageReceived.getByte("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a float");
+ try {
+ short s = messageReceived.getShort("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a long ");
+ try {
+ char c = messageReceived.getChar("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a float");
+ try {
+ int i = messageReceived.getInt("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a long");
+ try {
+ long l = messageReceived.getLong("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a float ");
+ try {
+ if (messageReceived.getFloat("floatValue") == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to float - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to double valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a float ");
+ try {
+ if (messageReceived.getDouble("floatValue") == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to double - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeDouble to write a double. Verify the
+ * proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionQTestsDouble(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionQTestsDouble";
+
+ try {
+
+ double doubleValue = 3;
+ boolean pass = true;
+ // now test conversions for byte
+ // -----------------------------------------------
+ // double to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a double ");
+ try {
+ boolean b = messageReceived.getBoolean("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a double");
+ try {
+ if (messageReceived.getString("doubleValue").equals(Double.toString(doubleValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: double to string");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a double ");
+ try {
+ byte[] b = messageReceived.getBytes("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a double ");
+ try {
+ byte b = messageReceived.getByte("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a double");
+ try {
+ short s = messageReceived.getShort("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a double ");
+ try {
+ char c = messageReceived.getChar("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a double");
+ try {
+ int i = messageReceived.getInt("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a double");
+ try {
+ long l = messageReceived.getLong("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a double ");
+ try {
+ float f = messageReceived.getFloat("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to double valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read an float ");
+ try {
+ if (messageReceived.getDouble("doubleValue") == doubleValue) {
+ logger.log(Logger.Level.TRACE, "Pass: double to double ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeString to write a string. Verify the
+ * proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionQTestsString(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionQTestsString";
+
+ try {
+
+ boolean pass = true;
+ String myString = "10";
+ String myString2 = "true";
+ // now test conversions for String
+ // -----------------------------------------------
+ // string to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a String");
+ try {
+ if (messageReceived.getString("myString").equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: string to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // string to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a String");
+ try {
+ byte[] b = messageReceived.getBytes("myString");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a String");
+ try {
+ if (messageReceived.getByte("myString") == Byte.parseByte(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to byte ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // string to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a string");
+ try {
+ if (messageReceived.getShort("myString") == Short.parseShort(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to short ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a String ");
+ try {
+ char c = messageReceived.getChar("myString");
+ logger.log(Logger.Level.TRACE, "getChar returned " + c);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // string to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a String");
+ try {
+ if (messageReceived.getInt("myString") == Integer.parseInt(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to int ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a String");
+ try {
+ if (messageReceived.getLong("myString") == Long.parseLong(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to long ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a String");
+ try {
+ if (messageReceived.getFloat("myString") == Float.parseFloat(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to float ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a String");
+ try {
+
+ if (messageReceived.getDouble("myString") == Double.parseDouble(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to double ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a string ");
+ try {
+ if (messageReceived.getBoolean("myString2") == Boolean.valueOf(myString2).booleanValue()) {
+ logger.log(Logger.Level.TRACE, "Pass: String to boolean ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a string that is not true");
+ try {
+ boolean b = messageReceived.getBoolean("myString");
+ if (b != false) {
+ logger.log(Logger.Level.TRACE, "Fail: !true should have returned false");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: !true returned false");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeBytes to write a byte[] to the
+ * message. Verify the proper conversion support as in 3.11.3
+ */
+ private void mapMessageConversionQTestsBytes(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionQTestsBytes";
+
+ try {
+
+ byte[] byteValues = { 1, 2, 3 };
+ boolean pass = true;
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // byte[] to byte[] - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a byte[] ");
+ try {
+ byte[] b = messageReceived.getBytes("byteValues");
+ for (int i = 0; i < b.length; i++) {
+ if (b[i] != byteValues[i]) {
+ logger.log(Logger.Level.TRACE, "Fail: byte[] value returned is invalid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte[] returned is valid");
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a byte[]");
+ try {
+ boolean b = messageReceived.getBoolean("byteValues");
+ logger.log(Logger.Level.TRACE,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to string invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a byte[]");
+ try {
+ String s = messageReceived.getString("byteValues");
+ logger.log(Logger.Level.TRACE,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a byte[] - expect MessageFormatException");
+ try {
+ byte b = messageReceived.getByte("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a byte[] - expect MessageFormatException");
+ try {
+ short s = messageReceived.getShort("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a byte[] - expect MessageFormatException");
+ try {
+
+ char c = messageReceived.getChar("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a byte[] - expect MessageFormatException");
+ try {
+ int i = messageReceived.getInt("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a byte[] - expect MessageFormatException");
+ try {
+ long l = messageReceived.getLong("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a byte[] - expect MessageFormatException");
+ try {
+ float f = messageReceived.getFloat("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a byte[] - expect MessageFormatException");
+ try {
+ double d = messageReceived.getDouble("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method setString to write a text string of
+ * "mytest string". Verify NumberFormatException is thrown
+ *
+ */
+ private void mapMessageConversionQTestsInvFormatString(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionQTestsInvFormatString";
+
+ try {
+ boolean pass = true;
+ String myString = "mytest string";
+
+ // -----------------------------------------------
+ // String to byte
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a String that is not valid ");
+ try {
+ byte b = messageReceived.getByte("myString");
+ logger.log(Logger.Level.TRACE, "Fail: java.lang.NumberFormatException expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // string to short
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a string that is not valid ");
+ try {
+ short s = messageReceived.getShort("myString");
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to int
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a String that is not valid ");
+ try {
+ int i = messageReceived.getInt("myString");
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a String that is not valid ");
+ try {
+ long l = messageReceived.getLong("myString");
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a String that is not valid ");
+ try {
+ float f = messageReceived.getFloat("myString");
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to double
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a String that is not valid ");
+ try {
+ double d = messageReceived.getDouble("myString");
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: send test results to response queue (MDB_QUEUE_REPLY) for
+ * verification
+ */
+ private void sendTestResults(String testCase, boolean results) {
+ TextMessage msg = null;
+
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ msg.setStringProperty("TestCase", testCase);
+ msg.setText(testCase);
+ if (results)
+ msg.setStringProperty("Status", "Pass");
+ else
+ msg.setStringProperty("Status", "Fail");
+
+ logger.log(Logger.Level.TRACE, "Sending response message");
+ logger.log(Logger.Level.TRACE, "==================================Test Results from: " + testCase);
+ logger.log(Logger.Level.TRACE, "==================================Status: " + results);
+ mSender.send(msg);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ logger.log(Logger.Level.TRACE, "Error: " + je.getClass().getName() + " was thrown");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.TRACE, "Error: " + ee.getClass().getName() + " was thrown");
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesQ1 In MsgBean::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesQ1 In MsgBean::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ2/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ2/MDBClient.java
deleted file mode 100644
index 6dc7469089..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ2/MDBClient.java
+++ /dev/null
@@ -1,535 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesQ2;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.MDB_Q_Test;
-
-import jakarta.ejb.EJB;
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_MSGQ2_Test")
- private static MDB_Q_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- //
- /*
- * @testName: mdbMessageObjectCopyQTest
- *
- * @assertion_ids: JMS:SPEC:85; JMS:JAVADOC:291;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create an object message. Write a StringBuffer to the message.. modify the
- * StringBuffer and send the msg, verify that it does not effect the msg
- */
- public void mdbMessageObjectCopyQTest() throws Exception {
- String testCase1 = "messageObjectCopyQTestCreate";
- String testCase2 = "messageObjectCopyQTest";
- try {
- // Have the EJB invoke the MDB
- System.out.println("client - run testcase messageObjectCopyQTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out
- .println("client - Check for response from messageObjectCopyQTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: messageObjectCopyQTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionQTestsBoolean
- *
- * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:219;
- * JMS:JAVADOC:150; JMS:JAVADOC:128; JMS:JAVADOC:144; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
- * JMS:JAVADOC:738; JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeBoolean to write a
- * boolean to the message. Verify the proper conversion support as in 3.11.3
- */
-
- public void mdbStreamMessageConversionQTestsBoolean() throws Exception {
- String testCase1 = "streamMessageConversionQTestsBooleanCreate";
- String testCase2 = "streamMessageConversionQTestsBoolean";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionQTestsBooleanCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionQTestsBoolean");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionQTestsBoolean failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionQTestsByte
- *
- * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:152;
- * JMS:JAVADOC:130; JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138;
- * JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:729; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeByte to write a
- * byte. Verify the proper conversion support as in 3.11.3
- */
- public void mdbStreamMessageConversionQTestsByte() throws Exception {
- String testCase1 = "streamMessageConversionQTestsByteCreate";
- String testCase2 = "streamMessageConversionQTestsByte";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionQTestsByteCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionQTestsByte");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionQTestsByte failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionQTestsShort
- *
- * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:154;
- * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144;
- * JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:729; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeShort to write a
- * short. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionQTestsShort() throws Exception {
- String testCase1 = "streamMessageConversionQTestsShortCreate";
- String testCase2 = "streamMessageConversionQTestsShort";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionQTestsShortCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionQTestsShort");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionQTestsShort failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionQTestsInt
- *
- * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:158;
- * JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720;
- * JMS:JAVADOC:723; JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeInt to write an
- * int. Verify the proper conversion support as in 3.11.3
- */
- public void mdbStreamMessageConversionQTestsInt() throws Exception {
- String testCase1 = "streamMessageConversionQTestsIntCreate";
- String testCase2 = "streamMessageConversionQTestsInt";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionQTestsIntCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionQTestsInt");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionQTestsInt failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionQTestsLong
- *
- * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:160;
- * JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeLong to write a
- * long. Verify the proper conversion support as in 3.11.3
- */
- public void mdbStreamMessageConversionQTestsLong() throws Exception {
- String testCase1 = "streamMessageConversionQTestsLongCreate";
- String testCase2 = "streamMessageConversionQTestsLong";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionQTestsLongCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionQTestsLong");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionQTestsLong failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionQTestsFloat
- *
- * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:162;
- * JMS:JAVADOC:140; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeFloat to write a
- * float. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionQTestsFloat() throws Exception {
- String testCase1 = "streamMessageConversionQTestsFloatCreate";
- String testCase2 = "streamMessageConversionQTestsFloat";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionQTestsFloatCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionQTestsFloat");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionQTestsFloat failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionQTestsDouble
- *
- * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:164;
- * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
- * JMS:JAVADOC:738; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeDouble to write a
- * double. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionQTestsDouble() throws Exception {
- String testCase1 = "streamMessageConversionQTestsDoubleCreate";
- String testCase2 = "streamMessageConversionQTestsDouble";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionQTestsDoubleCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionQTestsDouble");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionQTestsDouble failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionQTestsString
- *
- * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:SPEC:77;
- * JMS:JAVADOC:166; JMS:JAVADOC:128; JMS:JAVADOC:130; JMS:JAVADOC:132;
- * JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:140; JMS:JAVADOC:142;
- * JMS:JAVADOC:144; JMS:JAVADOC:729; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeString to write a
- * string. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionQTestsString() throws Exception {
- String testCase1 = "streamMessageConversionQTestsStringCreate";
- String testCase2 = "streamMessageConversionQTestsString";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionQTestsStringCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionQTestsString");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionQTestsString failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionQTestsChar
- *
- * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:156;
- * JMS:JAVADOC:134; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeChar to write a
- * char. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionQTestsChar() throws Exception {
- String testCase1 = "streamMessageConversionQTestsCharCreate";
- String testCase2 = "streamMessageConversionQTestsChar";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionQTestsCharCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionQTestsChar");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionQTestsChar failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionQTestsBytes
- *
- * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:168;
- * JMS:JAVADOC:146; JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:725;
- * JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:744;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeBytes to write a
- * byte[] to the message. Verify the proper conversion support as in 3.11.3
- */
- public void mdbStreamMessageConversionQTestsBytes() throws Exception {
- String testCase1 = "streamMessageConversionQTestsBytesCreate";
- String testCase2 = "streamMessageConversionQTestsBytes";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionQTestsBytesCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionQTestsBytes");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionQTestsBytes failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionQTestsInvFormatString
- *
- * @assertion_ids: JMS:SPEC:76; JMS:SPEC:81; JMS:JAVADOC:166; JMS:JAVADOC:130;
- * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:140;
- * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeString to write a
- * text string of "mytest string". Verify NumberFormatException is thrown
- * Verify that the pointer was not incremented by doing a read string
- *
- */
- public void mdbStreamMessageConversionQTestsInvFormatString() throws Exception {
- String testCase1 = "streamMessageConversionQTestsInvFormatStringCreate";
- String testCase2 = "streamMessageConversionQTestsInvFormatString";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionQTestsInvFormatStringCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionQTestsInvFormatString");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: streamMessageConversionQTestsInvFormatString failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageQTestsFullMsg
- *
- * @assertion_ids: JMS:SPEC:82; JMS:JAVADOC:150; JMS:JAVADOC:152;
- * JMS:JAVADOC:154; JMS:JAVADOC:156; JMS:JAVADOC:158; JMS:JAVADOC:160;
- * JMS:JAVADOC:162; JMS:JAVADOC:164; JMS:JAVADOC:166; JMS:JAVADOC:168;
- * JMS:JAVADOC:170; JMS:JAVADOC:172; JMS:JAVADOC:128; JMS:JAVADOC:130;
- * JMS:JAVADOC:132; JMS:JAVADOC:134; JMS:JAVADOC:136; JMS:JAVADOC:138;
- * JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
- * JMS:JAVADOC:148;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. write one of each primitive type. Send the
- * message. Verify the data received was as sent.
- */
- public void mdbStreamMessageQTestsFullMsg() throws Exception {
- String testCase1 = "streamMessageQTestsFullMsgCreate";
- String testCase2 = "streamMessageQTestsFullMsg";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase streamMessageQTestsFullMsgCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageQTestsFullMsg");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageQTestsFullMsg failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageQTestNull
- *
- * @assertion_ids: JMS:SPEC:78; JMS:SPEC:86; JMS:JAVADOC:144; JMS:JAVADOC:172;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. Use writeString to write a null, then use
- * readString to read it back.
- */
- public void mdbStreamMessageQTestNull() throws Exception {
- String testCase1 = "streamMessageQTestNullCreate";
- String testCase2 = "streamMessageQTestNull";
- try {
- // Have the EJB invoke the MDB
- System.out.println("client - run testcase streamMessageQTestNullCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out
- .println("client - Check for response from streamMessageQTestNull");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageQTestNull failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- ;
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ2/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ2/MDBClientIT.java
new file mode 100644
index 0000000000..357daf1cad
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ2/MDBClientIT.java
@@ -0,0 +1,527 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesQ2;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.commonee.MDB_Q_Test;
+
+import jakarta.ejb.EJB;
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_MSGQ2_Test")
+ private static MDB_Q_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+
+ hr.setup(props);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ //
+ /*
+ * @testName: mdbMessageObjectCopyQTest
+ *
+ * @assertion_ids: JMS:SPEC:85; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create an object message. Write a StringBuffer to the message.. modify the
+ * StringBuffer and send the msg, verify that it does not effect the msg
+ */
+ @Test
+ public void mdbMessageObjectCopyQTest() throws Exception {
+ String testCase1 = "messageObjectCopyQTestCreate";
+ String testCase2 = "messageObjectCopyQTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase messageObjectCopyQTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from messageObjectCopyQTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: messageObjectCopyQTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionQTestsBoolean
+ *
+ * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:219;
+ * JMS:JAVADOC:150; JMS:JAVADOC:128; JMS:JAVADOC:144; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
+ * JMS:JAVADOC:738; JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeBoolean to write a
+ * boolean to the message. Verify the proper conversion support as in 3.11.3
+ */
+ @Test
+ public void mdbStreamMessageConversionQTestsBoolean() throws Exception {
+ String testCase1 = "streamMessageConversionQTestsBooleanCreate";
+ String testCase2 = "streamMessageConversionQTestsBoolean";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionQTestsBooleanCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionQTestsBoolean");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionQTestsBoolean failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionQTestsByte
+ *
+ * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:152;
+ * JMS:JAVADOC:130; JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138;
+ * JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:729; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeByte to write a byte.
+ * Verify the proper conversion support as in 3.11.3
+ */
+ @Test
+ public void mdbStreamMessageConversionQTestsByte() throws Exception {
+ String testCase1 = "streamMessageConversionQTestsByteCreate";
+ String testCase2 = "streamMessageConversionQTestsByte";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionQTestsByteCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionQTestsByte");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionQTestsByte failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionQTestsShort
+ *
+ * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:154;
+ * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144;
+ * JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:729; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeShort to write a
+ * short. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionQTestsShort() throws Exception {
+ String testCase1 = "streamMessageConversionQTestsShortCreate";
+ String testCase2 = "streamMessageConversionQTestsShort";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionQTestsShortCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionQTestsShort");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionQTestsShort failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionQTestsInt
+ *
+ * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:158;
+ * JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720;
+ * JMS:JAVADOC:723; JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeInt to write an int.
+ * Verify the proper conversion support as in 3.11.3
+ */
+ @Test
+ public void mdbStreamMessageConversionQTestsInt() throws Exception {
+ String testCase1 = "streamMessageConversionQTestsIntCreate";
+ String testCase2 = "streamMessageConversionQTestsInt";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionQTestsIntCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionQTestsInt");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionQTestsInt failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionQTestsLong
+ *
+ * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:160;
+ * JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeLong to write a long.
+ * Verify the proper conversion support as in 3.11.3
+ */
+ @Test
+ public void mdbStreamMessageConversionQTestsLong() throws Exception {
+ String testCase1 = "streamMessageConversionQTestsLongCreate";
+ String testCase2 = "streamMessageConversionQTestsLong";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionQTestsLongCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionQTestsLong");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionQTestsLong failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionQTestsFloat
+ *
+ * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:162;
+ * JMS:JAVADOC:140; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeFloat to write a
+ * float. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionQTestsFloat() throws Exception {
+ String testCase1 = "streamMessageConversionQTestsFloatCreate";
+ String testCase2 = "streamMessageConversionQTestsFloat";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionQTestsFloatCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionQTestsFloat");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionQTestsFloat failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionQTestsDouble
+ *
+ * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:164;
+ * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
+ * JMS:JAVADOC:738; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeDouble to write a
+ * double. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionQTestsDouble() throws Exception {
+ String testCase1 = "streamMessageConversionQTestsDoubleCreate";
+ String testCase2 = "streamMessageConversionQTestsDouble";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionQTestsDoubleCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionQTestsDouble");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionQTestsDouble failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionQTestsString
+ *
+ * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:SPEC:77; JMS:JAVADOC:166;
+ * JMS:JAVADOC:128; JMS:JAVADOC:130; JMS:JAVADOC:132; JMS:JAVADOC:136;
+ * JMS:JAVADOC:138; JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144;
+ * JMS:JAVADOC:729; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeString to write a
+ * string. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionQTestsString() throws Exception {
+ String testCase1 = "streamMessageConversionQTestsStringCreate";
+ String testCase2 = "streamMessageConversionQTestsString";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionQTestsStringCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionQTestsString");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionQTestsString failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionQTestsChar
+ *
+ * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:156;
+ * JMS:JAVADOC:134; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeChar to write a char.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionQTestsChar() throws Exception {
+ String testCase1 = "streamMessageConversionQTestsCharCreate";
+ String testCase2 = "streamMessageConversionQTestsChar";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionQTestsCharCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionQTestsChar");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionQTestsChar failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionQTestsBytes
+ *
+ * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:168;
+ * JMS:JAVADOC:146; JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:725;
+ * JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:744;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeBytes to write a
+ * byte[] to the message. Verify the proper conversion support as in 3.11.3
+ */
+ @Test
+ public void mdbStreamMessageConversionQTestsBytes() throws Exception {
+ String testCase1 = "streamMessageConversionQTestsBytesCreate";
+ String testCase2 = "streamMessageConversionQTestsBytes";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionQTestsBytesCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionQTestsBytes");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionQTestsBytes failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionQTestsInvFormatString
+ *
+ * @assertion_ids: JMS:SPEC:76; JMS:SPEC:81; JMS:JAVADOC:166; JMS:JAVADOC:130;
+ * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:140;
+ * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeString to write a
+ * text string of "mytest string". Verify NumberFormatException is thrown Verify
+ * that the pointer was not incremented by doing a read string
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionQTestsInvFormatString() throws Exception {
+ String testCase1 = "streamMessageConversionQTestsInvFormatStringCreate";
+ String testCase2 = "streamMessageConversionQTestsInvFormatString";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionQTestsInvFormatStringCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionQTestsInvFormatString");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionQTestsInvFormatString failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageQTestsFullMsg
+ *
+ * @assertion_ids: JMS:SPEC:82; JMS:JAVADOC:150; JMS:JAVADOC:152;
+ * JMS:JAVADOC:154; JMS:JAVADOC:156; JMS:JAVADOC:158; JMS:JAVADOC:160;
+ * JMS:JAVADOC:162; JMS:JAVADOC:164; JMS:JAVADOC:166; JMS:JAVADOC:168;
+ * JMS:JAVADOC:170; JMS:JAVADOC:172; JMS:JAVADOC:128; JMS:JAVADOC:130;
+ * JMS:JAVADOC:132; JMS:JAVADOC:134; JMS:JAVADOC:136; JMS:JAVADOC:138;
+ * JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
+ * JMS:JAVADOC:148;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. write one of each primitive type. Send the message.
+ * Verify the data received was as sent.
+ */
+ @Test
+ public void mdbStreamMessageQTestsFullMsg() throws Exception {
+ String testCase1 = "streamMessageQTestsFullMsgCreate";
+ String testCase2 = "streamMessageQTestsFullMsg";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageQTestsFullMsgCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageQTestsFullMsg");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageQTestsFullMsg failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageQTestNull
+ *
+ * @assertion_ids: JMS:SPEC:78; JMS:SPEC:86; JMS:JAVADOC:144; JMS:JAVADOC:172;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. Use writeString to write a null, then use
+ * readString to read it back.
+ */
+ @Test
+ public void mdbStreamMessageQTestNull() throws Exception {
+ String testCase1 = "streamMessageQTestNullCreate";
+ String testCase2 = "streamMessageQTestNull";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageQTestNullCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageQTestNull");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageQTestNull failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ ;
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ2/MsgBeanMsgTestQ2.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ2/MsgBeanMsgTestQ2.java
index a9674d5cb5..81b5ad8194 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ2/MsgBeanMsgTestQ2.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ2/MsgBeanMsgTestQ2.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesQ2;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.TSNamingContext;
@@ -43,3483 +44,3254 @@
public class MsgBeanMsgTestQ2 implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- private MessageDrivenContext mdc = null;
-
- // JMS
- private QueueConnectionFactory qFactory = null;
-
- private QueueConnection qConnection = null;
-
- private Queue queueR = null;
-
- private Queue queue = null;
-
- private QueueSender mSender = null;
-
- private QueueSession qSession = null;
-
- public MsgBeanMsgTestQ2() {
- TestUtil.logTrace("@MsgBeanMsgTestQ2()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgTypesQ2 - @MsgBeanMsgTestQ2-ejbCreate() !!");
- try {
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- if (qFactory == null) {
- TestUtil.logTrace("qFactory error");
- }
- TestUtil.logTrace("got a qFactory !!");
-
- queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- if (queueR == null) {
- TestUtil.logTrace("queueR error");
- }
-
- queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
- if (queue == null) {
- TestUtil.logTrace("queue error");
- }
-
- p = new Properties();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
-
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("from jms.ee.mdb.mdb_msgTypesQ2 @onMessage!" + msg);
-
- try {
- TestUtil.logTrace(
- "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null) {
- TestUtil.logTrace("connection error");
- } else {
- qConnection.start();
- qSession = qConnection.createQueueSession(true, 0);
- }
-
- if (msg.getStringProperty("TestCase")
- .equals("messageObjectCopyQTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running messageObjectCopyQTestCreate - create the message");
- messageObjectCopyQTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("messageObjectCopyQTest")) {
- TestUtil.logTrace(
- "@onMessage - running messageObjectCopyQTest - read and verify the message");
- messageObjectCopyQTest((jakarta.jms.ObjectMessage) msg);
- }
- if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsBooleanCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsBooleanCreate - create the message");
- streamMessageConversionQTestsBooleanCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsBoolean")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsBoolean - read and verify the message");
- streamMessageConversionQTestsBoolean((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsByteCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsByteCreate - create the message");
- streamMessageConversionQTestsByteCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsByte")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsByte - read and verify the message");
- streamMessageConversionQTestsByte((jakarta.jms.StreamMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsShortCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsShortCreate - create the message");
- streamMessageConversionQTestsShortCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsShort")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsShort - read and verify the message");
- streamMessageConversionQTestsShort((jakarta.jms.StreamMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsIntCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsIntCreate - create the message");
- streamMessageConversionQTestsIntCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsInt")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsInt - read and verify the message");
- streamMessageConversionQTestsInt((jakarta.jms.StreamMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsLongCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsLongCreate - create the message");
- streamMessageConversionQTestsLongCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsLong")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsLong - read and verify the message");
- streamMessageConversionQTestsLong((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsFloatCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsFloatCreate - create the message");
- streamMessageConversionQTestsFloatCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsFloat")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsFloat - read and verify the message");
- streamMessageConversionQTestsFloat((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsDoubleCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsDoubleCreate - create the message");
- streamMessageConversionQTestsDoubleCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsDouble")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsDouble - read and verify the message");
- streamMessageConversionQTestsDouble((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsStringCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsStringCreate - create the message");
- streamMessageConversionQTestsStringCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsString")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsString - read and verify the message");
- streamMessageConversionQTestsString((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsCharCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsCharCreate - create the message");
- streamMessageConversionQTestsCharCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsChar")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsChar - read and verify the message");
- streamMessageConversionQTestsChar((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsBytesCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsBytesCreate - create the message");
- streamMessageConversionQTestsBytesCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsBytes")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsBytes - read and verify the message");
- streamMessageConversionQTestsBytes((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsInvFormatStringCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsInvFormatStringCreate - create the message");
- streamMessageConversionQTestsInvFormatStringCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionQTestsInvFormatString")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionQTestsInvFormatString - read and verify the message");
- streamMessageConversionQTestsInvFormatString(
- (jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageQTestsFullMsgCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageQTestsFullMsgCreate - create the message");
- streamMessageQTestsFullMsgCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageQTestsFullMsg")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageQTestsFullMsg - read and verify the message");
- streamMessageQTestsFullMsg((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageQTestNullCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageQTestNullCreate - create the message");
- streamMessageQTestNullCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageQTestNull")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageQTestNull - read and verify the message");
- streamMessageQTestNull((jakarta.jms.StreamMessage) msg);
- }
-
- else {
- TestUtil.logTrace(
- "@onMessage - invalid message type found in StringProperty");
- }
- TestUtil.logTrace("@onMessage - Finished for this test!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
-
- }
-
- /*
- * Description: Create an object message. Write a StringBuffer to the message.
- * modify the StringBuffer and send the msg, verify that it does not effect
- * the msg
- */
- public void messageObjectCopyQTestCreate() {
- boolean pass = true;
- try {
- ObjectMessage messageSentObjectMsg = null;
- StringBuffer sBuff = new StringBuffer("This is");
- String initial = "This is";
- messageSentObjectMsg = qSession.createObjectMessage();
- JmsUtil.addPropsToMessage(messageSentObjectMsg, p);
- messageSentObjectMsg.setObject(sBuff);
- sBuff.append("a test ");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "messageObjectCopyQTest");
- // set up testcase so onMessage invokes the correct method
- messageSentObjectMsg.setStringProperty("TestCase",
- "messageObjectCopyQTest");
-
- mSender = qSession.createSender(queue);
- mSender.send(messageSentObjectMsg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage -. use StreamMessage method
- * writeBoolean to write a boolean to the message. Verify the proper
- * conversion support as in 3.11.3
- */
- private void streamMessageConversionQTestsBooleanCreate() {
- try {
- StreamMessage messageSent = null;
- boolean abool = true;
-
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsBoolean");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for boolean primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionQTestsBoolean");
- messageSent.writeBoolean(abool);
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage -. use StreamMessage method writeByte
- * to write a byte. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsByteCreate() {
- try {
- StreamMessage messageSent = null;
-
- byte bValue = 127;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsByte");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionQTestsByte");
-
- messageSent.writeByte(bValue);
- // send the message and then get it back
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a StreamMessage -. use StreamMessage method writeShort
- * to write a short. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsShortCreate() {
- try {
- StreamMessage messageSent = null;
- short sValue = 1;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsShort");
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionQTestsShort");
- messageSent.writeShort(sValue);
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a StreamMessage -. use StreamMessage method writeInt to
- * write an int. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsIntCreate() {
- try {
- StreamMessage messageSent = null;
- int iValue = 6;
-
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsInt");
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionQTestsInt");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- messageSent.writeInt(iValue);
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a StreamMessage -. use StreamMessage method writeLong
- * to write a long. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsLongCreate() {
- try {
- StreamMessage messageSent = null;
- long lValue = 2;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsLong");
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionQTestsLong");
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- messageSent.writeLong(lValue);
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a StreamMessage -. use StreamMessage method writeFloat
- * to write a float. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsFloatCreate() {
- try {
- StreamMessage messageSent = null;
-
- float fValue = 5;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsFloat");
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionQTestsFloat");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.writeFloat(fValue);
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage -. use StreamMessage method writeDouble
- * to write a double. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsDoubleCreate() {
- try {
- StreamMessage messageSent = null;
-
- double dValue = 3;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsDouble");
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionQTestsDouble");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.writeDouble(dValue);
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a StreamMessage -. use StreamMessage method writeString
- * to write a string. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsStringCreate() {
- try {
- StreamMessage messageSent = null;
- String myString = "10";
-
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsString");
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionQTestsString");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.writeString(myString);
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a StreamMessage -. use StreamMessage method writeChar
- * to write a char. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsCharCreate() {
- try {
- StreamMessage messageSent = null;
-
- char charValue = 'a';
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsChar");
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionQTestsChar");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.writeChar(charValue);
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage -. use StreamMessage method writeBytes
- * to write a byte[] to the message. Verify the proper conversion support as
- * in 3.11.3
- */
- private void streamMessageConversionQTestsBytesCreate() {
- try {
- StreamMessage messageSent = null;
- byte[] bValues = { 1, 2, 3 };
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsBytes");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte[] primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionQTestsBytes");
-
- messageSent.writeBytes(bValues);
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage -. use StreamMessage method writeString
- * to write a text string of "mytest string". Verify NumberFormatException is
- * thrown Verify that the pointer was not incremented by doing a read string
- *
- */
- private void streamMessageConversionQTestsInvFormatStringCreate() {
- try {
- StreamMessage messageSent = null;
- String myString = "mytest string";
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionQTestsInvFormatString");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionQTestsInvFormatString");
- messageSent.writeString(myString);
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage -. write one of each primitive type.
- * Send the message. Verify the data received was as sent.
- *
- */
- private void streamMessageQTestsFullMsgCreate() {
- try {
-
- StreamMessage messageSent = null;
-
- byte bValue = 127;
- boolean abool = false;
- byte[] bValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
- byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
- char charValue = 'Z';
- short sValue = 32767;
- long lValue = 9223372036854775807L;
- double dValue = 6.02e23;
- float fValue = 6.02e23f;
- int iValue = 6;
- boolean pass = true;
- String myString = "text";
- String sTesting = "Testing StreamMessages";
-
- int nCount;
-
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageQTestsFullMsg");
-
- messageSent.writeBytes(bValues2, 0, bValues2.length);
- messageSent.writeBoolean(abool);
- messageSent.writeByte(bValue);
- messageSent.writeBytes(bValues);
- messageSent.writeChar(charValue);
- messageSent.writeDouble(dValue);
- messageSent.writeFloat(fValue);
- messageSent.writeInt(iValue);
- messageSent.writeLong(lValue);
- messageSent.writeObject(sTesting);
- messageSent.writeShort(sValue);
- messageSent.writeString(myString);
-
- // the next line causes a Message Format exception to be thrown
- // temporarily comment this out.
- messageSent.writeObject(null);
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase", "streamMessageQTestsFullMsg");
-
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage Use writeString to write a null, then
- * use readString to read it back.
- */
- private void streamMessageQTestNullCreate() {
- try {
- StreamMessage messageSent = null;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageQTestNull");
- // -----------------------------------------------------------------------------
- TestUtil.logTrace("writeString(null) ");
- // -----------------------------------------------------------------------------
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase", "streamMessageQTestNull");
- messageSent.writeString(null);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read ObjectMessage created by messageObjectCopyQTestCreate.
- * verify that modifying the sBuff object after the write does not effect the
- * msg
- */
- public void messageObjectCopyQTest(
- jakarta.jms.ObjectMessage messageReceivedObjectMsg) {
- boolean pass = true;
- String testCase = "messageObjectCopyQTest";
- String initial = "This is";
- try {
- TestUtil
- .logMsg("Ensure that changing the object did not change the message");
- StringBuffer s = (StringBuffer) messageReceivedObjectMsg.getObject();
- TestUtil.logTrace("s is " + s);
- if (s.toString().equals(initial)) {
- TestUtil.logTrace("Pass: msg was not changed");
- } else {
- TestUtil.logTrace("Fail: msg was changed!");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- */
- private void streamMessageConversionQTestsBoolean(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionQTestsBoolean";
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- boolean pass = true;
-
- // now test conversions for boolean
- // -----------------------------------------------
- // boolean to boolean - valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a boolean");
- try {
- if (messageReceived.readBoolean() == abool) {
- TestUtil.logTrace("Pass: boolean to boolean - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a boolean");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString()
- .equals((Boolean.valueOf(abool)).toString())) {
- TestUtil.logTrace("Pass: boolean to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to byte[] invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read a boolean - expect MessageFormatException");
- int nCount = 0;
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
- // -----------------------------------------------
- // boolean to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readByte to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- bValue = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readShort to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
-
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readChar to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // boolean to int invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readInt to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readInt();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readLong to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readLong();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to float invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readFloat to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
-
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to double invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readDouble to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
-
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsByte(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionQTestsByte";
- try {
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
- // now test conversions for byte
- // -----------------------------------------------
- // byte to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a byte");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Byte.toString(bValue))) {
- TestUtil.logTrace("Pass: byte to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read a byte - expect MessageFormatException");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // byte to byte valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a byte");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readByte() == bValue) {
- TestUtil.logTrace("Pass: byte to byte - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to short valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a byte");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readShort() == bValue) {
- TestUtil.logTrace("Pass: byte to short - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- pass = false;
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a byte");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == bValue) {
- TestUtil.logTrace("Pass: byte to int - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a byte");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == bValue) {
- TestUtil.logTrace("Pass: byte to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsShort(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionQTestsShort";
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // short to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a short - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a short");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Short.toString(sValue))) {
- TestUtil.logTrace("Pass: short to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read a short - expect MessageFormatException");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // short to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a short - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to short valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a short");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readShort() == sValue) {
- TestUtil.logTrace("Pass: short to short - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a short - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a byte");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == sValue) {
- TestUtil.logTrace("Pass: short to int - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a short");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == sValue) {
- TestUtil.logTrace("Pass: short to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a short - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read a short - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsInt(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionQTestsInt";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // int to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read an int - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read an int");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Integer.toString(iValue))) {
- TestUtil.logTrace("Pass: int to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read an int - expect MessageFormatException");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // int to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read an int - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read an int");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read an int - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read an int");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == iValue) {
- TestUtil.logTrace("Pass: int to int - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read an int");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == iValue) {
- TestUtil.logTrace("Pass: int to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read an int - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read an int - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- */
- private void streamMessageConversionQTestsLong(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionQTestsLong";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // long to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a long - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a long");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Long.toString(lValue))) {
- TestUtil.logTrace("Pass: long to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read a long - expect MessageFormatException");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // long to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read an long - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a long");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a long - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a long");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a long");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == lValue) {
- TestUtil.logTrace("Pass: int to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a long - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read an long - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- */
- private void streamMessageConversionQTestsFloat(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionQTestsFloat";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // float to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a float ");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a float");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Float.toString(fValue))) {
- TestUtil.logTrace("Pass: float to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBytes[] to read a float ");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // float to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a float ");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a float");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // float to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a long ");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a float");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a long");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to float valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a float ");
- try {
- messageReceived.reset();
- if (messageReceived.readFloat() == fValue) {
- TestUtil.logTrace("Pass: float to float - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read an float ");
- try {
- messageReceived.reset();
- if (messageReceived.readDouble() == fValue) {
- TestUtil.logTrace("Pass: float to double - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsDouble(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionQTestsDouble";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // double to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a double ");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a double");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Double.toString(dValue))) {
- TestUtil.logTrace("Pass: double to string");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBytes[] to read a double ");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // double to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a double ");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a double");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // double to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a double ");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a double");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a double");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // double to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a double ");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to double valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read a double ");
- try {
- messageReceived.reset();
- if (messageReceived.readDouble() == dValue) {
- TestUtil.logTrace("Pass: double to double ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- */
- private void streamMessageConversionQTestsString(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionQTestsString";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
- String myString = "10";
-
- // now test conversions for String
- // -----------------------------------------------
- // string to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a String");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(myString)) {
- TestUtil.logTrace("Pass: string to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // string to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBytes[] to read a String");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // String to byte valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a String");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readByte() == Byte.parseByte(myString)) {
- TestUtil.logTrace("Pass: String to byte ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // string to short valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a string");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readShort() == Short.parseShort(myString)) {
- TestUtil.logTrace("Pass: String to short ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a String ");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // string to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a String");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == Integer.parseInt(myString)) {
- TestUtil.logTrace("Pass: String to int ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a String");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == Long.parseLong(myString)) {
- TestUtil.logTrace("Pass: String to long ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a String");
- try {
- messageReceived.reset();
- if (messageReceived.readFloat() == Float.parseFloat(myString)) {
- TestUtil.logTrace("Pass: String to float ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to double valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read a String");
- try {
- messageReceived.reset();
- if (messageReceived.readDouble() == Double.parseDouble(myString)) {
- TestUtil.logTrace("Pass: String to double ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a string ");
- try {
- messageReceived.clearBody();
- messageReceived.writeString("true");
- messageReceived.reset();
- if (messageReceived.readBoolean() == abool) {
- TestUtil.logTrace("Pass: String to boolean ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a string that is !true ");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- if (b != true) {
- TestUtil.logTrace("Fail: !true should return false");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: !true returned false");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- *
- */
- private void streamMessageConversionQTestsChar(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionQTestsChar";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // char to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a char - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a char");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- String s = messageReceived.readString();
- TestUtil.logTrace("char returned for \"a\" is : " + s);
- if (s.equals("a")) {
- TestUtil.logTrace("Pass: char to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read a char - expect MessageFormatException");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // char to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a char - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a char");
- try {
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // char to char valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a char ");
- try {
- messageReceived.reset();
- if (messageReceived.readChar() == 'a') {
- TestUtil.logTrace("Pass: char to char - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a char ");
- try {
- messageReceived.reset();
- int i = messageReceived.readInt();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // char to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a char");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // char to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a char - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to double invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read a char - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- */
- private void streamMessageConversionQTestsBytes(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionQTestsBytes";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues2 = { 0, 0, 0 };
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for boolean
- // -----------------------------------------------
- // byte[] to byte[] - valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBytes[] to read a byte[] ");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readBytes(bValues2) == 3) { // count should be 3.
- TestUtil.logTrace("Pass: byte[] to byte[] - valid");
- } else {
- TestUtil.logTrace("Fail: count incorrect");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a byte[]");
- // position to beginning of stream message.
- messageReceived.reset();
- try {
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to string invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a byte[]");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- String s = messageReceived.readString();
- TestUtil.logTrace(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readByte to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readShort to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readChar to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to int invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readInt to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readLong to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to float invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readFloat to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to double invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readDouble to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (jakarta.jms.MessageFormatException e) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Read a StreamMessage -. Verify NumberFormatException is thrown
- * Verify that the pointer was not incremented by doing a read string
- *
- */
- private void streamMessageConversionQTestsInvFormatString(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionQTestsInvFormatString";
-
- try {
-
- boolean pass = true;
- String myString = "mytest string";
-
- // -----------------------------------------------
- // String to byte
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a String that is not valid ");
- try {
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: java.lang.NumberFormatException expected");
- pass = false;
- } catch (java.lang.NumberFormatException e) {
- TestUtil.logTrace(
- "Pass: java.lang.NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // pointer should not have moved
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Verify that the data can be read as a string and pointer did not move");
- try {
- String s = messageReceived.readString();
- TestUtil.logTrace("message read: " + s);
- if (s.equals(myString)) {
- TestUtil.logTrace("Pass: able to read the string");
- } else {
- TestUtil.logTrace("Fail: string not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to short
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a string that is not valid ");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (java.lang.NumberFormatException e) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to int
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a String that is not valid ");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- } catch (java.lang.NumberFormatException e) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a String that is not valid ");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (java.lang.NumberFormatException e) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a String that is not valid ");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (java.lang.NumberFormatException e) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to double
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read a String that is not valid ");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (java.lang.NumberFormatException e) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the data received was as sent.
- *
- */
- private void streamMessageQTestsFullMsg(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageQTestsFullMsg";
-
- try {
- byte bValue = 127;
- boolean abool = false;
- byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
- byte[] bValuesReturned = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- byte[] bValuesReturned2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- char charValue = 'Z';
- short sValue = 32767;
- long lValue = 9223372036854775807L;
- double dValue = 6.02e23;
- float fValue = 6.02e23f;
- int iValue = 6;
- boolean pass = true;
- String myString = "text";
- String sTesting = "Testing StreamMessages";
-
- try {
- int nCount = bValuesReturned2.length;
- do {
- nCount = messageReceived.readBytes(bValuesReturned2);
- TestUtil.logTrace("nCount is " + nCount);
- if (nCount != -1) {
- for (int i = 0; i < bValuesReturned2.length; i++) {
- if (bValuesReturned2[i] != bValues2[i]) {
- TestUtil.logTrace("Fail: byte[] " + i + " is not valid");
- pass = false;
- } else {
- TestUtil.logTrace("PASS: byte[]" + i + " is valid");
- }
- }
- }
- } while (nCount >= bValuesReturned2.length);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readBoolean() == abool) {
- TestUtil.logTrace("Pass: boolean returned ok");
- } else {
- TestUtil.logTrace("Fail: boolean not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readByte() == bValue) {
- TestUtil.logTrace("Pass: Byte returned ok");
- } else {
- TestUtil.logTrace("Fail: Byte not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- int nCount = bValuesReturned.length;
- do {
- nCount = messageReceived.readBytes(bValuesReturned);
- TestUtil.logTrace("nCount is " + nCount);
- if (nCount != -1) {
- for (int i = 0; i < bValuesReturned2.length; i++) {
- if (bValuesReturned2[i] != bValues2[i]) {
- TestUtil.logTrace("Fail: byte[] " + i + " is not valid");
- pass = false;
- } else {
- TestUtil.logTrace("PASS: byte[]" + i + " is valid");
- }
- }
- }
- } while (nCount >= bValuesReturned.length);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readChar() == charValue) {
- TestUtil.logTrace("Pass: correct char");
- } else {
- TestUtil.logTrace("Fail: char not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readDouble() == dValue) {
- TestUtil.logTrace("Pass: correct double");
- } else {
- TestUtil.logTrace("Fail: double not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readFloat() == fValue) {
- TestUtil.logTrace("Pass: correct float");
- } else {
- TestUtil.logTrace("Fail: float not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readInt() == iValue) {
- TestUtil.logTrace("Pass: correct int");
- } else {
- TestUtil.logTrace("Fail: int not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readLong() == lValue) {
- TestUtil.logTrace("Pass: correct long");
- } else {
- TestUtil.logTrace("Fail: long not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readObject().equals(sTesting)) {
- TestUtil.logTrace("Pass: correct object");
- } else {
- TestUtil.logTrace("Fail: object not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readShort() == sValue) {
- TestUtil.logTrace("Pass: correct short");
- } else {
- TestUtil.logTrace("Fail: short not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readString().equals(myString)) {
- TestUtil.logTrace("Pass: correct string");
- } else {
- TestUtil.logTrace("Fail: string not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readObject() == null) {
- TestUtil.logTrace("Pass: correct object");
- } else {
- TestUtil.logTrace("Fail: object not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage Use readString to read back a null
- */
- private void streamMessageQTestNull(jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageQTestNull";
- try {
- boolean pass = true;
- try {
- if (messageReceived.readObject() == null) {
- TestUtil.logTrace("Pass: Read a null");
- } else {
- TestUtil.logTrace("Fail: null value not returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error trying to read a null object");
- TestUtil.logTrace("Error: unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: send test results to response queue (MDB_QUEUE_REPLY) for
- * verification
- */
- private void sendTestResults(String testCase, boolean results) {
- TextMessage msg = null;
-
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- msg.setStringProperty("TestCase", testCase);
- msg.setText(testCase);
- if (results)
- msg.setStringProperty("Status", "Pass");
- else
- msg.setStringProperty("Status", "Fail");
-
- TestUtil.logTrace("Sending response message");
- mSender.send(msg);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- TestUtil.logTrace("Error: " + je.getClass().getName() + " was thrown");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logTrace("Error: " + ee.getClass().getName() + " was thrown");
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgTypesQ2 In MsgBeanMsgTestQ2::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil
- .logTrace("jms.ee.mdb.mdb_msgTypesQ2 In MsgBeanMsgTestQ2::remove()!!");
- }
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ private MessageDrivenContext mdc = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanMsgTestQ2.class.getName());
+
+ // JMS
+ private QueueConnectionFactory qFactory = null;
+
+ private QueueConnection qConnection = null;
+
+ private Queue queueR = null;
+
+ private Queue queue = null;
+
+ private QueueSender mSender = null;
+
+ private QueueSession qSession = null;
+
+ public MsgBeanMsgTestQ2() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanMsgTestQ2()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesQ2 - @MsgBeanMsgTestQ2-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ if (qFactory == null) {
+ logger.log(Logger.Level.TRACE, "qFactory error");
+ }
+ logger.log(Logger.Level.TRACE, "got a qFactory !!");
+
+ queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ if (queueR == null) {
+ logger.log(Logger.Level.TRACE, "queueR error");
+ }
+
+ queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
+ if (queue == null) {
+ logger.log(Logger.Level.TRACE, "queue error");
+ }
+
+ p = new Properties();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "from jms.ee.mdb.mdb_msgTypesQ2 @onMessage!" + msg);
+
+ try {
+ logger.log(Logger.Level.TRACE, "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null) {
+ logger.log(Logger.Level.TRACE, "connection error");
+ } else {
+ qConnection.start();
+ qSession = qConnection.createQueueSession(true, 0);
+ }
+
+ if (msg.getStringProperty("TestCase").equals("messageObjectCopyQTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running messageObjectCopyQTestCreate - create the message");
+ messageObjectCopyQTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("messageObjectCopyQTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running messageObjectCopyQTest - read and verify the message");
+ messageObjectCopyQTest((jakarta.jms.ObjectMessage) msg);
+ }
+ if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsBooleanCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsBooleanCreate - create the message");
+ streamMessageConversionQTestsBooleanCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsBoolean")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsBoolean - read and verify the message");
+ streamMessageConversionQTestsBoolean((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsByteCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsByteCreate - create the message");
+ streamMessageConversionQTestsByteCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsByte")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsByte - read and verify the message");
+ streamMessageConversionQTestsByte((jakarta.jms.StreamMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsShortCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsShortCreate - create the message");
+ streamMessageConversionQTestsShortCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsShort")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsShort - read and verify the message");
+ streamMessageConversionQTestsShort((jakarta.jms.StreamMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsIntCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsIntCreate - create the message");
+ streamMessageConversionQTestsIntCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsInt")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsInt - read and verify the message");
+ streamMessageConversionQTestsInt((jakarta.jms.StreamMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsLongCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsLongCreate - create the message");
+ streamMessageConversionQTestsLongCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsLong")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsLong - read and verify the message");
+ streamMessageConversionQTestsLong((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsFloatCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsFloatCreate - create the message");
+ streamMessageConversionQTestsFloatCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsFloat")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsFloat - read and verify the message");
+ streamMessageConversionQTestsFloat((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsDoubleCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsDoubleCreate - create the message");
+ streamMessageConversionQTestsDoubleCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsDouble")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsDouble - read and verify the message");
+ streamMessageConversionQTestsDouble((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsStringCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsStringCreate - create the message");
+ streamMessageConversionQTestsStringCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsString")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsString - read and verify the message");
+ streamMessageConversionQTestsString((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsCharCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsCharCreate - create the message");
+ streamMessageConversionQTestsCharCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsChar")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsChar - read and verify the message");
+ streamMessageConversionQTestsChar((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsBytesCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsBytesCreate - create the message");
+ streamMessageConversionQTestsBytesCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsBytes")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsBytes - read and verify the message");
+ streamMessageConversionQTestsBytes((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsInvFormatStringCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsInvFormatStringCreate - create the message");
+ streamMessageConversionQTestsInvFormatStringCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionQTestsInvFormatString")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionQTestsInvFormatString - read and verify the message");
+ streamMessageConversionQTestsInvFormatString((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageQTestsFullMsgCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageQTestsFullMsgCreate - create the message");
+ streamMessageQTestsFullMsgCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageQTestsFullMsg")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageQTestsFullMsg - read and verify the message");
+ streamMessageQTestsFullMsg((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageQTestNullCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageQTestNullCreate - create the message");
+ streamMessageQTestNullCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageQTestNull")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageQTestNull - read and verify the message");
+ streamMessageQTestNull((jakarta.jms.StreamMessage) msg);
+ }
+
+ else {
+ logger.log(Logger.Level.TRACE, "@onMessage - invalid message type found in StringProperty");
+ }
+ logger.log(Logger.Level.TRACE, "@onMessage - Finished for this test!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+
+ }
+
+ /*
+ * Description: Create an object message. Write a StringBuffer to the message.
+ * modify the StringBuffer and send the msg, verify that it does not effect the
+ * msg
+ */
+ public void messageObjectCopyQTestCreate() {
+ boolean pass = true;
+ try {
+ ObjectMessage messageSentObjectMsg = null;
+ StringBuffer sBuff = new StringBuffer("This is");
+ String initial = "This is";
+ messageSentObjectMsg = qSession.createObjectMessage();
+ JmsUtil.addPropsToMessage(messageSentObjectMsg, p);
+ messageSentObjectMsg.setObject(sBuff);
+ sBuff.append("a test ");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "messageObjectCopyQTest");
+ // set up testcase so onMessage invokes the correct method
+ messageSentObjectMsg.setStringProperty("TestCase", "messageObjectCopyQTest");
+
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSentObjectMsg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage -. use StreamMessage method writeBoolean
+ * to write a boolean to the message. Verify the proper conversion support as in
+ * 3.11.3
+ */
+ private void streamMessageConversionQTestsBooleanCreate() {
+ try {
+ StreamMessage messageSent = null;
+ boolean abool = true;
+
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsBoolean");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for boolean primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionQTestsBoolean");
+ messageSent.writeBoolean(abool);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage -. use StreamMessage method writeByte to
+ * write a byte. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsByteCreate() {
+ try {
+ StreamMessage messageSent = null;
+
+ byte bValue = 127;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsByte");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionQTestsByte");
+
+ messageSent.writeByte(bValue);
+ // send the message and then get it back
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a StreamMessage -. use StreamMessage method writeShort to
+ * write a short. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsShortCreate() {
+ try {
+ StreamMessage messageSent = null;
+ short sValue = 1;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsShort");
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionQTestsShort");
+ messageSent.writeShort(sValue);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a StreamMessage -. use StreamMessage method writeInt to
+ * write an int. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsIntCreate() {
+ try {
+ StreamMessage messageSent = null;
+ int iValue = 6;
+
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsInt");
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionQTestsInt");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ messageSent.writeInt(iValue);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a StreamMessage -. use StreamMessage method writeLong to
+ * write a long. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsLongCreate() {
+ try {
+ StreamMessage messageSent = null;
+ long lValue = 2;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsLong");
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionQTestsLong");
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ messageSent.writeLong(lValue);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a StreamMessage -. use StreamMessage method writeFloat to
+ * write a float. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsFloatCreate() {
+ try {
+ StreamMessage messageSent = null;
+
+ float fValue = 5;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsFloat");
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionQTestsFloat");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.writeFloat(fValue);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage -. use StreamMessage method writeDouble
+ * to write a double. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsDoubleCreate() {
+ try {
+ StreamMessage messageSent = null;
+
+ double dValue = 3;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsDouble");
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionQTestsDouble");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.writeDouble(dValue);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a StreamMessage -. use StreamMessage method writeString
+ * to write a string. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsStringCreate() {
+ try {
+ StreamMessage messageSent = null;
+ String myString = "10";
+
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsString");
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionQTestsString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.writeString(myString);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a StreamMessage -. use StreamMessage method writeChar to
+ * write a char. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsCharCreate() {
+ try {
+ StreamMessage messageSent = null;
+
+ char charValue = 'a';
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsChar");
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionQTestsChar");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.writeChar(charValue);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage -. use StreamMessage method writeBytes to
+ * write a byte[] to the message. Verify the proper conversion support as in
+ * 3.11.3
+ */
+ private void streamMessageConversionQTestsBytesCreate() {
+ try {
+ StreamMessage messageSent = null;
+ byte[] bValues = { 1, 2, 3 };
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsBytes");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte[] primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionQTestsBytes");
+
+ messageSent.writeBytes(bValues);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage -. use StreamMessage method writeString
+ * to write a text string of "mytest string". Verify NumberFormatException is
+ * thrown Verify that the pointer was not incremented by doing a read string
+ *
+ */
+ private void streamMessageConversionQTestsInvFormatStringCreate() {
+ try {
+ StreamMessage messageSent = null;
+ String myString = "mytest string";
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionQTestsInvFormatString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionQTestsInvFormatString");
+ messageSent.writeString(myString);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage -. write one of each primitive type. Send
+ * the message. Verify the data received was as sent.
+ *
+ */
+ private void streamMessageQTestsFullMsgCreate() {
+ try {
+
+ StreamMessage messageSent = null;
+
+ byte bValue = 127;
+ boolean abool = false;
+ byte[] bValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+ char charValue = 'Z';
+ short sValue = 32767;
+ long lValue = 9223372036854775807L;
+ double dValue = 6.02e23;
+ float fValue = 6.02e23f;
+ int iValue = 6;
+ boolean pass = true;
+ String myString = "text";
+ String sTesting = "Testing StreamMessages";
+
+ int nCount;
+
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageQTestsFullMsg");
+
+ messageSent.writeBytes(bValues2, 0, bValues2.length);
+ messageSent.writeBoolean(abool);
+ messageSent.writeByte(bValue);
+ messageSent.writeBytes(bValues);
+ messageSent.writeChar(charValue);
+ messageSent.writeDouble(dValue);
+ messageSent.writeFloat(fValue);
+ messageSent.writeInt(iValue);
+ messageSent.writeLong(lValue);
+ messageSent.writeObject(sTesting);
+ messageSent.writeShort(sValue);
+ messageSent.writeString(myString);
+
+ // the next line causes a Message Format exception to be thrown
+ // temporarily comment this out.
+ messageSent.writeObject(null);
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageQTestsFullMsg");
+
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage Use writeString to write a null, then use
+ * readString to read it back.
+ */
+ private void streamMessageQTestNullCreate() {
+ try {
+ StreamMessage messageSent = null;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageQTestNull");
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "writeString(null) ");
+ // -----------------------------------------------------------------------------
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageQTestNull");
+ messageSent.writeString(null);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read ObjectMessage created by messageObjectCopyQTestCreate.
+ * verify that modifying the sBuff object after the write does not effect the
+ * msg
+ */
+ public void messageObjectCopyQTest(jakarta.jms.ObjectMessage messageReceivedObjectMsg) {
+ boolean pass = true;
+ String testCase = "messageObjectCopyQTest";
+ String initial = "This is";
+ try {
+ logger.log(Logger.Level.INFO, "Ensure that changing the object did not change the message");
+ StringBuffer s = (StringBuffer) messageReceivedObjectMsg.getObject();
+ logger.log(Logger.Level.TRACE, "s is " + s);
+ if (s.toString().equals(initial)) {
+ logger.log(Logger.Level.TRACE, "Pass: msg was not changed");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: msg was changed!");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ */
+ private void streamMessageConversionQTestsBoolean(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionQTestsBoolean";
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ boolean pass = true;
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // boolean to boolean - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a boolean");
+ try {
+ if (messageReceived.readBoolean() == abool) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to boolean - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a boolean");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals((Boolean.valueOf(abool)).toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to byte[] invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a boolean - expect MessageFormatException");
+ int nCount = 0;
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+ // -----------------------------------------------
+ // boolean to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ bValue = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // boolean to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readLong();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to float invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsByte(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionQTestsByte";
+ try {
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+ // now test conversions for byte
+ // -----------------------------------------------
+ // byte to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a byte");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Byte.toString(bValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a byte - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // byte to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a byte");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readByte() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to byte - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a byte");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readShort() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to short - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ pass = false;
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a byte");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to int - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a byte");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsShort(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionQTestsShort";
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // short to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a short");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Short.toString(sValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: short to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a short - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // short to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a short");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readShort() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to short - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a byte");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to int - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a short");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsInt(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionQTestsInt";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // int to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read an int");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Integer.toString(iValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: int to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read an int - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // int to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read an int");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read an int");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == iValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to int - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read an int");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == iValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ */
+ private void streamMessageConversionQTestsLong(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionQTestsLong";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // long to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a long - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a long");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Long.toString(lValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: long to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a long - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // long to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read an long - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a long");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a long - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a long");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a long");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == lValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a long - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read an long - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ */
+ private void streamMessageConversionQTestsFloat(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionQTestsFloat";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // float to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a float ");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a float");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Float.toString(fValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: float to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a float ");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // float to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a float ");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a float");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a long ");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a float");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a long");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a float ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readFloat() == fValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to float - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read an float ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readDouble() == fValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to double - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsDouble(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionQTestsDouble";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // double to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a double ");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a double");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Double.toString(dValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: double to string");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a double ");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // double to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a double ");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a double");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a double ");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a double");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a double");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // double to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a double ");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to double valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a double ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readDouble() == dValue) {
+ logger.log(Logger.Level.TRACE, "Pass: double to double ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ */
+ private void streamMessageConversionQTestsString(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionQTestsString";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+ String myString = "10";
+
+ // now test conversions for String
+ // -----------------------------------------------
+ // string to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a String");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: string to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // string to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a String");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // String to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a String");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readByte() == Byte.parseByte(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to byte ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // string to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a string");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readShort() == Short.parseShort(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to short ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a String ");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // string to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a String");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == Integer.parseInt(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to int ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a String");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == Long.parseLong(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to long ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a String");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readFloat() == Float.parseFloat(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to float ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to double valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a String");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readDouble() == Double.parseDouble(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to double ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a string ");
+ try {
+ messageReceived.clearBody();
+ messageReceived.writeString("true");
+ messageReceived.reset();
+ if (messageReceived.readBoolean() == abool) {
+ logger.log(Logger.Level.TRACE, "Pass: String to boolean ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a string that is !true ");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ if (b != true) {
+ logger.log(Logger.Level.TRACE, "Fail: !true should return false");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: !true returned false");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ *
+ */
+ private void streamMessageConversionQTestsChar(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionQTestsChar";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // char to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a char");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ String s = messageReceived.readString();
+ logger.log(Logger.Level.TRACE, "char returned for \"a\" is : " + s);
+ if (s.equals("a")) {
+ logger.log(Logger.Level.TRACE, "Pass: char to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a char - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // char to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a char");
+ try {
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to char valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a char ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readChar() == 'a') {
+ logger.log(Logger.Level.TRACE, "Pass: char to char - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a char ");
+ try {
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a char");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // char to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ */
+ private void streamMessageConversionQTestsBytes(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionQTestsBytes";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues2 = { 0, 0, 0 };
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // byte[] to byte[] - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a byte[] ");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readBytes(bValues2) == 3) { // count should be 3.
+ logger.log(Logger.Level.TRACE, "Pass: byte[] to byte[] - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: count incorrect");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a byte[]");
+ // position to beginning of stream message.
+ messageReceived.reset();
+ try {
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to string invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a byte[]");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ String s = messageReceived.readString();
+ logger.log(Logger.Level.TRACE,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to float invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (jakarta.jms.MessageFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Read a StreamMessage -. Verify NumberFormatException is thrown
+ * Verify that the pointer was not incremented by doing a read string
+ *
+ */
+ private void streamMessageConversionQTestsInvFormatString(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionQTestsInvFormatString";
+
+ try {
+
+ boolean pass = true;
+ String myString = "mytest string";
+
+ // -----------------------------------------------
+ // String to byte
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a String that is not valid ");
+ try {
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: java.lang.NumberFormatException expected");
+ pass = false;
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: java.lang.NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // pointer should not have moved
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Verify that the data can be read as a string and pointer did not move");
+ try {
+ String s = messageReceived.readString();
+ logger.log(Logger.Level.TRACE, "message read: " + s);
+ if (s.equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: able to read the string");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: string not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to short
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a string that is not valid ");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to int
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a String that is not valid ");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a String that is not valid ");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a String that is not valid ");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to double
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a String that is not valid ");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (java.lang.NumberFormatException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the data received was as sent.
+ *
+ */
+ private void streamMessageQTestsFullMsg(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageQTestsFullMsg";
+
+ try {
+ byte bValue = 127;
+ boolean abool = false;
+ byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+ byte[] bValuesReturned = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ byte[] bValuesReturned2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ char charValue = 'Z';
+ short sValue = 32767;
+ long lValue = 9223372036854775807L;
+ double dValue = 6.02e23;
+ float fValue = 6.02e23f;
+ int iValue = 6;
+ boolean pass = true;
+ String myString = "text";
+ String sTesting = "Testing StreamMessages";
+
+ try {
+ int nCount = bValuesReturned2.length;
+ do {
+ nCount = messageReceived.readBytes(bValuesReturned2);
+ logger.log(Logger.Level.TRACE, "nCount is " + nCount);
+ if (nCount != -1) {
+ for (int i = 0; i < bValuesReturned2.length; i++) {
+ if (bValuesReturned2[i] != bValues2[i]) {
+ logger.log(Logger.Level.TRACE, "Fail: byte[] " + i + " is not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "PASS: byte[]" + i + " is valid");
+ }
+ }
+ }
+ } while (nCount >= bValuesReturned2.length);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readBoolean() == abool) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean returned ok");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: boolean not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readByte() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: Byte returned ok");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Byte not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ int nCount = bValuesReturned.length;
+ do {
+ nCount = messageReceived.readBytes(bValuesReturned);
+ logger.log(Logger.Level.TRACE, "nCount is " + nCount);
+ if (nCount != -1) {
+ for (int i = 0; i < bValuesReturned2.length; i++) {
+ if (bValuesReturned2[i] != bValues2[i]) {
+ logger.log(Logger.Level.TRACE, "Fail: byte[] " + i + " is not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "PASS: byte[]" + i + " is valid");
+ }
+ }
+ }
+ } while (nCount >= bValuesReturned.length);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readChar() == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct char");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: char not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readDouble() == dValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct double");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: double not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readFloat() == fValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct float");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: float not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readInt() == iValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct int");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: int not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readLong() == lValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct long");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: long not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readObject().equals(sTesting)) {
+ logger.log(Logger.Level.TRACE, "Pass: correct object");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: object not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readShort() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct short");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: short not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readString().equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: correct string");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: string not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readObject() == null) {
+ logger.log(Logger.Level.TRACE, "Pass: correct object");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: object not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage Use readString to read back a null
+ */
+ private void streamMessageQTestNull(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageQTestNull";
+ try {
+ boolean pass = true;
+ try {
+ if (messageReceived.readObject() == null) {
+ logger.log(Logger.Level.TRACE, "Pass: Read a null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: null value not returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error trying to read a null object");
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: send test results to response queue (MDB_QUEUE_REPLY) for
+ * verification
+ */
+ private void sendTestResults(String testCase, boolean results) {
+ TextMessage msg = null;
+
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ msg.setStringProperty("TestCase", testCase);
+ msg.setText(testCase);
+ if (results)
+ msg.setStringProperty("Status", "Pass");
+ else
+ msg.setStringProperty("Status", "Fail");
+
+ logger.log(Logger.Level.TRACE, "Sending response message");
+ mSender.send(msg);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ logger.log(Logger.Level.TRACE, "Error: " + je.getClass().getName() + " was thrown");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.TRACE, "Error: " + ee.getClass().getName() + " was thrown");
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesQ2 In MsgBeanMsgTestQ2::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesQ2 In MsgBeanMsgTestQ2::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ3/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ3/MDBClient.java
deleted file mode 100644
index 4454e6c7ae..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ3/MDBClient.java
+++ /dev/null
@@ -1,326 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesQ3;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.MDB_Q_Test;
-
-import jakarta.ejb.EJB;
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_MSGQ3_Test")
- private static MDB_Q_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
- //
-
- /*
- * @testName: mdbMsgClearBodyQueueTextTest
- *
- * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
- * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * Create and send a Text message. Have the mdb read the message call
- * clearBody, verify body is empty after clearBody. verify properties are not
- * effected by clearBody. Write to the message again 3.11
- */
- public void mdbMsgClearBodyQueueTextTest() throws Exception {
- String testCase1 = "msgClearBodyQueueTextTestCreate";
- String testCase2 = "msgClearBodyQueueTextTest";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase msgClearBodyQueueTextTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from msgClearBodyQueueTextTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgClearBodyQueueTextTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgClearBodyQueueObjectTest
- *
- * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
- * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * Create and send a Object message. Have the mdb read the message call
- * clearBody, verify body is empty after clearBody. verify properties are not
- * effected by clearBody. Write to the message again 3.11
- */
- public void mdbMsgClearBodyQueueObjectTest() throws Exception {
- String testCase1 = "msgClearBodyQueueObjectTestCreate";
- String testCase2 = "msgClearBodyQueueObjectTest";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase msgClearBodyQueueObjectTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from msgClearBodyQueueObjectTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgClearBodyQueueObjectTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgClearBodyQueueMapTest
- *
- * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
- * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * Create and send a Map message. Have the mdb read the message call
- * clearBody, verify body is empty after clearBody. verify properties are not
- * effected by clearBody. Write to the message again 3.11
- */
- public void mdbMsgClearBodyQueueMapTest() throws Exception {
- String testCase1 = "msgClearBodyQueueMapTestCreate";
- String testCase2 = "msgClearBodyQueueMapTest";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase msgClearBodyQueueMapTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out
- .println("client - Check for response from msgClearBodyQueueMapTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgClearBodyQueueMapTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgClearBodyQueueBytesTest
- *
- * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
- * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * Create and send a Bytes message. Have the mdb read the message call
- * clearBody, verify body is empty after clearBody. verify properties are not
- * effected by clearBody. Write to the message again 3.11
- */
- public void mdbMsgClearBodyQueueBytesTest() throws Exception {
- String testCase1 = "msgClearBodyQueueBytesTestCreate";
- String testCase2 = "msgClearBodyQueueBytesTest";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase msgClearBodyQueueBytesTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from msgClearBodyQueueBytesTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgClearBodyQueueBytesTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgClearBodyQueueStreamTest
- *
- * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
- * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * Create and send a Stream message. Have the mdb read the message call
- * clearBody, verify body is empty after clearBody. verify properties are not
- * effected by clearBody. Write to the message again 3.11
- */
- public void mdbMsgClearBodyQueueStreamTest() throws Exception {
- String testCase1 = "msgClearBodyQueueStreamTestCreate";
- String testCase2 = "msgClearBodyQueueStreamTest";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase msgClearBodyQueueStreamTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from msgClearBodyQueueStreamTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgClearBodyQueueStreamTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgResetQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:174; JMS:JAVADOC:584;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * create a stream message and a byte message. write to the message body, call
- * the reset method, try to write to the body expect a
- * MessageNotWriteableException to be thrown.
- */
- public void mdbMsgResetQueueTest() throws Exception {
- String testCase = "msgResetQueueTest";
- try {
- // Have the EJB invoke the MDB
- System.out.println("client - run testcase msgResetQueueTest");
- hr.askMDBToRunATest(testCase); // create and send message to MDB_QUEUE
- System.out.println("client - Check for response from msgResetQueueTest");
- if (!hr.checkOnResponse(testCase)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgResetQueueTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbReadNullCharNotValidQueueMapTest
- *
- * @assertion_ids: JMS:SPEC:79; JMS:JAVADOC:134; JMS:JAVADOC:439;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * write a null string to a MapMessage. Attempt to read the null value as a
- * char.
- */
- public void mdbReadNullCharNotValidQueueMapTest() throws Exception {
- String testCase1 = "readNullCharNotValidQueueMapTestCreate";
- String testCase2 = "readNullCharNotValidQueueMapTest";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase readNullCharNotValidQueueMapTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from readNullCharNotValidQueueMapTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: readNullCharNotValidQueueMapTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
- /*
- * @testName: mdbReadNullCharNotValidQueueStreamTest
- *
- * @assertion_ids: JMS:SPEC:79; JMS:JAVADOC:134; JMS:JAVADOC:439;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * write a null string to a StreamMessage. Attempt to read the null value as a
- * char.
- */
-
- public void mdbReadNullCharNotValidQueueStreamTest() throws Exception {
- String testCase1 = "readNullCharNotValidQueueStreamTestCreate";
- String testCase2 = "readNullCharNotValidQueueStreamTest";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase readNullCharNotValidQueueStreamTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from readNullCharNotValidQueueStreamTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: readNullCharNotValidQueueStreamTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- ;
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ3/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ3/MDBClientIT.java
new file mode 100644
index 0000000000..db5ccdbbe3
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ3/MDBClientIT.java
@@ -0,0 +1,325 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesQ3;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.commonee.MDB_Q_Test;
+
+import jakarta.ejb.EJB;
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_MSGQ3_Test")
+ private static MDB_Q_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ hr.setup(props);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+ //
+
+ /*
+ * @testName: mdbMsgClearBodyQueueTextTest
+ *
+ * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
+ * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * Create and send a Text message. Have the mdb read the message call clearBody,
+ * verify body is empty after clearBody. verify properties are not effected by
+ * clearBody. Write to the message again 3.11
+ */
+ @Test
+ public void mdbMsgClearBodyQueueTextTest() throws Exception {
+ String testCase1 = "msgClearBodyQueueTextTestCreate";
+ String testCase2 = "msgClearBodyQueueTextTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase msgClearBodyQueueTextTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from msgClearBodyQueueTextTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgClearBodyQueueTextTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgClearBodyQueueObjectTest
+ *
+ * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
+ * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * Create and send a Object message. Have the mdb read the message call
+ * clearBody, verify body is empty after clearBody. verify properties are not
+ * effected by clearBody. Write to the message again 3.11
+ */
+ @Test
+ public void mdbMsgClearBodyQueueObjectTest() throws Exception {
+ String testCase1 = "msgClearBodyQueueObjectTestCreate";
+ String testCase2 = "msgClearBodyQueueObjectTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase msgClearBodyQueueObjectTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from msgClearBodyQueueObjectTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgClearBodyQueueObjectTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgClearBodyQueueMapTest
+ *
+ * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
+ * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * Create and send a Map message. Have the mdb read the message call clearBody,
+ * verify body is empty after clearBody. verify properties are not effected by
+ * clearBody. Write to the message again 3.11
+ */
+ @Test
+ public void mdbMsgClearBodyQueueMapTest() throws Exception {
+ String testCase1 = "msgClearBodyQueueMapTestCreate";
+ String testCase2 = "msgClearBodyQueueMapTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase msgClearBodyQueueMapTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from msgClearBodyQueueMapTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgClearBodyQueueMapTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgClearBodyQueueBytesTest
+ *
+ * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
+ * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * Create and send a Bytes message. Have the mdb read the message call
+ * clearBody, verify body is empty after clearBody. verify properties are not
+ * effected by clearBody. Write to the message again 3.11
+ */
+ @Test
+ public void mdbMsgClearBodyQueueBytesTest() throws Exception {
+ String testCase1 = "msgClearBodyQueueBytesTestCreate";
+ String testCase2 = "msgClearBodyQueueBytesTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase msgClearBodyQueueBytesTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from msgClearBodyQueueBytesTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgClearBodyQueueBytesTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgClearBodyQueueStreamTest
+ *
+ * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
+ * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * Create and send a Stream message. Have the mdb read the message call
+ * clearBody, verify body is empty after clearBody. verify properties are not
+ * effected by clearBody. Write to the message again 3.11
+ */
+ @Test
+ public void mdbMsgClearBodyQueueStreamTest() throws Exception {
+ String testCase1 = "msgClearBodyQueueStreamTestCreate";
+ String testCase2 = "msgClearBodyQueueStreamTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase msgClearBodyQueueStreamTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from msgClearBodyQueueStreamTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgClearBodyQueueStreamTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgResetQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:174; JMS:JAVADOC:584;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * create a stream message and a byte message. write to the message body, call
+ * the reset method, try to write to the body expect a
+ * MessageNotWriteableException to be thrown.
+ */
+ @Test
+ public void mdbMsgResetQueueTest() throws Exception {
+ String testCase = "msgResetQueueTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase msgResetQueueTest");
+ hr.askMDBToRunATest(testCase); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from msgResetQueueTest");
+ if (!hr.checkOnResponse(testCase)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgResetQueueTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbReadNullCharNotValidQueueMapTest
+ *
+ * @assertion_ids: JMS:SPEC:79; JMS:JAVADOC:134; JMS:JAVADOC:439;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * write a null string to a MapMessage. Attempt to read the null value as a
+ * char.
+ */
+ @Test
+ public void mdbReadNullCharNotValidQueueMapTest() throws Exception {
+ String testCase1 = "readNullCharNotValidQueueMapTestCreate";
+ String testCase2 = "readNullCharNotValidQueueMapTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase readNullCharNotValidQueueMapTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from readNullCharNotValidQueueMapTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: readNullCharNotValidQueueMapTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbReadNullCharNotValidQueueStreamTest
+ *
+ * @assertion_ids: JMS:SPEC:79; JMS:JAVADOC:134; JMS:JAVADOC:439;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * write a null string to a StreamMessage. Attempt to read the null value as a
+ * char.
+ */
+ @Test
+ public void mdbReadNullCharNotValidQueueStreamTest() throws Exception {
+ String testCase1 = "readNullCharNotValidQueueStreamTestCreate";
+ String testCase2 = "readNullCharNotValidQueueStreamTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase readNullCharNotValidQueueStreamTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from readNullCharNotValidQueueStreamTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: readNullCharNotValidQueueStreamTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ ;
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ3/MsgBeanMsgTestQ3.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ3/MsgBeanMsgTestQ3.java
index 796310e1ae..b2e9ec6f7d 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ3/MsgBeanMsgTestQ3.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesQ3/MsgBeanMsgTestQ3.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesQ3;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.TSNamingContext;
@@ -47,778 +48,713 @@
public class MsgBeanMsgTestQ3 implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- private MessageDrivenContext mdc = null;
-
- // JMS
- private QueueConnectionFactory qFactory = null;
-
- private QueueConnection qConnection = null;
-
- private Queue queueR = null;
-
- private Queue queue = null;
-
- private QueueSender mSender = null;
-
- private QueueSession qSession = null;
-
- public MsgBeanMsgTestQ3() {
- TestUtil.logTrace("@MsgBeanMsgTest3()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgTypesQ3 - @MsgBeanMsgTest3-ejbCreate() !!");
- try {
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- if (qFactory == null) {
- TestUtil.logTrace("qFactory error");
- }
- TestUtil.logTrace("got a qFactory !!");
-
- queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- if (queueR == null) {
- TestUtil.logTrace("queueR error");
- }
-
- queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
- if (queue == null) {
- TestUtil.logTrace("queue error");
- }
-
- p = new Properties();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
-
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("from jms.ee.mdb.mdb_msgTypesQ3 @onMessage!" + msg);
-
- try {
- TestUtil.logTrace(
- "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null) {
- TestUtil.logTrace("connection error");
- } else {
- qConnection.start();
- qSession = qConnection.createQueueSession(true, 0);
- }
- if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyQueueTextTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyQueueTextTestCreate - create the message");
- msgClearBodyQueueTextTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyQueueTextTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyQueueTextTest - read and verify the message");
- msgClearBodyQueueTextTest((jakarta.jms.TextMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyQueueObjectTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyQueueObjectTestCreate - create the message");
- msgClearBodyQueueObjectTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyQueueObjectTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyQueueObjectTest - read and verify the message");
- msgClearBodyQueueObjectTest((jakarta.jms.ObjectMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyQueueMapTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyQueueMapTestCreate - create the message");
- msgClearBodyQueueMapTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyQueueMapTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyQueueMapTest - read and verify the message");
- msgClearBodyQueueMapTest((jakarta.jms.MapMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyQueueBytesTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyQueueBytesTestCreate - create the message");
- msgClearBodyQueueBytesTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyQueueBytesTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyQueueBytesTest - read and verify the message");
- msgClearBodyQueueBytesTest((jakarta.jms.BytesMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyQueueStreamTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyQueueStreamTestCreate - create the message");
- msgClearBodyQueueStreamTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyQueueStreamTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyQueueStreamTest - read and verify the message");
- msgClearBodyQueueStreamTest((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase").equals("msgResetQueueTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgResetQueueTest - read and verify the message");
- msgResetQueueTest();
- } else if (msg.getStringProperty("TestCase")
- .equals("readNullCharNotValidQueueStreamTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running readNullCharNotValidQueueStreamTestCreate - read and verify the message");
- readNullCharNotValidQueueStreamTestCreate();
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("readNullCharNotValidQueueStreamTest")) {
- TestUtil.logTrace(
- "@onMessage - running readNullCharNotValidQueueStreamTest - read and verify the message");
- readNullCharNotValidQueueStreamTest((jakarta.jms.StreamMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("readNullCharNotValidQueueMapTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running readNullCharNotValidQueueMapTestCreate - read and verify the message");
- readNullCharNotValidQueueMapTestCreate();
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("readNullCharNotValidQueueMapTest")) {
- TestUtil.logTrace(
- "@onMessage - running readNullCharNotValidQueueMapTest - read and verify the message");
- readNullCharNotValidQueueMapTest((jakarta.jms.MapMessage) msg);
- } else {
- TestUtil.logTrace(
- "@onMessage - invalid message type found in StringProperty");
- TestUtil.logTrace("Do not have a method for this testcase: "
- + msg.getStringProperty("TestCase"));
- }
- TestUtil.logTrace("@onMessage - Finished for this test!");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
-
- }
-
- /*
- * Description: create and send a text message
- */
- private void msgClearBodyQueueTextTestCreate() {
- try {
- TextMessage messageSent = null;
- messageSent = qSession.createTextMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("TestCase", "msgClearBodyQueueTextTest");
- TestUtil.logTrace("sending a Text message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create and send an object message
- */
- private void msgClearBodyQueueObjectTestCreate() {
- try {
- ObjectMessage messageSentObjectMsg = null;
- // send and receive Object message to Queue
- TestUtil.logTrace("Send ObjectMessage to Queue.");
- messageSentObjectMsg = qSession.createObjectMessage();
- JmsUtil.addPropsToMessage(messageSentObjectMsg, p);
- messageSentObjectMsg.setObject("Initial message");
- messageSentObjectMsg.setStringProperty("TestCase",
- "msgClearBodyQueueObjectTest");
- mSender = qSession.createSender(queue);
- mSender.send(messageSentObjectMsg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create and send a Map message
- */
- private void msgClearBodyQueueMapTestCreate() {
- try {
- MapMessage messageSentMapMessage = null;
- // send and receive Map message to Queue
- TestUtil.logTrace("Send MapMessage to Queue.");
- messageSentMapMessage = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSentMapMessage, p);
- messageSentMapMessage.setStringProperty("TestCase",
- "msgClearBodyQueueMapTest");
- messageSentMapMessage.setString("aString", "Initial message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSentMapMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create and send a Bytes message
- */
- private void msgClearBodyQueueBytesTestCreate() {
- byte bValue = 127;
- try {
- BytesMessage messageSentBytesMessage = null;
- // send and receive bytes message to Queue
- TestUtil.logTrace("Send BytesMessage to Queue.");
- messageSentBytesMessage = qSession.createBytesMessage();
- JmsUtil.addPropsToMessage(messageSentBytesMessage, p);
- messageSentBytesMessage.setStringProperty("TestCase",
- "msgClearBodyQueueBytesTest");
- messageSentBytesMessage.writeByte(bValue);
- mSender = qSession.createSender(queue);
- mSender.send(messageSentBytesMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create and send a Stream message
- */
- private void msgClearBodyQueueStreamTestCreate() {
- try {
- StreamMessage messageSentStreamMessage = null;
- // Send and receive a StreamMessage
- TestUtil.logTrace("sending a Stream message");
- messageSentStreamMessage = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSentStreamMessage, p);
- messageSentStreamMessage.setStringProperty("TestCase",
- "msgClearBodyQueueStreamTest");
- messageSentStreamMessage.writeString("Testing...");
- TestUtil.logTrace("Sending message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSentStreamMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Receive a single Text message call clearBody, verify body is
- * empty after clearBody. verify properties are not effected by clearBody.
- * Write to the message again 3.11
- */
- public void msgClearBodyQueueTextTest(jakarta.jms.TextMessage messageReceived) {
- String testCase = "msgClearBodyQueueTextTest";
- boolean pass = true;
- // Text Message
- try {
- TestUtil.logTrace("Test TextMessage ");
- TestUtil.logTrace("read 1st contents");
- TestUtil.logTrace(" " + messageReceived.getText());
- TestUtil.logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceived.clearBody();
- // message body should now be empty
- if (messageReceived.getText() == null) {
- TestUtil.logTrace("Empty body after clearBody as expected: null");
- } else {
- TestUtil.logTrace("Fail: message body was not empty");
- pass = false;
- }
- // properties should not have been deleted by the clearBody method.
- if (messageReceived.getStringProperty("TestCase")
- .equals("msgClearBodyQueueTextTest")) {
- TestUtil
- .logTrace("Pass: Text properties read ok after clearBody called");
- } else {
- TestUtil
- .logTrace("Fail: Text properties cleared after clearBody called");
- pass = false;
- }
- TestUtil.logTrace("write and read 2nd contents");
- messageReceived.setText("new data");
- if (messageReceived.getText().equals("new data")) {
- TestUtil.logTrace("Pass:");
- } else {
- TestUtil.logTrace("Fail:");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: Receive a single Object message call clearBody, verify body is
- * empty after clearBody. verify properties are not effected by clearBody.
- * Write to the message again 3.11
- */
- public void msgClearBodyQueueObjectTest(
- jakarta.jms.ObjectMessage messageReceivedObjectMsg) {
- String testCase = "msgClearBodyQueueObjectTest";
- boolean pass = true;
- try {
- TestUtil.logTrace("Testing Object message");
- TestUtil.logTrace("read 1st contents");
- TestUtil.logTrace(" " + messageReceivedObjectMsg.getObject());
- TestUtil.logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedObjectMsg.clearBody();
- // message body should now be empty
- if (messageReceivedObjectMsg.getObject() == null) {
- TestUtil.logTrace("Empty body after clearBody as expected: null");
- } else {
- TestUtil.logTrace("Fail: message body was not empty");
- pass = false;
- }
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedObjectMsg.getStringProperty("TestCase")
- .equals("msgClearBodyQueueObjectTest")) {
- TestUtil
- .logTrace("Pass: Object properties read ok after clearBody called");
- } else {
- TestUtil
- .logTrace("Fail: Object properties cleared after clearBody called");
- pass = false;
- }
- TestUtil.logTrace("write 2nd contents");
- messageReceivedObjectMsg.setObject("new stuff here!!!!!!");
- TestUtil.logTrace("read 2nd contents");
- if (messageReceivedObjectMsg.getObject().equals("new stuff here!!!!!!")) {
- TestUtil.logTrace("Pass:");
- } else {
- TestUtil.logTrace("Fail: ");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: Receive a single Map message call clearBody, verify body is
- * empty after clearBody. verify properties are not effected by clearBody.
- * Write to the message again 3.11
- */
- private void msgClearBodyQueueMapTest(
- jakarta.jms.MapMessage messageReceivedMapMessage) {
- String testCase = "msgClearBodyQueueMapTest";
- boolean pass = true;
- try {
- TestUtil.logTrace("Test for MapMessage ");
- TestUtil.logTrace("read 1st contents");
- TestUtil.logTrace(" " + messageReceivedMapMessage.getString("aString"));
- TestUtil.logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedMapMessage.clearBody();
- // message body should now be empty
- if (messageReceivedMapMessage.getString("aString") == null) {
- TestUtil.logTrace("Empty body after clearBody as expected: null");
- } else {
- TestUtil.logTrace("Fail: message body was not empty");
-
- TestUtil.logTrace(
- "Contains: " + messageReceivedMapMessage.getString("aString"));
- pass = false;
- }
-
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedMapMessage.getStringProperty("TestCase")
- .equals("msgClearBodyQueueMapTest")) {
- TestUtil
- .logTrace("Pass: Map properties read ok after clearBody called");
- } else {
- TestUtil
- .logTrace("Fail: Map properties cleared after clearBody called");
- pass = false;
- }
- TestUtil.logTrace("write 2nd contents");
- messageReceivedMapMessage.setString("yes", "new stuff !!!!!");
- TestUtil.logTrace("read 2nd contents");
- if (messageReceivedMapMessage.getString("yes")
- .equals("new stuff !!!!!")) {
- TestUtil.logTrace("PASS:");
- } else {
- TestUtil.logTrace("FAIL:");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: Receive a single Bytes message call clearBody, verify body is
- * empty after clearBody. verify properties are not effected by clearBody.
- * Write to the message again 3.11
- */
- public void msgClearBodyQueueBytesTest(
- jakarta.jms.BytesMessage messageReceivedBytesMessage) {
- String testCase = "msgClearBodyQueueBytesTest";
- boolean pass = true;
- byte bValue2 = 22;
- try {
- TestUtil.logTrace("Test BytesMessage ");
- TestUtil.logTrace("read 1st contents");
- TestUtil.logTrace(" " + messageReceivedBytesMessage.readByte());
- TestUtil.logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedBytesMessage.clearBody();
- TestUtil.logTrace(
- "Bytes message body should now be empty and in writeonly mode");
- try {
- byte b = messageReceivedBytesMessage.readByte();
- TestUtil.logTrace(
- "Fail: MessageNotReadableException not thrown as expected");
- pass = false;
- } catch (jakarta.jms.MessageNotReadableException e) {
- TestUtil
- .logTrace("Pass: MessageNotReadableException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedBytesMessage.getStringProperty("TestCase")
- .equals("msgClearBodyQueueBytesTest")) {
- TestUtil.logTrace(
- "Pass: Bytes msg properties read ok after clearBody called");
- } else {
- TestUtil.logTrace(
- "Fail: Bytes msg properties cleared after clearBody called");
- pass = false;
- }
-
- TestUtil.logTrace("write 2nd contents");
- messageReceivedBytesMessage.writeByte(bValue2);
- TestUtil.logTrace("read 2nd contents");
- messageReceivedBytesMessage.reset();
- if (messageReceivedBytesMessage.readByte() == bValue2) {
- TestUtil.logTrace("Pass:");
- } else {
- TestUtil.logTrace("Fail:");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: Receive a single Stream message call clearBody, verify body is
- * empty after clearBody. verify properties are not effected by clearBody.
- * Write to the message again 3.11
- */
- public void msgClearBodyQueueStreamTest(
- jakarta.jms.StreamMessage messageReceivedStreamMessage) {
- String testCase = "msgClearBodyQueueStreamTest";
- boolean pass = true;
- try {
- TestUtil.logTrace("Test StreamMessage ");
- TestUtil.logTrace("read 1st contents");
- TestUtil.logTrace(" " + messageReceivedStreamMessage.readString());
- TestUtil.logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedStreamMessage.clearBody();
-
- TestUtil.logTrace(
- "Stream message body should now be empty and in writeonly mode");
- try {
- String s = messageReceivedStreamMessage.readString();
- TestUtil.logTrace(
- "Fail: MessageNotReadableException should have been thrown");
- pass = false;
- } catch (MessageNotReadableException e) {
- TestUtil
- .logTrace("Pass: MessageNotReadableException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedStreamMessage.getStringProperty("TestCase")
- .equals("msgClearBodyQueueStreamTest")) {
- TestUtil.logTrace(
- "Pass: Stream msg properties read ok after clearBody called");
- } else {
- TestUtil.logTrace(
- "Fail: Stream msg properties cleared after clearBody called");
- pass = false;
- }
- TestUtil.logTrace("write 2nd contents");
- messageReceivedStreamMessage.writeString("new data");
- TestUtil.logTrace("read 2nd contents");
- messageReceivedStreamMessage.reset();
- if (messageReceivedStreamMessage.readString().equals("new data")) {
- TestUtil.logTrace("Pass:");
- } else {
- TestUtil.logTrace("Fail:");
- }
- } catch (Exception e) {
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- *
- * Description: create a stream message and a byte message. write to the
- * message body, call the reset method, try to write to the body expect a
- * MessageNotWriteableException to be thrown.
- */
- private void msgResetQueueTest() {
- boolean pass = true;
- int nInt = 1000;
- String testCase = "msgResetQueueTest";
- try {
- StreamMessage messageSentStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- // StreamMessage
- try {
- TestUtil.logTrace("creating a Stream message");
- messageSentStreamMessage = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSentStreamMessage, p);
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgResetQueueTest1");
- // write to the message
- messageSentStreamMessage.writeString("Testing...");
- TestUtil.logTrace(
- "reset stream message - now should be in readonly mode");
- messageSentStreamMessage.reset();
- messageSentStreamMessage.writeString("new data");
- TestUtil.logTrace(
- "Fail: message did not throw MessageNotWriteable exception as expected");
- pass = false;
- } catch (MessageNotWriteableException nw) {
- TestUtil.logTrace("Pass: MessageNotWriteable thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // BytesMessage
- try {
- TestUtil.logTrace("creating a Byte message");
- messageSentBytesMessage = qSession.createBytesMessage();
- JmsUtil.addPropsToMessage(messageSentBytesMessage, p);
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgResetQueueTest2");
- // write to the message
- messageSentBytesMessage.writeInt(nInt);
- TestUtil
- .logTrace("reset Byte message - now should be in readonly mode");
- messageSentBytesMessage.reset();
- messageSentBytesMessage.writeInt(nInt);
- TestUtil.logTrace(
- "Fail: message did not throw MessageNotWriteable exception as expected");
- pass = false;
- } catch (MessageNotWriteableException nw) {
- TestUtil.logTrace("Pass: MessageNotWriteable thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- *
- * Description: Write a null string to a MapMessage.
- *
- */
- public void readNullCharNotValidQueueMapTestCreate() {
- try {
- MapMessage mapSent = null;
- char c;
- boolean pass = true;
- mapSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(mapSent, p);
- mapSent.setStringProperty("TestCase", "readNullCharNotValidQueueMapTest");
- TestUtil.logTrace(
- "Write a null string to the map message object with mapMessage.setString");
- mapSent.setString("WriteANull", null);
- TestUtil.logTrace(" Send the message");
- mSender = qSession.createSender(queue);
- mSender.send(mapSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Write a null string to a StreamMessage.
- *
- */
- public void readNullCharNotValidQueueStreamTestCreate() {
- try {
- StreamMessage messageSent = null;
- char c;
- boolean pass = true;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("TestCase",
- "readNullCharNotValidQueueStreamTest");
- TestUtil.logTrace(
- "Write a null string to the map message object with streamMessage.setString");
- messageSent.writeString(null);
- TestUtil.logTrace(" Send the message");
- mSender = qSession.createSender(queue);
- mSender.send(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Attempt to read a null string from a MapMessage. Should throw
- * a null pointer exception
- */
-
- public void readNullCharNotValidQueueMapTest(
- jakarta.jms.MapMessage mapReceived) {
- String testCase = "readNullCharNotValidQueueMapTest";
- boolean pass = true;
- try {
- char c;
- TestUtil.logTrace("Use readChar to read a null ");
- try {
- c = mapReceived.getChar("WriteANull");
- TestUtil.logTrace("Fail: NullPointerException was not thrown");
- pass = false;
- } catch (java.lang.NullPointerException e) {
- TestUtil.logTrace("Pass: NullPointerException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
-
- }
- /*
- * Description: Attempt to read a null string from a StreamMessage. Should
- * throw a null pointer exception
- */
-
- public void readNullCharNotValidQueueStreamTest(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "readNullCharNotValidQueueStreamTest";
- boolean pass = true;
- try {
- char c;
- TestUtil.logTrace("Use readChar to read a null ");
- try {
- c = messageReceived.readChar();
- TestUtil.logTrace("Fail: NullPointerException was not thrown");
- pass = false;
- } catch (java.lang.NullPointerException e) {
- TestUtil.logTrace("Pass: NullPointerException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
-
- }
-
- /*
- * Description: send test results to response queue (MDB_QUEUE_REPLY) for
- * verification
- */
- private void sendTestResults(String testCase, boolean results) {
- TextMessage msg = null;
-
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- msg.setStringProperty("TestCase", testCase);
- msg.setText(testCase);
- if (results)
- msg.setStringProperty("Status", "Pass");
- else
- msg.setStringProperty("Status", "Fail");
-
- TestUtil.logTrace("Sending response message");
- TestUtil.logTrace(
- "==================================Test Results from: " + testCase);
- TestUtil.logTrace("==================================Status: " + results);
- mSender.send(msg);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- TestUtil.logTrace("Error: " + je.getClass().getName() + " was thrown");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logTrace("Error: " + ee.getClass().getName() + " was thrown");
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgTypesQ3 In MsgBeanMsgTest3::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil
- .logTrace("jms.ee.mdb.mdb_msgTypesQ3 In MsgBeanMsgTest3::remove()!!");
- }
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ private MessageDrivenContext mdc = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanMsgTestQ3.class.getName());
+
+ // JMS
+ private QueueConnectionFactory qFactory = null;
+
+ private QueueConnection qConnection = null;
+
+ private Queue queueR = null;
+
+ private Queue queue = null;
+
+ private QueueSender mSender = null;
+
+ private QueueSession qSession = null;
+
+ public MsgBeanMsgTestQ3() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanMsgTest3()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesQ3 - @MsgBeanMsgTest3-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ if (qFactory == null) {
+ logger.log(Logger.Level.TRACE, "qFactory error");
+ }
+ logger.log(Logger.Level.TRACE, "got a qFactory !!");
+
+ queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ if (queueR == null) {
+ logger.log(Logger.Level.TRACE, "queueR error");
+ }
+
+ queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
+ if (queue == null) {
+ logger.log(Logger.Level.TRACE, "queue error");
+ }
+
+ p = new Properties();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "from jms.ee.mdb.mdb_msgTypesQ3 @onMessage!" + msg);
+
+ try {
+ logger.log(Logger.Level.TRACE, "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null) {
+ logger.log(Logger.Level.TRACE, "connection error");
+ } else {
+ qConnection.start();
+ qSession = qConnection.createQueueSession(true, 0);
+ }
+ if (msg.getStringProperty("TestCase").equals("msgClearBodyQueueTextTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyQueueTextTestCreate - create the message");
+ msgClearBodyQueueTextTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyQueueTextTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyQueueTextTest - read and verify the message");
+ msgClearBodyQueueTextTest((jakarta.jms.TextMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyQueueObjectTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyQueueObjectTestCreate - create the message");
+ msgClearBodyQueueObjectTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyQueueObjectTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyQueueObjectTest - read and verify the message");
+ msgClearBodyQueueObjectTest((jakarta.jms.ObjectMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyQueueMapTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyQueueMapTestCreate - create the message");
+ msgClearBodyQueueMapTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyQueueMapTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyQueueMapTest - read and verify the message");
+ msgClearBodyQueueMapTest((jakarta.jms.MapMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("msgClearBodyQueueBytesTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyQueueBytesTestCreate - create the message");
+ msgClearBodyQueueBytesTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyQueueBytesTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyQueueBytesTest - read and verify the message");
+ msgClearBodyQueueBytesTest((jakarta.jms.BytesMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("msgClearBodyQueueStreamTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyQueueStreamTestCreate - create the message");
+ msgClearBodyQueueStreamTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyQueueStreamTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyQueueStreamTest - read and verify the message");
+ msgClearBodyQueueStreamTest((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("msgResetQueueTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - running msgResetQueueTest - read and verify the message");
+ msgResetQueueTest();
+ } else if (msg.getStringProperty("TestCase").equals("readNullCharNotValidQueueStreamTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running readNullCharNotValidQueueStreamTestCreate - read and verify the message");
+ readNullCharNotValidQueueStreamTestCreate();
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("readNullCharNotValidQueueStreamTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running readNullCharNotValidQueueStreamTest - read and verify the message");
+ readNullCharNotValidQueueStreamTest((jakarta.jms.StreamMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("readNullCharNotValidQueueMapTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running readNullCharNotValidQueueMapTestCreate - read and verify the message");
+ readNullCharNotValidQueueMapTestCreate();
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("readNullCharNotValidQueueMapTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running readNullCharNotValidQueueMapTest - read and verify the message");
+ readNullCharNotValidQueueMapTest((jakarta.jms.MapMessage) msg);
+ } else {
+ logger.log(Logger.Level.TRACE, "@onMessage - invalid message type found in StringProperty");
+ logger.log(Logger.Level.TRACE,
+ "Do not have a method for this testcase: " + msg.getStringProperty("TestCase"));
+ }
+ logger.log(Logger.Level.TRACE, "@onMessage - Finished for this test!");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+
+ }
+
+ /*
+ * Description: create and send a text message
+ */
+ private void msgClearBodyQueueTextTestCreate() {
+ try {
+ TextMessage messageSent = null;
+ messageSent = qSession.createTextMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("TestCase", "msgClearBodyQueueTextTest");
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create and send an object message
+ */
+ private void msgClearBodyQueueObjectTestCreate() {
+ try {
+ ObjectMessage messageSentObjectMsg = null;
+ // send and receive Object message to Queue
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Queue.");
+ messageSentObjectMsg = qSession.createObjectMessage();
+ JmsUtil.addPropsToMessage(messageSentObjectMsg, p);
+ messageSentObjectMsg.setObject("Initial message");
+ messageSentObjectMsg.setStringProperty("TestCase", "msgClearBodyQueueObjectTest");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSentObjectMsg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create and send a Map message
+ */
+ private void msgClearBodyQueueMapTestCreate() {
+ try {
+ MapMessage messageSentMapMessage = null;
+ // send and receive Map message to Queue
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Queue.");
+ messageSentMapMessage = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSentMapMessage, p);
+ messageSentMapMessage.setStringProperty("TestCase", "msgClearBodyQueueMapTest");
+ messageSentMapMessage.setString("aString", "Initial message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSentMapMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create and send a Bytes message
+ */
+ private void msgClearBodyQueueBytesTestCreate() {
+ byte bValue = 127;
+ try {
+ BytesMessage messageSentBytesMessage = null;
+ // send and receive bytes message to Queue
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Queue.");
+ messageSentBytesMessage = qSession.createBytesMessage();
+ JmsUtil.addPropsToMessage(messageSentBytesMessage, p);
+ messageSentBytesMessage.setStringProperty("TestCase", "msgClearBodyQueueBytesTest");
+ messageSentBytesMessage.writeByte(bValue);
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSentBytesMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create and send a Stream message
+ */
+ private void msgClearBodyQueueStreamTestCreate() {
+ try {
+ StreamMessage messageSentStreamMessage = null;
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a Stream message");
+ messageSentStreamMessage = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSentStreamMessage, p);
+ messageSentStreamMessage.setStringProperty("TestCase", "msgClearBodyQueueStreamTest");
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSentStreamMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Receive a single Text message call clearBody, verify body is
+ * empty after clearBody. verify properties are not effected by clearBody. Write
+ * to the message again 3.11
+ */
+ public void msgClearBodyQueueTextTest(jakarta.jms.TextMessage messageReceived) {
+ String testCase = "msgClearBodyQueueTextTest";
+ boolean pass = true;
+ // Text Message
+ try {
+ logger.log(Logger.Level.TRACE, "Test TextMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceived.getText());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceived.clearBody();
+ // message body should now be empty
+ if (messageReceived.getText() == null) {
+ logger.log(Logger.Level.TRACE, "Empty body after clearBody as expected: null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: message body was not empty");
+ pass = false;
+ }
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceived.getStringProperty("TestCase").equals("msgClearBodyQueueTextTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Text properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Text properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write and read 2nd contents");
+ messageReceived.setText("new data");
+ if (messageReceived.getText().equals("new data")) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail:");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: Receive a single Object message call clearBody, verify body is
+ * empty after clearBody. verify properties are not effected by clearBody. Write
+ * to the message again 3.11
+ */
+ public void msgClearBodyQueueObjectTest(jakarta.jms.ObjectMessage messageReceivedObjectMsg) {
+ String testCase = "msgClearBodyQueueObjectTest";
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.TRACE, "Testing Object message");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedObjectMsg.getObject());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedObjectMsg.clearBody();
+ // message body should now be empty
+ if (messageReceivedObjectMsg.getObject() == null) {
+ logger.log(Logger.Level.TRACE, "Empty body after clearBody as expected: null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: message body was not empty");
+ pass = false;
+ }
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedObjectMsg.getStringProperty("TestCase").equals("msgClearBodyQueueObjectTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Object properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Object properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedObjectMsg.setObject("new stuff here!!!!!!");
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ if (messageReceivedObjectMsg.getObject().equals("new stuff here!!!!!!")) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: ");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: Receive a single Map message call clearBody, verify body is
+ * empty after clearBody. verify properties are not effected by clearBody. Write
+ * to the message again 3.11
+ */
+ private void msgClearBodyQueueMapTest(jakarta.jms.MapMessage messageReceivedMapMessage) {
+ String testCase = "msgClearBodyQueueMapTest";
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.TRACE, "Test for MapMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedMapMessage.getString("aString"));
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedMapMessage.clearBody();
+ // message body should now be empty
+ if (messageReceivedMapMessage.getString("aString") == null) {
+ logger.log(Logger.Level.TRACE, "Empty body after clearBody as expected: null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: message body was not empty");
+
+ logger.log(Logger.Level.TRACE, "Contains: " + messageReceivedMapMessage.getString("aString"));
+ pass = false;
+ }
+
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedMapMessage.getStringProperty("TestCase").equals("msgClearBodyQueueMapTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Map properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Map properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedMapMessage.setString("yes", "new stuff !!!!!");
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ if (messageReceivedMapMessage.getString("yes").equals("new stuff !!!!!")) {
+ logger.log(Logger.Level.TRACE, "PASS:");
+ } else {
+ logger.log(Logger.Level.TRACE, "FAIL:");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: Receive a single Bytes message call clearBody, verify body is
+ * empty after clearBody. verify properties are not effected by clearBody. Write
+ * to the message again 3.11
+ */
+ public void msgClearBodyQueueBytesTest(jakarta.jms.BytesMessage messageReceivedBytesMessage) {
+ String testCase = "msgClearBodyQueueBytesTest";
+ boolean pass = true;
+ byte bValue2 = 22;
+ try {
+ logger.log(Logger.Level.TRACE, "Test BytesMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedBytesMessage.readByte());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedBytesMessage.clearBody();
+ logger.log(Logger.Level.TRACE, "Bytes message body should now be empty and in writeonly mode");
+ try {
+ byte b = messageReceivedBytesMessage.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageNotReadableException not thrown as expected");
+ pass = false;
+ } catch (jakarta.jms.MessageNotReadableException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotReadableException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedBytesMessage.getStringProperty("TestCase").equals("msgClearBodyQueueBytesTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Bytes msg properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Bytes msg properties cleared after clearBody called");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedBytesMessage.writeByte(bValue2);
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ messageReceivedBytesMessage.reset();
+ if (messageReceivedBytesMessage.readByte() == bValue2) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail:");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: Receive a single Stream message call clearBody, verify body is
+ * empty after clearBody. verify properties are not effected by clearBody. Write
+ * to the message again 3.11
+ */
+ public void msgClearBodyQueueStreamTest(jakarta.jms.StreamMessage messageReceivedStreamMessage) {
+ String testCase = "msgClearBodyQueueStreamTest";
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.TRACE, "Test StreamMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedStreamMessage.readString());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedStreamMessage.clearBody();
+
+ logger.log(Logger.Level.TRACE, "Stream message body should now be empty and in writeonly mode");
+ try {
+ String s = messageReceivedStreamMessage.readString();
+ logger.log(Logger.Level.TRACE, "Fail: MessageNotReadableException should have been thrown");
+ pass = false;
+ } catch (MessageNotReadableException e) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotReadableException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedStreamMessage.getStringProperty("TestCase").equals("msgClearBodyQueueStreamTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Stream msg properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Stream msg properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedStreamMessage.writeString("new data");
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ messageReceivedStreamMessage.reset();
+ if (messageReceivedStreamMessage.readString().equals("new data")) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail:");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ *
+ * Description: create a stream message and a byte message. write to the message
+ * body, call the reset method, try to write to the body expect a
+ * MessageNotWriteableException to be thrown.
+ */
+ private void msgResetQueueTest() {
+ boolean pass = true;
+ int nInt = 1000;
+ String testCase = "msgResetQueueTest";
+ try {
+ StreamMessage messageSentStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ // StreamMessage
+ try {
+ logger.log(Logger.Level.TRACE, "creating a Stream message");
+ messageSentStreamMessage = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSentStreamMessage, p);
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgResetQueueTest1");
+ // write to the message
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "reset stream message - now should be in readonly mode");
+ messageSentStreamMessage.reset();
+ messageSentStreamMessage.writeString("new data");
+ logger.log(Logger.Level.TRACE, "Fail: message did not throw MessageNotWriteable exception as expected");
+ pass = false;
+ } catch (MessageNotWriteableException nw) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotWriteable thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // BytesMessage
+ try {
+ logger.log(Logger.Level.TRACE, "creating a Byte message");
+ messageSentBytesMessage = qSession.createBytesMessage();
+ JmsUtil.addPropsToMessage(messageSentBytesMessage, p);
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgResetQueueTest2");
+ // write to the message
+ messageSentBytesMessage.writeInt(nInt);
+ logger.log(Logger.Level.TRACE, "reset Byte message - now should be in readonly mode");
+ messageSentBytesMessage.reset();
+ messageSentBytesMessage.writeInt(nInt);
+ logger.log(Logger.Level.TRACE, "Fail: message did not throw MessageNotWriteable exception as expected");
+ pass = false;
+ } catch (MessageNotWriteableException nw) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotWriteable thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ *
+ * Description: Write a null string to a MapMessage.
+ *
+ */
+ public void readNullCharNotValidQueueMapTestCreate() {
+ try {
+ MapMessage mapSent = null;
+ char c;
+ boolean pass = true;
+ mapSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(mapSent, p);
+ mapSent.setStringProperty("TestCase", "readNullCharNotValidQueueMapTest");
+ logger.log(Logger.Level.TRACE, "Write a null string to the map message object with mapMessage.setString");
+ mapSent.setString("WriteANull", null);
+ logger.log(Logger.Level.TRACE, " Send the message");
+ mSender = qSession.createSender(queue);
+ mSender.send(mapSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Write a null string to a StreamMessage.
+ *
+ */
+ public void readNullCharNotValidQueueStreamTestCreate() {
+ try {
+ StreamMessage messageSent = null;
+ char c;
+ boolean pass = true;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("TestCase", "readNullCharNotValidQueueStreamTest");
+ logger.log(Logger.Level.TRACE,
+ "Write a null string to the map message object with streamMessage.setString");
+ messageSent.writeString(null);
+ logger.log(Logger.Level.TRACE, " Send the message");
+ mSender = qSession.createSender(queue);
+ mSender.send(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Attempt to read a null string from a MapMessage. Should throw a
+ * null pointer exception
+ */
+
+ public void readNullCharNotValidQueueMapTest(jakarta.jms.MapMessage mapReceived) {
+ String testCase = "readNullCharNotValidQueueMapTest";
+ boolean pass = true;
+ try {
+ char c;
+ logger.log(Logger.Level.TRACE, "Use readChar to read a null ");
+ try {
+ c = mapReceived.getChar("WriteANull");
+ logger.log(Logger.Level.TRACE, "Fail: NullPointerException was not thrown");
+ pass = false;
+ } catch (java.lang.NullPointerException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+
+ }
+ /*
+ * Description: Attempt to read a null string from a StreamMessage. Should throw
+ * a null pointer exception
+ */
+
+ public void readNullCharNotValidQueueStreamTest(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "readNullCharNotValidQueueStreamTest";
+ boolean pass = true;
+ try {
+ char c;
+ logger.log(Logger.Level.TRACE, "Use readChar to read a null ");
+ try {
+ c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: NullPointerException was not thrown");
+ pass = false;
+ } catch (java.lang.NullPointerException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+
+ }
+
+ /*
+ * Description: send test results to response queue (MDB_QUEUE_REPLY) for
+ * verification
+ */
+ private void sendTestResults(String testCase, boolean results) {
+ TextMessage msg = null;
+
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ msg.setStringProperty("TestCase", testCase);
+ msg.setText(testCase);
+ if (results)
+ msg.setStringProperty("Status", "Pass");
+ else
+ msg.setStringProperty("Status", "Fail");
+
+ logger.log(Logger.Level.TRACE, "Sending response message");
+ logger.log(Logger.Level.TRACE, "==================================Test Results from: " + testCase);
+ logger.log(Logger.Level.TRACE, "==================================Status: " + results);
+ mSender.send(msg);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ logger.log(Logger.Level.TRACE, "Error: " + je.getClass().getName() + " was thrown");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.TRACE, "Error: " + ee.getClass().getName() + " was thrown");
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesQ3 In MsgBeanMsgTest3::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesQ3 In MsgBeanMsgTest3::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT1/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT1/MDBClient.java
deleted file mode 100644
index 01ee9e0275..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT1/MDBClient.java
+++ /dev/null
@@ -1,554 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesT1;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.MDB_T_Test;
-
-import jakarta.ejb.EJB;
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_MSGT1_Test")
- private static MDB_T_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.port;
- * harness.log.traceflag;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
- //
- /*
- * @testName: mdbBytesMsgNullStreamTopicTest
- *
- * @assertion_ids: JMS:SPEC:86.1; JMS:JAVADOC:714;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a byte message. Use writeObject to write a null. verify a
- * java.lang.NullPointerException is thrown.
- *
- *
- */
- public void mdbBytesMsgNullStreamTopicTest() throws Exception {
- String testCase = "bytesMsgNullStreamTopicTest";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace(
- "Call bean - have it tell mdb to run bytesMsgNullStreamTopicTest");
- hr.askMDBToRunATest(testCase);
- if (!hr.checkOnResponse(testCase)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbBytesMsgNullStreamTopicTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
- /*
- * @testName: mdbBytesMessageTopicTestsFullMsg
- *
- * @assertion_ids: JMS:JAVADOC:560; JMS:JAVADOC:562; JMS:JAVADOC:564;
- * JMS:JAVADOC:566; JMS:JAVADOC:568; JMS:JAVADOC:570; JMS:JAVADOC:572;
- * JMS:JAVADOC:574; JMS:JAVADOC:576; JMS:JAVADOC:578; JMS:JAVADOC:580;
- * JMS:JAVADOC:582; JMS:JAVADOC:534; JMS:JAVADOC:536; JMS:JAVADOC:540;
- * JMS:JAVADOC:544; JMS:JAVADOC:546; JMS:JAVADOC:548; JMS:JAVADOC:550;
- * JMS:JAVADOC:552; JMS:JAVADOC:554; JMS:JAVADOC:556; JMS:JAVADOC:558;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a BytesMessage -. write to the message using each type of method and
- * as an object. Send the message. Verify the data received was as sent.
- *
- */
-
- public void mdbBytesMessageTopicTestsFullMsg() throws Exception {
- String testCase1 = "bytesMessageTopicTestsFullMsgCreate";
- String testCase2 = "bytesMessageTopicTestsFullMsg";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase bytesMessageTopicTestsFullMsgCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- // System.out.println("client - run testcase2
- // bytesMessageTopicTestsFullMsg")
- // hr.askMDBToRunATest(testCase2) ; // read and verify message sent
- System.out.println(
- "client - Check for response from bytesMessageTopicTestsFullMsg");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: bytesMessageTopicTestsFullMsg failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageFullMsgTopicTest
- *
- * @assertion_ids: JMS:SPEC:74; JMS:JAVADOC:211; JMS:JAVADOC:457;
- * JMS:JAVADOC:459; JMS:JAVADOC:475; JMS:JAVADOC:477; JMS:JAVADOC:479;
- * JMS:JAVADOC:461; JMS:JAVADOC:463; JMS:JAVADOC:465; JMS:JAVADOC:467;
- * JMS:JAVADOC:469; JMS:JAVADOC:471; JMS:JAVADOC:473; JMS:JAVADOC:433;
- * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:439; JMS:JAVADOC:441;
- * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
- * JMS:JAVADOC:451; JMS:JAVADOC:453;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. write to the message using each type of method and
- * as an object. Send the message. Verify the data received was as sent.
- *
- */
- public void mdbMapMessageFullMsgTopicTest() throws Exception {
- String testCase1 = "mapMessageFullMsgTopicTestCreate";
- String testCase2 = "mapMessageFullMsgTopicTest";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase mapMessageFullMsgTopicTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- System.out.println(
- "client - Check for response from mapMessageFullMsgTopicTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageFullMsgTopicTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
- /*
- * @testName: mdbMapMessageConversionTopicTestsBoolean
- *
- * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:457;
- * JMS:JAVADOC:433; JMS:JAVADOC:449; JMS:JAVADOC:796; JMS:JAVADOC:797;
- * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeBoolean to write a
- * boolean to the message. Verify the proper conversion support as in 3.11.3
- */
-
- public void mdbMapMessageConversionTopicTestsBoolean() throws Exception {
- String testCase1 = "mapMessageConversionTopicTestsBooleanCreate";
- String testCase2 = "mapMessageConversionTopicTestsBoolean";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionTopicTestsBooleanCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- System.out.println(
- "client - Check for response from mapMessageConversionTopicTestsBoolean");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: mapMessageConversionTopicTestsBoolean failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionTopicTestsByte
- *
- * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:459;
- * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443;
- * JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:798; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method setByte to write a byte.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionTopicTestsByte() throws Exception {
- String testCase1 = "mapMessageConversionTopicTestsByteCreate";
- String testCase2 = "mapMessageConversionTopicTestsByte";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionTopicTestsByteCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- System.out.println(
- "client - Check for response from mapMessageConversionTopicTestsByte");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionTopicTestsByte failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionTopicTestsShort
- *
- * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:461;
- * JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449;
- * JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:798; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeShort to write a short.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionTopicTestsShort() throws Exception {
- String testCase1 = "mapMessageConversionTopicTestsShortCreate";
- String testCase2 = "mapMessageConversionTopicTestsShort";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionTopicTestsShortCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- System.out.println(
- "client - Check for response from mapMessageConversionTopicTestsShort");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: mapMessageConversionTopicTestsShort failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionTopicTestsChar
- *
- * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:463;
- * JMS:JAVADOC:439; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeChar to write a Char.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionTopicTestsChar() throws Exception {
- String testCase1 = "mapMessageConversionTopicTestsCharCreate";
- String testCase2 = "mapMessageConversionTopicTestsChar";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionTopicTestsCharCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- System.out.println(
- "client - Check for response from mapMessageConversionTopicTestsChar");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionTopicTestsChar failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionTopicTestsInt
- *
- * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:465;
- * JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795;
- * JMS:JAVADOC:796; JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeInt to write a int.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionTopicTestsInt() throws Exception {
- String testCase1 = "mapMessageConversionTopicTestsIntCreate";
- String testCase2 = "mapMessageConversionTopicTestsInt";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionTopicTestsIntCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- System.out.println(
- "client - Check for response from mapMessageConversionTopicTestsInt");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionTopicTestsInt failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionTopicTestsLong
- *
- * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:467;
- * JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeLong to write a long.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionTopicTestsLong() throws Exception {
- String testCase1 = "mapMessageConversionTopicTestsLongCreate";
- String testCase2 = "mapMessageConversionTopicTestsLong";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionTopicTestsLongCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- System.out.println(
- "client - Check for response from mapMessageConversionTopicTestsLong");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mapMessageConversionTopicTestsLong failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionTopicTestsFloat
- *
- * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:469;
- * JMS:JAVADOC:445; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
- * JMS:JAVADOC:802; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeFloat to write a float.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionTopicTestsFloat() throws Exception {
- String testCase1 = "mapMessageConversionTopicTestsFloatCreate";
- String testCase2 = "mapMessageConversionTopicTestsFloat";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionTopicTestsFloatCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- System.out.println(
- "client - Check for response from mapMessageConversionTopicTestsFloat");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: mapMessageConversionTopicTestsFloat failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionTopicTestsDouble
- *
- * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:471;
- * JMS:JAVADOC:447; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
- * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
- * JMS:JAVADOC:801; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeDouble to write a double.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionTopicTestsDouble() throws Exception {
- String testCase1 = "mapMessageConversionTopicTestsDoubleCreate";
- String testCase2 = "mapMessageConversionTopicTestsDouble";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionTopicTestsDoubleCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- System.out.println(
- "client - Check for response from mapMessageConversionTopicTestsDouble");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: mapMessageConversionTopicTestsDouble failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionTopicTestsString
- *
- * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:JAVADOC:473;
- * JMS:JAVADOC:433; JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441;
- * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
- * JMS:JAVADOC:798; JMS:JAVADOC:804;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeString to write a String.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionTopicTestsString() throws Exception {
- String testCase1 = "mapMessageConversionTopicTestsStringCreate";
- String testCase2 = "mapMessageConversionTopicTestsString";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionTopicTestsStringCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- System.out.println(
- "client - Check for response from mapMessageConversionTopicTestsString");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: mapMessageConversionTopicTestsString failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionTopicTestsBytes
- *
- * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:475;
- * JMS:JAVADOC:451; JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:797;
- * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
- * JMS:JAVADOC:802; JMS:JAVADOC:803;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method writeBytes to write a Bytes.
- * Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbMapMessageConversionTopicTestsBytes() throws Exception {
- String testCase1 = "mapMessageConversionTopicTestsBytesCreate";
- String testCase2 = "mapMessageConversionTopicTestsBytes";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionTopicTestsBytesCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- System.out.println(
- "client - Check for response from mapMessageConversionTopicTestsBytes");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: mapMessageConversionTopicTestsBytes failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMapMessageConversionTopicTestsInvFormatString
- *
- * @assertion_ids: JMS:SPEC:76;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a MapMessage -. use MapMessage method setString to write a text
- * string of "mytest string". Verify NumberFormatException is thrown
- *
- */
- public void mdbMapMessageConversionTopicTestsInvFormatString() throws Exception {
- String testCase1 = "mapMessageConversionTopicTestsInvFormatStringCreate";
- String testCase2 = "mapMessageConversionTopicTestsInvFormatString";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase mapMessageConversionTopicTestsInvFormatStringCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
- System.out.println(
- "client - Check for response from mapMessageConversionTopicTestsInvFormatString");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: mapMessageConversionTopicTestsInvFormatString failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- ;
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT1/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT1/MDBClientIT.java
new file mode 100644
index 0000000000..aea333af98
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT1/MDBClientIT.java
@@ -0,0 +1,539 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesT1;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.commonee.MDB_T_Test;
+
+import jakarta.ejb.EJB;
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_MSGT1_Test")
+ private static MDB_T_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password; harness.log.port;
+ * harness.log.traceflag;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ hr.setup(props);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+ //
+ /*
+ * @testName: mdbBytesMsgNullStreamTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:86.1; JMS:JAVADOC:714;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a byte message. Use writeObject to write a null. verify a
+ * java.lang.NullPointerException is thrown.
+ *
+ *
+ */
+ @Test
+ public void mdbBytesMsgNullStreamTopicTest() throws Exception {
+ String testCase = "bytesMsgNullStreamTopicTest";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to run bytesMsgNullStreamTopicTest");
+ hr.askMDBToRunATest(testCase);
+ if (!hr.checkOnResponse(testCase)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbBytesMsgNullStreamTopicTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbBytesMessageTopicTestsFullMsg
+ *
+ * @assertion_ids: JMS:JAVADOC:560; JMS:JAVADOC:562; JMS:JAVADOC:564;
+ * JMS:JAVADOC:566; JMS:JAVADOC:568; JMS:JAVADOC:570; JMS:JAVADOC:572;
+ * JMS:JAVADOC:574; JMS:JAVADOC:576; JMS:JAVADOC:578; JMS:JAVADOC:580;
+ * JMS:JAVADOC:582; JMS:JAVADOC:534; JMS:JAVADOC:536; JMS:JAVADOC:540;
+ * JMS:JAVADOC:544; JMS:JAVADOC:546; JMS:JAVADOC:548; JMS:JAVADOC:550;
+ * JMS:JAVADOC:552; JMS:JAVADOC:554; JMS:JAVADOC:556; JMS:JAVADOC:558;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a BytesMessage -. write to the message using each type of method and
+ * as an object. Send the message. Verify the data received was as sent.
+ *
+ */
+ @Test
+ public void mdbBytesMessageTopicTestsFullMsg() throws Exception {
+ String testCase1 = "bytesMessageTopicTestsFullMsgCreate";
+ String testCase2 = "bytesMessageTopicTestsFullMsg";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase bytesMessageTopicTestsFullMsgCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ // System.out.println("client - run testcase2
+ // bytesMessageTopicTestsFullMsg")
+ // hr.askMDBToRunATest(testCase2) ; // read and verify message sent
+ System.out.println("client - Check for response from bytesMessageTopicTestsFullMsg");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: bytesMessageTopicTestsFullMsg failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageFullMsgTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:74; JMS:JAVADOC:211; JMS:JAVADOC:457;
+ * JMS:JAVADOC:459; JMS:JAVADOC:475; JMS:JAVADOC:477; JMS:JAVADOC:479;
+ * JMS:JAVADOC:461; JMS:JAVADOC:463; JMS:JAVADOC:465; JMS:JAVADOC:467;
+ * JMS:JAVADOC:469; JMS:JAVADOC:471; JMS:JAVADOC:473; JMS:JAVADOC:433;
+ * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:439; JMS:JAVADOC:441;
+ * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
+ * JMS:JAVADOC:451; JMS:JAVADOC:453;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. write to the message using each type of method and as
+ * an object. Send the message. Verify the data received was as sent.
+ *
+ */
+ @Test
+ public void mdbMapMessageFullMsgTopicTest() throws Exception {
+ String testCase1 = "mapMessageFullMsgTopicTestCreate";
+ String testCase2 = "mapMessageFullMsgTopicTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageFullMsgTopicTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ System.out.println("client - Check for response from mapMessageFullMsgTopicTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageFullMsgTopicTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionTopicTestsBoolean
+ *
+ * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:457;
+ * JMS:JAVADOC:433; JMS:JAVADOC:449; JMS:JAVADOC:796; JMS:JAVADOC:797;
+ * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeBoolean to write a boolean
+ * to the message. Verify the proper conversion support as in 3.11.3
+ */
+ @Test
+ public void mdbMapMessageConversionTopicTestsBoolean() throws Exception {
+ String testCase1 = "mapMessageConversionTopicTestsBooleanCreate";
+ String testCase2 = "mapMessageConversionTopicTestsBoolean";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionTopicTestsBooleanCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ System.out.println("client - Check for response from mapMessageConversionTopicTestsBoolean");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionTopicTestsBoolean failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionTopicTestsByte
+ *
+ * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:459;
+ * JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443;
+ * JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:798; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method setByte to write a byte. Verify
+ * the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionTopicTestsByte() throws Exception {
+ String testCase1 = "mapMessageConversionTopicTestsByteCreate";
+ String testCase2 = "mapMessageConversionTopicTestsByte";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionTopicTestsByteCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ System.out.println("client - Check for response from mapMessageConversionTopicTestsByte");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionTopicTestsByte failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionTopicTestsShort
+ *
+ * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:461;
+ * JMS:JAVADOC:437; JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449;
+ * JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:798; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeShort to write a short.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionTopicTestsShort() throws Exception {
+ String testCase1 = "mapMessageConversionTopicTestsShortCreate";
+ String testCase2 = "mapMessageConversionTopicTestsShort";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionTopicTestsShortCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ System.out.println("client - Check for response from mapMessageConversionTopicTestsShort");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionTopicTestsShort failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionTopicTestsChar
+ *
+ * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:463;
+ * JMS:JAVADOC:439; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeChar to write a Char.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionTopicTestsChar() throws Exception {
+ String testCase1 = "mapMessageConversionTopicTestsCharCreate";
+ String testCase2 = "mapMessageConversionTopicTestsChar";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionTopicTestsCharCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ System.out.println("client - Check for response from mapMessageConversionTopicTestsChar");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionTopicTestsChar failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionTopicTestsInt
+ *
+ * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:465;
+ * JMS:JAVADOC:441; JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795;
+ * JMS:JAVADOC:796; JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeInt to write a int. Verify
+ * the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionTopicTestsInt() throws Exception {
+ String testCase1 = "mapMessageConversionTopicTestsIntCreate";
+ String testCase2 = "mapMessageConversionTopicTestsInt";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionTopicTestsIntCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ System.out.println("client - Check for response from mapMessageConversionTopicTestsInt");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionTopicTestsInt failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionTopicTestsLong
+ *
+ * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:467;
+ * JMS:JAVADOC:443; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeLong to write a long.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionTopicTestsLong() throws Exception {
+ String testCase1 = "mapMessageConversionTopicTestsLongCreate";
+ String testCase2 = "mapMessageConversionTopicTestsLong";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionTopicTestsLongCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ System.out.println("client - Check for response from mapMessageConversionTopicTestsLong");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionTopicTestsLong failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionTopicTestsFloat
+ *
+ * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:469;
+ * JMS:JAVADOC:445; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
+ * JMS:JAVADOC:802; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeFloat to write a float.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionTopicTestsFloat() throws Exception {
+ String testCase1 = "mapMessageConversionTopicTestsFloatCreate";
+ String testCase2 = "mapMessageConversionTopicTestsFloat";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionTopicTestsFloatCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ System.out.println("client - Check for response from mapMessageConversionTopicTestsFloat");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionTopicTestsFloat failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionTopicTestsDouble
+ *
+ * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:471;
+ * JMS:JAVADOC:447; JMS:JAVADOC:449; JMS:JAVADOC:795; JMS:JAVADOC:796;
+ * JMS:JAVADOC:797; JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800;
+ * JMS:JAVADOC:801; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeDouble to write a double.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionTopicTestsDouble() throws Exception {
+ String testCase1 = "mapMessageConversionTopicTestsDoubleCreate";
+ String testCase2 = "mapMessageConversionTopicTestsDouble";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionTopicTestsDoubleCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ System.out.println("client - Check for response from mapMessageConversionTopicTestsDouble");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionTopicTestsDouble failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionTopicTestsString
+ *
+ * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:JAVADOC:473;
+ * JMS:JAVADOC:433; JMS:JAVADOC:435; JMS:JAVADOC:437; JMS:JAVADOC:441;
+ * JMS:JAVADOC:443; JMS:JAVADOC:445; JMS:JAVADOC:447; JMS:JAVADOC:449;
+ * JMS:JAVADOC:798; JMS:JAVADOC:804;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeString to write a String.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionTopicTestsString() throws Exception {
+ String testCase1 = "mapMessageConversionTopicTestsStringCreate";
+ String testCase2 = "mapMessageConversionTopicTestsString";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionTopicTestsStringCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ System.out.println("client - Check for response from mapMessageConversionTopicTestsString");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionTopicTestsString failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionTopicTestsBytes
+ *
+ * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:475;
+ * JMS:JAVADOC:451; JMS:JAVADOC:795; JMS:JAVADOC:796; JMS:JAVADOC:797;
+ * JMS:JAVADOC:798; JMS:JAVADOC:799; JMS:JAVADOC:800; JMS:JAVADOC:801;
+ * JMS:JAVADOC:802; JMS:JAVADOC:803;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method writeBytes to write a Bytes.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionTopicTestsBytes() throws Exception {
+ String testCase1 = "mapMessageConversionTopicTestsBytesCreate";
+ String testCase2 = "mapMessageConversionTopicTestsBytes";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionTopicTestsBytesCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ System.out.println("client - Check for response from mapMessageConversionTopicTestsBytes");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionTopicTestsBytes failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMapMessageConversionTopicTestsInvFormatString
+ *
+ * @assertion_ids: JMS:SPEC:76;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a MapMessage -. use MapMessage method setString to write a text string
+ * of "mytest string". Verify NumberFormatException is thrown
+ *
+ */
+ @Test
+ public void mdbMapMessageConversionTopicTestsInvFormatString() throws Exception {
+ String testCase1 = "mapMessageConversionTopicTestsInvFormatStringCreate";
+ String testCase2 = "mapMessageConversionTopicTestsInvFormatString";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase mapMessageConversionTopicTestsInvFormatStringCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_TOPIC
+ System.out.println("client - Check for response from mapMessageConversionTopicTestsInvFormatString");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mapMessageConversionTopicTestsInvFormatString failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ ;
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT1/MsgBeanMsgTestT1.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT1/MsgBeanMsgTestT1.java
index cc26b7830e..666e9c7e04 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT1/MsgBeanMsgTestT1.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT1/MsgBeanMsgTestT1.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesT1;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.TSNamingContext;
@@ -49,3448 +50,3204 @@
public class MsgBeanMsgTestT1 implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- private MessageDrivenContext mdc = null;
-
- // JMS
- private QueueConnectionFactory qFactory = null;
-
- private TopicConnectionFactory tFactory = null;
-
- private QueueConnection qConnection = null;
-
- private TopicConnection tConnection = null;
-
- private Queue queueR = null;
-
- private Queue queue = null;
-
- private Topic topic = null;
-
- private QueueSender mSender = null;
-
- private QueueSession qSession = null;
-
- private TopicPublisher tPublisher = null;
-
- private TopicSession tSession = null;
-
- public MsgBeanMsgTestT1() {
- TestUtil.logTrace("@MsgBeanMsgTestT1()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgTypesT1 - @MsgBeanMsgTestT1-ejbCreate() !!");
- try {
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- if (qFactory == null) {
- TestUtil.logTrace("qFactory error");
- }
- TestUtil.logTrace("got a qFactory !!");
- tFactory = (TopicConnectionFactory) context
- .lookup("java:comp/env/jms/MyTopicConnectionFactory");
- if (tFactory == null) {
- TestUtil.logTrace("tFactory error");
- }
- TestUtil.logTrace("got a tFactory !!");
-
- queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- if (queueR == null) {
- TestUtil.logTrace("queueR error");
- }
-
- topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC");
- if (topic == null) {
- TestUtil.logTrace("topic error");
- }
-
- p = new Properties();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("from jms.ee.mdb.mdb_msgTypesT1 @onMessage!" + msg);
-
- try {
-
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null) {
- TestUtil.logTrace("connection error");
- } else {
- qConnection.start();
- qSession = qConnection.createQueueSession(true, 0);
- }
- tConnection = tFactory.createTopicConnection();
- if (tConnection == null) {
- TestUtil.logTrace("connection error");
- } else {
- tConnection.start();
- tSession = tConnection.createTopicSession(true, 0);
- }
-
- if (msg.getStringProperty("TestCase")
- .equals("bytesMsgNullStreamTopicTest")) {
- bytesMsgNullStreamTopicTest();
- } else if (msg.getStringProperty("TestCase")
- .equals("bytesMessageTopicTestsFullMsgCreate")) {
- TestUtil.logTrace(
- "@onMessage - running bytesMessageTopicTestsFullMsg1 - create the message");
- bytesMessageTopicTestsFullMsgCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("bytesMessageTopicTestsFullMsg")) {
- TestUtil.logTrace(
- "@onMessage - running bytesMessageTopicTestsFullMsg - read and verify the message");
- bytesMessageTopicTestsFullMsg((jakarta.jms.BytesMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageFullMsgTopicTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageFullMsgTopicTestCreate - read and verify the message");
- mapMessageFullMsgTopicTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageFullMsgTopicTest")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageFullMsgTopicTest - read and verify the message");
- mapMessageFullMsgTopicTest((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsBooleanCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsBooleanCreate - read and verify the message");
- mapMessageConversionTopicTestsBooleanCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsBoolean")) {
- TestUtil.logTrace(
- "@onMessage - running MapMessageConversionTopicTestsBoolean - read and verify the message");
- mapMessageConversionTopicTestsBoolean((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsByteCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsByteCreate - read and verify the message");
- mapMessageConversionTopicTestsByteCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsByte")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsByte - read and verify the message");
- mapMessageConversionTopicTestsByte((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsShortCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsShortCreate - read and verify the message");
- mapMessageConversionTopicTestsShortCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsShort")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsShort - read and verify the message");
- mapMessageConversionTopicTestsShort((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsCharCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsCharCreate - read and verify the message");
- mapMessageConversionTopicTestsCharCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsChar")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsChar - read and verify the message");
- mapMessageConversionTopicTestsChar((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsIntCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsIntCreate - read and verify the message");
- mapMessageConversionTopicTestsIntCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsInt")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsInt - read and verify the message");
- mapMessageConversionTopicTestsInt((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsLongCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsLongCreate - read and verify the message");
- mapMessageConversionTopicTestsLongCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsLong")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsLong - read and verify the message");
- mapMessageConversionTopicTestsLong((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsFloatCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsFloatCreate - read and verify the message");
- mapMessageConversionTopicTestsFloatCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsFloat")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsFloat - read and verify the message");
- mapMessageConversionTopicTestsFloat((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsDoubleCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsDoubleCreate - read and verify the message");
- mapMessageConversionTopicTestsDoubleCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsDouble")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsDouble - read and verify the message");
- mapMessageConversionTopicTestsDouble((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsStringCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsStringCreate - read and verify the message");
- mapMessageConversionTopicTestsStringCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsString")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsString - read and verify the message");
- mapMessageConversionTopicTestsString((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsBytesCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsBytesCreate - read and verify the message");
- mapMessageConversionTopicTestsBytesCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsBytes")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsBytes - read and verify the message");
- mapMessageConversionTopicTestsBytes((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsInvFormatStringCreate")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsInvFormatStringCreate - read and verify the message");
- mapMessageConversionTopicTestsInvFormatStringCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("mapMessageConversionTopicTestsInvFormatString")) {
- TestUtil.logTrace(
- "@onMessage - running mapMessageConversionTopicTestsInvFormatString - read and verify the message");
- mapMessageConversionTopicTestsInvFormatString(
- (jakarta.jms.MapMessage) msg);
- }
-
- else {
- TestUtil.logTrace(
- "@onMessage - invalid message type found in StringProperty");
- TestUtil
- .logTrace("@onMessage - could not find method for this testcase: "
- + msg.getStringProperty("TestCase"));
- }
- TestUtil.logTrace("@onMessage - Finished for this test!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- if (tConnection != null) {
- try {
- tConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
- }
-
- /*
- * BytesMessage does not support the concept of a null stream and attempting
- * to write a null into it must throw java.lang.NullPointerException. Jms
- * Specification 1.0.2, Section 3.12
- *
- * create a byte message. Use writeObject to write a null. verify a
- * java.lang.NullPointerException is thrown.
- *
- */
- private void bytesMsgNullStreamTopicTest() {
- BytesMessage messageSentBytesMessage = null;
- boolean ok = true;
- TextMessage msg = null;
- TestUtil.logTrace("@bytesMsgNullStreamTopicTest");
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.setStringProperty("TestCase", "bytesMsgNullStreamTopicTest");
- msg.setText("bytesMsgNullStreamTopicTest");
-
- TestUtil.logTrace(
- "Writing a null stream to byte message should throw a NullPointerException");
- messageSentBytesMessage = qSession.createBytesMessage();
- // write a null to the message
- messageSentBytesMessage.writeObject(null);
- TestUtil.logTrace(
- "Fail: message did not throw NullPointerException exception as expected");
- } catch (java.lang.NullPointerException np) {
- // this is what we want
- TestUtil.logTrace("Pass: NullPointerException thrown as expected");
- ok = true;
- } catch (JMSException jmsE) {
- TestUtil.printStackTrace(jmsE);
- // we did not get the anticipated exception
- TestUtil.logTrace("Error: " + jmsE.getClass().getName() + " was thrown");
- ok = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- // we did not get the anticipated exception here either!
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- ok = false;
- }
- try {
- if (ok)
- msg.setStringProperty("Status", "Pass");
- else
- msg.setStringProperty("Status", "Fail");
- TestUtil.logTrace("Sending response message");
- mSender.send(msg);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- TestUtil.logTrace("Error: " + je.getClass().getName() + " was thrown");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logTrace("Error: " + ee.getClass().getName() + " was thrown");
- }
- }
-
- /*
- * Description: Creates a BytesMessage -. writes to the message using each
- * type of method and as an object. Sends the message to MDB_QUEUE Msg
- * verified by ejb.
- *
- */
- private void bytesMessageTopicTestsFullMsgCreate() {
- mSender = null;
- TestUtil
- .logTrace("MsgBeanMsgTestT1 - @bytesMessageTopicTestsFullMsgCreate");
- try {
- BytesMessage messageSent = null;
- boolean pass = true;
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- Integer nInteger = new Integer(-2147483648);
- short shortValue = -32768;
- String utfValue = "what";
- TestUtil.logTrace("Creating 1 message");
-
- messageSent = qSession.createBytesMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "bytesMessageTopicTestsFullMsg");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace("Writing one of each primitive type to the message");
- // -----------------------------------------------------------------------------
-
- messageSent.writeBoolean(booleanValue);
- messageSent.writeByte(byteValue);
- messageSent.writeChar(charValue);
- messageSent.writeDouble(doubleValue);
- messageSent.writeFloat(floatValue);
- messageSent.writeInt(intValue);
- messageSent.writeLong(longValue);
- messageSent.writeObject(nInteger);
- messageSent.writeShort(shortValue);
- messageSent.writeUTF(utfValue);
- messageSent.writeBytes(bytesValue);
- messageSent.writeBytes(bytesValue, 0, 1);
-
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "bytesMessageTopicTestsFullMsg");
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- // send the message to defaultQueue
-
- tPublisher = tSession.createPublisher(topic);
- // send the message to another mdb handled Queue
- tPublisher.publish(messageSent);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: reads and verifies BytesMessage created by
- * bytesMessageTopicTestsFullMsgCreate
- */
- private void bytesMessageTopicTestsFullMsg(jakarta.jms.BytesMessage msg) {
- TestUtil.logTrace("MsgBeanMsgTestT1 - @bytesMessageTopicTestsFullMsg");
- String testCase = "bytesMessageTopicTestsFullMsg";
- try {
- BytesMessage messageSent = null;
- BytesMessage messageReceived = msg;
- boolean pass = true;
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- byte[] bytesValueRecvd = { 0, 0, 0, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- Integer nInteger = new Integer(-2147483648);
- short shortValue = -32768;
- String utfValue = "what";
-
- TestUtil.logTrace("Starting tests in @bytesMessageTopicTestsFullMsg");
-
- try {
- if (messageReceived.readBoolean() == booleanValue) {
- TestUtil.logTrace("Pass: boolean returned ok");
- } else {
- TestUtil.logTrace("Fail: boolean not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readByte() == byteValue) {
- TestUtil.logTrace("Pass: Byte returned ok");
- } else {
- TestUtil.logTrace("Fail: Byte not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readChar() == charValue) {
- TestUtil.logTrace("Pass: correct char");
- } else {
- TestUtil.logTrace("Fail: char not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readDouble() == doubleValue) {
- TestUtil.logTrace("Pass: correct double");
- } else {
- TestUtil.logTrace("Fail: double not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readFloat() == floatValue) {
- TestUtil.logTrace("Pass: correct float");
- } else {
- TestUtil.logTrace("Fail: float not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readInt() == intValue) {
- TestUtil.logTrace("Pass: correct int");
- } else {
- TestUtil.logTrace("Fail: int not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readLong() == longValue) {
- TestUtil.logTrace("Pass: correct long");
- } else {
- TestUtil.logTrace("Fail: long not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readInt() == nInteger.intValue()) {
- TestUtil.logTrace("Pass: correct Integer returned");
- } else {
- TestUtil.logTrace("Fail: Integer not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readShort() == shortValue) {
- TestUtil.logTrace("Pass: correct short");
- } else {
- TestUtil.logTrace("Fail: short not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readUTF().equals(utfValue)) {
- TestUtil.logTrace("Pass: correct UTF");
- } else {
- TestUtil.logTrace("Fail: UTF not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- int nCount = messageReceived.readBytes(bytesValueRecvd);
- for (int i = 0; i < nCount; i++) {
- if (bytesValueRecvd[i] != bytesValue[i]) {
- TestUtil.logTrace("Fail: bytes value incorrect");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte value " + i + " ok");
- }
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- int nCount = messageReceived.readBytes(bytesValueRecvd);
- TestUtil.logTrace("count returned " + nCount);
- if (bytesValueRecvd[0] != bytesValue[0]) {
- TestUtil.logTrace("Fail: bytes value incorrect");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte value ok");
- }
- if (nCount == 1) {
- TestUtil.logTrace("Pass: correct count");
- } else {
- TestUtil.logTrace("Fail: count not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- */
- private void mapMessageFullMsgTopicTestCreate() {
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- short shortValue = 32767;
- String stringValue = "Map Message Test";
- Integer integerValue = Integer.valueOf(100);
- String initial = "spring is here!";
- try {
- MapMessage messageSentMapMessage = null;
-
- TestUtil.logTrace("Send MapMessage to Topic.");
- messageSentMapMessage = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSentMapMessage, p);
- messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageFullMsgTopicTestCreate");
-
- messageSentMapMessage.setBoolean("booleanValue", booleanValue);
- messageSentMapMessage.setByte("byteValue", byteValue);
- messageSentMapMessage.setBytes("bytesValue", bytesValue);
- messageSentMapMessage.setBytes("bytesValue2", bytesValue, 0, 1);
- messageSentMapMessage.setChar("charValue", charValue);
- messageSentMapMessage.setDouble("doubleValue", doubleValue);
- messageSentMapMessage.setFloat("floatValue", floatValue);
- messageSentMapMessage.setInt("intValue", intValue);
- messageSentMapMessage.setLong("longValue", longValue);
- messageSentMapMessage.setObject("integerValue", integerValue);
- messageSentMapMessage.setShort("shortValue", shortValue);
-
- messageSentMapMessage.setString("stringValue", stringValue);
- messageSentMapMessage.setString("nullTest", null);
- // set up testcase so onMessage invokes the correct method
- messageSentMapMessage.setStringProperty("TestCase",
- "mapMessageFullMsgTopicTest");
-
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- // send the message to defaultQueue
-
- tPublisher = tSession.createPublisher(topic);
- // send the message to another mdb handled Queue
- tPublisher.publish(messageSentMapMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- */
- private void mapMessageFullMsgTopicTest(
- jakarta.jms.MapMessage messageReceivedMapMessage) {
- String testCase = "mapMessageFullMsgTopicTest";
- boolean pass = true;
- boolean booleanValue = false;
- byte byteValue = 127;
- byte[] bytesValue = { 127, -127, 1, 0 };
- char charValue = 'Z';
- double doubleValue = 6.02e23;
- float floatValue = 6.02e23f;
- int intValue = 2147483647;
- long longValue = 9223372036854775807L;
- short shortValue = 32767;
- String stringValue = "Map Message Test";
- Integer integerValue = Integer.valueOf(100);
- String initial = "spring is here!";
- try {
- try {
- if (messageReceivedMapMessage
- .getBoolean("booleanValue") == booleanValue) {
- TestUtil.logTrace("Pass: valid boolean returned");
- } else {
- TestUtil.logTrace("Fail: invalid boolean returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getByte("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: valid byte returned");
- } else {
- TestUtil.logTrace("Fail: invalid byte returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- byte[] b = messageReceivedMapMessage.getBytes("bytesValue");
- for (int i = 0; i < b.length; i++) {
- if (b[i] != bytesValue[i]) {
- TestUtil.logTrace("Fail: byte array " + i + " not valid");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte array " + i + " valid");
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- byte[] b = messageReceivedMapMessage.getBytes("bytesValue2");
- if (b[0] != bytesValue[0]) {
- TestUtil.logTrace("Fail: byte array not valid");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte array valid");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getChar("charValue") == charValue) {
- TestUtil.logTrace("Pass: valid char returned");
- } else {
- TestUtil.logTrace("Fail: invalid char returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getDouble("doubleValue") == doubleValue) {
- TestUtil.logTrace("Pass: valid double returned");
- } else {
- TestUtil.logTrace("Fail: invalid double returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getFloat("floatValue") == floatValue) {
- TestUtil.logTrace("Pass: valid float returned");
- } else {
- TestUtil.logTrace("Fail: invalid float returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getInt("intValue") == intValue) {
- TestUtil.logTrace("Pass: valid int returned");
- } else {
- TestUtil.logTrace("Fail: invalid int returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getLong("longValue") == longValue) {
- TestUtil.logTrace("Pass: valid long returned");
- } else {
- TestUtil.logTrace("Fail: invalid long returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
-
- if (messageReceivedMapMessage.getObject("integerValue").toString()
- .equals(integerValue.toString())) {
- TestUtil.logTrace("Pass: valid object returned");
- } else {
- TestUtil.logTrace("Fail: invalid object returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getShort("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: valid short returned");
- } else {
- TestUtil.logTrace("Fail: invalid short returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getString("stringValue")
- .equals(stringValue)) {
- TestUtil.logTrace("Pass: valid string returned");
- } else {
- TestUtil.logTrace("Fail: invalid string returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
-
- try {
- if (messageReceivedMapMessage.getString("nullTest") == null) {
- TestUtil.logTrace("Pass: null returned");
- } else {
-
- TestUtil.logTrace("Fail: null not returned from getString");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Fail: unexpected exception " + e.getClass().getName()
- + " was returned");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a MapMessage -. use MapMessage method writeBoolean to
- * write a boolean to the message.
- */
- private void mapMessageConversionTopicTestsBooleanCreate() {
- try {
- MapMessage messageSent = null;
- MapMessage messageReceived = null;
- boolean booleanValue = true;
- boolean pass = true;
-
- // set up test tool for Queue
- TestUtil.logTrace("Creating 1 message");
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionTopicTestsBooleanCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionTopicTestsBoolean");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for boolean primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setBoolean("booleanValue", booleanValue);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Descripton: For MapMessages Verify the proper conversion support for
- * boolean as in 3.11.3
- */
- private void mapMessageConversionTopicTestsBoolean(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionTopicTestsBoolean";
- try {
- boolean booleanValue = true;
- boolean pass = true;
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for boolean primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- // now test conversions for boolean
- // -----------------------------------------------
- // boolean to boolean - valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a boolean");
- try {
- if (messageReceived.getBoolean("booleanValue") == booleanValue) {
- TestUtil.logTrace("Pass: boolean to boolean - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a boolean");
- try {
- if (messageReceived.getString("booleanValue")
- .equals((Boolean.valueOf(booleanValue)).toString())) {
- TestUtil.logTrace("Pass: boolean to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to byte[] invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read a boolean - expect MessageFormatException");
- int nCount = 0;
- try {
- byte[] b = messageReceived.getBytes("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
- // -----------------------------------------------
- // boolean to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readByte to read a boolean - expect MessageFormatException");
- try {
- byte b = messageReceived.getByte("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readShort to read a boolean - expect MessageFormatException");
- try {
- short s = messageReceived.getShort("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
-
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readChar to read a boolean - expect MessageFormatException");
- try {
- char c = messageReceived.getChar("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to int invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readInt to read a boolean - expect MessageFormatException");
- try {
- int i = messageReceived.getInt("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readLong to read a boolean - expect MessageFormatException");
- try {
- long l = messageReceived.getLong("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to float invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readFloat to read a boolean - expect MessageFormatException");
- try {
- float f = messageReceived.getFloat("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
-
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to double invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readDouble to read a boolean - expect MessageFormatException");
- try {
- double d = messageReceived.getDouble("booleanValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
-
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- */
- private void mapMessageConversionTopicTestsByteCreate() {
- MapMessage messageSent = null;
- byte byteValue = 127;
- boolean pass = true;
- try {
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionTopicTestsByteCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionTopicTestsByte");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setByte("byteValue", byteValue);
- // send the message and then get it back
-
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- */
- private void mapMessageConversionTopicTestsByte(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionTopicTestsByte";
- MapMessage messageSent = null;
- byte byteValue = 127;
- boolean pass = true;
- try {
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------
- // byte to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a byte - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("byteValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a byte");
- try {
- if (messageReceived.getString("byteValue")
- .equals(Byte.toString(byteValue))) {
- TestUtil.logTrace("Pass: byte to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getBytes[] to read a byte - expect MessageFormatException");
- int nCount = 0;
- try {
- byte[] b = messageReceived.getBytes("byteValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to byte valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a byte");
- try {
- if (messageReceived.getByte("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to byte - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to short valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a byte");
- try {
- if (messageReceived.getShort("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to short - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a boolean - this is not valid");
- try {
- char c = messageReceived.getChar("byteValue");
- pass = false;
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a byte");
- try {
- if (messageReceived.getInt("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to int - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a byte");
- try {
- if (messageReceived.getLong("byteValue") == byteValue) {
- TestUtil.logTrace("Pass: byte to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a boolean - this is not valid");
- try {
- float f = messageReceived.getFloat("byteValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a boolean - this is not valid");
- try {
- double d = messageReceived.getDouble("byteValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeShort to
- * write a short.
- */
- public void mapMessageConversionTopicTestsShortCreate() {
- try {
- MapMessage messageSent = null;
- short shortValue = 1;
- boolean pass = true;
-
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "MapMessageConversionTopicTestsShort");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionTopicTestsShort");
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setShort("shortValue", shortValue);
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: MapMessage -. Verify the proper conversion support as in
- * 3.11.3
- */
- private void mapMessageConversionTopicTestsShort(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionTopicTestsShort";
- try {
- short shortValue = 1;
- boolean pass = true;
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- // now test conversions for byte
- // -----------------------------------------------
- // short to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a short - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("shortValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a short");
- try {
- if (messageReceived.getString("shortValue")
- .equals(Short.toString(shortValue))) {
- TestUtil.logTrace("Pass: short to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getBytes[] to read a short - expect MessageFormatException");
- try {
- byte[] b = messageReceived.getBytes("shortValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a short - this is not valid");
- try {
- byte b = messageReceived.getByte("shortValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to short valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a short");
- try {
- if (messageReceived.getShort("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: short to short - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a short - this is not valid");
- try {
- char c = messageReceived.getChar("shortValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a short");
- try {
- if (messageReceived.getInt("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: short to int - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a short");
- try {
- if (messageReceived.getLong("shortValue") == shortValue) {
- TestUtil.logTrace("Pass: short to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a short - this is not valid");
- try {
- float f = messageReceived.getFloat("shortValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a short - this is not valid");
- try {
- double d = messageReceived.getDouble("shortValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeChar to
- * write a char. Verify the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionTopicTestsCharCreate() {
- try {
- MapMessage messageSent = null;
- char charValue = 'a';
- boolean pass = true;
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionTopicTestsChar");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionTopicTestsChar");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- messageSent.setChar("charValue", charValue);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeInt to write
- * an int. Verify the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionTopicTestsIntCreate() {
- try {
- MapMessage messageSent = null;
- int intValue = 6;
- boolean pass = true;
-
- // set up test tool for Queue
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionTopicTestsIntCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionTopicTestsInt");
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setInt("intValue", intValue);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeLong to
- * write a long. Verify the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionTopicTestsLongCreate() {
- try {
- MapMessage messageSent = null;
- long longValue = 2;
- boolean pass = true;
-
- TestUtil.logTrace("Creating 1 message");
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionTopicTestsLongCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionTopicTestsLong");
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setLong("longValue", longValue);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeFloat to
- * write a float. Verify the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionTopicTestsFloatCreate() {
- try {
- MapMessage messageSent = null;
- float floatValue = 5;
- boolean pass = true;
-
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionTopicTestsFloatCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionTopicTestsFloat");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setFloat("floatValue", floatValue);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeDouble to
- * write a double. Verify the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionTopicTestsDoubleCreate() {
- try {
- MapMessage messageSent = null;
- double doubleValue = 3;
- boolean pass = true;
-
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionTopicTestsDoubleCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionTopicTestsDouble");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- messageSent.setDouble("doubleValue", doubleValue);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a MapMessage -. use MapMessage method writeString to
- * write a string. Verify the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionTopicTestsStringCreate() {
- try {
- MapMessage messageSent = null;
- boolean pass = true;
- String myString = "10";
- String myString2 = "true";
-
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionTopicTestsStringCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionTopicTestsString");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- messageSent.setString("myString", myString);
- messageSent.setString("myString2", myString2);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a MapMessage -. use MapMessage method writeBytes to
- * write a byte[] to the message. Verify the proper conversion support as in
- * 3.11.3
- */
- private void mapMessageConversionTopicTestsBytesCreate() {
- try {
- MapMessage messageSent = null;
- byte[] byteValues = { 1, 2, 3 };
- boolean pass = true;
-
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionTopicTestsBytesCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionTopicTestsBytes");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte[] primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setBytes("byteValues", byteValues);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a MapMessage -. use MapMessage method setString to
- * write a text string of "mytest string". Verify NumberFormatException is
- * thrown
- *
- */
- private void mapMessageConversionTopicTestsInvFormatStringCreate() {
- try {
- MapMessage messageSent = null;
- boolean pass = true;
- String myString = "mytest string";
-
- messageSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "mapMessageConversionTopicTestsInvFormatStringCreate");
- messageSent.setStringProperty("TestCase",
- "mapMessageConversionTopicTestsInvFormatString");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.setString("myString", myString);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeChar to write a char. Verify the
- * proper conversion support as in 3.11.3
- */
- private void mapMessageConversionTopicTestsChar(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionTopicTestsChar";
- try {
- char charValue = 'a';
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // char to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a char - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a char");
- try {
- if (messageReceived.getString("charValue")
- .equals(Character.valueOf(charValue).toString())) {
- TestUtil.logTrace("Pass: char to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getBytes[] to read a char - expect MessageFormatException");
- try {
- byte[] b = messageReceived.getBytes("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a char - this is not valid");
- try {
-
- byte b = messageReceived.getByte("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a char");
- try {
- short s = messageReceived.getShort("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to char valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a char ");
- try {
- if (messageReceived.getChar("charValue") == charValue) {
- TestUtil.logTrace("Pass: char to char - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to int invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a char ");
- try {
- int i = messageReceived.getInt("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a char");
- try {
- long l = messageReceived.getLong("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a char - this is not valid");
- try {
- float f = messageReceived.getFloat("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to double invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a char - this is not valid");
- try {
- double d = messageReceived.getDouble("charValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeInt to write an int. Verify the
- * proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionTopicTestsInt(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionTopicTestsInt";
- try {
-
- int intValue = 6;
- boolean pass = true;
- // now test conversions for byte
- // -----------------------------------------------
- // int to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read an int - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read an int");
- try {
- if (messageReceived.getString("intValue")
- .equals(Integer.toString(intValue))) {
- TestUtil.logTrace("Pass: int to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getBytes[] to read an int - expect MessageFormatException");
- int nCount = 0;
- try {
- byte[] b = messageReceived.getBytes("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read an int - this is not valid");
- try {
- byte b = messageReceived.getByte("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read an int");
- try {
- short s = messageReceived.getShort("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read an int - this is not valid");
- try {
- char c = messageReceived.getChar("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read an int");
- try {
- if (messageReceived.getInt("intValue") == intValue) {
- TestUtil.logTrace("Pass: int to int - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read an int");
- try {
- if (messageReceived.getLong("intValue") == intValue) {
- TestUtil.logTrace("Pass: int to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read an int - this is not valid");
- try {
- float f = messageReceived.getFloat("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read an int - this is not valid");
- try {
- double d = messageReceived.getDouble("intValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeLong to write a long. Verify the
- * proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionTopicTestsLong(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionTopicTestsLong";
- try {
-
- long longValue = 2;
- boolean pass = true;
- // now test conversions for byte
- // -----------------------------------------------
- // long to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a long - this is not valid");
- try {
- boolean b = messageReceived.getBoolean("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a long");
- try {
- if (messageReceived.getString("longValue")
- .equals(Long.toString(longValue))) {
- TestUtil.logTrace("Pass: long to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getBytes[] to read a long - expect MessageFormatException");
- try {
- byte[] b = messageReceived.getBytes("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read an long - this is not valid");
- try {
- byte b = messageReceived.getByte("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a long");
- try {
- short s = messageReceived.getShort("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a long - this is not valid");
- try {
- char c = messageReceived.getChar("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a long");
- try {
- int i = messageReceived.getInt("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a long");
- try {
- if (messageReceived.getLong("longValue") == longValue) {
- TestUtil.logTrace("Pass: int to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a long - this is not valid");
- try {
- float f = messageReceived.getFloat("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a long ");
- try {
- double d = messageReceived.getDouble("longValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeFloat to write a float. Verify the
- * proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionTopicTestsFloat(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionTopicTestsFloat";
- try {
- float floatValue = 5;
- boolean pass = true;
- // now test conversions for byte
- // -----------------------------------------------
- // float to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a float ");
- try {
- boolean b = messageReceived.getBoolean("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a float");
- try {
- if (messageReceived.getString("floatValue")
- .equals(Float.toString(floatValue))) {
- TestUtil.logTrace("Pass: float to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBytes[] to read a float ");
- try {
- byte[] b = messageReceived.getBytes("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // float to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a float ");
- try {
- byte b = messageReceived.getByte("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a float");
- try {
- short s = messageReceived.getShort("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // float to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a long ");
- try {
- char c = messageReceived.getChar("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a float");
- try {
- int i = messageReceived.getInt("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a long");
- try {
- long l = messageReceived.getLong("floatValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to float valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a float ");
- try {
- if (messageReceived.getFloat("floatValue") == floatValue) {
- TestUtil.logTrace("Pass: float to float - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to double valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a float ");
- try {
- if (messageReceived.getDouble("floatValue") == floatValue) {
- TestUtil.logTrace("Pass: float to double - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeDouble to write a double. Verify
- * the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionTopicTestsDouble(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionTopicTestsDouble";
-
- try {
-
- double doubleValue = 3;
- boolean pass = true;
- // now test conversions for byte
- // -----------------------------------------------
- // double to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a double ");
- try {
- boolean b = messageReceived.getBoolean("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a double");
- try {
- if (messageReceived.getString("doubleValue")
- .equals(Double.toString(doubleValue))) {
- TestUtil.logTrace("Pass: double to string");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBytes[] to read a double ");
- try {
- byte[] b = messageReceived.getBytes("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a double ");
- try {
- byte b = messageReceived.getByte("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a double");
- try {
- short s = messageReceived.getShort("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a double ");
- try {
- char c = messageReceived.getChar("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a double");
- try {
- int i = messageReceived.getInt("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a double");
- try {
- long l = messageReceived.getLong("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a double ");
- try {
- float f = messageReceived.getFloat("doubleValue");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to double valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read an float ");
- try {
- if (messageReceived.getDouble("doubleValue") == doubleValue) {
- TestUtil.logTrace("Pass: double to double ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeString to write a string. Verify
- * the proper conversion support as in 3.11.3
- *
- */
- private void mapMessageConversionTopicTestsString(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionTopicTestsString";
-
- try {
-
- boolean pass = true;
- String myString = "10";
- String myString2 = "true";
- // now test conversions for String
- // -----------------------------------------------
- // string to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a String");
- try {
- if (messageReceived.getString("myString").equals(myString)) {
- TestUtil.logTrace("Pass: string to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // string to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBytes[] to read a String");
- try {
- byte[] b = messageReceived.getBytes("myString");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to byte valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a String");
- try {
- if (messageReceived.getByte("myString") == Byte.parseByte(myString)) {
- TestUtil.logTrace("Pass: String to byte ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // string to short valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a string");
- try {
- if (messageReceived.getShort("myString") == Short
- .parseShort(myString)) {
- TestUtil.logTrace("Pass: String to short ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getChar to read a String ");
- try {
- char c = messageReceived.getChar("myString");
- TestUtil.logTrace("getChar returned " + c);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // string to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a String");
- try {
- if (messageReceived.getInt("myString") == Integer.parseInt(myString)) {
- TestUtil.logTrace("Pass: String to int ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a String");
- try {
- if (messageReceived.getLong("myString") == Long.parseLong(myString)) {
- TestUtil.logTrace("Pass: String to long ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a String");
- try {
- if (messageReceived.getFloat("myString") == Float
- .parseFloat(myString)) {
- TestUtil.logTrace("Pass: String to float ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to double valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a String");
- try {
-
- if (messageReceived.getDouble("myString") == Double
- .parseDouble(myString)) {
- TestUtil.logTrace("Pass: String to double ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a string ");
- try {
- if (messageReceived.getBoolean("myString2") == Boolean
- .valueOf(myString2).booleanValue()) {
- TestUtil.logTrace("Pass: String to boolean ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a string that is not true");
- try {
- boolean b = messageReceived.getBoolean("myString");
- if (b != false) {
- TestUtil.logTrace("Fail: !true should have returned false");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: !true returned false");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method writeBytes to write a byte[] to the
- * message. Verify the proper conversion support as in 3.11.3
- */
- private void mapMessageConversionTopicTestsBytes(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionTopicTestsBytes";
-
- try {
-
- byte[] byteValues = { 1, 2, 3 };
- boolean pass = true;
-
- // now test conversions for boolean
- // -----------------------------------------------
- // byte[] to byte[] - valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBytes[] to read a byte[] ");
- try {
- byte[] b = messageReceived.getBytes("byteValues");
- for (int i = 0; i < b.length; i++) {
- if (b[i] != byteValues[i]) {
- TestUtil.logTrace("Fail: byte[] value returned is invalid");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: byte[] returned is valid");
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getBoolean to read a byte[]");
- try {
- boolean b = messageReceived.getBoolean("byteValues");
- TestUtil.logTrace(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to string invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getString to read a byte[]");
- try {
- String s = messageReceived.getString("byteValues");
- TestUtil.logTrace(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getByte to read a byte[] - expect MessageFormatException");
- try {
- byte b = messageReceived.getByte("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getShort to read a byte[] - expect MessageFormatException");
- try {
- short s = messageReceived.getShort("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getChar to read a byte[] - expect MessageFormatException");
- try {
-
- char c = messageReceived.getChar("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to int invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getInt to read a byte[] - expect MessageFormatException");
- try {
- int i = messageReceived.getInt("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getLong to read a byte[] - expect MessageFormatException");
- try {
- long l = messageReceived.getLong("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getFloat to read a byte[] - expect MessageFormatException");
- try {
- float f = messageReceived.getFloat("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte[] to double invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use getDouble to read a byte[] - expect MessageFormatException");
- try {
- double d = messageReceived.getDouble("byteValues");
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (MessageFormatException mf) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: use MapMessage method setString to write a text string of
- * "mytest string". Verify NumberFormatException is thrown
- *
- */
- private void mapMessageConversionTopicTestsInvFormatString(
- jakarta.jms.MapMessage messageReceived) {
- String testCase = "mapMessageConversionTopicTestsInvFormatString";
-
- try {
- boolean pass = true;
- String myString = "mytest string";
-
- // -----------------------------------------------
- // String to byte
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getByte to read a String that is not valid ");
- try {
- byte b = messageReceived.getByte("myString");
- TestUtil.logTrace("Fail: java.lang.NumberFormatException expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // string to short
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getShort to read a string that is not valid ");
- try {
- short s = messageReceived.getShort("myString");
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to int
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getInt to read a String that is not valid ");
- try {
- int i = messageReceived.getInt("myString");
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getLong to read a String that is not valid ");
- try {
- long l = messageReceived.getLong("myString");
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getFloat to read a String that is not valid ");
- try {
- float f = messageReceived.getFloat("myString");
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to double
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use getDouble to read a String that is not valid ");
- try {
- double d = messageReceived.getDouble("myString");
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (NumberFormatException nf) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: send test results to response queue (MDB_QUEUE_REPLY) for
- * verification
- */
- private void sendTestResults(String testCase, boolean results) {
- TextMessage msg = null;
-
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- msg.setStringProperty("TestCase", testCase);
- msg.setText(testCase);
- if (results)
- msg.setStringProperty("Status", "Pass");
- else
- msg.setStringProperty("Status", "Fail");
-
- TestUtil.logTrace("Sending response message");
- TestUtil.logTrace(
- "==================================Test Results from: " + testCase);
- TestUtil.logTrace("==================================Status: " + results);
- mSender.send(msg);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- TestUtil.logTrace("Error: " + je.getClass().getName() + " was thrown");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logTrace("Error: " + ee.getClass().getName() + " was thrown");
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgTypesT1 In MsgBeanMsgTestT1::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil
- .logTrace("jms.ee.mdb.mdb_msgTypesT1 In MsgBeanMsgTestT1::remove()!!");
- }
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ private MessageDrivenContext mdc = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanMsgTestT1.class.getName());
+
+ // JMS
+ private QueueConnectionFactory qFactory = null;
+
+ private TopicConnectionFactory tFactory = null;
+
+ private QueueConnection qConnection = null;
+
+ private TopicConnection tConnection = null;
+
+ private Queue queueR = null;
+
+ private Queue queue = null;
+
+ private Topic topic = null;
+
+ private QueueSender mSender = null;
+
+ private QueueSession qSession = null;
+
+ private TopicPublisher tPublisher = null;
+
+ private TopicSession tSession = null;
+
+ public MsgBeanMsgTestT1() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanMsgTestT1()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesT1 - @MsgBeanMsgTestT1-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ if (qFactory == null) {
+ logger.log(Logger.Level.TRACE, "qFactory error");
+ }
+ logger.log(Logger.Level.TRACE, "got a qFactory !!");
+ tFactory = (TopicConnectionFactory) context.lookup("java:comp/env/jms/MyTopicConnectionFactory");
+ if (tFactory == null) {
+ logger.log(Logger.Level.TRACE, "tFactory error");
+ }
+ logger.log(Logger.Level.TRACE, "got a tFactory !!");
+
+ queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ if (queueR == null) {
+ logger.log(Logger.Level.TRACE, "queueR error");
+ }
+
+ topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC");
+ if (topic == null) {
+ logger.log(Logger.Level.TRACE, "topic error");
+ }
+
+ p = new Properties();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "from jms.ee.mdb.mdb_msgTypesT1 @onMessage!" + msg);
+
+ try {
+
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null) {
+ logger.log(Logger.Level.TRACE, "connection error");
+ } else {
+ qConnection.start();
+ qSession = qConnection.createQueueSession(true, 0);
+ }
+ tConnection = tFactory.createTopicConnection();
+ if (tConnection == null) {
+ logger.log(Logger.Level.TRACE, "connection error");
+ } else {
+ tConnection.start();
+ tSession = tConnection.createTopicSession(true, 0);
+ }
+
+ if (msg.getStringProperty("TestCase").equals("bytesMsgNullStreamTopicTest")) {
+ bytesMsgNullStreamTopicTest();
+ } else if (msg.getStringProperty("TestCase").equals("bytesMessageTopicTestsFullMsgCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running bytesMessageTopicTestsFullMsg1 - create the message");
+ bytesMessageTopicTestsFullMsgCreate();
+ } else if (msg.getStringProperty("TestCase").equals("bytesMessageTopicTestsFullMsg")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running bytesMessageTopicTestsFullMsg - read and verify the message");
+ bytesMessageTopicTestsFullMsg((jakarta.jms.BytesMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageFullMsgTopicTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageFullMsgTopicTestCreate - read and verify the message");
+ mapMessageFullMsgTopicTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageFullMsgTopicTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageFullMsgTopicTest - read and verify the message");
+ mapMessageFullMsgTopicTest((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsBooleanCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsBooleanCreate - read and verify the message");
+ mapMessageConversionTopicTestsBooleanCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsBoolean")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running MapMessageConversionTopicTestsBoolean - read and verify the message");
+ mapMessageConversionTopicTestsBoolean((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsByteCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsByteCreate - read and verify the message");
+ mapMessageConversionTopicTestsByteCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsByte")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsByte - read and verify the message");
+ mapMessageConversionTopicTestsByte((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsShortCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsShortCreate - read and verify the message");
+ mapMessageConversionTopicTestsShortCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsShort")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsShort - read and verify the message");
+ mapMessageConversionTopicTestsShort((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsCharCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsCharCreate - read and verify the message");
+ mapMessageConversionTopicTestsCharCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsChar")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsChar - read and verify the message");
+ mapMessageConversionTopicTestsChar((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsIntCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsIntCreate - read and verify the message");
+ mapMessageConversionTopicTestsIntCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsInt")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsInt - read and verify the message");
+ mapMessageConversionTopicTestsInt((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsLongCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsLongCreate - read and verify the message");
+ mapMessageConversionTopicTestsLongCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsLong")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsLong - read and verify the message");
+ mapMessageConversionTopicTestsLong((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsFloatCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsFloatCreate - read and verify the message");
+ mapMessageConversionTopicTestsFloatCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsFloat")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsFloat - read and verify the message");
+ mapMessageConversionTopicTestsFloat((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsDoubleCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsDoubleCreate - read and verify the message");
+ mapMessageConversionTopicTestsDoubleCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsDouble")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsDouble - read and verify the message");
+ mapMessageConversionTopicTestsDouble((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsStringCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsStringCreate - read and verify the message");
+ mapMessageConversionTopicTestsStringCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsString")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsString - read and verify the message");
+ mapMessageConversionTopicTestsString((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsBytesCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsBytesCreate - read and verify the message");
+ mapMessageConversionTopicTestsBytesCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsBytes")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsBytes - read and verify the message");
+ mapMessageConversionTopicTestsBytes((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase")
+ .equals("mapMessageConversionTopicTestsInvFormatStringCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsInvFormatStringCreate - read and verify the message");
+ mapMessageConversionTopicTestsInvFormatStringCreate();
+ } else if (msg.getStringProperty("TestCase").equals("mapMessageConversionTopicTestsInvFormatString")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running mapMessageConversionTopicTestsInvFormatString - read and verify the message");
+ mapMessageConversionTopicTestsInvFormatString((jakarta.jms.MapMessage) msg);
+ }
+
+ else {
+ logger.log(Logger.Level.TRACE, "@onMessage - invalid message type found in StringProperty");
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - could not find method for this testcase: " + msg.getStringProperty("TestCase"));
+ }
+ logger.log(Logger.Level.TRACE, "@onMessage - Finished for this test!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ if (tConnection != null) {
+ try {
+ tConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+ }
+
+ /*
+ * BytesMessage does not support the concept of a null stream and attempting to
+ * write a null into it must throw java.lang.NullPointerException. Jms
+ * Specification 1.0.2, Section 3.12
+ *
+ * create a byte message. Use writeObject to write a null. verify a
+ * java.lang.NullPointerException is thrown.
+ *
+ */
+ private void bytesMsgNullStreamTopicTest() {
+ BytesMessage messageSentBytesMessage = null;
+ boolean ok = true;
+ TextMessage msg = null;
+ logger.log(Logger.Level.TRACE, "@bytesMsgNullStreamTopicTest");
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.setStringProperty("TestCase", "bytesMsgNullStreamTopicTest");
+ msg.setText("bytesMsgNullStreamTopicTest");
+
+ logger.log(Logger.Level.TRACE, "Writing a null stream to byte message should throw a NullPointerException");
+ messageSentBytesMessage = qSession.createBytesMessage();
+ // write a null to the message
+ messageSentBytesMessage.writeObject(null);
+ logger.log(Logger.Level.TRACE, "Fail: message did not throw NullPointerException exception as expected");
+ } catch (java.lang.NullPointerException np) {
+ // this is what we want
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException thrown as expected");
+ ok = true;
+ } catch (JMSException jmsE) {
+ TestUtil.printStackTrace(jmsE);
+ // we did not get the anticipated exception
+ logger.log(Logger.Level.TRACE, "Error: " + jmsE.getClass().getName() + " was thrown");
+ ok = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ // we did not get the anticipated exception here either!
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ ok = false;
+ }
+ try {
+ if (ok)
+ msg.setStringProperty("Status", "Pass");
+ else
+ msg.setStringProperty("Status", "Fail");
+ logger.log(Logger.Level.TRACE, "Sending response message");
+ mSender.send(msg);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ logger.log(Logger.Level.TRACE, "Error: " + je.getClass().getName() + " was thrown");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.TRACE, "Error: " + ee.getClass().getName() + " was thrown");
+ }
+ }
+
+ /*
+ * Description: Creates a BytesMessage -. writes to the message using each type
+ * of method and as an object. Sends the message to MDB_QUEUE Msg verified by
+ * ejb.
+ *
+ */
+ private void bytesMessageTopicTestsFullMsgCreate() {
+ mSender = null;
+ logger.log(Logger.Level.TRACE, "MsgBeanMsgTestT1 - @bytesMessageTopicTestsFullMsgCreate");
+ try {
+ BytesMessage messageSent = null;
+ boolean pass = true;
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ Integer nInteger = new Integer(-2147483648);
+ short shortValue = -32768;
+ String utfValue = "what";
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+
+ messageSent = qSession.createBytesMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "bytesMessageTopicTestsFullMsg");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Writing one of each primitive type to the message");
+ // -----------------------------------------------------------------------------
+
+ messageSent.writeBoolean(booleanValue);
+ messageSent.writeByte(byteValue);
+ messageSent.writeChar(charValue);
+ messageSent.writeDouble(doubleValue);
+ messageSent.writeFloat(floatValue);
+ messageSent.writeInt(intValue);
+ messageSent.writeLong(longValue);
+ messageSent.writeObject(nInteger);
+ messageSent.writeShort(shortValue);
+ messageSent.writeUTF(utfValue);
+ messageSent.writeBytes(bytesValue);
+ messageSent.writeBytes(bytesValue, 0, 1);
+
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "bytesMessageTopicTestsFullMsg");
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ // send the message to defaultQueue
+
+ tPublisher = tSession.createPublisher(topic);
+ // send the message to another mdb handled Queue
+ tPublisher.publish(messageSent);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: reads and verifies BytesMessage created by
+ * bytesMessageTopicTestsFullMsgCreate
+ */
+ private void bytesMessageTopicTestsFullMsg(jakarta.jms.BytesMessage msg) {
+ logger.log(Logger.Level.TRACE, "MsgBeanMsgTestT1 - @bytesMessageTopicTestsFullMsg");
+ String testCase = "bytesMessageTopicTestsFullMsg";
+ try {
+ BytesMessage messageSent = null;
+ BytesMessage messageReceived = msg;
+ boolean pass = true;
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ byte[] bytesValueRecvd = { 0, 0, 0, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ Integer nInteger = new Integer(-2147483648);
+ short shortValue = -32768;
+ String utfValue = "what";
+
+ logger.log(Logger.Level.TRACE, "Starting tests in @bytesMessageTopicTestsFullMsg");
+
+ try {
+ if (messageReceived.readBoolean() == booleanValue) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean returned ok");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: boolean not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readByte() == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: Byte returned ok");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Byte not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readChar() == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct char");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: char not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readDouble() == doubleValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct double");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: double not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readFloat() == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct float");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: float not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readInt() == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct int");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: int not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readLong() == longValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct long");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: long not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readInt() == nInteger.intValue()) {
+ logger.log(Logger.Level.TRACE, "Pass: correct Integer returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Integer not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readShort() == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct short");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: short not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readUTF().equals(utfValue)) {
+ logger.log(Logger.Level.TRACE, "Pass: correct UTF");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: UTF not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ int nCount = messageReceived.readBytes(bytesValueRecvd);
+ for (int i = 0; i < nCount; i++) {
+ if (bytesValueRecvd[i] != bytesValue[i]) {
+ logger.log(Logger.Level.TRACE, "Fail: bytes value incorrect");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte value " + i + " ok");
+ }
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ int nCount = messageReceived.readBytes(bytesValueRecvd);
+ logger.log(Logger.Level.TRACE, "count returned " + nCount);
+ if (bytesValueRecvd[0] != bytesValue[0]) {
+ logger.log(Logger.Level.TRACE, "Fail: bytes value incorrect");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte value ok");
+ }
+ if (nCount == 1) {
+ logger.log(Logger.Level.TRACE, "Pass: correct count");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: count not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ */
+ private void mapMessageFullMsgTopicTestCreate() {
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ short shortValue = 32767;
+ String stringValue = "Map Message Test";
+ Integer integerValue = Integer.valueOf(100);
+ String initial = "spring is here!";
+ try {
+ MapMessage messageSentMapMessage = null;
+
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Topic.");
+ messageSentMapMessage = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSentMapMessage, p);
+ messageSentMapMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageFullMsgTopicTestCreate");
+
+ messageSentMapMessage.setBoolean("booleanValue", booleanValue);
+ messageSentMapMessage.setByte("byteValue", byteValue);
+ messageSentMapMessage.setBytes("bytesValue", bytesValue);
+ messageSentMapMessage.setBytes("bytesValue2", bytesValue, 0, 1);
+ messageSentMapMessage.setChar("charValue", charValue);
+ messageSentMapMessage.setDouble("doubleValue", doubleValue);
+ messageSentMapMessage.setFloat("floatValue", floatValue);
+ messageSentMapMessage.setInt("intValue", intValue);
+ messageSentMapMessage.setLong("longValue", longValue);
+ messageSentMapMessage.setObject("integerValue", integerValue);
+ messageSentMapMessage.setShort("shortValue", shortValue);
+
+ messageSentMapMessage.setString("stringValue", stringValue);
+ messageSentMapMessage.setString("nullTest", null);
+ // set up testcase so onMessage invokes the correct method
+ messageSentMapMessage.setStringProperty("TestCase", "mapMessageFullMsgTopicTest");
+
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ // send the message to defaultQueue
+
+ tPublisher = tSession.createPublisher(topic);
+ // send the message to another mdb handled Queue
+ tPublisher.publish(messageSentMapMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ */
+ private void mapMessageFullMsgTopicTest(jakarta.jms.MapMessage messageReceivedMapMessage) {
+ String testCase = "mapMessageFullMsgTopicTest";
+ boolean pass = true;
+ boolean booleanValue = false;
+ byte byteValue = 127;
+ byte[] bytesValue = { 127, -127, 1, 0 };
+ char charValue = 'Z';
+ double doubleValue = 6.02e23;
+ float floatValue = 6.02e23f;
+ int intValue = 2147483647;
+ long longValue = 9223372036854775807L;
+ short shortValue = 32767;
+ String stringValue = "Map Message Test";
+ Integer integerValue = Integer.valueOf(100);
+ String initial = "spring is here!";
+ try {
+ try {
+ if (messageReceivedMapMessage.getBoolean("booleanValue") == booleanValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid boolean returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid boolean returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getByte("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid byte returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid byte returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ byte[] b = messageReceivedMapMessage.getBytes("bytesValue");
+ for (int i = 0; i < b.length; i++) {
+ if (b[i] != bytesValue[i]) {
+ logger.log(Logger.Level.TRACE, "Fail: byte array " + i + " not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte array " + i + " valid");
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ byte[] b = messageReceivedMapMessage.getBytes("bytesValue2");
+ if (b[0] != bytesValue[0]) {
+ logger.log(Logger.Level.TRACE, "Fail: byte array not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte array valid");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getChar("charValue") == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid char returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid char returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getDouble("doubleValue") == doubleValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid double returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid double returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getFloat("floatValue") == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid float returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid float returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getInt("intValue") == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid int returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid int returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getLong("longValue") == longValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid long returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid long returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+
+ if (messageReceivedMapMessage.getObject("integerValue").toString().equals(integerValue.toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: valid object returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid object returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getShort("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: valid short returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid short returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getString("stringValue").equals(stringValue)) {
+ logger.log(Logger.Level.TRACE, "Pass: valid string returned");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: invalid string returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+
+ try {
+ if (messageReceivedMapMessage.getString("nullTest") == null) {
+ logger.log(Logger.Level.TRACE, "Pass: null returned");
+ } else {
+
+ logger.log(Logger.Level.TRACE, "Fail: null not returned from getString");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE,
+ "Fail: unexpected exception " + e.getClass().getName() + " was returned");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a MapMessage -. use MapMessage method writeBoolean to
+ * write a boolean to the message.
+ */
+ private void mapMessageConversionTopicTestsBooleanCreate() {
+ try {
+ MapMessage messageSent = null;
+ MapMessage messageReceived = null;
+ boolean booleanValue = true;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionTopicTestsBooleanCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionTopicTestsBoolean");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for boolean primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setBoolean("booleanValue", booleanValue);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Descripton: For MapMessages Verify the proper conversion support for boolean
+ * as in 3.11.3
+ */
+ private void mapMessageConversionTopicTestsBoolean(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionTopicTestsBoolean";
+ try {
+ boolean booleanValue = true;
+ boolean pass = true;
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for boolean primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // boolean to boolean - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a boolean");
+ try {
+ if (messageReceived.getBoolean("booleanValue") == booleanValue) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to boolean - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a boolean");
+ try {
+ if (messageReceived.getString("booleanValue").equals((Boolean.valueOf(booleanValue)).toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to byte[] invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a boolean - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ byte[] b = messageReceived.getBytes("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+ // -----------------------------------------------
+ // boolean to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a boolean - expect MessageFormatException");
+ try {
+ byte b = messageReceived.getByte("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a boolean - expect MessageFormatException");
+ try {
+ short s = messageReceived.getShort("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a boolean - expect MessageFormatException");
+ try {
+ char c = messageReceived.getChar("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a boolean - expect MessageFormatException");
+ try {
+ int i = messageReceived.getInt("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a boolean - expect MessageFormatException");
+ try {
+ long l = messageReceived.getLong("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to float invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a boolean - expect MessageFormatException");
+ try {
+ float f = messageReceived.getFloat("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a boolean - expect MessageFormatException");
+ try {
+ double d = messageReceived.getDouble("booleanValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ */
+ private void mapMessageConversionTopicTestsByteCreate() {
+ MapMessage messageSent = null;
+ byte byteValue = 127;
+ boolean pass = true;
+ try {
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionTopicTestsByteCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionTopicTestsByte");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setByte("byteValue", byteValue);
+ // send the message and then get it back
+
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ */
+ private void mapMessageConversionTopicTestsByte(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionTopicTestsByte";
+ MapMessage messageSent = null;
+ byte byteValue = 127;
+ boolean pass = true;
+ try {
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------
+ // byte to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a byte - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("byteValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a byte");
+ try {
+ if (messageReceived.getString("byteValue").equals(Byte.toString(byteValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a byte - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ byte[] b = messageReceived.getBytes("byteValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a byte");
+ try {
+ if (messageReceived.getByte("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to byte - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a byte");
+ try {
+ if (messageReceived.getShort("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to short - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a boolean - this is not valid");
+ try {
+ char c = messageReceived.getChar("byteValue");
+ pass = false;
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a byte");
+ try {
+ if (messageReceived.getInt("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to int - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a byte");
+ try {
+ if (messageReceived.getLong("byteValue") == byteValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a boolean - this is not valid");
+ try {
+ float f = messageReceived.getFloat("byteValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a boolean - this is not valid");
+ try {
+ double d = messageReceived.getDouble("byteValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeShort to write
+ * a short.
+ */
+ public void mapMessageConversionTopicTestsShortCreate() {
+ try {
+ MapMessage messageSent = null;
+ short shortValue = 1;
+ boolean pass = true;
+
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "MapMessageConversionTopicTestsShort");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionTopicTestsShort");
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setShort("shortValue", shortValue);
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: MapMessage -. Verify the proper conversion support as in 3.11.3
+ */
+ private void mapMessageConversionTopicTestsShort(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionTopicTestsShort";
+ try {
+ short shortValue = 1;
+ boolean pass = true;
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // short to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a short - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("shortValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a short");
+ try {
+ if (messageReceived.getString("shortValue").equals(Short.toString(shortValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: short to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a short - expect MessageFormatException");
+ try {
+ byte[] b = messageReceived.getBytes("shortValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a short - this is not valid");
+ try {
+ byte b = messageReceived.getByte("shortValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a short");
+ try {
+ if (messageReceived.getShort("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to short - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a short - this is not valid");
+ try {
+ char c = messageReceived.getChar("shortValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a short");
+ try {
+ if (messageReceived.getInt("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to int - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a short");
+ try {
+ if (messageReceived.getLong("shortValue") == shortValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a short - this is not valid");
+ try {
+ float f = messageReceived.getFloat("shortValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a short - this is not valid");
+ try {
+ double d = messageReceived.getDouble("shortValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeChar to write
+ * a char. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionTopicTestsCharCreate() {
+ try {
+ MapMessage messageSent = null;
+ char charValue = 'a';
+ boolean pass = true;
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionTopicTestsChar");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionTopicTestsChar");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ messageSent.setChar("charValue", charValue);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeInt to write
+ * an int. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionTopicTestsIntCreate() {
+ try {
+ MapMessage messageSent = null;
+ int intValue = 6;
+ boolean pass = true;
+
+ // set up test tool for Queue
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionTopicTestsIntCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionTopicTestsInt");
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setInt("intValue", intValue);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeLong to write
+ * a long. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionTopicTestsLongCreate() {
+ try {
+ MapMessage messageSent = null;
+ long longValue = 2;
+ boolean pass = true;
+
+ logger.log(Logger.Level.TRACE, "Creating 1 message");
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionTopicTestsLongCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionTopicTestsLong");
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setLong("longValue", longValue);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeFloat to write
+ * a float. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionTopicTestsFloatCreate() {
+ try {
+ MapMessage messageSent = null;
+ float floatValue = 5;
+ boolean pass = true;
+
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionTopicTestsFloatCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionTopicTestsFloat");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setFloat("floatValue", floatValue);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeDouble to
+ * write a double. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionTopicTestsDoubleCreate() {
+ try {
+ MapMessage messageSent = null;
+ double doubleValue = 3;
+ boolean pass = true;
+
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionTopicTestsDoubleCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionTopicTestsDouble");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ messageSent.setDouble("doubleValue", doubleValue);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a MapMessage -. use MapMessage method writeString to
+ * write a string. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionTopicTestsStringCreate() {
+ try {
+ MapMessage messageSent = null;
+ boolean pass = true;
+ String myString = "10";
+ String myString2 = "true";
+
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionTopicTestsStringCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionTopicTestsString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ messageSent.setString("myString", myString);
+ messageSent.setString("myString2", myString2);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a MapMessage -. use MapMessage method writeBytes to write
+ * a byte[] to the message. Verify the proper conversion support as in 3.11.3
+ */
+ private void mapMessageConversionTopicTestsBytesCreate() {
+ try {
+ MapMessage messageSent = null;
+ byte[] byteValues = { 1, 2, 3 };
+ boolean pass = true;
+
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "mapMessageConversionTopicTestsBytesCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionTopicTestsBytes");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte[] primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setBytes("byteValues", byteValues);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a MapMessage -. use MapMessage method setString to write
+ * a text string of "mytest string". Verify NumberFormatException is thrown
+ *
+ */
+ private void mapMessageConversionTopicTestsInvFormatStringCreate() {
+ try {
+ MapMessage messageSent = null;
+ boolean pass = true;
+ String myString = "mytest string";
+
+ messageSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
+ "mapMessageConversionTopicTestsInvFormatStringCreate");
+ messageSent.setStringProperty("TestCase", "mapMessageConversionTopicTestsInvFormatString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.setString("myString", myString);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeChar to write a char. Verify the
+ * proper conversion support as in 3.11.3
+ */
+ private void mapMessageConversionTopicTestsChar(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionTopicTestsChar";
+ try {
+ char charValue = 'a';
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // char to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a char - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a char");
+ try {
+ if (messageReceived.getString("charValue").equals(Character.valueOf(charValue).toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: char to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a char - expect MessageFormatException");
+ try {
+ byte[] b = messageReceived.getBytes("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a char - this is not valid");
+ try {
+
+ byte b = messageReceived.getByte("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a char");
+ try {
+ short s = messageReceived.getShort("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to char valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a char ");
+ try {
+ if (messageReceived.getChar("charValue") == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: char to char - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a char ");
+ try {
+ int i = messageReceived.getInt("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a char");
+ try {
+ long l = messageReceived.getLong("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a char - this is not valid");
+ try {
+ float f = messageReceived.getFloat("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a char - this is not valid");
+ try {
+ double d = messageReceived.getDouble("charValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeInt to write an int. Verify the
+ * proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionTopicTestsInt(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionTopicTestsInt";
+ try {
+
+ int intValue = 6;
+ boolean pass = true;
+ // now test conversions for byte
+ // -----------------------------------------------
+ // int to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read an int - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read an int");
+ try {
+ if (messageReceived.getString("intValue").equals(Integer.toString(intValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: int to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read an int - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ byte[] b = messageReceived.getBytes("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read an int - this is not valid");
+ try {
+ byte b = messageReceived.getByte("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read an int");
+ try {
+ short s = messageReceived.getShort("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read an int - this is not valid");
+ try {
+ char c = messageReceived.getChar("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read an int");
+ try {
+ if (messageReceived.getInt("intValue") == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to int - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read an int");
+ try {
+ if (messageReceived.getLong("intValue") == intValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read an int - this is not valid");
+ try {
+ float f = messageReceived.getFloat("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read an int - this is not valid");
+ try {
+ double d = messageReceived.getDouble("intValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeLong to write a long. Verify the
+ * proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionTopicTestsLong(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionTopicTestsLong";
+ try {
+
+ long longValue = 2;
+ boolean pass = true;
+ // now test conversions for byte
+ // -----------------------------------------------
+ // long to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a long - this is not valid");
+ try {
+ boolean b = messageReceived.getBoolean("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a long");
+ try {
+ if (messageReceived.getString("longValue").equals(Long.toString(longValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: long to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a long - expect MessageFormatException");
+ try {
+ byte[] b = messageReceived.getBytes("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read an long - this is not valid");
+ try {
+ byte b = messageReceived.getByte("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a long");
+ try {
+ short s = messageReceived.getShort("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a long - this is not valid");
+ try {
+ char c = messageReceived.getChar("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a long");
+ try {
+ int i = messageReceived.getInt("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a long");
+ try {
+ if (messageReceived.getLong("longValue") == longValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a long - this is not valid");
+ try {
+ float f = messageReceived.getFloat("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a long ");
+ try {
+ double d = messageReceived.getDouble("longValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeFloat to write a float. Verify the
+ * proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionTopicTestsFloat(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionTopicTestsFloat";
+ try {
+ float floatValue = 5;
+ boolean pass = true;
+ // now test conversions for byte
+ // -----------------------------------------------
+ // float to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a float ");
+ try {
+ boolean b = messageReceived.getBoolean("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a float");
+ try {
+ if (messageReceived.getString("floatValue").equals(Float.toString(floatValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: float to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a float ");
+ try {
+ byte[] b = messageReceived.getBytes("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a float ");
+ try {
+ byte b = messageReceived.getByte("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a float");
+ try {
+ short s = messageReceived.getShort("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // float to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a long ");
+ try {
+ char c = messageReceived.getChar("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a float");
+ try {
+ int i = messageReceived.getInt("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a long");
+ try {
+ long l = messageReceived.getLong("floatValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a float ");
+ try {
+ if (messageReceived.getFloat("floatValue") == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to float - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to double valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a float ");
+ try {
+ if (messageReceived.getDouble("floatValue") == floatValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to double - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeDouble to write a double. Verify the
+ * proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionTopicTestsDouble(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionTopicTestsDouble";
+
+ try {
+
+ double doubleValue = 3;
+ boolean pass = true;
+ // now test conversions for byte
+ // -----------------------------------------------
+ // double to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a double ");
+ try {
+ boolean b = messageReceived.getBoolean("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a double");
+ try {
+ if (messageReceived.getString("doubleValue").equals(Double.toString(doubleValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: double to string");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a double ");
+ try {
+ byte[] b = messageReceived.getBytes("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a double ");
+ try {
+ byte b = messageReceived.getByte("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a double");
+ try {
+ short s = messageReceived.getShort("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a double ");
+ try {
+ char c = messageReceived.getChar("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a double");
+ try {
+ int i = messageReceived.getInt("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a double");
+ try {
+ long l = messageReceived.getLong("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a double ");
+ try {
+ float f = messageReceived.getFloat("doubleValue");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to double valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read an float ");
+ try {
+ if (messageReceived.getDouble("doubleValue") == doubleValue) {
+ logger.log(Logger.Level.TRACE, "Pass: double to double ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeString to write a string. Verify the
+ * proper conversion support as in 3.11.3
+ *
+ */
+ private void mapMessageConversionTopicTestsString(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionTopicTestsString";
+
+ try {
+
+ boolean pass = true;
+ String myString = "10";
+ String myString2 = "true";
+ // now test conversions for String
+ // -----------------------------------------------
+ // string to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a String");
+ try {
+ if (messageReceived.getString("myString").equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: string to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // string to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a String");
+ try {
+ byte[] b = messageReceived.getBytes("myString");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a String");
+ try {
+ if (messageReceived.getByte("myString") == Byte.parseByte(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to byte ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // string to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a string");
+ try {
+ if (messageReceived.getShort("myString") == Short.parseShort(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to short ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a String ");
+ try {
+ char c = messageReceived.getChar("myString");
+ logger.log(Logger.Level.TRACE, "getChar returned " + c);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // string to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a String");
+ try {
+ if (messageReceived.getInt("myString") == Integer.parseInt(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to int ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a String");
+ try {
+ if (messageReceived.getLong("myString") == Long.parseLong(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to long ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a String");
+ try {
+ if (messageReceived.getFloat("myString") == Float.parseFloat(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to float ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to double valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a String");
+ try {
+
+ if (messageReceived.getDouble("myString") == Double.parseDouble(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to double ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a string ");
+ try {
+ if (messageReceived.getBoolean("myString2") == Boolean.valueOf(myString2).booleanValue()) {
+ logger.log(Logger.Level.TRACE, "Pass: String to boolean ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a string that is not true");
+ try {
+ boolean b = messageReceived.getBoolean("myString");
+ if (b != false) {
+ logger.log(Logger.Level.TRACE, "Fail: !true should have returned false");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: !true returned false");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method writeBytes to write a byte[] to the
+ * message. Verify the proper conversion support as in 3.11.3
+ */
+ private void mapMessageConversionTopicTestsBytes(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionTopicTestsBytes";
+
+ try {
+
+ byte[] byteValues = { 1, 2, 3 };
+ boolean pass = true;
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // byte[] to byte[] - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBytes[] to read a byte[] ");
+ try {
+ byte[] b = messageReceived.getBytes("byteValues");
+ for (int i = 0; i < b.length; i++) {
+ if (b[i] != byteValues[i]) {
+ logger.log(Logger.Level.TRACE, "Fail: byte[] value returned is invalid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: byte[] returned is valid");
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getBoolean to read a byte[]");
+ try {
+ boolean b = messageReceived.getBoolean("byteValues");
+ logger.log(Logger.Level.TRACE,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to string invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getString to read a byte[]");
+ try {
+ String s = messageReceived.getString("byteValues");
+ logger.log(Logger.Level.TRACE,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a byte[] - expect MessageFormatException");
+ try {
+ byte b = messageReceived.getByte("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a byte[] - expect MessageFormatException");
+ try {
+ short s = messageReceived.getShort("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getChar to read a byte[] - expect MessageFormatException");
+ try {
+
+ char c = messageReceived.getChar("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a byte[] - expect MessageFormatException");
+ try {
+ int i = messageReceived.getInt("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a byte[] - expect MessageFormatException");
+ try {
+ long l = messageReceived.getLong("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a byte[] - expect MessageFormatException");
+ try {
+ float f = messageReceived.getFloat("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte[] to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a byte[] - expect MessageFormatException");
+ try {
+ double d = messageReceived.getDouble("byteValues");
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (MessageFormatException mf) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: use MapMessage method setString to write a text string of
+ * "mytest string". Verify NumberFormatException is thrown
+ *
+ */
+ private void mapMessageConversionTopicTestsInvFormatString(jakarta.jms.MapMessage messageReceived) {
+ String testCase = "mapMessageConversionTopicTestsInvFormatString";
+
+ try {
+ boolean pass = true;
+ String myString = "mytest string";
+
+ // -----------------------------------------------
+ // String to byte
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getByte to read a String that is not valid ");
+ try {
+ byte b = messageReceived.getByte("myString");
+ logger.log(Logger.Level.TRACE, "Fail: java.lang.NumberFormatException expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // string to short
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getShort to read a string that is not valid ");
+ try {
+ short s = messageReceived.getShort("myString");
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to int
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getInt to read a String that is not valid ");
+ try {
+ int i = messageReceived.getInt("myString");
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getLong to read a String that is not valid ");
+ try {
+ long l = messageReceived.getLong("myString");
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getFloat to read a String that is not valid ");
+ try {
+ float f = messageReceived.getFloat("myString");
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to double
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use getDouble to read a String that is not valid ");
+ try {
+ double d = messageReceived.getDouble("myString");
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (NumberFormatException nf) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: send test results to response queue (MDB_QUEUE_REPLY) for
+ * verification
+ */
+ private void sendTestResults(String testCase, boolean results) {
+ TextMessage msg = null;
+
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ msg.setStringProperty("TestCase", testCase);
+ msg.setText(testCase);
+ if (results)
+ msg.setStringProperty("Status", "Pass");
+ else
+ msg.setStringProperty("Status", "Fail");
+
+ logger.log(Logger.Level.TRACE, "Sending response message");
+ logger.log(Logger.Level.TRACE, "==================================Test Results from: " + testCase);
+ logger.log(Logger.Level.TRACE, "==================================Status: " + results);
+ mSender.send(msg);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ logger.log(Logger.Level.TRACE, "Error: " + je.getClass().getName() + " was thrown");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.TRACE, "Error: " + ee.getClass().getName() + " was thrown");
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesT1 In MsgBeanMsgTestT1::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesT1 In MsgBeanMsgTestT1::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT2/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT2/MDBClient.java
deleted file mode 100644
index 9e59fc8647..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT2/MDBClient.java
+++ /dev/null
@@ -1,547 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesT2;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.MDB_T_Test;
-
-import jakarta.ejb.EJB;
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_MSGT2_Test")
- private static MDB_T_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.port;
- * harness.log.traceflag;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
- //
- /*
- * @testName: mdbMessageObjectCopyTopicTest
- *
- * @assertion_ids: JMS:SPEC:85; JMS:JAVADOC:291;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create an object message. Write a StringBuffer to the message.. modify the
- * StringBuffer and send the msg, verify that it does not effect the msg
- */
- public void mdbMessageObjectCopyTopicTest() throws Exception {
- String testCase1 = "messageObjectCopyTopicTestCreate";
- String testCase2 = "messageObjectCopyTopicTest";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase messageObjectCopyTopicTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from messageObjectCopyTopicTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: messageObjectCopyTopicTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionTopicTestsBoolean
- *
- * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:219;
- * JMS:JAVADOC:150; JMS:JAVADOC:128; JMS:JAVADOC:144; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
- * JMS:JAVADOC:738; JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeBoolean to write a
- * boolean to the message. Verify the proper conversion support as in 3.11.3
- */
-
- public void mdbStreamMessageConversionTopicTestsBoolean() throws Exception {
- String testCase1 = "streamMessageConversionTopicTestsBooleanCreate";
- String testCase2 = "streamMessageConversionTopicTestsBoolean";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionTopicTestsBooleanCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionTopicTestsBoolean");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: streamMessageConversionTopicTestsBoolean failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionTopicTestsByte
- *
- * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:152;
- * JMS:JAVADOC:130; JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138;
- * JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:729; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeByte to write a
- * byte. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionTopicTestsByte() throws Exception {
- String testCase1 = "streamMessageConversionTopicTestsByteCreate";
- String testCase2 = "streamMessageConversionTopicTestsByte";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionTopicTestsByteCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionTopicTestsByte");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionTopicTestsByte failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionTopicTestsShort
- *
- * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:154;
- * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144;
- * JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:729; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeShort to write a
- * short. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionTopicTestsShort() throws Exception {
- String testCase1 = "streamMessageConversionTopicTestsShortCreate";
- String testCase2 = "streamMessageConversionTopicTestsShort";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionTopicTestsShortCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionTopicTestsShort");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionTopicTestsShort failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionTopicTestsInt
- *
- * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:158;
- * JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720;
- * JMS:JAVADOC:723; JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeInt to write an
- * int. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionTopicTestsInt() throws Exception {
- String testCase1 = "streamMessageConversionTopicTestsIntCreate";
- String testCase2 = "streamMessageConversionTopicTestsInt";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionTopicTestsIntCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionTopicTestsInt");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionTopicTestsInt failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionTopicTestsLong
- *
- * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:160;
- * JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeLong to write a
- * long. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionTopicTestsLong() throws Exception {
- String testCase1 = "streamMessageConversionTopicTestsLongCreate";
- String testCase2 = "streamMessageConversionTopicTestsLong";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionTopicTestsLongCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionTopicTestsLong");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionTopicTestsLong failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionTopicTestsFloat
- *
- * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:162;
- * JMS:JAVADOC:140; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeFloat to write a
- * float. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionTopicTestsFloat() throws Exception {
- String testCase1 = "streamMessageConversionTopicTestsFloatCreate";
- String testCase2 = "streamMessageConversionTopicTestsFloat";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionTopicTestsFloatCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionTopicTestsFloat");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionTopicTestsFloat failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionTopicTestsDouble
- *
- * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:164;
- * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
- * JMS:JAVADOC:738; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeDouble to write a
- * double. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionTopicTestsDouble() throws Exception {
- String testCase1 = "streamMessageConversionTopicTestsDoubleCreate";
- String testCase2 = "streamMessageConversionTopicTestsDouble";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionTopicTestsDoubleCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionTopicTestsDouble");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: streamMessageConversionTopicTestsDouble failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionTopicTestsString
- *
- * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:SPEC:77;
- * JMS:JAVADOC:166; JMS:JAVADOC:128; JMS:JAVADOC:130; JMS:JAVADOC:132;
- * JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:140; JMS:JAVADOC:142;
- * JMS:JAVADOC:144; JMS:JAVADOC:729; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeString to write a
- * string. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionTopicTestsString() throws Exception {
- String testCase1 = "streamMessageConversionTopicTestsStringCreate";
- String testCase2 = "streamMessageConversionTopicTestsString";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionTopicTestsStringCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionTopicTestsString");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: streamMessageConversionTopicTestsString failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionTopicTestsChar
- *
- * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:156;
- * JMS:JAVADOC:134; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
- * JMS:JAVADOC:726; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:747;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeChar to write a
- * char. Verify the proper conversion support as in 3.11.3
- *
- */
- public void mdbStreamMessageConversionTopicTestsChar() throws Exception {
- String testCase1 = "streamMessageConversionTopicTestsCharCreate";
- String testCase2 = "streamMessageConversionTopicTestsChar";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionTopicTestsCharCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionTopicTestsChar");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionTopicTestsChar failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionTopicTestsBytes
- *
- * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:168;
- * JMS:JAVADOC:146; JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:725;
- * JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
- * JMS:JAVADOC:741; JMS:JAVADOC:744;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeBytes to write a
- * byte[] to the message. Verify the proper conversion support as in 3.11.3
- */
- public void mdbStreamMessageConversionTopicTestsBytes() throws Exception {
- String testCase1 = "streamMessageConversionTopicTestsBytesCreate";
- String testCase2 = "streamMessageConversionTopicTestsBytes";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionTopicTestsBytesCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionTopicTestsBytes");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageConversionTopicTestsBytes failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageConversionTopicTestsInvFormatString
- *
- * @assertion_ids: JMS:SPEC:76; JMS:SPEC:81; JMS:JAVADOC:166; JMS:JAVADOC:130;
- * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:140;
- * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. use StreamMessage method writeString to write a
- * text string of "mytest string". Verify NumberFormatException is thrown
- * Verify that the pointer was not incremented by doing a read string
- *
- */
- public void mdbStreamMessageConversionTopicTestsInvFormatString()
- throws Exception {
- String testCase1 = "streamMessageConversionTopicTestsInvFormatStringCreate";
- String testCase2 = "streamMessageConversionTopicTestsInvFormatString";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageConversionTopicTestsInvFormatStringCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageConversionTopicTestsInvFormatString");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception(
- "ERROR: streamMessageConversionTopicTestsInvFormatString failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageTopicTestsFullMsg
- *
- * @assertion_ids: JMS:SPEC:82; JMS:JAVADOC:150; JMS:JAVADOC:152;
- * JMS:JAVADOC:154; JMS:JAVADOC:156; JMS:JAVADOC:158; JMS:JAVADOC:160;
- * JMS:JAVADOC:162; JMS:JAVADOC:164; JMS:JAVADOC:166; JMS:JAVADOC:168;
- * JMS:JAVADOC:170; JMS:JAVADOC:172; JMS:JAVADOC:128; JMS:JAVADOC:130;
- * JMS:JAVADOC:132; JMS:JAVADOC:134; JMS:JAVADOC:136; JMS:JAVADOC:138;
- * JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
- * JMS:JAVADOC:148;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. write one of each primitive type. Send the
- * message. Verify the data received was as sent.
- *
- */
- public void mdbStreamMessageTopicTestsFullMsg() throws Exception {
- String testCase1 = "streamMessageTopicTestsFullMsgCreate";
- String testCase2 = "streamMessageTopicTestsFullMsg";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase streamMessageTopicTestsFullMsgCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageTopicTestsFullMsg");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageTopicTestsFullMsg failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbStreamMessageTopicTestNull
- *
- * @assertion_ids: JMS:SPEC:78; JMS:SPEC:86; JMS:JAVADOC:144; JMS:JAVADOC:172;
- *
- * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
- * create a StreamMessage -. Use writeString to write a null, then use
- * readString to read it back.
- */
- public void mdbStreamMessageTopicTestNull() throws Exception {
- String testCase1 = "streamMessageTopicTestNullCreate";
- String testCase2 = "streamMessageTopicTestNull";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase streamMessageTopicTestNullCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from streamMessageTopicTestNull");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: streamMessageTopicTestNull failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- ;
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT2/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT2/MDBClientIT.java
new file mode 100644
index 0000000000..c159950283
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT2/MDBClientIT.java
@@ -0,0 +1,532 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesT2;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.commonee.MDB_T_Test;
+
+import jakarta.ejb.EJB;
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_MSGT2_Test")
+ private static MDB_T_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password; harness.log.port;
+ * harness.log.traceflag;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ hr.setup(props);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+ //
+ /*
+ * @testName: mdbMessageObjectCopyTopicTest
+ *
+ * @assertion_ids: JMS:SPEC:85; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create an object message. Write a StringBuffer to the message.. modify the
+ * StringBuffer and send the msg, verify that it does not effect the msg
+ */
+ @Test
+ public void mdbMessageObjectCopyTopicTest() throws Exception {
+ String testCase1 = "messageObjectCopyTopicTestCreate";
+ String testCase2 = "messageObjectCopyTopicTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase messageObjectCopyTopicTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from messageObjectCopyTopicTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: messageObjectCopyTopicTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionTopicTestsBoolean
+ *
+ * @assertion_ids: JMS:SPEC:75.1; JMS:SPEC:75.2; JMS:JAVADOC:219;
+ * JMS:JAVADOC:150; JMS:JAVADOC:128; JMS:JAVADOC:144; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
+ * JMS:JAVADOC:738; JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeBoolean to write a
+ * boolean to the message. Verify the proper conversion support as in 3.11.3
+ */
+ @Test
+ public void mdbStreamMessageConversionTopicTestsBoolean() throws Exception {
+ String testCase1 = "streamMessageConversionTopicTestsBooleanCreate";
+ String testCase2 = "streamMessageConversionTopicTestsBoolean";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionTopicTestsBooleanCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionTopicTestsBoolean");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionTopicTestsBoolean failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionTopicTestsByte
+ *
+ * @assertion_ids: JMS:SPEC:75.3; JMS:SPEC:75.4; JMS:JAVADOC:152;
+ * JMS:JAVADOC:130; JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138;
+ * JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:729; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeByte to write a byte.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionTopicTestsByte() throws Exception {
+ String testCase1 = "streamMessageConversionTopicTestsByteCreate";
+ String testCase2 = "streamMessageConversionTopicTestsByte";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionTopicTestsByteCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionTopicTestsByte");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionTopicTestsByte failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionTopicTestsShort
+ *
+ * @assertion_ids: JMS:SPEC:75.5; JMS:SPEC:75.6; JMS:JAVADOC:154;
+ * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144;
+ * JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:729; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeShort to write a
+ * short. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionTopicTestsShort() throws Exception {
+ String testCase1 = "streamMessageConversionTopicTestsShortCreate";
+ String testCase2 = "streamMessageConversionTopicTestsShort";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionTopicTestsShortCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionTopicTestsShort");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionTopicTestsShort failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionTopicTestsInt
+ *
+ * @assertion_ids: JMS:SPEC:75.9; JMS:SPEC:75.10; JMS:JAVADOC:158;
+ * JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720;
+ * JMS:JAVADOC:723; JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeInt to write an int.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionTopicTestsInt() throws Exception {
+ String testCase1 = "streamMessageConversionTopicTestsIntCreate";
+ String testCase2 = "streamMessageConversionTopicTestsInt";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionTopicTestsIntCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionTopicTestsInt");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionTopicTestsInt failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionTopicTestsLong
+ *
+ * @assertion_ids: JMS:SPEC:75.11; JMS:SPEC:75.12; JMS:JAVADOC:160;
+ * JMS:JAVADOC:138; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeLong to write a long.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionTopicTestsLong() throws Exception {
+ String testCase1 = "streamMessageConversionTopicTestsLongCreate";
+ String testCase2 = "streamMessageConversionTopicTestsLong";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionTopicTestsLongCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionTopicTestsLong");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionTopicTestsLong failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionTopicTestsFloat
+ *
+ * @assertion_ids: JMS:SPEC:75.13; JMS:SPEC:75.14; JMS:JAVADOC:162;
+ * JMS:JAVADOC:140; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeFloat to write a
+ * float. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionTopicTestsFloat() throws Exception {
+ String testCase1 = "streamMessageConversionTopicTestsFloatCreate";
+ String testCase2 = "streamMessageConversionTopicTestsFloat";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionTopicTestsFloatCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionTopicTestsFloat");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionTopicTestsFloat failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionTopicTestsDouble
+ *
+ * @assertion_ids: JMS:SPEC:75.15; JMS:SPEC:75.16; JMS:JAVADOC:164;
+ * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:725; JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735;
+ * JMS:JAVADOC:738; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeDouble to write a
+ * double. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionTopicTestsDouble() throws Exception {
+ String testCase1 = "streamMessageConversionTopicTestsDoubleCreate";
+ String testCase2 = "streamMessageConversionTopicTestsDouble";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionTopicTestsDoubleCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionTopicTestsDouble");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionTopicTestsDouble failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionTopicTestsString
+ *
+ * @assertion_ids: JMS:SPEC:75.17; JMS:SPEC:75.18; JMS:SPEC:77; JMS:JAVADOC:166;
+ * JMS:JAVADOC:128; JMS:JAVADOC:130; JMS:JAVADOC:132; JMS:JAVADOC:136;
+ * JMS:JAVADOC:138; JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144;
+ * JMS:JAVADOC:729; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeString to write a
+ * string. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionTopicTestsString() throws Exception {
+ String testCase1 = "streamMessageConversionTopicTestsStringCreate";
+ String testCase2 = "streamMessageConversionTopicTestsString";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionTopicTestsStringCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionTopicTestsString");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionTopicTestsString failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionTopicTestsChar
+ *
+ * @assertion_ids: JMS:SPEC:75.7; JMS:SPEC:75.8; JMS:JAVADOC:156;
+ * JMS:JAVADOC:134; JMS:JAVADOC:144; JMS:JAVADOC:720; JMS:JAVADOC:723;
+ * JMS:JAVADOC:726; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:747;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeChar to write a char.
+ * Verify the proper conversion support as in 3.11.3
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionTopicTestsChar() throws Exception {
+ String testCase1 = "streamMessageConversionTopicTestsCharCreate";
+ String testCase2 = "streamMessageConversionTopicTestsChar";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionTopicTestsCharCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionTopicTestsChar");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionTopicTestsChar failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionTopicTestsBytes
+ *
+ * @assertion_ids: JMS:SPEC:75.19; JMS:SPEC:75.20; JMS:JAVADOC:168;
+ * JMS:JAVADOC:146; JMS:JAVADOC:720; JMS:JAVADOC:723; JMS:JAVADOC:725;
+ * JMS:JAVADOC:729; JMS:JAVADOC:732; JMS:JAVADOC:735; JMS:JAVADOC:738;
+ * JMS:JAVADOC:741; JMS:JAVADOC:744;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeBytes to write a
+ * byte[] to the message. Verify the proper conversion support as in 3.11.3
+ */
+ @Test
+ public void mdbStreamMessageConversionTopicTestsBytes() throws Exception {
+ String testCase1 = "streamMessageConversionTopicTestsBytesCreate";
+ String testCase2 = "streamMessageConversionTopicTestsBytes";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionTopicTestsBytesCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionTopicTestsBytes");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionTopicTestsBytes failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageConversionTopicTestsInvFormatString
+ *
+ * @assertion_ids: JMS:SPEC:76; JMS:SPEC:81; JMS:JAVADOC:166; JMS:JAVADOC:130;
+ * JMS:JAVADOC:132; JMS:JAVADOC:136; JMS:JAVADOC:138; JMS:JAVADOC:140;
+ * JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. use StreamMessage method writeString to write a
+ * text string of "mytest string". Verify NumberFormatException is thrown Verify
+ * that the pointer was not incremented by doing a read string
+ *
+ */
+ @Test
+ public void mdbStreamMessageConversionTopicTestsInvFormatString() throws Exception {
+ String testCase1 = "streamMessageConversionTopicTestsInvFormatStringCreate";
+ String testCase2 = "streamMessageConversionTopicTestsInvFormatString";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageConversionTopicTestsInvFormatStringCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageConversionTopicTestsInvFormatString");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageConversionTopicTestsInvFormatString failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageTopicTestsFullMsg
+ *
+ * @assertion_ids: JMS:SPEC:82; JMS:JAVADOC:150; JMS:JAVADOC:152;
+ * JMS:JAVADOC:154; JMS:JAVADOC:156; JMS:JAVADOC:158; JMS:JAVADOC:160;
+ * JMS:JAVADOC:162; JMS:JAVADOC:164; JMS:JAVADOC:166; JMS:JAVADOC:168;
+ * JMS:JAVADOC:170; JMS:JAVADOC:172; JMS:JAVADOC:128; JMS:JAVADOC:130;
+ * JMS:JAVADOC:132; JMS:JAVADOC:134; JMS:JAVADOC:136; JMS:JAVADOC:138;
+ * JMS:JAVADOC:140; JMS:JAVADOC:142; JMS:JAVADOC:144; JMS:JAVADOC:146;
+ * JMS:JAVADOC:148;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. write one of each primitive type. Send the message.
+ * Verify the data received was as sent.
+ *
+ */
+ @Test
+ public void mdbStreamMessageTopicTestsFullMsg() throws Exception {
+ String testCase1 = "streamMessageTopicTestsFullMsgCreate";
+ String testCase2 = "streamMessageTopicTestsFullMsg";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageTopicTestsFullMsgCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageTopicTestsFullMsg");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageTopicTestsFullMsg failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbStreamMessageTopicTestNull
+ *
+ * @assertion_ids: JMS:SPEC:78; JMS:SPEC:86; JMS:JAVADOC:144; JMS:JAVADOC:172;
+ *
+ * @test_Strategy: Invoke a session bean. Have it send a request to an mdb to
+ * create a StreamMessage -. Use writeString to write a null, then use
+ * readString to read it back.
+ */
+ @Test
+ public void mdbStreamMessageTopicTestNull() throws Exception {
+ String testCase1 = "streamMessageTopicTestNullCreate";
+ String testCase2 = "streamMessageTopicTestNull";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase streamMessageTopicTestNullCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from streamMessageTopicTestNull");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: streamMessageTopicTestNull failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ ;
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT2/MsgBeanMsgTestT2.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT2/MsgBeanMsgTestT2.java
index dad8d56e31..2c3dd3beb3 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT2/MsgBeanMsgTestT2.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT2/MsgBeanMsgTestT2.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesT2;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.TSNamingContext;
@@ -48,3656 +49,3500 @@
public class MsgBeanMsgTestT2 implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- private MessageDrivenContext mdc = null;
-
- // JMS
- private QueueConnectionFactory qFactory = null;
-
- private QueueConnection qConnection = null;
-
- private Queue queueR = null;
-
- private QueueSender mSender = null;
-
- private QueueSession qSession = null;
-
- private TopicConnectionFactory tFactory = null;
-
- private TopicConnection tConnection = null;
-
- private Topic topic = null;
-
- private TopicPublisher tPublisher = null;
-
- private TopicSession tSession = null;
-
- public MsgBeanMsgTestT2() {
- TestUtil.logTrace("@MsgBeanMsgTest2()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgTypesT2 - @MsgBeanMsgTest2-ejbCreate() !!");
- try {
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- if (qFactory == null) {
- TestUtil.logTrace("qFactory error");
- }
- TestUtil.logTrace("got a qFactory !!");
-
- queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- if (queueR == null) {
- TestUtil.logTrace("queueR error");
- }
-
- tFactory = (TopicConnectionFactory) context
- .lookup("java:comp/env/jms/MyTopicConnectionFactory");
- if (tFactory == null) {
- TestUtil.logTrace("tFactory error");
- }
- TestUtil.logTrace("got a tFactory !!");
-
- topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC");
- if (topic == null) {
- TestUtil.logTrace("topic error");
- }
-
- p = new Properties();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("from jms.ee.mdb.mdb_msgTypesT2 @onMessage!" + msg);
-
- try {
- TestUtil.logTrace("TestCase:" + msg.getStringProperty("TestCase"));
- TestUtil.logTrace(
- "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null) {
- TestUtil.logTrace("connection error");
- } else {
- qConnection.start();
- qSession = qConnection.createQueueSession(true, 0);
- }
-
- tConnection = tFactory.createTopicConnection();
- if (tConnection == null) {
- TestUtil.logTrace("connection error");
- } else {
- tConnection.start();
- tSession = tConnection.createTopicSession(true, 0);
- }
-
- if (msg.getStringProperty("TestCase")
- .equals("messageObjectCopyTopicTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running messageObjectCopyTopicTestCreate - create the message");
- messageObjectCopyTopicTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("messageObjectCopyTopicTest")) {
- TestUtil.logTrace(
- "@onMessage - running messageObjectCopyTopicTest - read and verify the message");
- messageObjectCopyTopicTest((jakarta.jms.ObjectMessage) msg);
- }
-
- if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsBooleanCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsBooleanCreate - create the message");
- streamMessageConversionTopicTestsBooleanCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsBoolean")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsBoolean - read and verify the message");
- streamMessageConversionTopicTestsBoolean((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsByteCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsByteCreate - create the message");
- streamMessageConversionTopicTestsByteCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsByte")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsByte - read and verify the message");
- streamMessageConversionTopicTestsByte((jakarta.jms.StreamMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsShortCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsShortCreate - create the message");
- streamMessageConversionTopicTestsShortCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsShort")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsShort - read and verify the message");
- streamMessageConversionTopicTestsShort((jakarta.jms.StreamMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsIntCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsIntCreate - create the message");
- streamMessageConversionTopicTestsIntCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsInt")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsInt - read and verify the message");
- streamMessageConversionTopicTestsInt((jakarta.jms.StreamMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsLongCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsLongCreate - create the message");
- streamMessageConversionTopicTestsLongCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsLong")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsLong - read and verify the message");
- streamMessageConversionTopicTestsLong((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsFloatCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsFloatCreate - create the message");
- streamMessageConversionTopicTestsFloatCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsFloat")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsFloat - read and verify the message");
- streamMessageConversionTopicTestsFloat((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsDoubleCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsDoubleCreate - create the message");
- streamMessageConversionTopicTestsDoubleCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsDouble")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsDouble - read and verify the message");
- streamMessageConversionTopicTestsDouble((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsStringCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsStringCreate - create the message");
- streamMessageConversionTopicTestsStringCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsString")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsString - read and verify the message");
- streamMessageConversionTopicTestsString((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsCharCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsCharCreate - create the message");
- streamMessageConversionTopicTestsCharCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsChar")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsChar - read and verify the message");
- streamMessageConversionTopicTestsChar((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsBytesCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsBytesCreate - create the message");
- streamMessageConversionTopicTestsBytesCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsBytes")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsBytes - read and verify the message");
- streamMessageConversionTopicTestsBytes((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsInvFormatStringCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsInvFormatStringCreate - create the message");
- streamMessageConversionTopicTestsInvFormatStringCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageConversionTopicTestsInvFormatString")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageConversionTopicTestsInvFormatString - read and verify the message");
- streamMessageConversionTopicTestsInvFormatString(
- (jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageTopicTestsFullMsgCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageTopicTestsFullMsgCreate - create the message");
- streamMessageTopicTestsFullMsgCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageTopicTestsFullMsg")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageTopicTestsFullMsg - read and verify the message");
- streamMessageTopicTestsFullMsg((jakarta.jms.StreamMessage) msg);
- }
-
- else if (msg.getStringProperty("TestCase")
- .equals("streamMessageTopicTestNullCreate")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageTopicTestNullCreate - create the message");
- streamMessageTopicTestNullCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("streamMessageTopicTestNull")) {
- TestUtil.logTrace(
- "@onMessage - running streamMessageTopicTestNull - read and verify the message");
- streamMessageTopicTestNull((jakarta.jms.StreamMessage) msg);
- } else {
- TestUtil.logTrace(
- "@onMessage - invalid message type found in StringProperty");
- }
- TestUtil.logTrace("@onMessage - Finished for this test!");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- if (tConnection != null) {
- try {
- tConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
-
- }
-
- /*
- * Description: Create an object message. Write a StringBuffer to the message.
- * modify the StringBuffer and send the msg, verify that it does not effect
- * the msg
- */
- public void messageObjectCopyTopicTestCreate() {
- boolean pass = true;
- try {
- ObjectMessage messageSentObjectMsg = null;
- StringBuffer sBuff = new StringBuffer("This is");
- String initial = "This is";
- messageSentObjectMsg = qSession.createObjectMessage();
- JmsUtil.addPropsToMessage(messageSentObjectMsg, p);
- messageSentObjectMsg.setObject(sBuff);
- sBuff.append("a test ");
- messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME",
- "messageObjectCopyTopicTest");
- // set up testcase so onMessage invokes the correct method
- messageSentObjectMsg.setStringProperty("TestCase",
- "messageObjectCopyTopicTest");
-
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSentObjectMsg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage -. use StreamMessage method
- * writeBoolean to write a boolean to the message. Verify the proper
- * conversion support as in 3.11.3
- */
- private void streamMessageConversionTopicTestsBooleanCreate() {
- try {
- StreamMessage messageSent = null;
- boolean abool = true;
-
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsBoolean");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for boolean primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionTopicTestsBoolean");
- messageSent.writeBoolean(abool);
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage -. use StreamMessage method writeByte
- * to write a byte. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsByteCreate() {
- try {
- StreamMessage messageSent = null;
-
- byte bValue = 127;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsByte");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionTopicTestsByte");
-
- messageSent.writeByte(bValue);
- // send the message and then get it back
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a StreamMessage -. use StreamMessage method writeShort
- * to write a short. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsShortCreate() {
- try {
- StreamMessage messageSent = null;
- short sValue = 1;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsShort");
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionTopicTestsShort");
- messageSent.writeShort(sValue);
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a StreamMessage -. use StreamMessage method writeInt to
- * write an int. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsIntCreate() {
- try {
- StreamMessage messageSent = null;
- int iValue = 6;
-
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsInt");
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionTopicTestsInt");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- messageSent.writeInt(iValue);
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a StreamMessage -. use StreamMessage method writeLong
- * to write a long. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsLongCreate() {
- try {
- StreamMessage messageSent = null;
- long lValue = 2;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsLong");
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionTopicTestsLong");
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- messageSent.writeLong(lValue);
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a StreamMessage -. use StreamMessage method writeFloat
- * to write a float. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsFloatCreate() {
- try {
- StreamMessage messageSent = null;
-
- float fValue = 5;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsFloat");
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionTopicTestsFloat");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.writeFloat(fValue);
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage -. use StreamMessage method writeDouble
- * to write a double. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsDoubleCreate() {
- try {
- StreamMessage messageSent = null;
-
- double dValue = 3;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsDouble");
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionTopicTestsDouble");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.writeDouble(dValue);
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a StreamMessage -. use StreamMessage method writeString
- * to write a string. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsStringCreate() {
- try {
- StreamMessage messageSent = null;
- String myString = "10";
-
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsString");
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionTopicTestsString");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.writeString(myString);
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Create a StreamMessage -. use StreamMessage method writeChar
- * to write a char. Verify the proper conversion support as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsCharCreate() {
- try {
- StreamMessage messageSent = null;
-
- char charValue = 'a';
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsChar");
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionTopicTestsChar");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
-
- messageSent.writeChar(charValue);
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage -. use StreamMessage method writeBytes
- * to write a byte[] to the message. Verify the proper conversion support as
- * in 3.11.3
- */
- private void streamMessageConversionTopicTestsBytesCreate() {
- try {
- StreamMessage messageSent = null;
- byte[] bValues = { 1, 2, 3 };
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsBytes");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte[] primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionTopicTestsBytes");
-
- messageSent.writeBytes(bValues);
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage -. use StreamMessage method writeString
- * to write a text string of "mytest string". Verify NumberFormatException is
- * thrown Verify that the pointer was not incremented by doing a read string
- *
- */
- private void streamMessageConversionTopicTestsInvFormatStringCreate() {
- try {
- StreamMessage messageSent = null;
- String myString = "mytest string";
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageConversionTopicTestsInvFormatString");
-
- // -----------------------------------------------------------------------------
- TestUtil.logTrace(
- "Verify conversion support for byte primitive type section 3.11.3");
- // -----------------------------------------------------------------------------
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageConversionTopicTestsInvFormatString");
- messageSent.writeString(myString);
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage -. write one of each primitive type.
- * Send the message. Verify the data received was as sent.
- *
- */
- private void streamMessageTopicTestsFullMsgCreate() {
- try {
-
- StreamMessage messageSent = null;
-
- byte bValue = 127;
- boolean abool = false;
- byte[] bValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
- byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
- char charValue = 'Z';
- short sValue = 32767;
- long lValue = 9223372036854775807L;
- double dValue = 6.02e23;
- float fValue = 6.02e23f;
- int iValue = 6;
- boolean pass = true;
- String myString = "text";
- String sTesting = "Testing StreamMessages";
-
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageTopicTestsFullMsg");
-
- messageSent.writeBytes(bValues2, 0, bValues.length);
- messageSent.writeBoolean(abool);
- messageSent.writeByte(bValue);
- messageSent.writeBytes(bValues);
- messageSent.writeChar(charValue);
- messageSent.writeDouble(dValue);
- messageSent.writeFloat(fValue);
- messageSent.writeInt(iValue);
- messageSent.writeLong(lValue);
- messageSent.writeObject(sTesting);
- messageSent.writeShort(sValue);
- messageSent.writeString(myString);
-
- messageSent.writeObject(null);
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase",
- "streamMessageTopicTestsFullMsg");
-
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Create a StreamMessage Use writeString to write a null, then
- * use readString to read it back.
- */
- private void streamMessageTopicTestNullCreate() {
- try {
- StreamMessage messageSent = null;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "streamMessageTopicTestNull");
- // -----------------------------------------------------------------------------
- TestUtil.logTrace("writeString(null) ");
- // -----------------------------------------------------------------------------
- // set up testcase so onMessage invokes the correct method
- messageSent.setStringProperty("TestCase", "streamMessageTopicTestNull");
- messageSent.writeString(null);
- // send the message and then get it back
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read ObjectMessage created by
- * messageObjectCopyTopicTestCreate. verify that modifying the sBuff object
- * after the write does not effect the msg
- */
- public void messageObjectCopyTopicTest(
- jakarta.jms.ObjectMessage messageReceivedObjectMsg) {
- boolean pass = true;
- String testCase = "messageObjectCopyTopicTest";
- String initial = "This is";
- try {
- TestUtil
- .logMsg("Ensure that changing the object did not change the message");
- StringBuffer s = (StringBuffer) messageReceivedObjectMsg.getObject();
- TestUtil.logTrace("s is " + s);
- if (s.toString().equals(initial)) {
- TestUtil.logTrace("Pass: msg was not changed");
- } else {
- TestUtil.logTrace("Fail: msg was changed!");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- */
- private void streamMessageConversionTopicTestsBoolean(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionTopicTestsBoolean";
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- boolean pass = true;
-
- // now test conversions for boolean
- // -----------------------------------------------
- // boolean to boolean - valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a boolean");
- try {
- if (messageReceived.readBoolean() == abool) {
- TestUtil.logTrace("Pass: boolean to boolean - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a boolean");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString()
- .equals((Boolean.valueOf(abool)).toString())) {
- TestUtil.logTrace("Pass: boolean to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // boolean to byte[] invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read a boolean - expect MessageFormatException");
- int nCount = 0;
- try {
-
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
- // -----------------------------------------------
- // boolean to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readByte to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- bValue = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // boolean to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readShort to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // boolean to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readChar to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // boolean to int invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readInt to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readInt();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // boolean to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readLong to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readLong();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // boolean to float invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readFloat to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // boolean to double invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readDouble to read a boolean - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsByte(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionTopicTestsByte";
- try {
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
- // now test conversions for byte
- // -----------------------------------------------
- // byte to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // byte to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a byte");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Byte.toString(bValue))) {
- TestUtil.logTrace("Pass: byte to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read a byte - expect MessageFormatException");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // byte to byte valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a byte");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readByte() == bValue) {
- TestUtil.logTrace("Pass: byte to byte - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // byte to short valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a byte");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readShort() == bValue) {
- TestUtil.logTrace("Pass: byte to short - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- pass = false;
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // byte to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a byte");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == bValue) {
- TestUtil.logTrace("Pass: byte to int - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a byte");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == bValue) {
- TestUtil.logTrace("Pass: byte to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read a boolean - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsShort(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionTopicTestsShort";
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // short to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a short - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // short to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a short");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Short.toString(sValue))) {
- TestUtil.logTrace("Pass: short to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // short to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read a short - expect MessageFormatException");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // short to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a short - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // short to short valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a short");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readShort() == sValue) {
- TestUtil.logTrace("Pass: short to short - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a short - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // short to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a byte");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == sValue) {
- TestUtil.logTrace("Pass: short to int - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a short");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == sValue) {
- TestUtil.logTrace("Pass: short to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // short to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a short - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // short to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read a short - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsInt(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionTopicTestsInt";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // int to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read an int - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // int to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read an int");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Integer.toString(iValue))) {
- TestUtil.logTrace("Pass: int to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // int to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read an int - expect MessageFormatException");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // int to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read an int - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // int to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read an int");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // int to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read an int - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // int to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read an int");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == iValue) {
- TestUtil.logTrace("Pass: int to int - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read an int");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == iValue) {
- TestUtil.logTrace("Pass: int to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // int to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read an int - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // int to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read an int - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- */
- private void streamMessageConversionTopicTestsLong(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionTopicTestsLong";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // long to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a long - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // long to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a long");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Long.toString(lValue))) {
- TestUtil.logTrace("Pass: long to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // long to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read a long - expect MessageFormatException");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // long to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read an long - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // long to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a long");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // long to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a long - this is not valid");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // long to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a long");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // long to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a long");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == lValue) {
- TestUtil.logTrace("Pass: int to long - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // long to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a long - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // long to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read an long - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- */
- private void streamMessageConversionTopicTestsFloat(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionTopicTestsFloat";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // float to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a float ");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // float to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a float");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Float.toString(fValue))) {
- TestUtil.logTrace("Pass: float to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBytes[] to read a float ");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // float to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a float ");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // float to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a float");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // float to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a long ");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // float to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a float");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // float to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a long");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // float to float valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a float ");
- try {
- messageReceived.reset();
- if (messageReceived.readFloat() == fValue) {
- TestUtil.logTrace("Pass: float to float - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // float to double invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read an float ");
- try {
- messageReceived.reset();
- if (messageReceived.readDouble() == fValue) {
- TestUtil.logTrace("Pass: float to double - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsDouble(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionTopicTestsDouble";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // double to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a double ");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // double to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a double");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(Double.toString(dValue))) {
- TestUtil.logTrace("Pass: double to string");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // double to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBytes[] to read a double ");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // double to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a double ");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // double to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a double");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // double to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a double ");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // double to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a double");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // double to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a double");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // double to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a double ");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // double to double valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read a double ");
- try {
- messageReceived.reset();
- if (messageReceived.readDouble() == dValue) {
- TestUtil.logTrace("Pass: double to double ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- */
- private void streamMessageConversionTopicTestsString(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionTopicTestsString";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
- String myString = "10";
-
- // now test conversions for String
- // -----------------------------------------------
- // string to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a String");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readString().equals(myString)) {
- TestUtil.logTrace("Pass: string to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // string to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBytes[] to read a String");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // String to byte valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a String");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readByte() == Byte.parseByte(myString)) {
- TestUtil.logTrace("Pass: String to byte ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // string to short valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a string");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readShort() == Short.parseShort(myString)) {
- TestUtil.logTrace("Pass: String to short ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a String ");
- try {
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // string to int valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a String");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readInt() == Integer.parseInt(myString)) {
- TestUtil.logTrace("Pass: String to int ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to long valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a String");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readLong() == Long.parseLong(myString)) {
- TestUtil.logTrace("Pass: String to long ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to float valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a String");
- try {
- messageReceived.reset();
- if (messageReceived.readFloat() == Float.parseFloat(myString)) {
- TestUtil.logTrace("Pass: String to float ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to double valid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read a String");
- try {
- messageReceived.reset();
- if (messageReceived.readDouble() == Double.parseDouble(myString)) {
- TestUtil.logTrace("Pass: String to double ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a string ");
- try {
- messageReceived.clearBody();
- messageReceived.writeString("true");
- messageReceived.reset();
- if (messageReceived.readBoolean() == abool) {
- TestUtil.logTrace("Pass: String to boolean ");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // String to boolean
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a string that is !true ");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- if (b != true) {
- TestUtil.logTrace("Fail: !true should return false");
- pass = false;
- } else {
- TestUtil.logTrace("Pass: !true returned false");
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- *
- */
- private void streamMessageConversionTopicTestsChar(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionTopicTestsChar";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues = { 0 };
- char charValue = 'a';
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for byte
- // -----------------------------------------------
- // char to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a char - this is not valid");
- try {
- messageReceived.reset();
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // char to string valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a char");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- String s = messageReceived.readString();
- TestUtil.logTrace("char returned for \"a\" is : " + s);
- if (s.equals("a")) {
- TestUtil.logTrace("Pass: char to string - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to byte[] invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readBytes[] to read a char - expect MessageFormatException");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- nCount = messageReceived.readBytes(bValues);
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- TestUtil.logTrace("Count returned from readBytes is : " + nCount);
-
- // -----------------------------------------------
- // char to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a char - this is not valid");
- try {
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // char to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a char");
- try {
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // char to char valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readChar to read a char ");
- try {
- messageReceived.reset();
- if (messageReceived.readChar() == 'a') {
- TestUtil.logTrace("Pass: char to char - valid");
- } else {
- TestUtil.logTrace("Fail: wrong value returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- // -----------------------------------------------
- // char to int invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a char ");
- try {
- messageReceived.reset();
- int i = messageReceived.readInt();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // char to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a char");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // char to float invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a char - this is not valid");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // char to double invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read a char - this is not valid");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the proper conversion support
- * as in 3.11.3
- */
- private void streamMessageConversionTopicTestsBytes(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionTopicTestsBytes";
-
- try {
-
- byte bValue = 127;
- boolean abool = true;
- byte[] bValues2 = { 0, 0, 0 };
- short sValue = 1;
- long lValue = 2;
- double dValue = 3;
- float fValue = 5;
- int iValue = 6;
- boolean pass = true;
-
- // now test conversions for boolean
- // -----------------------------------------------
- // byte[] to byte[] - valid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBytes[] to read a byte[] ");
- int nCount = 0;
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- if (messageReceived.readBytes(bValues2) == 3) { // count should be 3.
- TestUtil.logTrace("Pass: byte[] to byte[] - valid");
- } else {
- TestUtil.logTrace("Fail: count incorrect");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // byte[] to boolean - invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readBoolean to read a byte[]");
- // position to beginning of stream message.
- messageReceived.reset();
- try {
- boolean b = messageReceived.readBoolean();
- TestUtil.logTrace(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // byte[] to string invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readString to read a byte[]");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- String s = messageReceived.readString();
- TestUtil.logTrace(
- "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // byte[] to byte invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readByte to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // byte[] to short invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readShort to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // byte[] to char invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readChar to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- char c = messageReceived.readChar();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // byte[] to int invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readInt to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // byte[] to long invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readLong to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // byte[] to float invalid
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readFloat to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // byte[] to double invalid
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Use readDouble to read a byte[] - expect MessageFormatException");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: MessageFormatException was not thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageFormatException) {
- TestUtil.logTrace("Pass: MessageFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Read a StreamMessage -. Verify NumberFormatException is thrown
- * Verify that the pointer was not incremented by doing a read string
- *
- */
- private void streamMessageConversionTopicTestsInvFormatString(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageConversionTopicTestsInvFormatString";
-
- try {
-
- boolean pass = true;
- String myString = "mytest string";
-
- // -----------------------------------------------
- // String to byte
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readByte to read a String that is not valid ");
- try {
- byte b = messageReceived.readByte();
- TestUtil.logTrace("Fail: java.lang.NumberFormatException expected");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof java.lang.NumberFormatException) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // pointer should not have moved
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace(
- "Verify that the data can be read as a string and pointer did not move");
- try {
- String s = messageReceived.readString();
- TestUtil.logTrace("message read: " + s);
- if (s.equals(myString)) {
- TestUtil.logTrace("Pass: able to read the string");
- } else {
- TestUtil.logTrace("Fail: string not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- // -----------------------------------------------
- // string to short
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readShort to read a string that is not valid ");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- short s = messageReceived.readShort();
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof java.lang.NumberFormatException) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // string to int
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readInt to read a String that is not valid ");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- int i = messageReceived.readInt();
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof java.lang.NumberFormatException) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // string to long
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readLong to read a String that is not valid ");
- try {
- // position to beginning of stream message.
- messageReceived.reset();
- long l = messageReceived.readLong();
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof java.lang.NumberFormatException) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- // -----------------------------------------------
- // String to float
- // -----------------------------------------------
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readFloat to read a String that is not valid ");
- try {
- messageReceived.reset();
- float f = messageReceived.readFloat();
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof java.lang.NumberFormatException) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // -----------------------------------------------
- // String to double
- // -----------------------------------------------
-
- TestUtil.logTrace("--");
- TestUtil.logTrace("Use readDouble to read a String that is not valid ");
- try {
- messageReceived.reset();
- double d = messageReceived.readDouble();
- TestUtil.logTrace("Fail: NumberFormatException was expected");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof java.lang.NumberFormatException) {
- TestUtil.logTrace("Pass: NumberFormatException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
-
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage -. Verify the data received was as sent.
- *
- */
- private void streamMessageTopicTestsFullMsg(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageTopicTestsFullMsg";
-
- try {
- byte bValue = 127;
- boolean abool = false;
- byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
- byte[] bValuesReturned = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- byte[] bValuesReturned2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- char charValue = 'Z';
- short sValue = 32767;
- long lValue = 9223372036854775807L;
- double dValue = 6.02e23;
- float fValue = 6.02e23f;
- int iValue = 6;
- boolean pass = true;
- String myString = "text";
- String sTesting = "Testing StreamMessages";
-
- try {
- int nCount = bValuesReturned2.length;
- do {
- nCount = messageReceived.readBytes(bValuesReturned2);
- TestUtil.logTrace("nCount is " + nCount);
- if (nCount != -1) {
- for (int i = 0; i < bValuesReturned2.length; i++) {
- if (bValuesReturned2[i] != bValues2[i]) {
- TestUtil.logTrace("Fail: byte[] " + i + " is not valid");
- pass = false;
- } else {
- TestUtil.logTrace("PASS: byte[]" + i + " is valid");
- }
- }
- }
- } while (nCount >= bValuesReturned2.length);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readBoolean() == abool) {
- TestUtil.logTrace("Pass: boolean returned ok");
- } else {
- TestUtil.logTrace("Fail: boolean not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readByte() == bValue) {
- TestUtil.logTrace("Pass: Byte returned ok");
- } else {
- TestUtil.logTrace("Fail: Byte not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- int nCount = bValuesReturned.length;
- do {
- nCount = messageReceived.readBytes(bValuesReturned);
- TestUtil.logTrace("nCount is " + nCount);
- if (nCount != -1) {
- for (int i = 0; i < bValuesReturned2.length; i++) {
- if (bValuesReturned2[i] != bValues2[i]) {
- TestUtil.logTrace("Fail: byte[] " + i + " is not valid");
- pass = false;
- } else {
- TestUtil.logTrace("PASS: byte[]" + i + " is valid");
- }
- }
- }
- } while (nCount >= bValuesReturned.length);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readChar() == charValue) {
- TestUtil.logTrace("Pass: correct char");
- } else {
- TestUtil.logTrace("Fail: char not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readDouble() == dValue) {
- TestUtil.logTrace("Pass: correct double");
- } else {
- TestUtil.logTrace("Fail: double not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readFloat() == fValue) {
- TestUtil.logTrace("Pass: correct float");
- } else {
- TestUtil.logTrace("Fail: float not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readInt() == iValue) {
- TestUtil.logTrace("Pass: correct int");
- } else {
- TestUtil.logTrace("Fail: int not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- try {
- if (messageReceived.readLong() == lValue) {
- TestUtil.logTrace("Pass: correct long");
- } else {
- TestUtil.logTrace("Fail: long not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readObject().equals(sTesting)) {
- TestUtil.logTrace("Pass: correct object");
- } else {
- TestUtil.logTrace("Fail: object not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readShort() == sValue) {
- TestUtil.logTrace("Pass: correct short");
- } else {
- TestUtil.logTrace("Fail: short not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readString().equals(myString)) {
- TestUtil.logTrace("Pass: correct string");
- } else {
- TestUtil.logTrace("Fail: string not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
-
- try {
- if (messageReceived.readObject() == null) {
- TestUtil.logTrace("Pass: correct object");
- } else {
- TestUtil.logTrace("Fail: object not returned as expected");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: unexpected exception" + e.getClass().getName()
- + "was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Read a StreamMessage Use readString to read back a null
- */
- private void streamMessageTopicTestNull(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "streamMessageTopicTestNull";
- try {
- boolean pass = true;
- try {
- if (messageReceived.readObject() == null) {
- TestUtil.logTrace("Pass: Read a null");
- } else {
- TestUtil.logTrace("Fail: null value not returned");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error trying to read a null object");
- TestUtil.logTrace("Error: unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- sendTestResults(testCase, pass);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: send test results to response queue (MDB_QUEUE_REPLY) for
- * verification
- */
- private void sendTestResults(String testCase, boolean results) {
- TextMessage msg = null;
-
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- msg.setStringProperty("TestCase", testCase);
- msg.setText(testCase);
- if (results)
- msg.setStringProperty("Status", "Pass");
- else
- msg.setStringProperty("Status", "Fail");
-
- TestUtil.logTrace("Sending response message");
- mSender.send(msg);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- TestUtil.logTrace("Error: " + je.getClass().getName() + " was thrown");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logTrace("Error: " + ee.getClass().getName() + " was thrown");
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgTypesT2 In MsgBeanMsgTest2::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil
- .logTrace("jms.ee.mdb.mdb_msgTypesT2 In MsgBeanMsgTest2::remove()!!");
- }
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ private MessageDrivenContext mdc = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanMsgTestT2.class.getName());
+
+ // JMS
+ private QueueConnectionFactory qFactory = null;
+
+ private QueueConnection qConnection = null;
+
+ private Queue queueR = null;
+
+ private QueueSender mSender = null;
+
+ private QueueSession qSession = null;
+
+ private TopicConnectionFactory tFactory = null;
+
+ private TopicConnection tConnection = null;
+
+ private Topic topic = null;
+
+ private TopicPublisher tPublisher = null;
+
+ private TopicSession tSession = null;
+
+ public MsgBeanMsgTestT2() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanMsgTest2()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesT2 - @MsgBeanMsgTest2-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ if (qFactory == null) {
+ logger.log(Logger.Level.TRACE, "qFactory error");
+ }
+ logger.log(Logger.Level.TRACE, "got a qFactory !!");
+
+ queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ if (queueR == null) {
+ logger.log(Logger.Level.TRACE, "queueR error");
+ }
+
+ tFactory = (TopicConnectionFactory) context.lookup("java:comp/env/jms/MyTopicConnectionFactory");
+ if (tFactory == null) {
+ logger.log(Logger.Level.TRACE, "tFactory error");
+ }
+ logger.log(Logger.Level.TRACE, "got a tFactory !!");
+
+ topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC");
+ if (topic == null) {
+ logger.log(Logger.Level.TRACE, "topic error");
+ }
+
+ p = new Properties();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "from jms.ee.mdb.mdb_msgTypesT2 @onMessage!" + msg);
+
+ try {
+ logger.log(Logger.Level.TRACE, "TestCase:" + msg.getStringProperty("TestCase"));
+ logger.log(Logger.Level.TRACE, "onMessage will run TestCase: " + msg.getStringProperty("TestCase"));
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null) {
+ logger.log(Logger.Level.TRACE, "connection error");
+ } else {
+ qConnection.start();
+ qSession = qConnection.createQueueSession(true, 0);
+ }
+
+ tConnection = tFactory.createTopicConnection();
+ if (tConnection == null) {
+ logger.log(Logger.Level.TRACE, "connection error");
+ } else {
+ tConnection.start();
+ tSession = tConnection.createTopicSession(true, 0);
+ }
+
+ if (msg.getStringProperty("TestCase").equals("messageObjectCopyTopicTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running messageObjectCopyTopicTestCreate - create the message");
+ messageObjectCopyTopicTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("messageObjectCopyTopicTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running messageObjectCopyTopicTest - read and verify the message");
+ messageObjectCopyTopicTest((jakarta.jms.ObjectMessage) msg);
+ }
+
+ if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsBooleanCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsBooleanCreate - create the message");
+ streamMessageConversionTopicTestsBooleanCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsBoolean")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsBoolean - read and verify the message");
+ streamMessageConversionTopicTestsBoolean((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsByteCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsByteCreate - create the message");
+ streamMessageConversionTopicTestsByteCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsByte")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsByte - read and verify the message");
+ streamMessageConversionTopicTestsByte((jakarta.jms.StreamMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsShortCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsShortCreate - create the message");
+ streamMessageConversionTopicTestsShortCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsShort")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsShort - read and verify the message");
+ streamMessageConversionTopicTestsShort((jakarta.jms.StreamMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsIntCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsIntCreate - create the message");
+ streamMessageConversionTopicTestsIntCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsInt")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsInt - read and verify the message");
+ streamMessageConversionTopicTestsInt((jakarta.jms.StreamMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsLongCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsLongCreate - create the message");
+ streamMessageConversionTopicTestsLongCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsLong")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsLong - read and verify the message");
+ streamMessageConversionTopicTestsLong((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsFloatCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsFloatCreate - create the message");
+ streamMessageConversionTopicTestsFloatCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsFloat")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsFloat - read and verify the message");
+ streamMessageConversionTopicTestsFloat((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsDoubleCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsDoubleCreate - create the message");
+ streamMessageConversionTopicTestsDoubleCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsDouble")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsDouble - read and verify the message");
+ streamMessageConversionTopicTestsDouble((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsStringCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsStringCreate - create the message");
+ streamMessageConversionTopicTestsStringCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsString")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsString - read and verify the message");
+ streamMessageConversionTopicTestsString((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsCharCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsCharCreate - create the message");
+ streamMessageConversionTopicTestsCharCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsChar")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsChar - read and verify the message");
+ streamMessageConversionTopicTestsChar((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsBytesCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsBytesCreate - create the message");
+ streamMessageConversionTopicTestsBytesCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsBytes")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsBytes - read and verify the message");
+ streamMessageConversionTopicTestsBytes((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase")
+ .equals("streamMessageConversionTopicTestsInvFormatStringCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsInvFormatStringCreate - create the message");
+ streamMessageConversionTopicTestsInvFormatStringCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageConversionTopicTestsInvFormatString")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageConversionTopicTestsInvFormatString - read and verify the message");
+ streamMessageConversionTopicTestsInvFormatString((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageTopicTestsFullMsgCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageTopicTestsFullMsgCreate - create the message");
+ streamMessageTopicTestsFullMsgCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageTopicTestsFullMsg")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageTopicTestsFullMsg - read and verify the message");
+ streamMessageTopicTestsFullMsg((jakarta.jms.StreamMessage) msg);
+ }
+
+ else if (msg.getStringProperty("TestCase").equals("streamMessageTopicTestNullCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageTopicTestNullCreate - create the message");
+ streamMessageTopicTestNullCreate();
+ } else if (msg.getStringProperty("TestCase").equals("streamMessageTopicTestNull")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running streamMessageTopicTestNull - read and verify the message");
+ streamMessageTopicTestNull((jakarta.jms.StreamMessage) msg);
+ } else {
+ logger.log(Logger.Level.TRACE, "@onMessage - invalid message type found in StringProperty");
+ }
+ logger.log(Logger.Level.TRACE, "@onMessage - Finished for this test!");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ if (tConnection != null) {
+ try {
+ tConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+
+ }
+
+ /*
+ * Description: Create an object message. Write a StringBuffer to the message.
+ * modify the StringBuffer and send the msg, verify that it does not effect the
+ * msg
+ */
+ public void messageObjectCopyTopicTestCreate() {
+ boolean pass = true;
+ try {
+ ObjectMessage messageSentObjectMsg = null;
+ StringBuffer sBuff = new StringBuffer("This is");
+ String initial = "This is";
+ messageSentObjectMsg = qSession.createObjectMessage();
+ JmsUtil.addPropsToMessage(messageSentObjectMsg, p);
+ messageSentObjectMsg.setObject(sBuff);
+ sBuff.append("a test ");
+ messageSentObjectMsg.setStringProperty("COM_SUN_JMS_TESTNAME", "messageObjectCopyTopicTest");
+ // set up testcase so onMessage invokes the correct method
+ messageSentObjectMsg.setStringProperty("TestCase", "messageObjectCopyTopicTest");
+
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSentObjectMsg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage -. use StreamMessage method writeBoolean
+ * to write a boolean to the message. Verify the proper conversion support as in
+ * 3.11.3
+ */
+ private void streamMessageConversionTopicTestsBooleanCreate() {
+ try {
+ StreamMessage messageSent = null;
+ boolean abool = true;
+
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsBoolean");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for boolean primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionTopicTestsBoolean");
+ messageSent.writeBoolean(abool);
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage -. use StreamMessage method writeByte to
+ * write a byte. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsByteCreate() {
+ try {
+ StreamMessage messageSent = null;
+
+ byte bValue = 127;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsByte");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionTopicTestsByte");
+
+ messageSent.writeByte(bValue);
+ // send the message and then get it back
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a StreamMessage -. use StreamMessage method writeShort to
+ * write a short. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsShortCreate() {
+ try {
+ StreamMessage messageSent = null;
+ short sValue = 1;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsShort");
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionTopicTestsShort");
+ messageSent.writeShort(sValue);
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a StreamMessage -. use StreamMessage method writeInt to
+ * write an int. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsIntCreate() {
+ try {
+ StreamMessage messageSent = null;
+ int iValue = 6;
+
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsInt");
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionTopicTestsInt");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ messageSent.writeInt(iValue);
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a StreamMessage -. use StreamMessage method writeLong to
+ * write a long. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsLongCreate() {
+ try {
+ StreamMessage messageSent = null;
+ long lValue = 2;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsLong");
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionTopicTestsLong");
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ messageSent.writeLong(lValue);
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a StreamMessage -. use StreamMessage method writeFloat to
+ * write a float. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsFloatCreate() {
+ try {
+ StreamMessage messageSent = null;
+
+ float fValue = 5;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsFloat");
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionTopicTestsFloat");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.writeFloat(fValue);
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage -. use StreamMessage method writeDouble
+ * to write a double. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsDoubleCreate() {
+ try {
+ StreamMessage messageSent = null;
+
+ double dValue = 3;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsDouble");
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionTopicTestsDouble");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.writeDouble(dValue);
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a StreamMessage -. use StreamMessage method writeString
+ * to write a string. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsStringCreate() {
+ try {
+ StreamMessage messageSent = null;
+ String myString = "10";
+
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsString");
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionTopicTestsString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.writeString(myString);
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Create a StreamMessage -. use StreamMessage method writeChar to
+ * write a char. Verify the proper conversion support as in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsCharCreate() {
+ try {
+ StreamMessage messageSent = null;
+
+ char charValue = 'a';
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsChar");
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionTopicTestsChar");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+
+ messageSent.writeChar(charValue);
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage -. use StreamMessage method writeBytes to
+ * write a byte[] to the message. Verify the proper conversion support as in
+ * 3.11.3
+ */
+ private void streamMessageConversionTopicTestsBytesCreate() {
+ try {
+ StreamMessage messageSent = null;
+ byte[] bValues = { 1, 2, 3 };
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsBytes");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte[] primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionTopicTestsBytes");
+
+ messageSent.writeBytes(bValues);
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage -. use StreamMessage method writeString
+ * to write a text string of "mytest string". Verify NumberFormatException is
+ * thrown Verify that the pointer was not incremented by doing a read string
+ *
+ */
+ private void streamMessageConversionTopicTestsInvFormatStringCreate() {
+ try {
+ StreamMessage messageSent = null;
+ String myString = "mytest string";
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageConversionTopicTestsInvFormatString");
+
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "Verify conversion support for byte primitive type section 3.11.3");
+ // -----------------------------------------------------------------------------
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageConversionTopicTestsInvFormatString");
+ messageSent.writeString(myString);
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage -. write one of each primitive type. Send
+ * the message. Verify the data received was as sent.
+ *
+ */
+ private void streamMessageTopicTestsFullMsgCreate() {
+ try {
+
+ StreamMessage messageSent = null;
+
+ byte bValue = 127;
+ boolean abool = false;
+ byte[] bValues = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
+ byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+ char charValue = 'Z';
+ short sValue = 32767;
+ long lValue = 9223372036854775807L;
+ double dValue = 6.02e23;
+ float fValue = 6.02e23f;
+ int iValue = 6;
+ boolean pass = true;
+ String myString = "text";
+ String sTesting = "Testing StreamMessages";
+
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageTopicTestsFullMsg");
+
+ messageSent.writeBytes(bValues2, 0, bValues.length);
+ messageSent.writeBoolean(abool);
+ messageSent.writeByte(bValue);
+ messageSent.writeBytes(bValues);
+ messageSent.writeChar(charValue);
+ messageSent.writeDouble(dValue);
+ messageSent.writeFloat(fValue);
+ messageSent.writeInt(iValue);
+ messageSent.writeLong(lValue);
+ messageSent.writeObject(sTesting);
+ messageSent.writeShort(sValue);
+ messageSent.writeString(myString);
+
+ messageSent.writeObject(null);
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageTopicTestsFullMsg");
+
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Create a StreamMessage Use writeString to write a null, then use
+ * readString to read it back.
+ */
+ private void streamMessageTopicTestNullCreate() {
+ try {
+ StreamMessage messageSent = null;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "streamMessageTopicTestNull");
+ // -----------------------------------------------------------------------------
+ logger.log(Logger.Level.TRACE, "writeString(null) ");
+ // -----------------------------------------------------------------------------
+ // set up testcase so onMessage invokes the correct method
+ messageSent.setStringProperty("TestCase", "streamMessageTopicTestNull");
+ messageSent.writeString(null);
+ // send the message and then get it back
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read ObjectMessage created by messageObjectCopyTopicTestCreate.
+ * verify that modifying the sBuff object after the write does not effect the
+ * msg
+ */
+ public void messageObjectCopyTopicTest(jakarta.jms.ObjectMessage messageReceivedObjectMsg) {
+ boolean pass = true;
+ String testCase = "messageObjectCopyTopicTest";
+ String initial = "This is";
+ try {
+ logger.log(Logger.Level.INFO, "Ensure that changing the object did not change the message");
+ StringBuffer s = (StringBuffer) messageReceivedObjectMsg.getObject();
+ logger.log(Logger.Level.TRACE, "s is " + s);
+ if (s.toString().equals(initial)) {
+ logger.log(Logger.Level.TRACE, "Pass: msg was not changed");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: msg was changed!");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ */
+ private void streamMessageConversionTopicTestsBoolean(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionTopicTestsBoolean";
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ boolean pass = true;
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // boolean to boolean - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a boolean");
+ try {
+ if (messageReceived.readBoolean() == abool) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to boolean - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a boolean");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals((Boolean.valueOf(abool)).toString())) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // boolean to byte[] invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a boolean - expect MessageFormatException");
+ int nCount = 0;
+ try {
+
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+ // -----------------------------------------------
+ // boolean to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ bValue = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // boolean to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // boolean to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // boolean to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // boolean to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readLong();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // boolean to float invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // boolean to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a boolean - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsByte(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionTopicTestsByte";
+ try {
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+ // now test conversions for byte
+ // -----------------------------------------------
+ // byte to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // byte to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a byte");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Byte.toString(bValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a byte - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // byte to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a byte");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readByte() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to byte - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // byte to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a byte");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readShort() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to short - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ pass = false;
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // byte to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a byte");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to int - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a byte");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: byte to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a boolean - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsShort(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionTopicTestsShort";
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // short to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // short to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a short");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Short.toString(sValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: short to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // short to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a short - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // short to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // short to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a short");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readShort() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to short - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // short to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a byte");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to int - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a short");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: short to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // short to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // short to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a short - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsInt(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionTopicTestsInt";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // int to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // int to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read an int");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Integer.toString(iValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: int to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // int to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read an int - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // int to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // int to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read an int");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // int to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // int to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read an int");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == iValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to int - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read an int");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == iValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // int to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // int to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read an int - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ */
+ private void streamMessageConversionTopicTestsLong(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionTopicTestsLong";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // long to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a long - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // long to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a long");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Long.toString(lValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: long to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // long to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a long - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // long to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read an long - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // long to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a long");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // long to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a long - this is not valid");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // long to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a long");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // long to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a long");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == lValue) {
+ logger.log(Logger.Level.TRACE, "Pass: int to long - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // long to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a long - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // long to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read an long - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ */
+ private void streamMessageConversionTopicTestsFloat(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionTopicTestsFloat";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // float to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a float ");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // float to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a float");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Float.toString(fValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: float to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a float ");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // float to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a float ");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // float to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a float");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // float to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a long ");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // float to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a float");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // float to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a long");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // float to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a float ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readFloat() == fValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to float - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // float to double invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read an float ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readDouble() == fValue) {
+ logger.log(Logger.Level.TRACE, "Pass: float to double - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsDouble(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionTopicTestsDouble";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // double to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a double ");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // double to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a double");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(Double.toString(dValue))) {
+ logger.log(Logger.Level.TRACE, "Pass: double to string");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // double to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a double ");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // double to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a double ");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // double to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a double");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // double to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a double ");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // double to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a double");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // double to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a double");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // double to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a double ");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // double to double valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a double ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readDouble() == dValue) {
+ logger.log(Logger.Level.TRACE, "Pass: double to double ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ */
+ private void streamMessageConversionTopicTestsString(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionTopicTestsString";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+ String myString = "10";
+
+ // now test conversions for String
+ // -----------------------------------------------
+ // string to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a String");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readString().equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: string to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // string to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a String");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // String to byte valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a String");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readByte() == Byte.parseByte(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to byte ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // string to short valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a string");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readShort() == Short.parseShort(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to short ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a String ");
+ try {
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // string to int valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a String");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readInt() == Integer.parseInt(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to int ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to long valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a String");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readLong() == Long.parseLong(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to long ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to float valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a String");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readFloat() == Float.parseFloat(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to float ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to double valid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a String");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readDouble() == Double.parseDouble(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: String to double ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a string ");
+ try {
+ messageReceived.clearBody();
+ messageReceived.writeString("true");
+ messageReceived.reset();
+ if (messageReceived.readBoolean() == abool) {
+ logger.log(Logger.Level.TRACE, "Pass: String to boolean ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // String to boolean
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a string that is !true ");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ if (b != true) {
+ logger.log(Logger.Level.TRACE, "Fail: !true should return false");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "Pass: !true returned false");
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ *
+ */
+ private void streamMessageConversionTopicTestsChar(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionTopicTestsChar";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues = { 0 };
+ char charValue = 'a';
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for byte
+ // -----------------------------------------------
+ // char to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // char to string valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a char");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ String s = messageReceived.readString();
+ logger.log(Logger.Level.TRACE, "char returned for \"a\" is : " + s);
+ if (s.equals("a")) {
+ logger.log(Logger.Level.TRACE, "Pass: char to string - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to byte[] invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a char - expect MessageFormatException");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ nCount = messageReceived.readBytes(bValues);
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ logger.log(Logger.Level.TRACE, "Count returned from readBytes is : " + nCount);
+
+ // -----------------------------------------------
+ // char to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // char to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a char");
+ try {
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // char to char valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a char ");
+ try {
+ messageReceived.reset();
+ if (messageReceived.readChar() == 'a') {
+ logger.log(Logger.Level.TRACE, "Pass: char to char - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: wrong value returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ // -----------------------------------------------
+ // char to int invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a char ");
+ try {
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // char to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a char");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // char to float invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // char to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a char - this is not valid");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the proper conversion support as
+ * in 3.11.3
+ */
+ private void streamMessageConversionTopicTestsBytes(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionTopicTestsBytes";
+
+ try {
+
+ byte bValue = 127;
+ boolean abool = true;
+ byte[] bValues2 = { 0, 0, 0 };
+ short sValue = 1;
+ long lValue = 2;
+ double dValue = 3;
+ float fValue = 5;
+ int iValue = 6;
+ boolean pass = true;
+
+ // now test conversions for boolean
+ // -----------------------------------------------
+ // byte[] to byte[] - valid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBytes[] to read a byte[] ");
+ int nCount = 0;
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ if (messageReceived.readBytes(bValues2) == 3) { // count should be 3.
+ logger.log(Logger.Level.TRACE, "Pass: byte[] to byte[] - valid");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: count incorrect");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // byte[] to boolean - invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readBoolean to read a byte[]");
+ // position to beginning of stream message.
+ messageReceived.reset();
+ try {
+ boolean b = messageReceived.readBoolean();
+ logger.log(Logger.Level.TRACE,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // byte[] to string invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readString to read a byte[]");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ String s = messageReceived.readString();
+ logger.log(Logger.Level.TRACE,
+ "Fail: byte[] to boolean conversion should have thrown MessageFormatException");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // byte[] to byte invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // byte[] to short invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // byte[] to char invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readChar to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ char c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // byte[] to int invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // byte[] to long invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // byte[] to float invalid
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // byte[] to double invalid
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a byte[] - expect MessageFormatException");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: MessageFormatException was not thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Read a StreamMessage -. Verify NumberFormatException is thrown
+ * Verify that the pointer was not incremented by doing a read string
+ *
+ */
+ private void streamMessageConversionTopicTestsInvFormatString(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageConversionTopicTestsInvFormatString";
+
+ try {
+
+ boolean pass = true;
+ String myString = "mytest string";
+
+ // -----------------------------------------------
+ // String to byte
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readByte to read a String that is not valid ");
+ try {
+ byte b = messageReceived.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: java.lang.NumberFormatException expected");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof java.lang.NumberFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // pointer should not have moved
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Verify that the data can be read as a string and pointer did not move");
+ try {
+ String s = messageReceived.readString();
+ logger.log(Logger.Level.TRACE, "message read: " + s);
+ if (s.equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: able to read the string");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: string not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ // -----------------------------------------------
+ // string to short
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readShort to read a string that is not valid ");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ short s = messageReceived.readShort();
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof java.lang.NumberFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // string to int
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readInt to read a String that is not valid ");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ int i = messageReceived.readInt();
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof java.lang.NumberFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // string to long
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readLong to read a String that is not valid ");
+ try {
+ // position to beginning of stream message.
+ messageReceived.reset();
+ long l = messageReceived.readLong();
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof java.lang.NumberFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ // -----------------------------------------------
+ // String to float
+ // -----------------------------------------------
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readFloat to read a String that is not valid ");
+ try {
+ messageReceived.reset();
+ float f = messageReceived.readFloat();
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof java.lang.NumberFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // -----------------------------------------------
+ // String to double
+ // -----------------------------------------------
+
+ logger.log(Logger.Level.TRACE, "--");
+ logger.log(Logger.Level.TRACE, "Use readDouble to read a String that is not valid ");
+ try {
+ messageReceived.reset();
+ double d = messageReceived.readDouble();
+ logger.log(Logger.Level.TRACE, "Fail: NumberFormatException was expected");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof java.lang.NumberFormatException) {
+ logger.log(Logger.Level.TRACE, "Pass: NumberFormatException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage -. Verify the data received was as sent.
+ *
+ */
+ private void streamMessageTopicTestsFullMsg(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageTopicTestsFullMsg";
+
+ try {
+ byte bValue = 127;
+ boolean abool = false;
+ byte[] bValues2 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
+ byte[] bValuesReturned = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ byte[] bValuesReturned2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
+ char charValue = 'Z';
+ short sValue = 32767;
+ long lValue = 9223372036854775807L;
+ double dValue = 6.02e23;
+ float fValue = 6.02e23f;
+ int iValue = 6;
+ boolean pass = true;
+ String myString = "text";
+ String sTesting = "Testing StreamMessages";
+
+ try {
+ int nCount = bValuesReturned2.length;
+ do {
+ nCount = messageReceived.readBytes(bValuesReturned2);
+ logger.log(Logger.Level.TRACE, "nCount is " + nCount);
+ if (nCount != -1) {
+ for (int i = 0; i < bValuesReturned2.length; i++) {
+ if (bValuesReturned2[i] != bValues2[i]) {
+ logger.log(Logger.Level.TRACE, "Fail: byte[] " + i + " is not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "PASS: byte[]" + i + " is valid");
+ }
+ }
+ }
+ } while (nCount >= bValuesReturned2.length);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readBoolean() == abool) {
+ logger.log(Logger.Level.TRACE, "Pass: boolean returned ok");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: boolean not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readByte() == bValue) {
+ logger.log(Logger.Level.TRACE, "Pass: Byte returned ok");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Byte not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ int nCount = bValuesReturned.length;
+ do {
+ nCount = messageReceived.readBytes(bValuesReturned);
+ logger.log(Logger.Level.TRACE, "nCount is " + nCount);
+ if (nCount != -1) {
+ for (int i = 0; i < bValuesReturned2.length; i++) {
+ if (bValuesReturned2[i] != bValues2[i]) {
+ logger.log(Logger.Level.TRACE, "Fail: byte[] " + i + " is not valid");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.TRACE, "PASS: byte[]" + i + " is valid");
+ }
+ }
+ }
+ } while (nCount >= bValuesReturned.length);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readChar() == charValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct char");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: char not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readDouble() == dValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct double");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: double not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readFloat() == fValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct float");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: float not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readInt() == iValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct int");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: int not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ try {
+ if (messageReceived.readLong() == lValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct long");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: long not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readObject().equals(sTesting)) {
+ logger.log(Logger.Level.TRACE, "Pass: correct object");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: object not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readShort() == sValue) {
+ logger.log(Logger.Level.TRACE, "Pass: correct short");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: short not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readString().equals(myString)) {
+ logger.log(Logger.Level.TRACE, "Pass: correct string");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: string not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+
+ try {
+ if (messageReceived.readObject() == null) {
+ logger.log(Logger.Level.TRACE, "Pass: correct object");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: object not returned as expected");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception" + e.getClass().getName() + "was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Read a StreamMessage Use readString to read back a null
+ */
+ private void streamMessageTopicTestNull(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "streamMessageTopicTestNull";
+ try {
+ boolean pass = true;
+ try {
+ if (messageReceived.readObject() == null) {
+ logger.log(Logger.Level.TRACE, "Pass: Read a null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: null value not returned");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error trying to read a null object");
+ logger.log(Logger.Level.TRACE, "Error: unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ sendTestResults(testCase, pass);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: send test results to response queue (MDB_QUEUE_REPLY) for
+ * verification
+ */
+ private void sendTestResults(String testCase, boolean results) {
+ TextMessage msg = null;
+
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ msg.setStringProperty("TestCase", testCase);
+ msg.setText(testCase);
+ if (results)
+ msg.setStringProperty("Status", "Pass");
+ else
+ msg.setStringProperty("Status", "Fail");
+
+ logger.log(Logger.Level.TRACE, "Sending response message");
+ mSender.send(msg);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ logger.log(Logger.Level.TRACE, "Error: " + je.getClass().getName() + " was thrown");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.TRACE, "Error: " + ee.getClass().getName() + " was thrown");
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesT2 In MsgBeanMsgTest2::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesT2 In MsgBeanMsgTest2::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT3/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT3/MDBClient.java
deleted file mode 100644
index c2c534b3a5..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT3/MDBClient.java
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesT3;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.MDB_T_Test;
-
-import jakarta.ejb.EJB;
-
-/**
- * The MDBClient class invokes a test session bean, which will ask and the
- * message driven bean to send a text, byte, map, stream, and object message to
- * a queue
- */
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_MSGT3_Test")
- private static MDB_T_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.port;
- * harness.log.traceflag;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
- //
-
- /*
- * @testName: mdbMsgClearBodyTopicTextTest
- *
- * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
- * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * Create and send a Text message. Have the mdb read the message call
- * clearBody, verify body is empty after clearBody. verify properties are not
- * effected by clearBody. Write to the message again 3.11
- */
- public void mdbMsgClearBodyTopicTextTest() throws Exception {
- String testCase1 = "msgClearBodyTopicTextTestCreate";
- String testCase2 = "msgClearBodyTopicTextTest";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase msgClearBodyTopicTextTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from msgClearBodyTopicTextTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgClearBodyTopicTextTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgClearBodyTopicObjectTest
- *
- * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
- * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * Create and send a Object message. Have the mdb read the message call
- * clearBody, verify body is empty after clearBody. verify properties are not
- * effected by clearBody. Write to the message again 3.11
- */
- public void mdbMsgClearBodyTopicObjectTest() throws Exception {
- String testCase1 = "msgClearBodyTopicObjectTestCreate";
- String testCase2 = "msgClearBodyTopicObjectTest";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase msgClearBodyTopicObjectTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from msgClearBodyTopicObjectTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgClearBodyTopicObjectTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgClearBodyTopicMapTest
- *
- * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
- * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * Create and send a Map message. Have the mdb read the message call
- * clearBody, verify body is empty after clearBody. verify properties are not
- * effected by clearBody. Write to the message again 3.11
- */
- public void mdbMsgClearBodyTopicMapTest() throws Exception {
- String testCase1 = "msgClearBodyTopicMapTestCreate";
- String testCase2 = "msgClearBodyTopicMapTest";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase msgClearBodyTopicMapTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out
- .println("client - Check for response from msgClearBodyTopicMapTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgClearBodyTopicMapTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgClearBodyTopicBytesTest
- *
- * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
- * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * Create and send a Bytes message. Have the mdb read the message call
- * clearBody, verify body is empty after clearBody. verify properties are not
- * effected by clearBody. Write to the message again 3.11
- */
- public void mdbMsgClearBodyTopicBytesTest() throws Exception {
- String testCase1 = "msgClearBodyTopicBytesTestCreate";
- String testCase2 = "msgClearBodyTopicBytesTest";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase msgClearBodyTopicBytesTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from msgClearBodyTopicBytesTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgClearBodyTopicBytesTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgClearBodyTopicStreamTest
- *
- * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
- * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * Create and send a Stream message. Have the mdb read the message call
- * clearBody, verify body is empty after clearBody. verify properties are not
- * effected by clearBody. Write to the message again 3.11
- */
- public void mdbMsgClearBodyTopicStreamTest() throws Exception {
- String testCase1 = "msgClearBodyTopicStreamTestCreate";
- String testCase2 = "msgClearBodyTopicStreamTest";
- try {
- // Have the EJB invoke the MDB
- System.out
- .println("client - run testcase msgClearBodyTopicStreamTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from msgClearBodyTopicStreamTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgClearBodyTopicStreamTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbMsgResetTopicTest
- *
- * @assertion_ids: JMS:JAVADOC:174; JMS:JAVADOC:584;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * create a stream message and a byte message. write to the message body, call
- * the reset method, try to write to the body expect a
- * MessageNotWriteableException to be thrown.
- *
- *
- *
- */
- public void mdbMsgResetTopicTest() throws Exception {
- String testCase = "msgResetTopicTest";
- try {
- // Have the EJB invoke the MDB
- System.out.println("client - run testcase msgResetTopicTest");
- hr.askMDBToRunATest(testCase); // create and send message to MDB_QUEUE
- System.out.println("client - Check for response from msgResetTopicTest");
- if (!hr.checkOnResponse(testCase)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: msgResetTopicTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbReadNullCharNotValidTopicMapTest
- *
- * @assertion_ids: JMS:SPEC:79; JMS:JAVADOC:134; JMS:JAVADOC:439;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * write a null string to a MapMessage. Attempt to read the null value as a
- * char.
- */
- public void mdbReadNullCharNotValidTopicMapTest() throws Exception {
- String testCase1 = "readNullCharNotValidTopicMapTestCreate";
- String testCase2 = "readNullCharNotValidTopicMapTest";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase readNullCharNotValidTopicMapTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from readNullCharNotValidTopicMapTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: readNullCharNotValidTopicMapTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
- /*
- * @testName: mdbReadNullCharNotValidTopicStreamTest
- *
- * @assertion_ids: JMS:SPEC:79; JMS:JAVADOC:134; JMS:JAVADOC:439;
- *
- * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
- * write a null string to a StreamMessage. Attempt to read the null value as a
- * char.
- */
-
- public void mdbReadNullCharNotValidTopicStreamTest() throws Exception {
- String testCase1 = "readNullCharNotValidTopicStreamTestCreate";
- String testCase2 = "readNullCharNotValidTopicStreamTest";
- try {
- // Have the EJB invoke the MDB
- System.out.println(
- "client - run testcase readNullCharNotValidTopicStreamTestCreate");
- hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
- System.out.println(
- "client - Check for response from readNullCharNotValidTopicStreamTest");
- if (!hr.checkOnResponse(testCase2)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: readNullCharNotValidTopicStreamTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- ;
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT3/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT3/MDBClientIT.java
new file mode 100644
index 0000000000..575b0c7329
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT3/MDBClientIT.java
@@ -0,0 +1,334 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesT3;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.commonee.MDB_T_Test;
+
+import jakarta.ejb.EJB;
+
+/**
+ * The MDBClient class invokes a test session bean, which will ask and the
+ * message driven bean to send a text, byte, map, stream, and object message to
+ * a queue
+ */
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_MSGT3_Test")
+ private static MDB_T_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ hr.setup(props);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+ //
+
+ /*
+ * @testName: mdbMsgClearBodyTopicTextTest
+ *
+ * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
+ * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * Create and send a Text message. Have the mdb read the message call clearBody,
+ * verify body is empty after clearBody. verify properties are not effected by
+ * clearBody. Write to the message again 3.11
+ */
+ @Test
+ public void mdbMsgClearBodyTopicTextTest() throws Exception {
+ String testCase1 = "msgClearBodyTopicTextTestCreate";
+ String testCase2 = "msgClearBodyTopicTextTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase msgClearBodyTopicTextTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from msgClearBodyTopicTextTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgClearBodyTopicTextTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgClearBodyTopicObjectTest
+ *
+ * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
+ * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * Create and send a Object message. Have the mdb read the message call
+ * clearBody, verify body is empty after clearBody. verify properties are not
+ * effected by clearBody. Write to the message again 3.11
+ */
+ @Test
+ public void mdbMsgClearBodyTopicObjectTest() throws Exception {
+ String testCase1 = "msgClearBodyTopicObjectTestCreate";
+ String testCase2 = "msgClearBodyTopicObjectTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase msgClearBodyTopicObjectTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from msgClearBodyTopicObjectTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgClearBodyTopicObjectTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgClearBodyTopicMapTest
+ *
+ * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
+ * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * Create and send a Map message. Have the mdb read the message call clearBody,
+ * verify body is empty after clearBody. verify properties are not effected by
+ * clearBody. Write to the message again 3.11
+ */
+ @Test
+ public void mdbMsgClearBodyTopicMapTest() throws Exception {
+ String testCase1 = "msgClearBodyTopicMapTestCreate";
+ String testCase2 = "msgClearBodyTopicMapTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase msgClearBodyTopicMapTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from msgClearBodyTopicMapTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgClearBodyTopicMapTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgClearBodyTopicBytesTest
+ *
+ * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
+ * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * Create and send a Bytes message. Have the mdb read the message call
+ * clearBody, verify body is empty after clearBody. verify properties are not
+ * effected by clearBody. Write to the message again 3.11
+ */
+ @Test
+ public void mdbMsgClearBodyTopicBytesTest() throws Exception {
+ String testCase1 = "msgClearBodyTopicBytesTestCreate";
+ String testCase2 = "msgClearBodyTopicBytesTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase msgClearBodyTopicBytesTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from msgClearBodyTopicBytesTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgClearBodyTopicBytesTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgClearBodyTopicStreamTest
+ *
+ * @assertion_ids: JMS:SPEC:71; JMS:SPEC:72; JMS:JAVADOC:431; JMS:JAVADOC:473;
+ * JMS:JAVADOC:449; JMS:SPEC:178; JMS:JAVADOC:291;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * Create and send a Stream message. Have the mdb read the message call
+ * clearBody, verify body is empty after clearBody. verify properties are not
+ * effected by clearBody. Write to the message again 3.11
+ */
+ @Test
+ public void mdbMsgClearBodyTopicStreamTest() throws Exception {
+ String testCase1 = "msgClearBodyTopicStreamTestCreate";
+ String testCase2 = "msgClearBodyTopicStreamTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase msgClearBodyTopicStreamTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from msgClearBodyTopicStreamTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgClearBodyTopicStreamTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbMsgResetTopicTest
+ *
+ * @assertion_ids: JMS:JAVADOC:174; JMS:JAVADOC:584;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * create a stream message and a byte message. write to the message body, call
+ * the reset method, try to write to the body expect a
+ * MessageNotWriteableException to be thrown.
+ *
+ *
+ *
+ */
+ @Test
+ public void mdbMsgResetTopicTest() throws Exception {
+ String testCase = "msgResetTopicTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase msgResetTopicTest");
+ hr.askMDBToRunATest(testCase); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from msgResetTopicTest");
+ if (!hr.checkOnResponse(testCase)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: msgResetTopicTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbReadNullCharNotValidTopicMapTest
+ *
+ * @assertion_ids: JMS:SPEC:79; JMS:JAVADOC:134; JMS:JAVADOC:439;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * write a null string to a MapMessage. Attempt to read the null value as a
+ * char.
+ */
+ @Test
+ public void mdbReadNullCharNotValidTopicMapTest() throws Exception {
+ String testCase1 = "readNullCharNotValidTopicMapTestCreate";
+ String testCase2 = "readNullCharNotValidTopicMapTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase readNullCharNotValidTopicMapTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from readNullCharNotValidTopicMapTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: readNullCharNotValidTopicMapTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbReadNullCharNotValidTopicStreamTest
+ *
+ * @assertion_ids: JMS:SPEC:79; JMS:JAVADOC:134; JMS:JAVADOC:439;
+ *
+ * @test_Strategy: Call a session bean. Have the session bean invoke an mdb to
+ * write a null string to a StreamMessage. Attempt to read the null value as a
+ * char.
+ */
+ @Test
+ public void mdbReadNullCharNotValidTopicStreamTest() throws Exception {
+ String testCase1 = "readNullCharNotValidTopicStreamTestCreate";
+ String testCase2 = "readNullCharNotValidTopicStreamTest";
+ try {
+ // Have the EJB invoke the MDB
+ System.out.println("client - run testcase readNullCharNotValidTopicStreamTestCreate");
+ hr.askMDBToRunATest(testCase1); // create and send message to MDB_QUEUE
+ System.out.println("client - Check for response from readNullCharNotValidTopicStreamTest");
+ if (!hr.checkOnResponse(testCase2)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: readNullCharNotValidTopicStreamTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ ;
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT3/MsgBeanMsgTestT3.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT3/MsgBeanMsgTestT3.java
index c221858dde..4a5b98e9a7 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT3/MsgBeanMsgTestT3.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_msgTypesT3/MsgBeanMsgTestT3.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_msgTypesT3;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.TSNamingContext;
@@ -51,805 +52,741 @@
public class MsgBeanMsgTestT3 implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- private MessageDrivenContext mdc = null;
-
- // JMS
- private QueueConnectionFactory qFactory = null;
-
- private TopicConnectionFactory tFactory = null;
-
- private QueueConnection qConnection = null;
-
- private TopicConnection tConnection = null;
-
- private Queue queueR = null;
-
- private Queue queue = null;
-
- private Topic topic = null;
-
- private QueueSender mSender = null;
-
- private QueueSession qSession = null;
-
- private TopicPublisher tPublisher = null;
-
- private TopicSession tSession = null;
-
- public MsgBeanMsgTestT3() {
- TestUtil.logTrace("@MsgBeanMsgTest3()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgTypesT3 - @MsgBeanMsgTest3-ejbCreate() !!");
- try {
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- if (qFactory == null) {
- System.out.println("qFactory error");
- }
- System.out.println("got a qFactory !!");
- tFactory = (TopicConnectionFactory) context
- .lookup("java:comp/env/jms/MyTopicConnectionFactory");
- if (tFactory == null) {
- System.out.println("tFactory error");
- }
- System.out.println("got a tFactory !!");
-
- queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- if (queueR == null) {
- System.out.println("queueR error");
- }
-
- topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC");
- if (topic == null) {
- System.out.println("topic error");
- }
-
- p = new Properties();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("from jms.ee.mdb.mdb_msgTypesT3 @onMessage!" + msg);
-
- try {
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null) {
- System.out.println("connection error");
- } else {
- qConnection.start();
- qSession = qConnection.createQueueSession(true, 0);
- }
- tConnection = tFactory.createTopicConnection();
- if (tConnection == null) {
- System.out.println("connection error");
- } else {
- tConnection.start();
- tSession = tConnection.createTopicSession(true, 0);
- }
- if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyTopicTextTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyTopicTextTestCreate - create the message");
- msgClearBodyTopicTextTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyTopicTextTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyTopicTextTest - read and verify the message");
- msgClearBodyTopicTextTest((jakarta.jms.TextMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyTopicObjectTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyTopicObjectTestCreate - create the message");
- msgClearBodyTopicObjectTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyTopicObjectTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyTopicObjectTest - read and verify the message");
- msgClearBodyTopicObjectTest((jakarta.jms.ObjectMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyTopicMapTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyTopicMapTestCreate - create the message");
- msgClearBodyTopicMapTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyTopicMapTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyTopicMapTest - read and verify the message");
- msgClearBodyTopicMapTest((jakarta.jms.MapMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyTopicBytesTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyTopicBytesTestCreate - create the message");
- msgClearBodyTopicBytesTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyTopicBytesTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyTopicBytesTest - read and verify the message");
- msgClearBodyTopicBytesTest((jakarta.jms.BytesMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyTopicStreamTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyTopicStreamTestCreate - create the message");
- msgClearBodyTopicStreamTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("msgClearBodyTopicStreamTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgClearBodyTopicStreamTest - read and verify the message");
- msgClearBodyTopicStreamTest((jakarta.jms.StreamMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("msgResetTopicTest")) {
- TestUtil.logTrace(
- "@onMessage - running msgResetTopicTest - read and verify the message");
- msgResetTopicTest();
- } else if (msg.getStringProperty("TestCase")
- .equals("readNullCharNotValidTopicStreamTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running readNullCharNotValidTopicStreamTestCreate - read and verify the message");
- readNullCharNotValidTopicStreamTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("readNullCharNotValidTopicStreamTest")) {
- TestUtil.logTrace(
- "@onMessage - running readNullCharNotValidTopicStreamTest - read and verify the message");
- readNullCharNotValidTopicStreamTest((jakarta.jms.StreamMessage) msg);
- } else if (msg.getStringProperty("TestCase")
- .equals("readNullCharNotValidTopicMapTestCreate")) {
- TestUtil.logTrace(
- "@onMessage - running readNullCharNotValidTopicMapTestCreate - read and verify the message");
- readNullCharNotValidTopicMapTestCreate();
- } else if (msg.getStringProperty("TestCase")
- .equals("readNullCharNotValidTopicMapTest")) {
- TestUtil.logTrace(
- "@onMessage - running readNullCharNotValidTopicMapTest - read and verify the message");
- readNullCharNotValidTopicMapTest((jakarta.jms.MapMessage) msg);
- } else {
- TestUtil.logTrace(
- "@onMessage - invalid message type found in StringProperty");
- TestUtil.logTrace("Do not have a method for this testcase: "
- + msg.getStringProperty("TestCase"));
- }
- TestUtil.logTrace("@onMessage - Finished for this test!");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- if (tConnection != null) {
- try {
- tConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
-
- }
-
- /*
- *
- * Description: create and send a text message
- */
- private void msgClearBodyTopicTextTestCreate() {
- try {
- TextMessage messageSent = null;
- messageSent = qSession.createTextMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setText("sending a Text message");
- messageSent.setStringProperty("TestCase", "msgClearBodyTopicTextTest");
- TestUtil.logTrace("sending a Text message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create and send an object message
- */
- private void msgClearBodyTopicObjectTestCreate() {
- try {
- ObjectMessage messageSentObjectMsg = null;
- // send and receive Object message to Topic
- TestUtil.logTrace("Send ObjectMessage to Topic.");
- messageSentObjectMsg = qSession.createObjectMessage();
- JmsUtil.addPropsToMessage(messageSentObjectMsg, p);
- messageSentObjectMsg.setObject("Initial message");
- messageSentObjectMsg.setStringProperty("TestCase",
- "msgClearBodyTopicObjectTest");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSentObjectMsg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create and send a Map message
- */
- private void msgClearBodyTopicMapTestCreate() {
- try {
- MapMessage messageSentMapMessage = null;
- // send and receive Map message to Topic
- TestUtil.logTrace("Send MapMessage to Topic.");
- messageSentMapMessage = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(messageSentMapMessage, p);
- messageSentMapMessage.setStringProperty("TestCase",
- "msgClearBodyTopicMapTest");
- messageSentMapMessage.setString("aString", "Initial message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSentMapMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create and send a Bytes message
- */
- private void msgClearBodyTopicBytesTestCreate() {
- byte bValue = 127;
- try {
- BytesMessage messageSentBytesMessage = null;
- // send and receive bytes message to Topic
- TestUtil.logTrace("Send BytesMessage to Topic.");
- messageSentBytesMessage = qSession.createBytesMessage();
- JmsUtil.addPropsToMessage(messageSentBytesMessage, p);
- messageSentBytesMessage.setStringProperty("TestCase",
- "msgClearBodyTopicBytesTest");
- messageSentBytesMessage.writeByte(bValue);
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSentBytesMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: create and send a Stream message
- */
- private void msgClearBodyTopicStreamTestCreate() {
- try {
- StreamMessage messageSentStreamMessage = null;
- // Send and receive a StreamMessage
- TestUtil.logTrace("sending a Stream message");
- messageSentStreamMessage = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSentStreamMessage, p);
- messageSentStreamMessage.setStringProperty("TestCase",
- "msgClearBodyTopicStreamTest");
- messageSentStreamMessage.writeString("Testing...");
- TestUtil.logTrace("Sending message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSentStreamMessage);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Receive a single Text message call clearBody, verify body is
- * empty after clearBody. verify properties are not effected by clearBody.
- * Write to the message again 3.11
- */
- public void msgClearBodyTopicTextTest(jakarta.jms.TextMessage messageReceived) {
- String testCase = "msgClearBodyTopicTextTest";
- boolean pass = true;
- // Text Message
- try {
- TestUtil.logTrace("Test TextMessage ");
- TestUtil.logTrace("read 1st contents");
- TestUtil.logTrace(" " + messageReceived.getText());
- TestUtil.logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceived.clearBody();
- // message body should now be empty
- if (messageReceived.getText() == null) {
- TestUtil.logTrace("Empty body after clearBody as expected: null");
- } else {
- TestUtil.logTrace("Fail: message body was not empty");
- pass = false;
- }
- // properties should not have been deleted by the clearBody method.
- if (messageReceived.getStringProperty("TestCase")
- .equals("msgClearBodyTopicTextTest")) {
- TestUtil
- .logTrace("Pass: Text properties read ok after clearBody called");
- } else {
- TestUtil
- .logTrace("Fail: Text properties cleared after clearBody called");
- pass = false;
- }
- TestUtil.logTrace("write and read 2nd contents");
- messageReceived.setText("new data");
- if (messageReceived.getText().equals("new data")) {
- TestUtil.logTrace("Pass:");
- } else {
- TestUtil.logTrace("Fail:");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: Receive a single Object message call clearBody, verify body is
- * empty after clearBody. verify properties are not effected by clearBody.
- * Write to the message again 3.11
- */
- public void msgClearBodyTopicObjectTest(
- jakarta.jms.ObjectMessage messageReceivedObjectMsg) {
- String testCase = "msgClearBodyTopicObjectTest";
- boolean pass = true;
- try {
- TestUtil.logTrace("Testing Object message");
- TestUtil.logTrace("read 1st contents");
- TestUtil.logTrace(" " + messageReceivedObjectMsg.getObject());
- TestUtil.logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedObjectMsg.clearBody();
- // message body should now be empty
- if (messageReceivedObjectMsg.getObject() == null) {
- TestUtil.logTrace("Empty body after clearBody as expected: null");
- } else {
- TestUtil.logTrace("Fail: message body was not empty");
- pass = false;
- }
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedObjectMsg.getStringProperty("TestCase")
- .equals("msgClearBodyTopicObjectTest")) {
- TestUtil
- .logTrace("Pass: Object properties read ok after clearBody called");
- } else {
- TestUtil
- .logTrace("Fail: Object properties cleared after clearBody called");
- pass = false;
- }
- TestUtil.logTrace("write 2nd contents");
- messageReceivedObjectMsg.setObject("new stuff here!!!!!!");
- TestUtil.logTrace("read 2nd contents");
- if (messageReceivedObjectMsg.getObject().equals("new stuff here!!!!!!")) {
- TestUtil.logTrace("Pass:");
- } else {
- TestUtil.logTrace("Fail: ");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: Receive a single Map message call clearBody, verify body is
- * empty after clearBody. verify properties are not effected by clearBody.
- * Write to the message again 3.11
- */
- private void msgClearBodyTopicMapTest(
- jakarta.jms.MapMessage messageReceivedMapMessage) {
- String testCase = "msgClearBodyTopicMapTest";
- boolean pass = true;
- try {
- TestUtil.logTrace("Test for MapMessage ");
- TestUtil.logTrace("read 1st contents");
- TestUtil.logTrace(" " + messageReceivedMapMessage.getString("aString"));
- TestUtil.logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedMapMessage.clearBody();
- // message body should now be empty
- if (messageReceivedMapMessage.getString("aString") == null) {
- TestUtil.logTrace("Empty body after clearBody as expected: null");
- } else {
- TestUtil.logTrace("Fail: message body was not empty");
- pass = false;
- }
-
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedMapMessage.getStringProperty("TestCase")
- .equals("msgClearBodyTopicMapTest")) {
- TestUtil
- .logTrace("Pass: Map properties read ok after clearBody called");
- } else {
- TestUtil
- .logTrace("Fail: Map properties cleared after clearBody called");
- pass = false;
- }
- TestUtil.logTrace("write 2nd contents");
- messageReceivedMapMessage.setString("yes", "new stuff !!!!!");
- TestUtil.logTrace("read 2nd contents");
- if (messageReceivedMapMessage.getString("yes")
- .equals("new stuff !!!!!")) {
- TestUtil.logTrace("PASS:");
- } else {
- TestUtil.logTrace("FAIL:");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: Receive a single Bytes message call clearBody, verify body is
- * empty after clearBody. verify properties are not effected by clearBody.
- * Write to the message again 3.11
- */
- public void msgClearBodyTopicBytesTest(
- jakarta.jms.BytesMessage messageReceivedBytesMessage) {
- String testCase = "msgClearBodyTopicBytesTest";
- boolean pass = true;
- byte bValue2 = 22;
- try {
- TestUtil.logTrace("Test BytesMessage ");
- TestUtil.logTrace("read 1st contents");
- TestUtil.logTrace(" " + messageReceivedBytesMessage.readByte());
- TestUtil.logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedBytesMessage.clearBody();
- TestUtil.logTrace(
- "Bytes message body should now be empty and in writeonly mode");
- try {
- byte b = messageReceivedBytesMessage.readByte();
- TestUtil.logTrace(
- "Fail: MessageNotReadableException not thrown as expected");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageNotReadableException) {
- TestUtil
- .logTrace("Pass: MessageNotReadableException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedBytesMessage.getStringProperty("TestCase")
- .equals("msgClearBodyTopicBytesTest")) {
- TestUtil.logTrace(
- "Pass: Bytes msg properties read ok after clearBody called");
- } else {
- TestUtil.logTrace(
- "Fail: Bytes msg properties cleared after clearBody called");
- pass = false;
- }
-
- TestUtil.logTrace("write 2nd contents");
- messageReceivedBytesMessage.writeByte(bValue2);
- TestUtil.logTrace("read 2nd contents");
- messageReceivedBytesMessage.reset();
- if (messageReceivedBytesMessage.readByte() == bValue2) {
- TestUtil.logTrace("Pass:");
- } else {
- TestUtil.logTrace("Fail:");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- * Description: Receive a single Stream message call clearBody, verify body is
- * empty after clearBody. verify properties are not effected by clearBody.
- * Write to the message again 3.11
- */
- public void msgClearBodyTopicStreamTest(
- jakarta.jms.StreamMessage messageReceivedStreamMessage) {
- String testCase = "msgClearBodyTopicStreamTest";
- boolean pass = true;
- try {
- TestUtil.logTrace("Test StreamMessage ");
- TestUtil.logTrace("read 1st contents");
- TestUtil.logTrace(" " + messageReceivedStreamMessage.readString());
- TestUtil.logTrace("Call to clearBody !!!!!!!!!!!!!!!");
- messageReceivedStreamMessage.clearBody();
-
- TestUtil.logTrace(
- "Stream message body should now be empty and in writeonly mode");
- try {
- String s = messageReceivedStreamMessage.readString();
- TestUtil.logTrace(
- "Fail: MessageNotReadableException should have been thrown");
- pass = false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- if (e instanceof jakarta.jms.MessageNotReadableException) {
- TestUtil
- .logTrace("Pass: MessageNotReadableException thrown as expected");
- } else {
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- }
- // properties should not have been deleted by the clearBody method.
- if (messageReceivedStreamMessage.getStringProperty("TestCase")
- .equals("msgClearBodyTopicStreamTest")) {
- TestUtil.logTrace(
- "Pass: Stream msg properties read ok after clearBody called");
- } else {
- TestUtil.logTrace(
- "Fail: Stream msg properties cleared after clearBody called");
- pass = false;
- }
- TestUtil.logTrace("write 2nd contents");
- messageReceivedStreamMessage.writeString("new data");
- TestUtil.logTrace("read 2nd contents");
- messageReceivedStreamMessage.reset();
- if (messageReceivedStreamMessage.readString().equals("new data")) {
- TestUtil.logTrace("Pass:");
- } else {
- TestUtil.logTrace("Fail:");
- }
- } catch (Exception e) {
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- TestUtil.printStackTrace(e);
- pass = false;
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- *
- * Description: create a stream message and a byte message. write to the
- * message body, call the reset method, try to write to the body expect a
- * MessageNotWriteableException to be thrown.
- */
- private void msgResetTopicTest() {
- boolean pass = true;
- int nInt = 1000;
- String testCase = "msgResetTopicTest";
- try {
- StreamMessage messageSentStreamMessage = null;
- BytesMessage messageSentBytesMessage = null;
- // StreamMessage
- try {
- TestUtil.logTrace("creating a Stream message");
- messageSentStreamMessage = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSentStreamMessage, p);
- messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgResetTopicTest1");
- // write to the message
- messageSentStreamMessage.writeString("Testing...");
- TestUtil.logTrace(
- "reset stream message - now should be in readonly mode");
- messageSentStreamMessage.reset();
- messageSentStreamMessage.writeString("new data");
- TestUtil.logTrace(
- "Fail: message did not throw MessageNotWriteable exception as expected");
- pass = false;
- } catch (MessageNotWriteableException nw) {
- TestUtil.logTrace("Pass: MessageNotWriteable thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
-
- // BytesMessage
- try {
- TestUtil.logTrace("creating a Byte message");
- messageSentBytesMessage = qSession.createBytesMessage();
- JmsUtil.addPropsToMessage(messageSentBytesMessage, p);
- messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "msgResetTopicTest2");
- // write to the message
- messageSentBytesMessage.writeInt(nInt);
- TestUtil
- .logTrace("reset Byte message - now should be in readonly mode");
- messageSentBytesMessage.reset();
- messageSentBytesMessage.writeInt(nInt);
- TestUtil.logTrace(
- "Fail: message did not throw MessageNotWriteable exception as expected");
- pass = false;
- } catch (MessageNotWriteableException nw) {
- TestUtil.logTrace("Pass: MessageNotWriteable thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: " + e.getClass().getName() + " was thrown");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
- }
-
- /*
- *
- * Description: Write a null string to a MapMessage.
- *
- */
- public void readNullCharNotValidTopicMapTestCreate() {
- try {
- MapMessage mapSent = null;
- char c;
- boolean pass = true;
- mapSent = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(mapSent, p);
- mapSent.setStringProperty("TestCase", "readNullCharNotValidTopicMapTest");
- TestUtil.logTrace(
- "Write a null string to the map message object with mapMessage.setString");
- mapSent.setString("WriteANull", null);
- TestUtil.logTrace(" Send the message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(mapSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- * Description: Write a null string to a StreamMessage.
- *
- */
- public void readNullCharNotValidTopicStreamTestCreate() {
- try {
- StreamMessage messageSent = null;
- char c;
- boolean pass = true;
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("TestCase",
- "readNullCharNotValidTopicStreamTest");
- // -----------------------------------------------------------------------------
- // stream Message
- // -----------------------------------------------------------------------------
- messageSent = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(messageSent, p);
- messageSent.setStringProperty("TestCase",
- "readNullCharNotValidTopicStreamTest");
- TestUtil.logTrace(
- "Write a null string to the map message object with streamMessage.setString");
- messageSent.writeString(null);
- TestUtil.logTrace(" Send the message");
- tPublisher = tSession.createPublisher(topic);
- tPublisher.publish(messageSent);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- * Description: Attempt to read a null string from a MapMessage. Should throw
- * a null pointer exception
- */
-
- public void readNullCharNotValidTopicMapTest(
- jakarta.jms.MapMessage mapReceived) {
- String testCase = "readNullCharNotValidTopicMapTest";
- boolean pass = true;
- try {
- char c;
- TestUtil.logTrace("Use readChar to read a null ");
- try {
- c = mapReceived.getChar("WriteANull");
- TestUtil.logTrace("Fail: NullPointerException was not thrown");
- pass = false;
- } catch (java.lang.NullPointerException e) {
- TestUtil.logTrace("Pass: NullPointerException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
-
- }
- /*
- * Description: Attempt to read a null string from a StreamMessage. Should
- * throw a null pointer exception
- */
-
- public void readNullCharNotValidTopicStreamTest(
- jakarta.jms.StreamMessage messageReceived) {
- String testCase = "readNullCharNotValidTopicStreamTest";
- boolean pass = true;
- try {
- char c;
- TestUtil.logTrace("Use readChar to read a null ");
- try {
- c = messageReceived.readChar();
- TestUtil.logTrace("Fail: NullPointerException was not thrown");
- pass = false;
- } catch (java.lang.NullPointerException e) {
- TestUtil.logTrace("Pass: NullPointerException thrown as expected");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error: Unexpected exception "
- + e.getClass().getName() + " was thrown");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- sendTestResults(testCase, pass);
- }
-
- }
-
- /*
- * Description: send test results to response queue (MDB_QUEUE_REPLY) for
- * verification
- */
- private void sendTestResults(String testCase, boolean results) {
- TextMessage msg = null;
-
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- msg.setStringProperty("TestCase", testCase);
- msg.setText(testCase);
- if (results)
- msg.setStringProperty("Status", "Pass");
- else
- msg.setStringProperty("Status", "Fail");
-
- TestUtil.logTrace("Sending response message");
- TestUtil.logTrace(
- "==================================Test Results from: " + testCase);
- TestUtil.logTrace("==================================Status: " + results);
- mSender.send(msg);
- } catch (JMSException je) {
- TestUtil.printStackTrace(je);
- TestUtil.logTrace("Error: " + je.getClass().getName() + " was thrown");
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- TestUtil.logTrace("Error: " + ee.getClass().getName() + " was thrown");
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace(
- "jms.ee.mdb.mdb_msgTypesT3 In MsgBeanMsgTest3::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil
- .logTrace("jms.ee.mdb.mdb_msgTypesT3 In MsgBeanMsgTest3::remove()!!");
- }
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ private MessageDrivenContext mdc = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanMsgTestT3.class.getName());
+
+ // JMS
+ private QueueConnectionFactory qFactory = null;
+
+ private TopicConnectionFactory tFactory = null;
+
+ private QueueConnection qConnection = null;
+
+ private TopicConnection tConnection = null;
+
+ private Queue queueR = null;
+
+ private Queue queue = null;
+
+ private Topic topic = null;
+
+ private QueueSender mSender = null;
+
+ private QueueSession qSession = null;
+
+ private TopicPublisher tPublisher = null;
+
+ private TopicSession tSession = null;
+
+ public MsgBeanMsgTestT3() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanMsgTest3()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesT3 - @MsgBeanMsgTest3-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ if (qFactory == null) {
+ System.out.println("qFactory error");
+ }
+ System.out.println("got a qFactory !!");
+ tFactory = (TopicConnectionFactory) context.lookup("java:comp/env/jms/MyTopicConnectionFactory");
+ if (tFactory == null) {
+ System.out.println("tFactory error");
+ }
+ System.out.println("got a tFactory !!");
+
+ queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ if (queueR == null) {
+ System.out.println("queueR error");
+ }
+
+ topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC");
+ if (topic == null) {
+ System.out.println("topic error");
+ }
+
+ p = new Properties();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "from jms.ee.mdb.mdb_msgTypesT3 @onMessage!" + msg);
+
+ try {
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null) {
+ System.out.println("connection error");
+ } else {
+ qConnection.start();
+ qSession = qConnection.createQueueSession(true, 0);
+ }
+ tConnection = tFactory.createTopicConnection();
+ if (tConnection == null) {
+ System.out.println("connection error");
+ } else {
+ tConnection.start();
+ tSession = tConnection.createTopicSession(true, 0);
+ }
+ if (msg.getStringProperty("TestCase").equals("msgClearBodyTopicTextTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyTopicTextTestCreate - create the message");
+ msgClearBodyTopicTextTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyTopicTextTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyTopicTextTest - read and verify the message");
+ msgClearBodyTopicTextTest((jakarta.jms.TextMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyTopicObjectTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyTopicObjectTestCreate - create the message");
+ msgClearBodyTopicObjectTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyTopicObjectTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyTopicObjectTest - read and verify the message");
+ msgClearBodyTopicObjectTest((jakarta.jms.ObjectMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyTopicMapTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyTopicMapTestCreate - create the message");
+ msgClearBodyTopicMapTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyTopicMapTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyTopicMapTest - read and verify the message");
+ msgClearBodyTopicMapTest((jakarta.jms.MapMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyTopicBytesTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyTopicBytesTestCreate - create the message");
+ msgClearBodyTopicBytesTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyTopicBytesTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyTopicBytesTest - read and verify the message");
+ msgClearBodyTopicBytesTest((jakarta.jms.BytesMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyTopicStreamTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyTopicStreamTestCreate - create the message");
+ msgClearBodyTopicStreamTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("msgClearBodyTopicStreamTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running msgClearBodyTopicStreamTest - read and verify the message");
+ msgClearBodyTopicStreamTest((jakarta.jms.StreamMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("msgResetTopicTest")) {
+ logger.log(Logger.Level.TRACE, "@onMessage - running msgResetTopicTest - read and verify the message");
+ msgResetTopicTest();
+ } else if (msg.getStringProperty("TestCase").equals("readNullCharNotValidTopicStreamTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running readNullCharNotValidTopicStreamTestCreate - read and verify the message");
+ readNullCharNotValidTopicStreamTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("readNullCharNotValidTopicStreamTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running readNullCharNotValidTopicStreamTest - read and verify the message");
+ readNullCharNotValidTopicStreamTest((jakarta.jms.StreamMessage) msg);
+ } else if (msg.getStringProperty("TestCase").equals("readNullCharNotValidTopicMapTestCreate")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running readNullCharNotValidTopicMapTestCreate - read and verify the message");
+ readNullCharNotValidTopicMapTestCreate();
+ } else if (msg.getStringProperty("TestCase").equals("readNullCharNotValidTopicMapTest")) {
+ logger.log(Logger.Level.TRACE,
+ "@onMessage - running readNullCharNotValidTopicMapTest - read and verify the message");
+ readNullCharNotValidTopicMapTest((jakarta.jms.MapMessage) msg);
+ } else {
+ logger.log(Logger.Level.TRACE, "@onMessage - invalid message type found in StringProperty");
+ logger.log(Logger.Level.TRACE,
+ "Do not have a method for this testcase: " + msg.getStringProperty("TestCase"));
+ }
+ logger.log(Logger.Level.TRACE, "@onMessage - Finished for this test!");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ if (tConnection != null) {
+ try {
+ tConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+
+ }
+
+ /*
+ *
+ * Description: create and send a text message
+ */
+ private void msgClearBodyTopicTextTestCreate() {
+ try {
+ TextMessage messageSent = null;
+ messageSent = qSession.createTextMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setText("sending a Text message");
+ messageSent.setStringProperty("TestCase", "msgClearBodyTopicTextTest");
+ logger.log(Logger.Level.TRACE, "sending a Text message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create and send an object message
+ */
+ private void msgClearBodyTopicObjectTestCreate() {
+ try {
+ ObjectMessage messageSentObjectMsg = null;
+ // send and receive Object message to Topic
+ logger.log(Logger.Level.TRACE, "Send ObjectMessage to Topic.");
+ messageSentObjectMsg = qSession.createObjectMessage();
+ JmsUtil.addPropsToMessage(messageSentObjectMsg, p);
+ messageSentObjectMsg.setObject("Initial message");
+ messageSentObjectMsg.setStringProperty("TestCase", "msgClearBodyTopicObjectTest");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSentObjectMsg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create and send a Map message
+ */
+ private void msgClearBodyTopicMapTestCreate() {
+ try {
+ MapMessage messageSentMapMessage = null;
+ // send and receive Map message to Topic
+ logger.log(Logger.Level.TRACE, "Send MapMessage to Topic.");
+ messageSentMapMessage = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(messageSentMapMessage, p);
+ messageSentMapMessage.setStringProperty("TestCase", "msgClearBodyTopicMapTest");
+ messageSentMapMessage.setString("aString", "Initial message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSentMapMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create and send a Bytes message
+ */
+ private void msgClearBodyTopicBytesTestCreate() {
+ byte bValue = 127;
+ try {
+ BytesMessage messageSentBytesMessage = null;
+ // send and receive bytes message to Topic
+ logger.log(Logger.Level.TRACE, "Send BytesMessage to Topic.");
+ messageSentBytesMessage = qSession.createBytesMessage();
+ JmsUtil.addPropsToMessage(messageSentBytesMessage, p);
+ messageSentBytesMessage.setStringProperty("TestCase", "msgClearBodyTopicBytesTest");
+ messageSentBytesMessage.writeByte(bValue);
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSentBytesMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: create and send a Stream message
+ */
+ private void msgClearBodyTopicStreamTestCreate() {
+ try {
+ StreamMessage messageSentStreamMessage = null;
+ // Send and receive a StreamMessage
+ logger.log(Logger.Level.TRACE, "sending a Stream message");
+ messageSentStreamMessage = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSentStreamMessage, p);
+ messageSentStreamMessage.setStringProperty("TestCase", "msgClearBodyTopicStreamTest");
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "Sending message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSentStreamMessage);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Receive a single Text message call clearBody, verify body is
+ * empty after clearBody. verify properties are not effected by clearBody. Write
+ * to the message again 3.11
+ */
+ public void msgClearBodyTopicTextTest(jakarta.jms.TextMessage messageReceived) {
+ String testCase = "msgClearBodyTopicTextTest";
+ boolean pass = true;
+ // Text Message
+ try {
+ logger.log(Logger.Level.TRACE, "Test TextMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceived.getText());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceived.clearBody();
+ // message body should now be empty
+ if (messageReceived.getText() == null) {
+ logger.log(Logger.Level.TRACE, "Empty body after clearBody as expected: null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: message body was not empty");
+ pass = false;
+ }
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceived.getStringProperty("TestCase").equals("msgClearBodyTopicTextTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Text properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Text properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write and read 2nd contents");
+ messageReceived.setText("new data");
+ if (messageReceived.getText().equals("new data")) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail:");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: Receive a single Object message call clearBody, verify body is
+ * empty after clearBody. verify properties are not effected by clearBody. Write
+ * to the message again 3.11
+ */
+ public void msgClearBodyTopicObjectTest(jakarta.jms.ObjectMessage messageReceivedObjectMsg) {
+ String testCase = "msgClearBodyTopicObjectTest";
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.TRACE, "Testing Object message");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedObjectMsg.getObject());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedObjectMsg.clearBody();
+ // message body should now be empty
+ if (messageReceivedObjectMsg.getObject() == null) {
+ logger.log(Logger.Level.TRACE, "Empty body after clearBody as expected: null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: message body was not empty");
+ pass = false;
+ }
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedObjectMsg.getStringProperty("TestCase").equals("msgClearBodyTopicObjectTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Object properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Object properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedObjectMsg.setObject("new stuff here!!!!!!");
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ if (messageReceivedObjectMsg.getObject().equals("new stuff here!!!!!!")) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: ");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: Receive a single Map message call clearBody, verify body is
+ * empty after clearBody. verify properties are not effected by clearBody. Write
+ * to the message again 3.11
+ */
+ private void msgClearBodyTopicMapTest(jakarta.jms.MapMessage messageReceivedMapMessage) {
+ String testCase = "msgClearBodyTopicMapTest";
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.TRACE, "Test for MapMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedMapMessage.getString("aString"));
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedMapMessage.clearBody();
+ // message body should now be empty
+ if (messageReceivedMapMessage.getString("aString") == null) {
+ logger.log(Logger.Level.TRACE, "Empty body after clearBody as expected: null");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: message body was not empty");
+ pass = false;
+ }
+
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedMapMessage.getStringProperty("TestCase").equals("msgClearBodyTopicMapTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Map properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Map properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedMapMessage.setString("yes", "new stuff !!!!!");
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ if (messageReceivedMapMessage.getString("yes").equals("new stuff !!!!!")) {
+ logger.log(Logger.Level.TRACE, "PASS:");
+ } else {
+ logger.log(Logger.Level.TRACE, "FAIL:");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: Receive a single Bytes message call clearBody, verify body is
+ * empty after clearBody. verify properties are not effected by clearBody. Write
+ * to the message again 3.11
+ */
+ public void msgClearBodyTopicBytesTest(jakarta.jms.BytesMessage messageReceivedBytesMessage) {
+ String testCase = "msgClearBodyTopicBytesTest";
+ boolean pass = true;
+ byte bValue2 = 22;
+ try {
+ logger.log(Logger.Level.TRACE, "Test BytesMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedBytesMessage.readByte());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedBytesMessage.clearBody();
+ logger.log(Logger.Level.TRACE, "Bytes message body should now be empty and in writeonly mode");
+ try {
+ byte b = messageReceivedBytesMessage.readByte();
+ logger.log(Logger.Level.TRACE, "Fail: MessageNotReadableException not thrown as expected");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageNotReadableException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotReadableException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedBytesMessage.getStringProperty("TestCase").equals("msgClearBodyTopicBytesTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Bytes msg properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Bytes msg properties cleared after clearBody called");
+ pass = false;
+ }
+
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedBytesMessage.writeByte(bValue2);
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ messageReceivedBytesMessage.reset();
+ if (messageReceivedBytesMessage.readByte() == bValue2) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail:");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ * Description: Receive a single Stream message call clearBody, verify body is
+ * empty after clearBody. verify properties are not effected by clearBody. Write
+ * to the message again 3.11
+ */
+ public void msgClearBodyTopicStreamTest(jakarta.jms.StreamMessage messageReceivedStreamMessage) {
+ String testCase = "msgClearBodyTopicStreamTest";
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.TRACE, "Test StreamMessage ");
+ logger.log(Logger.Level.TRACE, "read 1st contents");
+ logger.log(Logger.Level.TRACE, " " + messageReceivedStreamMessage.readString());
+ logger.log(Logger.Level.TRACE, "Call to clearBody !!!!!!!!!!!!!!!");
+ messageReceivedStreamMessage.clearBody();
+
+ logger.log(Logger.Level.TRACE, "Stream message body should now be empty and in writeonly mode");
+ try {
+ String s = messageReceivedStreamMessage.readString();
+ logger.log(Logger.Level.TRACE, "Fail: MessageNotReadableException should have been thrown");
+ pass = false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ if (e instanceof jakarta.jms.MessageNotReadableException) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotReadableException thrown as expected");
+ } else {
+ logger.log(Logger.Level.TRACE,
+ "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ }
+ // properties should not have been deleted by the clearBody method.
+ if (messageReceivedStreamMessage.getStringProperty("TestCase").equals("msgClearBodyTopicStreamTest")) {
+ logger.log(Logger.Level.TRACE, "Pass: Stream msg properties read ok after clearBody called");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: Stream msg properties cleared after clearBody called");
+ pass = false;
+ }
+ logger.log(Logger.Level.TRACE, "write 2nd contents");
+ messageReceivedStreamMessage.writeString("new data");
+ logger.log(Logger.Level.TRACE, "read 2nd contents");
+ messageReceivedStreamMessage.reset();
+ if (messageReceivedStreamMessage.readString().equals("new data")) {
+ logger.log(Logger.Level.TRACE, "Pass:");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail:");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ TestUtil.printStackTrace(e);
+ pass = false;
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ *
+ * Description: create a stream message and a byte message. write to the message
+ * body, call the reset method, try to write to the body expect a
+ * MessageNotWriteableException to be thrown.
+ */
+ private void msgResetTopicTest() {
+ boolean pass = true;
+ int nInt = 1000;
+ String testCase = "msgResetTopicTest";
+ try {
+ StreamMessage messageSentStreamMessage = null;
+ BytesMessage messageSentBytesMessage = null;
+ // StreamMessage
+ try {
+ logger.log(Logger.Level.TRACE, "creating a Stream message");
+ messageSentStreamMessage = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSentStreamMessage, p);
+ messageSentStreamMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgResetTopicTest1");
+ // write to the message
+ messageSentStreamMessage.writeString("Testing...");
+ logger.log(Logger.Level.TRACE, "reset stream message - now should be in readonly mode");
+ messageSentStreamMessage.reset();
+ messageSentStreamMessage.writeString("new data");
+ logger.log(Logger.Level.TRACE, "Fail: message did not throw MessageNotWriteable exception as expected");
+ pass = false;
+ } catch (MessageNotWriteableException nw) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotWriteable thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+
+ // BytesMessage
+ try {
+ logger.log(Logger.Level.TRACE, "creating a Byte message");
+ messageSentBytesMessage = qSession.createBytesMessage();
+ JmsUtil.addPropsToMessage(messageSentBytesMessage, p);
+ messageSentBytesMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "msgResetTopicTest2");
+ // write to the message
+ messageSentBytesMessage.writeInt(nInt);
+ logger.log(Logger.Level.TRACE, "reset Byte message - now should be in readonly mode");
+ messageSentBytesMessage.reset();
+ messageSentBytesMessage.writeInt(nInt);
+ logger.log(Logger.Level.TRACE, "Fail: message did not throw MessageNotWriteable exception as expected");
+ pass = false;
+ } catch (MessageNotWriteableException nw) {
+ logger.log(Logger.Level.TRACE, "Pass: MessageNotWriteable thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+ }
+
+ /*
+ *
+ * Description: Write a null string to a MapMessage.
+ *
+ */
+ public void readNullCharNotValidTopicMapTestCreate() {
+ try {
+ MapMessage mapSent = null;
+ char c;
+ boolean pass = true;
+ mapSent = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(mapSent, p);
+ mapSent.setStringProperty("TestCase", "readNullCharNotValidTopicMapTest");
+ logger.log(Logger.Level.TRACE, "Write a null string to the map message object with mapMessage.setString");
+ mapSent.setString("WriteANull", null);
+ logger.log(Logger.Level.TRACE, " Send the message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(mapSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ * Description: Write a null string to a StreamMessage.
+ *
+ */
+ public void readNullCharNotValidTopicStreamTestCreate() {
+ try {
+ StreamMessage messageSent = null;
+ char c;
+ boolean pass = true;
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("TestCase", "readNullCharNotValidTopicStreamTest");
+ // -----------------------------------------------------------------------------
+ // stream Message
+ // -----------------------------------------------------------------------------
+ messageSent = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(messageSent, p);
+ messageSent.setStringProperty("TestCase", "readNullCharNotValidTopicStreamTest");
+ logger.log(Logger.Level.TRACE,
+ "Write a null string to the map message object with streamMessage.setString");
+ messageSent.writeString(null);
+ logger.log(Logger.Level.TRACE, " Send the message");
+ tPublisher = tSession.createPublisher(topic);
+ tPublisher.publish(messageSent);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ * Description: Attempt to read a null string from a MapMessage. Should throw a
+ * null pointer exception
+ */
+
+ public void readNullCharNotValidTopicMapTest(jakarta.jms.MapMessage mapReceived) {
+ String testCase = "readNullCharNotValidTopicMapTest";
+ boolean pass = true;
+ try {
+ char c;
+ logger.log(Logger.Level.TRACE, "Use readChar to read a null ");
+ try {
+ c = mapReceived.getChar("WriteANull");
+ logger.log(Logger.Level.TRACE, "Fail: NullPointerException was not thrown");
+ pass = false;
+ } catch (java.lang.NullPointerException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+
+ }
+ /*
+ * Description: Attempt to read a null string from a StreamMessage. Should throw
+ * a null pointer exception
+ */
+
+ public void readNullCharNotValidTopicStreamTest(jakarta.jms.StreamMessage messageReceived) {
+ String testCase = "readNullCharNotValidTopicStreamTest";
+ boolean pass = true;
+ try {
+ char c;
+ logger.log(Logger.Level.TRACE, "Use readChar to read a null ");
+ try {
+ c = messageReceived.readChar();
+ logger.log(Logger.Level.TRACE, "Fail: NullPointerException was not thrown");
+ pass = false;
+ } catch (java.lang.NullPointerException e) {
+ logger.log(Logger.Level.TRACE, "Pass: NullPointerException thrown as expected");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error: Unexpected exception " + e.getClass().getName() + " was thrown");
+ pass = false;
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ sendTestResults(testCase, pass);
+ }
+
+ }
+
+ /*
+ * Description: send test results to response queue (MDB_QUEUE_REPLY) for
+ * verification
+ */
+ private void sendTestResults(String testCase, boolean results) {
+ TextMessage msg = null;
+
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ msg.setStringProperty("TestCase", testCase);
+ msg.setText(testCase);
+ if (results)
+ msg.setStringProperty("Status", "Pass");
+ else
+ msg.setStringProperty("Status", "Fail");
+
+ logger.log(Logger.Level.TRACE, "Sending response message");
+ logger.log(Logger.Level.TRACE, "==================================Test Results from: " + testCase);
+ logger.log(Logger.Level.TRACE, "==================================Status: " + results);
+ mSender.send(msg);
+ } catch (JMSException je) {
+ TestUtil.printStackTrace(je);
+ logger.log(Logger.Level.TRACE, "Error: " + je.getClass().getName() + " was thrown");
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ logger.log(Logger.Level.TRACE, "Error: " + ee.getClass().getName() + " was thrown");
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesT3 In MsgBeanMsgTest3::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "jms.ee.mdb.mdb_msgTypesT3 In MsgBeanMsgTest3::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDBClient.java
deleted file mode 100644
index e3a39f1cbd..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDBClient.java
+++ /dev/null
@@ -1,436 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee.mdb.mdb_rec;
-
-import java.util.Properties;
-
-/**
- * The MDBClient class invokes a test bean to send each type of
- * jms message to a message driven bean for a queue and a topic
- */
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-
-import jakarta.ejb.EJB;
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_AR_Test")
- private static MDB_AR_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.port;
- * harness.log.traceflag;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
- // Tests mdb asynchronous receives
- // Test with Queue and Topic
- // Test with Text,Stream,Byte,Map and Object messages
- //
-
- /*
- * @testName: asynRecTextMsgQueueTest
- *
- * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
- * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198;
- *
- * @test_Strategy: Test with a Text message Create a stateful Session EJB
- * Bean. Deploy it on the J2EE server. Have the EJB component send a text
- * message to a Queue Destination. handled by a message-driven bean Verify
- * that the mdb received the message
- *
- *
- */
- public void asynRecTextMsgQueueTest() throws Exception {
- String matchMe;
-
- try {
- // Have the EJB invoke the MDB
- logMsg("Call bean - have it send mdb a message;");
-
- matchMe = "mdb_asynchRecFromQueue_Text_Msg_Test";
- hr.sendTextMessageToQ(matchMe);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: test1 failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: asynRecMapMsgQueueTest
- *
- * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
- * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:211; JMS:JAVADOC:473;
- *
- * @test_Strategy: Test with a Map message Create a stateful Session EJB Bean.
- * Deploy it on the J2EE server. Have the EJB component send a text message to
- * a Queue Destination. handled by a message-driven bean Verify that the mdb
- * received the message
- *
- *
- */
- public void asynRecMapMsgQueueTest() throws Exception {
- String matchMe;
-
- try {
- // Have the EJB invoke the MDB
- logMsg("Call bean - have it send mdb a message;");
-
- matchMe = "mdb_asynchRecFromQueue_MapMessage_Test";
- TestUtil.logTrace("Have bean send mdb a map message;");
- hr.sendMapMessageToQ(matchMe);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: test3 failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: asynRecObjectMsgQueueTest
- *
- * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
- * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:215; JMS:JAVADOC:289;
- *
- * @test_Strategy: Test with a Object message Create a stateful Session EJB
- * Bean. Deploy it on the J2EE server. Have the EJB component send a text
- * message to a Queue Destination. handled by a message-driven bean Verify
- * that the mdb received the message
- *
- *
- */
- public void asynRecObjectMsgQueueTest() throws Exception {
- String matchMe;
-
- try {
- // Have the EJB invoke the MDB
- logMsg("Call bean - have it send mdb a message;");
-
- matchMe = "mdb_asynchRecFromQueue_ObjectMessage_Test";
- TestUtil.logTrace("Have bean send mdb a object message;");
- hr.sendObjectMessageToQ(matchMe);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: test5 failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: asynRecTextMsgTopicTest
- *
- * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
- * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:109; JMS:JAVADOC:111; JMS:JAVADOC:91;
- * JMS:JAVADOC:99;
- *
- * @test_Strategy: Testing with a Text message Create a stateful Session EJB
- * Bean. Deploy it on the J2EE server. Have the EJB component send a Text
- * message to a Topic Destination. handled by a message-driven bean Verify
- * that the mdb received the message
- *
- *
- */
- public void asynRecTextMsgTopicTest() throws Exception {
- String matchMe = "mdb_asynchRecFromTopic_Text_Msg_Test";
- try {
- // Have the EJB invoke the MDB
- logMsg("Call bean - have it send mdb a message;");
- hr.sendTextMessageToTopic(matchMe);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: test6 failed");
- }
- logMsg("Test passed;");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: asynRecBytesMsgQueueTest
- *
- * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
- * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:209; JMS:JAVADOC:562;
- *
- * @test_Strategy: Test with a Bytes message Create a stateful Session EJB
- * Bean. Deploy it on the J2EE server. Have the EJB component send a text
- * message to a Queue Destination. handled by a message-driven bean Verify
- * that the mdb received the message
- *
- *
- */
- public void asynRecBytesMsgQueueTest() throws Exception {
- String matchMe;
-
- try {
- // Have the EJB invoke the MDB
- logMsg("Call bean - have it send mdb a message;");
-
- matchMe = "mdb_asynchRecFromQueue_BytesMessage_Test";
- TestUtil.logTrace("Have bean send mdb a bytes message;");
- hr.sendBytesMessageToQ(matchMe);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: test2 failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: asynRecStreamMsgQueueTest
- *
- * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
- * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:219; JMS:JAVADOC:166;
- *
- * @test_Strategy: Test with a Stream message Create a stateful Session EJB
- * Bean. Deploy it on the J2EE server. Have the EJB component send a text
- * message to a Queue Destination. handled by a message-driven bean Verify
- * that the mdb received the message
- *
- *
- */
- public void asynRecStreamMsgQueueTest() throws Exception {
- String matchMe;
-
- try {
- // Have the EJB invoke the MDB
- logMsg("Call bean - have it send mdb a message;");
-
- matchMe = "mdb_asynchRecFromQueue_StreamMessage_Test";
- TestUtil.logTrace("Have bean send mdb a stream message;");
- hr.sendStreamMessageToQ(matchMe);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: test4 failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: asynRecMapMsgTopicTest
- *
- * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
- * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:109; JMS:JAVADOC:111; JMS:JAVADOC:91;
- * JMS:JAVADOC:99; JMS:JAVADOC:211; JMS:JAVADOC:473;
- *
- * @test_Strategy: Testing with a Map message Create a stateful Session EJB
- * Bean. Deploy it on the J2EE server. Have the EJB component send a Map
- * message to a Topic Destination. handled by a message-driven bean Verify
- * that the mdb received the message
- *
- *
- */
- public void asynRecMapMsgTopicTest() throws Exception {
- String matchMe = "mdb_asynchRecFromTopic_Map_Msg_Test";
- try {
- // Have the EJB invoke the MDB
- logMsg("Call bean - have it send mdb a message;");
- hr.sendMapMessageToTopic(matchMe);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: asynRecMapMsgTopicTest failed");
- }
- logMsg("Test passed;");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: asynRecObjectMsgTopicTest
- *
- * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
- * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:109; JMS:JAVADOC:111; JMS:JAVADOC:91;
- * JMS:JAVADOC:99; JMS:JAVADOC:215; JMS:JAVADOC:289;
- *
- * @test_Strategy: Testing with a Object message Create a stateful Session EJB
- * Bean. Deploy it on the J2EE server. Have the EJB component send a Object
- * message to a Topic Destination. handled by a message-driven bean Verify
- * that the mdb received the message
- *
- *
- */
- public void asynRecObjectMsgTopicTest() throws Exception {
- String matchMe = "mdb_asynchRecFromTopic_Object_Msg_Test";
- try {
- // Have the EJB invoke the MDB
- logMsg("Call bean - have it send mdb a message;");
- hr.sendObjectMessageToTopic(matchMe);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: asynRecObjectMsgTopicTest failed");
- }
- logMsg("Test passed;");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: asynRecBytesMsgTopicTest
- *
- * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
- * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:109; JMS:JAVADOC:111; JMS:JAVADOC:91;
- * JMS:JAVADOC:99; JMS:JAVADOC:209; JMS:JAVADOC:562;
- *
- * @test_Strategy: Testing with a Bytes message Create a stateful Session EJB
- * Bean. Deploy it on the J2EE server. Have the EJB component send a Bytes
- * message to a Topic Destination. handled by a message-driven bean Verify
- * that the mdb received the message
- *
- *
- */
- public void asynRecBytesMsgTopicTest() throws Exception {
- String matchMe = "mdb_asynchRecFromTopic_Bytes_Msg_Test";
- try {
- // Have the EJB invoke the MDB
- logMsg("Call bean - have it send mdb a message;");
- hr.sendBytesMessageToTopic(matchMe);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: asynRecBytesMsgTopicTest failed");
- }
- logMsg("Test passed;");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: asynRecStreamMsgTopicTest
- *
- * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
- * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:109; JMS:JAVADOC:111; JMS:JAVADOC:91;
- * JMS:JAVADOC:99; JMS:JAVADOC:219; JMS:JAVADOC:166;
- *
- * @test_Strategy: Testing with a Stream message Create a stateful Session EJB
- * Bean. Deploy it on the J2EE server. Have the EJB component send a Stream
- * message to a Topic Destination. handled by a message-driven bean Verify
- * that the mdb received the message
- *
- *
- */
- public void asynRecStreamMsgTopicTest() throws Exception {
- String matchMe = "mdb_asynchRecFromTopic_Stream_Msg_Test";
- try {
- // Have the EJB invoke the MDB
- logMsg("Call bean - have it send mdb a message;");
- hr.sendStreamMessageToTopic(matchMe);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: asynRecStreamMsgTopicTest failed");
- }
- logMsg("Test passed;");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- logErr("Unexpected Exception cleaning up the Queue", e);
- } finally {
- TestUtil.logTrace("Closing all connections");
- try {
- hr.cleanup();
- } catch (Exception oh) {
- TestUtil.logErr("Fail: unexpected exception closing Connections", oh);
- TestUtil.printStackTrace(oh);
- throw new Exception("Fail");
- }
- TestUtil.logTrace("Removing EJBs");
- try {
- hr.remove();
- } catch (Exception oh) {
- TestUtil.logErr("Fail: unexpected exception removing EJB", oh);
- TestUtil.printStackTrace(oh);
- throw new Exception("Fail");
- }
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDBClientIT.java
new file mode 100644
index 0000000000..58ea79bf60
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDBClientIT.java
@@ -0,0 +1,446 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee.mdb.mdb_rec;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+
+import jakarta.ejb.EJB;
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_AR_Test")
+ private static MDB_AR_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ hr.setup(props);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+ // Tests mdb asynchronous receives
+ // Test with Queue and Topic
+ // Test with Text,Stream,Byte,Map and Object messages
+ //
+
+ /*
+ * @testName: asynRecTextMsgQueueTest
+ *
+ * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
+ * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198;
+ *
+ * @test_Strategy: Test with a Text message Create a stateful Session EJB Bean.
+ * Deploy it on the J2EE server. Have the EJB component send a text message to a
+ * Queue Destination. handled by a message-driven bean Verify that the mdb
+ * received the message
+ *
+ *
+ */
+ @Test
+ public void asynRecTextMsgQueueTest() throws Exception {
+ String matchMe;
+
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.INFO, "Call bean - have it send mdb a message;");
+
+ matchMe = "mdb_asynchRecFromQueue_Text_Msg_Test";
+ hr.sendTextMessageToQ(matchMe);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: test1 failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: asynRecMapMsgQueueTest
+ *
+ * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
+ * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:211; JMS:JAVADOC:473;
+ *
+ * @test_Strategy: Test with a Map message Create a stateful Session EJB Bean.
+ * Deploy it on the J2EE server. Have the EJB component send a text message to a
+ * Queue Destination. handled by a message-driven bean Verify that the mdb
+ * received the message
+ *
+ *
+ */
+ @Test
+ public void asynRecMapMsgQueueTest() throws Exception {
+ String matchMe;
+
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.INFO, "Call bean - have it send mdb a message;");
+
+ matchMe = "mdb_asynchRecFromQueue_MapMessage_Test";
+ logger.log(Logger.Level.TRACE, "Have bean send mdb a map message;");
+ hr.sendMapMessageToQ(matchMe);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: test3 failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: asynRecObjectMsgQueueTest
+ *
+ * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
+ * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:215; JMS:JAVADOC:289;
+ *
+ * @test_Strategy: Test with a Object message Create a stateful Session EJB
+ * Bean. Deploy it on the J2EE server. Have the EJB component send a text
+ * message to a Queue Destination. handled by a message-driven bean Verify that
+ * the mdb received the message
+ *
+ *
+ */
+ @Test
+ public void asynRecObjectMsgQueueTest() throws Exception {
+ String matchMe;
+
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.INFO, "Call bean - have it send mdb a message;");
+
+ matchMe = "mdb_asynchRecFromQueue_ObjectMessage_Test";
+ logger.log(Logger.Level.TRACE, "Have bean send mdb a object message;");
+ hr.sendObjectMessageToQ(matchMe);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: test5 failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: asynRecTextMsgTopicTest
+ *
+ * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
+ * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:109; JMS:JAVADOC:111; JMS:JAVADOC:91;
+ * JMS:JAVADOC:99;
+ *
+ * @test_Strategy: Testing with a Text message Create a stateful Session EJB
+ * Bean. Deploy it on the J2EE server. Have the EJB component send a Text
+ * message to a Topic Destination. handled by a message-driven bean Verify that
+ * the mdb received the message
+ *
+ *
+ */
+ @Test
+ public void asynRecTextMsgTopicTest() throws Exception {
+ String matchMe = "mdb_asynchRecFromTopic_Text_Msg_Test";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.INFO, "Call bean - have it send mdb a message;");
+ hr.sendTextMessageToTopic(matchMe);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: test6 failed");
+ }
+ logger.log(Logger.Level.INFO, "Test passed;");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: asynRecBytesMsgQueueTest
+ *
+ * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
+ * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:209; JMS:JAVADOC:562;
+ *
+ * @test_Strategy: Test with a Bytes message Create a stateful Session EJB Bean.
+ * Deploy it on the J2EE server. Have the EJB component send a text message to a
+ * Queue Destination. handled by a message-driven bean Verify that the mdb
+ * received the message
+ *
+ *
+ */
+ @Test
+ public void asynRecBytesMsgQueueTest() throws Exception {
+ String matchMe;
+
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.INFO, "Call bean - have it send mdb a message;");
+
+ matchMe = "mdb_asynchRecFromQueue_BytesMessage_Test";
+ logger.log(Logger.Level.TRACE, "Have bean send mdb a bytes message;");
+ hr.sendBytesMessageToQ(matchMe);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: test2 failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: asynRecStreamMsgQueueTest
+ *
+ * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
+ * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:219; JMS:JAVADOC:166;
+ *
+ * @test_Strategy: Test with a Stream message Create a stateful Session EJB
+ * Bean. Deploy it on the J2EE server. Have the EJB component send a text
+ * message to a Queue Destination. handled by a message-driven bean Verify that
+ * the mdb received the message
+ *
+ *
+ */
+ @Test
+ public void asynRecStreamMsgQueueTest() throws Exception {
+ String matchMe;
+
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.INFO, "Call bean - have it send mdb a message;");
+
+ matchMe = "mdb_asynchRecFromQueue_StreamMessage_Test";
+ logger.log(Logger.Level.TRACE, "Have bean send mdb a stream message;");
+ hr.sendStreamMessageToQ(matchMe);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: test4 failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: asynRecMapMsgTopicTest
+ *
+ * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
+ * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:109; JMS:JAVADOC:111; JMS:JAVADOC:91;
+ * JMS:JAVADOC:99; JMS:JAVADOC:211; JMS:JAVADOC:473;
+ *
+ * @test_Strategy: Testing with a Map message Create a stateful Session EJB
+ * Bean. Deploy it on the J2EE server. Have the EJB component send a Map message
+ * to a Topic Destination. handled by a message-driven bean Verify that the mdb
+ * received the message
+ *
+ *
+ */
+ @Test
+ public void asynRecMapMsgTopicTest() throws Exception {
+ String matchMe = "mdb_asynchRecFromTopic_Map_Msg_Test";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.INFO, "Call bean - have it send mdb a message;");
+ hr.sendMapMessageToTopic(matchMe);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: asynRecMapMsgTopicTest failed");
+ }
+ logger.log(Logger.Level.INFO, "Test passed;");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: asynRecObjectMsgTopicTest
+ *
+ * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
+ * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:109; JMS:JAVADOC:111; JMS:JAVADOC:91;
+ * JMS:JAVADOC:99; JMS:JAVADOC:215; JMS:JAVADOC:289;
+ *
+ * @test_Strategy: Testing with a Object message Create a stateful Session EJB
+ * Bean. Deploy it on the J2EE server. Have the EJB component send a Object
+ * message to a Topic Destination. handled by a message-driven bean Verify that
+ * the mdb received the message
+ *
+ *
+ */
+ @Test
+ public void asynRecObjectMsgTopicTest() throws Exception {
+ String matchMe = "mdb_asynchRecFromTopic_Object_Msg_Test";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.INFO, "Call bean - have it send mdb a message;");
+ hr.sendObjectMessageToTopic(matchMe);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: asynRecObjectMsgTopicTest failed");
+ }
+ logger.log(Logger.Level.INFO, "Test passed;");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: asynRecBytesMsgTopicTest
+ *
+ * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
+ * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:109; JMS:JAVADOC:111; JMS:JAVADOC:91;
+ * JMS:JAVADOC:99; JMS:JAVADOC:209; JMS:JAVADOC:562;
+ *
+ * @test_Strategy: Testing with a Bytes message Create a stateful Session EJB
+ * Bean. Deploy it on the J2EE server. Have the EJB component send a Bytes
+ * message to a Topic Destination. handled by a message-driven bean Verify that
+ * the mdb received the message
+ *
+ *
+ */
+ @Test
+ public void asynRecBytesMsgTopicTest() throws Exception {
+ String matchMe = "mdb_asynchRecFromTopic_Bytes_Msg_Test";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.INFO, "Call bean - have it send mdb a message;");
+ hr.sendBytesMessageToTopic(matchMe);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: asynRecBytesMsgTopicTest failed");
+ }
+ logger.log(Logger.Level.INFO, "Test passed;");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: asynRecStreamMsgTopicTest
+ *
+ * @assertion_ids: EJB:SPEC:506; JMS:JAVADOC:270; JMS:JAVADOC:274;
+ * JMS:JAVADOC:221; JMS:JAVADOC:188; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:109; JMS:JAVADOC:111; JMS:JAVADOC:91;
+ * JMS:JAVADOC:99; JMS:JAVADOC:219; JMS:JAVADOC:166;
+ *
+ * @test_Strategy: Testing with a Stream message Create a stateful Session EJB
+ * Bean. Deploy it on the J2EE server. Have the EJB component send a Stream
+ * message to a Topic Destination. handled by a message-driven bean Verify that
+ * the mdb received the message
+ *
+ *
+ */
+ @Test
+ public void asynRecStreamMsgTopicTest() throws Exception {
+ String matchMe = "mdb_asynchRecFromTopic_Stream_Msg_Test";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.INFO, "Call bean - have it send mdb a message;");
+ hr.sendStreamMessageToTopic(matchMe);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: asynRecStreamMsgTopicTest failed");
+ }
+ logger.log(Logger.Level.INFO, "Test passed;");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected Exception cleaning up the Queue", e);
+ } finally {
+ logger.log(Logger.Level.TRACE, "Closing all connections");
+ try {
+ hr.cleanup();
+ } catch (Exception oh) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception closing Connections", oh);
+ TestUtil.printStackTrace(oh);
+ throw new Exception("Fail");
+ }
+ logger.log(Logger.Level.TRACE, "Removing EJBs");
+ try {
+ hr.remove();
+ } catch (Exception oh) {
+ logger.log(Logger.Level.ERROR, "Fail: unexpected exception removing EJB", oh);
+ TestUtil.printStackTrace(oh);
+ throw new Exception("Fail");
+ }
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDB_AR_Test.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDB_AR_Test.java
index b258bf8aec..110b91de44 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDB_AR_Test.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDB_AR_Test.java
@@ -26,35 +26,35 @@
@Remote
public interface MDB_AR_Test {
- boolean isThereSomethingInTheQueue();
+ boolean isThereSomethingInTheQueue();
- void sendTextMessageToQ(String property);
+ void sendTextMessageToQ(String property);
- void sendBytesMessageToQ(String property);
+ void sendBytesMessageToQ(String property);
- void sendMapMessageToQ(String property);
+ void sendMapMessageToQ(String property);
- void sendStreamMessageToQ(String property);
+ void sendStreamMessageToQ(String property);
- void sendObjectMessageToQ(String property);
+ void sendObjectMessageToQ(String property);
- void sendTextMessageToTopic(String s);
+ void sendTextMessageToTopic(String s);
- void sendBytesMessageToTopic(String s);
+ void sendBytesMessageToTopic(String s);
- void sendMapMessageToTopic(String s);
+ void sendMapMessageToTopic(String s);
- void sendStreamMessageToTopic(String s);
+ void sendStreamMessageToTopic(String s);
- void sendObjectMessageToTopic(String s);
+ void sendObjectMessageToTopic(String s);
- boolean checkOnResponse(String property);
+ boolean checkOnResponse(String property);
- void cleanTheQueue();
+ void cleanTheQueue();
- void cleanup();
+ void cleanup();
- void remove();
+ void remove();
- void setup(Properties p);
+ void setup(Properties p);
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDB_AR_TestEJB.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDB_AR_TestEJB.java
index d6023089cb..a05f28f2da 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDB_AR_TestEJB.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MDB_AR_TestEJB.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_rec;
+import java.lang.System.Logger;
import java.util.Enumeration;
import java.util.Properties;
@@ -59,558 +60,540 @@
@Remote(MDB_AR_Test.class)
public class MDB_AR_TestEJB {
- @Resource
- private SessionContext sessionContext;
-
- @Resource(name = "jms/MDB_QUEUE_REPLY")
- private transient Queue rcvrQueue;
-
- @Resource(name = "jms/MDB_QUEUE")
- private transient Queue queue;
-
- @Resource(name = "jms/MyQueueConnectionFactory")
- private transient QueueConnectionFactory qcFactory;
-
- @Resource(name = "jms/MDB_TOPIC")
- private transient Topic topic;
-
- @Resource(name = "jms/MyTopicConnectionFactory")
- private transient TopicConnectionFactory tcFactory;
-
- private transient QueueConnection connection = null;
-
- private transient TopicConnection tConn = null;
-
- private Properties p = null;
-
- private String jmsUser;
-
- private String jmsPassword;
-
- private long timeout;
-
- // Use this stateful session bean to test asynchronous receives of message
- // driven beans.
- // Has send methods for each type of jms message.
-
- public MDB_AR_TestEJB() {
- }
-
- public void setup(Properties props) {
- p = props;
- try {
- TestUtil.init(props);
- // get props
- timeout = Long.parseLong(props.getProperty("jms_timeout"));
- jmsUser = props.getProperty("user");
- jmsPassword = props.getProperty("password");
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (jmsUser == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (jmsPassword == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (qcFactory == null || tcFactory == null || queue == null
- || rcvrQueue == null || topic == null || sessionContext == null) {
- throw new Exception("@Resource injection failed");
- }
- tConn = tcFactory.createTopicConnection(jmsUser, jmsPassword);
- connection = qcFactory.createQueueConnection(jmsUser, jmsPassword);
-
- connection.start();
- tConn.start();
- } catch (Exception e) {
- throw new EJBException("@setup failed: ", e);
- }
- }
-
- public boolean isThereSomethingInTheQueue() {
- TestUtil.logTrace("MDB_AR_TestEJB.isThereSomethingInTheQueue()");
- QueueBrowser qBrowser = null;
- Enumeration msgs = null;
- boolean ret = false;
-
- try {
- // Hopefully nothing is left in the queue
- QueueSession session = connection.createQueueSession(true, 0);
- qBrowser = session.createBrowser(rcvrQueue);
- msgs = qBrowser.getEnumeration();
- if (msgs.hasMoreElements()) {
- ret = true;
- }
- qBrowser.close();
- session.close();
-
- } catch (Exception e) {
- TestUtil.logErr("Error in isThereSomethingInTheQueue", e);
- }
- return ret;
- }
-
- public void cleanTheQueue() {
- TestUtil.logTrace("MDB_AR_TestEJB.cleanTheQueue()");
- QueueBrowser qBrowser = null;
- Enumeration msgs = null;
- int numMsgs = 0;
-
- try {
- QueueSession session = connection.createQueueSession(true, 0);
- TextMessage msgRec = null;
-
- // delete anything left in the queue
- qBrowser = session.createBrowser(rcvrQueue);
- // count the number of messages
- msgs = qBrowser.getEnumeration();
- while (msgs.hasMoreElements()) {
- msgs.nextElement();
- numMsgs++;
- }
- qBrowser.close();
-
- // Read messages until Q is cleaned
- QueueReceiver rcvr = session.createReceiver(rcvrQueue);
- TestUtil.logTrace("Cleaning " + numMsgs + " messages from the Q: "
- + rcvrQueue.getQueueName());
- for (int n = 0; n < numMsgs; n++) {
-
- TestUtil.logTrace(
- "dequeuing msg: " + n + " from the Q: " + rcvrQueue.getQueueName());
- for (int i = 0; i < 10; ++i) {
- msgRec = (TextMessage) rcvr.receive(timeout);
- if (msgRec != null) {
- TestUtil.logTrace("dequeued message: " + n);
- break;
- }
- TestUtil.logTrace(
- "Attempt no: " + i + " Trying to dequeue message: " + n);
- } // end of internal for loop
- }
- session.close();
- } catch (Exception e) {
- TestUtil.logErr("Error in cleanTheQueue", e);
- }
- }
-
- public boolean checkOnResponse(String prop) {
- TestUtil.logTrace("MDB_AR_TestEJB.checkOnResponse()");
- boolean status = false;
-
- try {
- QueueSession session = connection.createQueueSession(true, 0);
- status = recvMessageInternal(session, prop);
- TestUtil.logTrace("Close the session");
- session.close();
- } catch (Exception e) {
- TestUtil.logErr("Exception in checkOnResponse", e);
- }
- return status;
- }
-
- /**
- * Send a message. In bmt case, create session BEFORE starting tx.
- */
- public void sendTextMessageToQ(String prop) {
- try {
- String msg = "Test with a text message";
- TestUtil.logTrace("MDB_AR_TestEJB.sendTextMessageToQ()");
- QueueSession session = connection.createQueueSession(true, 0);
- //
-
- TestUtil.logTrace("calling send method with: " + msg + " + " + prop);
- QueueSender sender = session.createSender(queue);
- //
- TestUtil
- .logTrace("got a q sender for: " + sender.getQueue().getQueueName());
- // Send a message.
- TextMessage message = session.createTextMessage();
- JmsUtil.addPropsToMessage(message, p);
- message.setText(msg);
- message.setStringProperty("Verify", prop);
- TestUtil.logTrace("gonna send msg with this property to the mdb: "
- + message.getStringProperty("Verify"));
-
- sender.send(message);
- TestUtil.logTrace("Close the session");
- session.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
-
- }
-
- /**
- * Send a bytes message.
- */
- public void sendBytesMessageToQ(String prop) {
-
- byte bValue = 9;
- try {
- TestUtil.logTrace("MDB_AR_TestEJB.sendBytesMessageToQ()");
- QueueSession session = connection.createQueueSession(true, 0);
- //
-
- TestUtil.logTrace("calling send method with: " + prop);
- QueueSender sender = session.createSender(queue);
- //
- TestUtil
- .logTrace("got a q sender for: " + sender.getQueue().getQueueName());
- // Create a bytes message
- BytesMessage message = session.createBytesMessage();
- JmsUtil.addPropsToMessage(message, p);
- message.writeByte(bValue);
- message.setStringProperty("Verify", prop);
- TestUtil.logTrace("gonna send msg with this property to the mdb: "
- + message.getStringProperty("Verify"));
-
- sender.send(message);
- TestUtil.logTrace("Close the session");
- session.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /**
- * Send a stream message.
- */
- public void sendStreamMessageToQ(String prop) {
- try {
- TestUtil.logTrace("MDB_AR_TestEJB.sendStreamMessageToQ()");
- QueueSession session = connection.createQueueSession(true, 0);
- //
-
- TestUtil.logTrace("calling send method with: " + prop);
- QueueSender sender = session.createSender(queue);
- //
- TestUtil
- .logTrace("got a q sender for: " + sender.getQueue().getQueueName());
- // Create a stream message
- StreamMessage message = session.createStreamMessage();
- JmsUtil.addPropsToMessage(message, p);
- message.writeString("Testing with a Stream message...");
- message.setStringProperty("Verify", prop);
- TestUtil.logTrace("gonna send msg with this property to the mdb: "
- + message.getStringProperty("Verify"));
-
- sender.send(message);
- TestUtil.logTrace("Close the session");
- session.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
-
- }
-
- /**
- * Send a map message.
- */
- public void sendMapMessageToQ(String prop) {
- try {
- TestUtil.logTrace("MDB_AR_TestEJB.sendMapMessageToQ()");
- QueueSession session = connection.createQueueSession(true, 0);
- //
-
- TestUtil.logTrace("calling send method with: " + prop);
- QueueSender sender = session.createSender(queue);
- //
- TestUtil
- .logTrace("got a q sender for: " + sender.getQueue().getQueueName());
- // Create a map message
- MapMessage message = session.createMapMessage();
- JmsUtil.addPropsToMessage(message, p);
- message.setString("aString", "Testing async receives");
- message.setStringProperty("Verify", prop);
- TestUtil.logTrace("gonna send msg with this property to the mdb: "
- + message.getStringProperty("Verify"));
-
- sender.send(message);
- TestUtil.logTrace("Close the session");
- session.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
-
- }
-
- /**
- * Send an object message.
- */
- public void sendObjectMessageToQ(String prop) {
- try {
- TestUtil.logTrace("MDB_AR_TestEJB.sendObjectMessageToQ()");
- QueueSession session = connection.createQueueSession(true, 0);
- //
-
- TestUtil.logTrace("calling send method with: " + prop);
- QueueSender sender = session.createSender(queue);
- //
- TestUtil
- .logTrace("got a q sender for: " + sender.getQueue().getQueueName());
- // Create a object message
- ObjectMessage message = session.createObjectMessage();
- JmsUtil.addPropsToMessage(message, p);
- message.setObject("Object Message !!!!");
- message.setStringProperty("Verify", prop);
- TestUtil.logTrace("gonna send msg with this property to the mdb: "
- + message.getStringProperty("Verify"));
-
- sender.send(message);
- TestUtil.logTrace("Close the session");
- session.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /**
- * Send a text message to a topic.
- */
- public void sendTextMessageToTopic(String prop) {
- try {
- String msg = "Testing a Text message";
- TestUtil.logTrace("MDB_AR_TestEJB.sendTextMessageToTopic()");
- TopicSession session = tConn.createTopicSession(true, 0);
-
- TestUtil.logTrace("calling send method with: " + prop);
- TopicPublisher publisher = session.createPublisher(topic);
- TestUtil.logTrace(
- "got a topic publisher for: " + publisher.getTopic().getTopicName());
- // Send a message.
- TextMessage message = session.createTextMessage();
- JmsUtil.addPropsToMessage(message, p);
- message.setText(msg);
- message.setStringProperty("Verify", prop);
- TestUtil.logTrace("gonna send msg with this property to the mdb: "
- + message.getStringProperty("Verify"));
-
- publisher.publish(message);
- TestUtil.logTrace("Close the session");
- session.close();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception in sendTextMessageToTopic", e);
- }
-
- }
-
- /**
- * Send a map message to a topic.
- */
- public void sendMapMessageToTopic(String prop) {
- try {
- String msg = "Testing a Map message";
- TestUtil.logTrace("MDB_AR_TestEJB.sendMapMessageToTopic()");
- TopicSession session = tConn.createTopicSession(true, 0);
-
- TestUtil.logTrace("calling send method with: " + prop);
- TopicPublisher publisher = session.createPublisher(topic);
- TestUtil.logTrace(
- "got a topic publisher for: " + publisher.getTopic().getTopicName());
-
- // Send a message.
- MapMessage message = session.createMapMessage();
- JmsUtil.addPropsToMessage(message, p);
- message.setString("aString", "Testing async receives");
- message.setStringProperty("Verify", prop);
- TestUtil.logTrace("gonna send msg with this property to the mdb: "
- + message.getStringProperty("Verify"));
-
- publisher.publish(message);
- TestUtil.logTrace("Close the session");
- session.close();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception in sendMapMessageToTopic", e);
- }
- }
-
- /**
- * Send a object message to a topic.
- */
- public void sendObjectMessageToTopic(String prop) {
- try {
- String msg = "Testing a Object message";
- TestUtil.logTrace("MDB_AR_TestEJB.sendObjectMessageToTopic()");
- TopicSession session = tConn.createTopicSession(true, 0);
-
- TestUtil.logTrace("calling send method with: " + prop);
- TopicPublisher publisher = session.createPublisher(topic);
- TestUtil.logTrace(
- "got a topic publisher for: " + publisher.getTopic().getTopicName());
-
- // Send a message.
- ObjectMessage message = session.createObjectMessage();
- JmsUtil.addPropsToMessage(message, p);
- message.setObject("Object Message !!!!");
- message.setStringProperty("Verify", prop);
- TestUtil.logTrace("gonna send msg with this property to the mdb: "
- + message.getStringProperty("Verify"));
-
- publisher.publish(message);
- TestUtil.logTrace("Close the session");
- session.close();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception in sendObjectMessageToTopic", e);
- }
- }
-
- /**
- * Send a Bytes message to a topic.
- */
- public void sendBytesMessageToTopic(String prop) {
- byte bValue = 11;
- try {
- String msg = "Testing a Bytes message";
- TestUtil.logTrace("MDB_AR_TestEJB.sendBytesMessageToTopic()");
- TopicSession session = tConn.createTopicSession(true, 0);
-
- TestUtil.logTrace("calling send method with: " + prop);
- TopicPublisher publisher = session.createPublisher(topic);
- TestUtil.logTrace(
- "got a topic publisher for: " + publisher.getTopic().getTopicName());
-
- // Send a message.
- BytesMessage message = session.createBytesMessage();
- JmsUtil.addPropsToMessage(message, p);
- message.writeByte(bValue);
- message.setStringProperty("Verify", prop);
- TestUtil.logTrace("gonna send msg with this property to the mdb: "
- + message.getStringProperty("Verify"));
-
- publisher.publish(message);
- TestUtil.logTrace("Close the session");
- session.close();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception in sendBytesMessageToTopic", e);
- }
- }
-
- /**
- * Send a Stream message to a topic.
- */
- public void sendStreamMessageToTopic(String prop) {
- byte bValue = 11;
- try {
- String msg = "Testing a Stream message";
- TestUtil.logTrace("MDB_AR_TestEJB.sendStreamMessageToTopic()");
- TopicSession session = tConn.createTopicSession(true, 0);
-
- TestUtil.logTrace("calling send method with: " + prop);
- TopicPublisher publisher = session.createPublisher(topic);
- TestUtil.logTrace(
- "got a topic publisher for: " + publisher.getTopic().getTopicName());
-
- // Send a message.
- StreamMessage message = session.createStreamMessage();
- JmsUtil.addPropsToMessage(message, p);
- message.writeString("Testing with a Stream message...");
- message.setStringProperty("Verify", prop);
- TestUtil.logTrace("gonna send msg with this property to the mdb: "
- + message.getStringProperty("Verify"));
-
- publisher.publish(message);
- TestUtil.logTrace("Close the session");
- session.close();
- } catch (Exception e) {
- TestUtil.logErr("Unexpected exception in sendStreamMessageToTopic", e);
- }
- }
-
- private boolean recvMessageInternal(QueueSession session, String prop)
- throws JMSException {
- boolean retcode = false;
- TestUtil.logTrace("MDB_AR_TestEJB.recvMessageInternal()");
- // Create a message producer.
- QueueReceiver rcvr = session.createReceiver(rcvrQueue);
- // dequeue the response from the mdb
- Message msgRec = null;
-
- for (int i = 0; i < 10; ++i) {
- TestUtil
- .logTrace("@recvMessageInternal trying to receive the message: " + i);
- msgRec = rcvr.receive(timeout);
- if (msgRec != null) {
- break;
- }
- } // end for loop
-
- if (msgRec != null) {
- TestUtil.logTrace("Success: received Msg from Q! "
- + msgRec.getStringProperty("Verify"));
- if (msgRec.getStringProperty("Verify").equals(prop)) {
- TestUtil.logTrace("Pass: we got the expected msg back! ");
- retcode = true;
- } else {
- TestUtil.logTrace("Fail: we didnt get the expected msg back! ");
- }
- } else {
- TestUtil.logTrace("Fail: we didnt get any msg back! ");
- }
- return retcode;
- }
-
- public void cleanup() {
- TestUtil.logTrace("In EJB cleanup");
- try {
- if (connection != null) {
- connection.close();
- }
-
- if (tConn != null) {
- tConn.close();
- }
- } catch (Exception e) {
- TestUtil.logErr("Exception in cleanup", e);
- }
- }
-
- @PostActivate
- public void activate() {
- TestUtil.logTrace("MDB_AR_TestEJB.activate()");
- try {
- TSNamingContext context = new TSNamingContext();
- TestUtil.logTrace("Got TSNamingContext");
-
- qcFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- rcvrQueue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
-
- tcFactory = (TopicConnectionFactory) context
- .lookup("java:comp/env/jms/MyTopicConnectionFactory");
- topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC");
-
- tConn = tcFactory.createTopicConnection(jmsUser, jmsPassword);
- connection = qcFactory.createQueueConnection(jmsUser, jmsPassword);
-
- connection.start();
- tConn.start();
- } catch (Exception e) {
- TestUtil.logErr(
- "Error looking up Queue, Topic, ConnectionFactory objects, Starting connections",
- e);
- throw new EJBException("@activate: Error!", e);
- }
- }
-
- @PrePassivate
- public void passivate() {
- TestUtil.logTrace("MDB_AR_TestEJB.passivate()");
-
- queue = null;
- rcvrQueue = null;
- qcFactory = null;
- topic = null;
- tcFactory = null;
-
- cleanup();
- }
-
- @Remove
- public void remove() {
- TestUtil.logTrace("MDB_AR_TestEJB.remove()");
- }
+ @Resource
+ private SessionContext sessionContext;
+
+ @Resource(name = "jms/MDB_QUEUE_REPLY")
+ private transient Queue rcvrQueue;
+
+ @Resource(name = "jms/MDB_QUEUE")
+ private transient Queue queue;
+
+ @Resource(name = "jms/MyQueueConnectionFactory")
+ private transient QueueConnectionFactory qcFactory;
+
+ @Resource(name = "jms/MDB_TOPIC")
+ private transient Topic topic;
+
+ @Resource(name = "jms/MyTopicConnectionFactory")
+ private transient TopicConnectionFactory tcFactory;
+
+ private transient QueueConnection connection = null;
+
+ private transient TopicConnection tConn = null;
+
+ private Properties p = null;
+
+ private String jmsUser;
+
+ private String jmsPassword;
+
+ private long timeout;
+
+ private static final Logger logger = (Logger) System.getLogger(MDB_AR_TestEJB.class.getName());
+
+ // Use this stateful session bean to test asynchronous receives of message
+ // driven beans.
+ // Has send methods for each type of jms message.
+
+ public MDB_AR_TestEJB() {
+ }
+
+ public void setup(Properties props) {
+ p = props;
+ try {
+ TestUtil.init(props);
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (jmsUser == null) {
+ throw new Exception("'user' is null");
+ }
+ if (jmsPassword == null) {
+ throw new Exception("'password' is null");
+ }
+ if (qcFactory == null || tcFactory == null || queue == null || rcvrQueue == null || topic == null
+ || sessionContext == null) {
+ throw new Exception("@Resource injection failed");
+ }
+ tConn = tcFactory.createTopicConnection(jmsUser, jmsPassword);
+ connection = qcFactory.createQueueConnection(jmsUser, jmsPassword);
+
+ connection.start();
+ tConn.start();
+ } catch (Exception e) {
+ throw new EJBException("@setup failed: ", e);
+ }
+ }
+
+ public boolean isThereSomethingInTheQueue() {
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.isThereSomethingInTheQueue()");
+ QueueBrowser qBrowser = null;
+ Enumeration msgs = null;
+ boolean ret = false;
+
+ try {
+ // Hopefully nothing is left in the queue
+ QueueSession session = connection.createQueueSession(true, 0);
+ qBrowser = session.createBrowser(rcvrQueue);
+ msgs = qBrowser.getEnumeration();
+ if (msgs.hasMoreElements()) {
+ ret = true;
+ }
+ qBrowser.close();
+ session.close();
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error in isThereSomethingInTheQueue", e);
+ }
+ return ret;
+ }
+
+ public void cleanTheQueue() {
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.cleanTheQueue()");
+ QueueBrowser qBrowser = null;
+ Enumeration msgs = null;
+ int numMsgs = 0;
+
+ try {
+ QueueSession session = connection.createQueueSession(true, 0);
+ TextMessage msgRec = null;
+
+ // delete anything left in the queue
+ qBrowser = session.createBrowser(rcvrQueue);
+ // count the number of messages
+ msgs = qBrowser.getEnumeration();
+ while (msgs.hasMoreElements()) {
+ msgs.nextElement();
+ numMsgs++;
+ }
+ qBrowser.close();
+
+ // Read messages until Q is cleaned
+ QueueReceiver rcvr = session.createReceiver(rcvrQueue);
+ logger.log(Logger.Level.TRACE, "Cleaning " + numMsgs + " messages from the Q: " + rcvrQueue.getQueueName());
+ for (int n = 0; n < numMsgs; n++) {
+
+ logger.log(Logger.Level.TRACE, "dequeuing msg: " + n + " from the Q: " + rcvrQueue.getQueueName());
+ for (int i = 0; i < 10; ++i) {
+ msgRec = (TextMessage) rcvr.receive(timeout);
+ if (msgRec != null) {
+ logger.log(Logger.Level.TRACE, "dequeued message: " + n);
+ break;
+ }
+ logger.log(Logger.Level.TRACE, "Attempt no: " + i + " Trying to dequeue message: " + n);
+ } // end of internal for loop
+ }
+ session.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error in cleanTheQueue", e);
+ }
+ }
+
+ public boolean checkOnResponse(String prop) {
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.checkOnResponse()");
+ boolean status = false;
+
+ try {
+ QueueSession session = connection.createQueueSession(true, 0);
+ status = recvMessageInternal(session, prop);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ session.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception in checkOnResponse", e);
+ }
+ return status;
+ }
+
+ /**
+ * Send a message. In bmt case, create session BEFORE starting tx.
+ */
+ public void sendTextMessageToQ(String prop) {
+ try {
+ String msg = "Test with a text message";
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.sendTextMessageToQ()");
+ QueueSession session = connection.createQueueSession(true, 0);
+ //
+
+ logger.log(Logger.Level.TRACE, "calling send method with: " + msg + " + " + prop);
+ QueueSender sender = session.createSender(queue);
+ //
+ logger.log(Logger.Level.TRACE, "got a q sender for: " + sender.getQueue().getQueueName());
+ // Send a message.
+ TextMessage message = session.createTextMessage();
+ JmsUtil.addPropsToMessage(message, p);
+ message.setText(msg);
+ message.setStringProperty("Verify", prop);
+ logger.log(Logger.Level.TRACE,
+ "gonna send msg with this property to the mdb: " + message.getStringProperty("Verify"));
+
+ sender.send(message);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ session.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+
+ }
+
+ /**
+ * Send a bytes message.
+ */
+ public void sendBytesMessageToQ(String prop) {
+
+ byte bValue = 9;
+ try {
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.sendBytesMessageToQ()");
+ QueueSession session = connection.createQueueSession(true, 0);
+ //
+
+ logger.log(Logger.Level.TRACE, "calling send method with: " + prop);
+ QueueSender sender = session.createSender(queue);
+ //
+ logger.log(Logger.Level.TRACE, "got a q sender for: " + sender.getQueue().getQueueName());
+ // Create a bytes message
+ BytesMessage message = session.createBytesMessage();
+ JmsUtil.addPropsToMessage(message, p);
+ message.writeByte(bValue);
+ message.setStringProperty("Verify", prop);
+ logger.log(Logger.Level.TRACE,
+ "gonna send msg with this property to the mdb: " + message.getStringProperty("Verify"));
+
+ sender.send(message);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ session.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /**
+ * Send a stream message.
+ */
+ public void sendStreamMessageToQ(String prop) {
+ try {
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.sendStreamMessageToQ()");
+ QueueSession session = connection.createQueueSession(true, 0);
+ //
+
+ logger.log(Logger.Level.TRACE, "calling send method with: " + prop);
+ QueueSender sender = session.createSender(queue);
+ //
+ logger.log(Logger.Level.TRACE, "got a q sender for: " + sender.getQueue().getQueueName());
+ // Create a stream message
+ StreamMessage message = session.createStreamMessage();
+ JmsUtil.addPropsToMessage(message, p);
+ message.writeString("Testing with a Stream message...");
+ message.setStringProperty("Verify", prop);
+ logger.log(Logger.Level.TRACE,
+ "gonna send msg with this property to the mdb: " + message.getStringProperty("Verify"));
+
+ sender.send(message);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ session.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+
+ }
+
+ /**
+ * Send a map message.
+ */
+ public void sendMapMessageToQ(String prop) {
+ try {
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.sendMapMessageToQ()");
+ QueueSession session = connection.createQueueSession(true, 0);
+ //
+
+ logger.log(Logger.Level.TRACE, "calling send method with: " + prop);
+ QueueSender sender = session.createSender(queue);
+ //
+ logger.log(Logger.Level.TRACE, "got a q sender for: " + sender.getQueue().getQueueName());
+ // Create a map message
+ MapMessage message = session.createMapMessage();
+ JmsUtil.addPropsToMessage(message, p);
+ message.setString("aString", "Testing async receives");
+ message.setStringProperty("Verify", prop);
+ logger.log(Logger.Level.TRACE,
+ "gonna send msg with this property to the mdb: " + message.getStringProperty("Verify"));
+
+ sender.send(message);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ session.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+
+ }
+
+ /**
+ * Send an object message.
+ */
+ public void sendObjectMessageToQ(String prop) {
+ try {
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.sendObjectMessageToQ()");
+ QueueSession session = connection.createQueueSession(true, 0);
+ //
+
+ logger.log(Logger.Level.TRACE, "calling send method with: " + prop);
+ QueueSender sender = session.createSender(queue);
+ //
+ logger.log(Logger.Level.TRACE, "got a q sender for: " + sender.getQueue().getQueueName());
+ // Create a object message
+ ObjectMessage message = session.createObjectMessage();
+ JmsUtil.addPropsToMessage(message, p);
+ message.setObject("Object Message !!!!");
+ message.setStringProperty("Verify", prop);
+ logger.log(Logger.Level.TRACE,
+ "gonna send msg with this property to the mdb: " + message.getStringProperty("Verify"));
+
+ sender.send(message);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ session.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /**
+ * Send a text message to a topic.
+ */
+ public void sendTextMessageToTopic(String prop) {
+ try {
+ String msg = "Testing a Text message";
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.sendTextMessageToTopic()");
+ TopicSession session = tConn.createTopicSession(true, 0);
+
+ logger.log(Logger.Level.TRACE, "calling send method with: " + prop);
+ TopicPublisher publisher = session.createPublisher(topic);
+ logger.log(Logger.Level.TRACE, "got a topic publisher for: " + publisher.getTopic().getTopicName());
+ // Send a message.
+ TextMessage message = session.createTextMessage();
+ JmsUtil.addPropsToMessage(message, p);
+ message.setText(msg);
+ message.setStringProperty("Verify", prop);
+ logger.log(Logger.Level.TRACE,
+ "gonna send msg with this property to the mdb: " + message.getStringProperty("Verify"));
+
+ publisher.publish(message);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ session.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception in sendTextMessageToTopic", e);
+ }
+
+ }
+
+ /**
+ * Send a map message to a topic.
+ */
+ public void sendMapMessageToTopic(String prop) {
+ try {
+ String msg = "Testing a Map message";
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.sendMapMessageToTopic()");
+ TopicSession session = tConn.createTopicSession(true, 0);
+
+ logger.log(Logger.Level.TRACE, "calling send method with: " + prop);
+ TopicPublisher publisher = session.createPublisher(topic);
+ logger.log(Logger.Level.TRACE, "got a topic publisher for: " + publisher.getTopic().getTopicName());
+
+ // Send a message.
+ MapMessage message = session.createMapMessage();
+ JmsUtil.addPropsToMessage(message, p);
+ message.setString("aString", "Testing async receives");
+ message.setStringProperty("Verify", prop);
+ logger.log(Logger.Level.TRACE,
+ "gonna send msg with this property to the mdb: " + message.getStringProperty("Verify"));
+
+ publisher.publish(message);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ session.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception in sendMapMessageToTopic", e);
+ }
+ }
+
+ /**
+ * Send a object message to a topic.
+ */
+ public void sendObjectMessageToTopic(String prop) {
+ try {
+ String msg = "Testing a Object message";
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.sendObjectMessageToTopic()");
+ TopicSession session = tConn.createTopicSession(true, 0);
+
+ logger.log(Logger.Level.TRACE, "calling send method with: " + prop);
+ TopicPublisher publisher = session.createPublisher(topic);
+ logger.log(Logger.Level.TRACE, "got a topic publisher for: " + publisher.getTopic().getTopicName());
+
+ // Send a message.
+ ObjectMessage message = session.createObjectMessage();
+ JmsUtil.addPropsToMessage(message, p);
+ message.setObject("Object Message !!!!");
+ message.setStringProperty("Verify", prop);
+ logger.log(Logger.Level.TRACE,
+ "gonna send msg with this property to the mdb: " + message.getStringProperty("Verify"));
+
+ publisher.publish(message);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ session.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception in sendObjectMessageToTopic", e);
+ }
+ }
+
+ /**
+ * Send a Bytes message to a topic.
+ */
+ public void sendBytesMessageToTopic(String prop) {
+ byte bValue = 11;
+ try {
+ String msg = "Testing a Bytes message";
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.sendBytesMessageToTopic()");
+ TopicSession session = tConn.createTopicSession(true, 0);
+
+ logger.log(Logger.Level.TRACE, "calling send method with: " + prop);
+ TopicPublisher publisher = session.createPublisher(topic);
+ logger.log(Logger.Level.TRACE, "got a topic publisher for: " + publisher.getTopic().getTopicName());
+
+ // Send a message.
+ BytesMessage message = session.createBytesMessage();
+ JmsUtil.addPropsToMessage(message, p);
+ message.writeByte(bValue);
+ message.setStringProperty("Verify", prop);
+ logger.log(Logger.Level.TRACE,
+ "gonna send msg with this property to the mdb: " + message.getStringProperty("Verify"));
+
+ publisher.publish(message);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ session.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception in sendBytesMessageToTopic", e);
+ }
+ }
+
+ /**
+ * Send a Stream message to a topic.
+ */
+ public void sendStreamMessageToTopic(String prop) {
+ byte bValue = 11;
+ try {
+ String msg = "Testing a Stream message";
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.sendStreamMessageToTopic()");
+ TopicSession session = tConn.createTopicSession(true, 0);
+
+ logger.log(Logger.Level.TRACE, "calling send method with: " + prop);
+ TopicPublisher publisher = session.createPublisher(topic);
+ logger.log(Logger.Level.TRACE, "got a topic publisher for: " + publisher.getTopic().getTopicName());
+
+ // Send a message.
+ StreamMessage message = session.createStreamMessage();
+ JmsUtil.addPropsToMessage(message, p);
+ message.writeString("Testing with a Stream message...");
+ message.setStringProperty("Verify", prop);
+ logger.log(Logger.Level.TRACE,
+ "gonna send msg with this property to the mdb: " + message.getStringProperty("Verify"));
+
+ publisher.publish(message);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ session.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Unexpected exception in sendStreamMessageToTopic", e);
+ }
+ }
+
+ private boolean recvMessageInternal(QueueSession session, String prop) throws JMSException {
+ boolean retcode = false;
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.recvMessageInternal()");
+ // Create a message producer.
+ QueueReceiver rcvr = session.createReceiver(rcvrQueue);
+ // dequeue the response from the mdb
+ Message msgRec = null;
+
+ for (int i = 0; i < 10; ++i) {
+ logger.log(Logger.Level.TRACE, "@recvMessageInternal trying to receive the message: " + i);
+ msgRec = rcvr.receive(timeout);
+ if (msgRec != null) {
+ break;
+ }
+ } // end for loop
+
+ if (msgRec != null) {
+ logger.log(Logger.Level.TRACE, "Success: received Msg from Q! " + msgRec.getStringProperty("Verify"));
+ if (msgRec.getStringProperty("Verify").equals(prop)) {
+ logger.log(Logger.Level.TRACE, "Pass: we got the expected msg back! ");
+ retcode = true;
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: we didnt get the expected msg back! ");
+ }
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: we didnt get any msg back! ");
+ }
+ return retcode;
+ }
+
+ public void cleanup() {
+ logger.log(Logger.Level.TRACE, "In EJB cleanup");
+ try {
+ if (connection != null) {
+ connection.close();
+ }
+
+ if (tConn != null) {
+ tConn.close();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception in cleanup", e);
+ }
+ }
+
+ @PostActivate
+ public void activate() {
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.activate()");
+ try {
+ TSNamingContext context = new TSNamingContext();
+ logger.log(Logger.Level.TRACE, "Got TSNamingContext");
+
+ qcFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ rcvrQueue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
+
+ tcFactory = (TopicConnectionFactory) context.lookup("java:comp/env/jms/MyTopicConnectionFactory");
+ topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC");
+
+ tConn = tcFactory.createTopicConnection(jmsUser, jmsPassword);
+ connection = qcFactory.createQueueConnection(jmsUser, jmsPassword);
+
+ connection.start();
+ tConn.start();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR,
+ "Error looking up Queue, Topic, ConnectionFactory objects, Starting connections", e);
+ throw new EJBException("@activate: Error!", e);
+ }
+ }
+
+ @PrePassivate
+ public void passivate() {
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.passivate()");
+
+ queue = null;
+ rcvrQueue = null;
+ qcFactory = null;
+ topic = null;
+ tcFactory = null;
+
+ cleanup();
+ }
+
+ @Remove
+ public void remove() {
+ logger.log(Logger.Level.TRACE, "MDB_AR_TestEJB.remove()");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MsgBeanForQueue.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MsgBeanForQueue.java
index 73fd2aff08..489e029a9a 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MsgBeanForQueue.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MsgBeanForQueue.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_rec;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.TSNamingContext;
@@ -38,73 +39,72 @@
public class MsgBeanForQueue implements MessageDrivenBean, MessageListener {
- private MessageDrivenContext mdc = null;
-
- private QueueConnectionFactory qcFactory;
-
- private QueueConnection connection = null;
-
- private Properties p = null;
-
- public MsgBeanForQueue() {
- TestUtil.logTrace("In MsgBeanForQueue::MsgBeanForQueue()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace("In MsgBeanForQueue::ejbCreate() !!");
- p = new Properties();
- }
-
- public void onMessage(Message msg) {
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("In MsgBeanForQueue::onMessage() : " + msg);
- // Send a message back to acknowledge that the mdb received the message.
- try {
- sendReply(msg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void sendReply(Message msg) {
- try {
- TSNamingContext context = new TSNamingContext();
- qcFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- connection = qcFactory.createQueueConnection();
-
- // get the reply to queue
- Queue replyQueue = (Queue) context
- .lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- connection.start();
-
- QueueSession session = connection.createQueueSession(true, 0);
- jakarta.jms.TextMessage reply = session.createTextMessage();
- QueueSender replier = session.createSender(replyQueue);
- reply.setText("MDB Responding to message receipt");
- reply.setStringProperty("Verify", msg.getStringProperty("Verify"));
-
- replier.send(reply);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (connection != null) {
- try {
- connection.close();
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- }
- }
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil
- .logTrace("In MsgBeanForQueueForQueue::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil.logTrace("In MsgBeanForQueue::remove()!!");
- }
+ private MessageDrivenContext mdc = null;
+
+ private QueueConnectionFactory qcFactory;
+
+ private QueueConnection connection = null;
+
+ private Properties p = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanForQueue.class.getName());
+
+ public MsgBeanForQueue() {
+ logger.log(Logger.Level.TRACE, "In MsgBeanForQueue::MsgBeanForQueue()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "In MsgBeanForQueue::ejbCreate() !!");
+ p = new Properties();
+ }
+
+ public void onMessage(Message msg) {
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "In MsgBeanForQueue::onMessage() : " + msg);
+ // Send a message back to acknowledge that the mdb received the message.
+ try {
+ sendReply(msg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void sendReply(Message msg) {
+ try {
+ TSNamingContext context = new TSNamingContext();
+ qcFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ connection = qcFactory.createQueueConnection();
+
+ // get the reply to queue
+ Queue replyQueue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ connection.start();
+
+ QueueSession session = connection.createQueueSession(true, 0);
+ jakarta.jms.TextMessage reply = session.createTextMessage();
+ QueueSender replier = session.createSender(replyQueue);
+ reply.setText("MDB Responding to message receipt");
+ reply.setStringProperty("Verify", msg.getStringProperty("Verify"));
+
+ replier.send(reply);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ }
+ }
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "In MsgBeanForQueueForQueue::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "In MsgBeanForQueue::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MsgBeanForTopic.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MsgBeanForTopic.java
index b7a83dc11c..d97edbc6c4 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MsgBeanForTopic.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_rec/MsgBeanForTopic.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_rec;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.TSNamingContext;
@@ -38,72 +39,71 @@
public class MsgBeanForTopic implements MessageDrivenBean, MessageListener {
- private MessageDrivenContext mdc = null;
-
- private QueueConnectionFactory qcFactory;
-
- private QueueConnection connection = null;
-
- private Properties p = null;
-
- public MsgBeanForTopic() {
- TestUtil.logTrace("In MsgBeanForTopic::MsgBeanForTopic()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace("In MsgBeanForTopic::ejbCreate() !!");
- p = new Properties();
- }
-
- public void onMessage(Message msg) {
- try {
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("In MsgBeanForTopic::onMessage() : " + msg);
- sendReply(msg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void sendReply(Message msg) {
- try {
- TSNamingContext context = new TSNamingContext();
- qcFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- connection = qcFactory.createQueueConnection();
-
- // get the reply to queue
- Queue replyQueue = (Queue) context
- .lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- connection.start();
-
- QueueSession session = connection.createQueueSession(true, 0);
- jakarta.jms.TextMessage reply = session.createTextMessage();
- QueueSender replier = session.createSender(replyQueue);
- reply.setText("MDB Responding to message receipt");
- reply.setStringProperty("Verify", msg.getStringProperty("Verify"));
-
- replier.send(reply);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (connection != null) {
- try {
- connection.close();
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- }
- }
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil
- .logTrace("In MsgBeanForTopicForQueue::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil.logTrace("In MsgBeanForTopicForQueue::remove()!!");
- }
+ private MessageDrivenContext mdc = null;
+
+ private QueueConnectionFactory qcFactory;
+
+ private QueueConnection connection = null;
+
+ private Properties p = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanForTopic.class.getName());
+
+ public MsgBeanForTopic() {
+ logger.log(Logger.Level.TRACE, "In MsgBeanForTopic::MsgBeanForTopic()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "In MsgBeanForTopic::ejbCreate() !!");
+ p = new Properties();
+ }
+
+ public void onMessage(Message msg) {
+ try {
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "In MsgBeanForTopic::onMessage() : " + msg);
+ sendReply(msg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void sendReply(Message msg) {
+ try {
+ TSNamingContext context = new TSNamingContext();
+ qcFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ connection = qcFactory.createQueueConnection();
+
+ // get the reply to queue
+ Queue replyQueue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ connection.start();
+
+ QueueSession session = connection.createQueueSession(true, 0);
+ jakarta.jms.TextMessage reply = session.createTextMessage();
+ QueueSender replier = session.createSender(replyQueue);
+ reply.setText("MDB Responding to message receipt");
+ reply.setStringProperty("Verify", msg.getStringProperty("Verify"));
+
+ replier.send(reply);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ }
+ }
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "In MsgBeanForTopicForQueue::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "In MsgBeanForTopicForQueue::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDBClient.java
deleted file mode 100644
index 9da284920b..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDBClient.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_sndQ;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-
-import jakarta.ejb.EJB;
-
-/**
- * The MDBClient class invokes a test session bean, which will send messages to
- * ask the message driven bean to send a text, byte, map, stream, and object
- * messages to a Destination
- */
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_SNDQ_Test")
- private static MDB_SNDQ_Test hr = null;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.port;
- * harness.log.traceflag;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /*
- * @testName: mdbSendTextMsgTest
- *
- * @assertion_ids: JMS:JAVADOC:334; JMS:JAVADOC:122; JMS:JAVADOC:504;
- * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
- * JMS:JAVADOC:317;
- *
- * @test_Strategy: Instruct the mdb to send a text msg.
- *
- * Create a stateful Session Bean and a Message-Diven Bean. Deploy them on the
- * J2EE server. Have the Session EJb send a message to a Queue Destination.
- * handled by a message-driven bean Tell the mdb to send a text message with
- * MessageProducer. Verify that the text message was sent.
- *
- */
- public void mdbSendTextMsgTest() throws Exception {
- String messageType = "TextMessage";
- String matchMe = "TextMessageFromMsgBean";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace("Call bean - have it tell mdb to send a text message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logErr("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendTextMsgTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbSendBytesMsgTest
- *
- * @assertion_ids: JMS:JAVADOC:334; JMS:JAVADOC:122; JMS:JAVADOC:504;
- * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
- * JMS:JAVADOC:317;
- *
- * @test_Strategy: Instruct the mdb to send a bytes msg.
- *
- * Create a stateful Session Bean and a Message-Diven Bean. Deploy them on the
- * J2EE server. Have the Session EJb send a message to a Queue Destination.
- * handled by a message-driven bean Tell the mdb to send a BytesMessage with
- * MessageProducer. Verify that the BytesMessage was sent.
- *
- */
- public void mdbSendBytesMsgTest() throws Exception {
- String messageType = "BytesMessage";
- String matchMe = "BytesMessageFromMsgBean";
- try {
- // Have the EJB invoke the MDB
- TestUtil
- .logTrace("Call bean - have it tell mdb to send a Bytes message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logErr("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendBytesMsgTest failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbSendMapMsgTest
- *
- * @assertion_ids: JMS:JAVADOC:334; JMS:JAVADOC:122; JMS:JAVADOC:504;
- * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
- * JMS:JAVADOC:317;
- *
- * @test_Strategy: Instruct the mdb to send a MapMessage.
- *
- * Create a stateful Session Bean and a Message-Diven Bean. Deploy them on the
- * J2EE server. Have the Session EJB send a message to a Queue Destination.
- * handled by a message-driven bean Tell the mdb to send a MapMessage with
- * MessageProducer. Verify that the MapMessage was sent.
- *
- */
- public void mdbSendMapMsgTest() throws Exception {
- String matchMe = "MapMessageFromMsgBean";
- String messageType = "MapMessage";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace("Call bean - have it tell mdb to send a map message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logErr("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendMapMsgTest failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbSendStreamMsgTest
- *
- * @assertion_ids: JMS:JAVADOC:334; JMS:JAVADOC:122; JMS:JAVADOC:504;
- * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
- * JMS:JAVADOC:317;
- *
- * @test_Strategy: Instruct the mdb to send a StreamMessage.
- *
- * Create a stateful Session Bean and a Message-Diven Bean. Deploy them on the
- * J2EE server. Have the Session EJB send a message to a Queue Destination.
- * handled by a message-driven bean Tell the mdb to send a StreamMessage with
- * MessageProducer. Verify that the StreamMessage was sent.
- *
- */
- public void mdbSendStreamMsgTest() throws Exception {
- String matchMe = "StreamMessageFromMsgBean";
- String messageType = "StreamMessage";
- try {
- // Have the EJB invoke the MDB
- TestUtil
- .logTrace("Call bean - have it tell mdb to send a stream message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logErr("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendStreamMsgTest failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbSendObjectMsgTest
- *
- * @assertion_ids: JMS:JAVADOC:334; JMS:JAVADOC:122; JMS:JAVADOC:504;
- * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
- * JMS:JAVADOC:317;
- *
- * @test_Strategy: Instruct the mdb to send an ObjectMessage.
- *
- * Create a stateful Session Bean and a Message-Diven Bean. Deploy them on the
- * J2EE server. Have the Session EJB send a message to a Queue Destination.
- * handled by a message-driven bean Tell the mdb to send an ObjectMessage with
- * MessageProducer. Verify that the ObjectMessage was sent.
- */
- public void mdbSendObjectMsgTest() throws Exception {
- String matchMe = "ObjectMessageFromMsgBean";
- String messageType = "ObjectMessage";
- try {
- // Have the EJB invoke the MDB
- TestUtil
- .logTrace("Call bean - have it tell mdb to send an object message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logErr("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendObjectMsgTest failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
-
- if (hr != null) {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- } catch (Exception e) {
- TestUtil.logErr("Error cleaning up messages", e);
- } finally {
- try {
- hr.remove();
- } catch (Exception er) {
- TestUtil.logErr("Error removing bean", er);
- }
- }
- }
- logMsg("End of client cleanup;");
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDBClientIT.java
new file mode 100644
index 0000000000..36f9dcda48
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDBClientIT.java
@@ -0,0 +1,263 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_sndQ;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import jakarta.ejb.EJB;
+
+/**
+ * The MDBClient class invokes a test session bean, which will send messages to
+ * ask the message driven bean to send a text, byte, map, stream, and object
+ * messages to a Destination
+ */
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_SNDQ_Test")
+ private static MDB_SNDQ_Test hr = null;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password; harness.log.port;
+ * harness.log.traceflag;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ // hr.setup(p);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbSendTextMsgTest
+ *
+ * @assertion_ids: JMS:JAVADOC:334; JMS:JAVADOC:122; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
+ * JMS:JAVADOC:317;
+ *
+ * @test_Strategy: Instruct the mdb to send a text msg.
+ *
+ * Create a stateful Session Bean and a Message-Diven Bean. Deploy them on the
+ * J2EE server. Have the Session EJb send a message to a Queue Destination.
+ * handled by a message-driven bean Tell the mdb to send a text message with
+ * MessageProducer. Verify that the text message was sent.
+ *
+ */
+ @Test
+ public void mdbSendTextMsgTest() throws Exception {
+ String messageType = "TextMessage";
+ String matchMe = "TextMessageFromMsgBean";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send a text message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.ERROR, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendTextMsgTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbSendBytesMsgTest
+ *
+ * @assertion_ids: JMS:JAVADOC:334; JMS:JAVADOC:122; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
+ * JMS:JAVADOC:317;
+ *
+ * @test_Strategy: Instruct the mdb to send a bytes msg.
+ *
+ * Create a stateful Session Bean and a Message-Diven Bean. Deploy them on the
+ * J2EE server. Have the Session EJb send a message to a Queue Destination.
+ * handled by a message-driven bean Tell the mdb to send a BytesMessage with
+ * MessageProducer. Verify that the BytesMessage was sent.
+ *
+ */
+ @Test
+ public void mdbSendBytesMsgTest() throws Exception {
+ String messageType = "BytesMessage";
+ String matchMe = "BytesMessageFromMsgBean";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send a Bytes message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.ERROR, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendBytesMsgTest failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbSendMapMsgTest
+ *
+ * @assertion_ids: JMS:JAVADOC:334; JMS:JAVADOC:122; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
+ * JMS:JAVADOC:317;
+ *
+ * @test_Strategy: Instruct the mdb to send a MapMessage.
+ *
+ * Create a stateful Session Bean and a Message-Diven Bean. Deploy them on the
+ * J2EE server. Have the Session EJB send a message to a Queue Destination.
+ * handled by a message-driven bean Tell the mdb to send a MapMessage with
+ * MessageProducer. Verify that the MapMessage was sent.
+ *
+ */
+ @Test
+ public void mdbSendMapMsgTest() throws Exception {
+ String matchMe = "MapMessageFromMsgBean";
+ String messageType = "MapMessage";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send a map message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.ERROR, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendMapMsgTest failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbSendStreamMsgTest
+ *
+ * @assertion_ids: JMS:JAVADOC:334; JMS:JAVADOC:122; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
+ * JMS:JAVADOC:317;
+ *
+ * @test_Strategy: Instruct the mdb to send a StreamMessage.
+ *
+ * Create a stateful Session Bean and a Message-Diven Bean. Deploy them on the
+ * J2EE server. Have the Session EJB send a message to a Queue Destination.
+ * handled by a message-driven bean Tell the mdb to send a StreamMessage with
+ * MessageProducer. Verify that the StreamMessage was sent.
+ *
+ */
+ @Test
+ public void mdbSendStreamMsgTest() throws Exception {
+ String matchMe = "StreamMessageFromMsgBean";
+ String messageType = "StreamMessage";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send a stream message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.ERROR, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendStreamMsgTest failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbSendObjectMsgTest
+ *
+ * @assertion_ids: JMS:JAVADOC:334; JMS:JAVADOC:122; JMS:JAVADOC:504;
+ * JMS:JAVADOC:510; JMS:JAVADOC:242; JMS:JAVADOC:244; JMS:JAVADOC:221;
+ * JMS:JAVADOC:317;
+ *
+ * @test_Strategy: Instruct the mdb to send an ObjectMessage.
+ *
+ * Create a stateful Session Bean and a Message-Diven Bean. Deploy them on the
+ * J2EE server. Have the Session EJB send a message to a Queue Destination.
+ * handled by a message-driven bean Tell the mdb to send an ObjectMessage with
+ * MessageProducer. Verify that the ObjectMessage was sent.
+ */
+ @Test
+ public void mdbSendObjectMsgTest() throws Exception {
+ String matchMe = "ObjectMessageFromMsgBean";
+ String messageType = "ObjectMessage";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send an object message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.ERROR, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendObjectMsgTest failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+
+ if (hr != null) {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error cleaning up messages", e);
+ } finally {
+ try {
+ hr.remove();
+ } catch (Exception er) {
+ logger.log(Logger.Level.ERROR, "Error removing bean", er);
+ }
+ }
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDB_SNDQ_Test.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDB_SNDQ_Test.java
index 33304d8dba..78417e8d26 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDB_SNDQ_Test.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDB_SNDQ_Test.java
@@ -26,15 +26,15 @@
@Remote
public interface MDB_SNDQ_Test {
- boolean askMDBToSendAMessage(String messageType);
+ boolean askMDBToSendAMessage(String messageType);
- boolean checkOnResponse(String prop);
+ boolean checkOnResponse(String prop);
- boolean isThereSomethingInTheQueue();
+ boolean isThereSomethingInTheQueue();
- void setup(Properties p);
+ void setup(Properties p);
- void cleanTheQueue();
+ void cleanTheQueue();
- void remove();
+ void remove();
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDB_SNDQ_TestEJB.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDB_SNDQ_TestEJB.java
index c25fda939b..966d70cacd 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDB_SNDQ_TestEJB.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MDB_SNDQ_TestEJB.java
@@ -19,6 +19,7 @@
*/
package com.sun.ts.tests.jms.ee.mdb.mdb_sndQ;
+import java.lang.System.Logger;
import java.util.Enumeration;
import java.util.Properties;
@@ -49,273 +50,265 @@
@Remote(MDB_SNDQ_Test.class)
public class MDB_SNDQ_TestEJB {
- @Resource
- private SessionContext sessionContext;
-
- @Resource(name = "jms/MDB_QUEUE")
- private transient Queue Dest;
-
- @Resource(name = "jms/MDB_QUEUE_REPLY")
- private transient Queue receiveDest;
-
- @Resource(name = "jms/MyQueueConnectionFactory")
- private transient ConnectionFactory cf;
-
- private transient Connection Conn;
-
- private Properties p = null;
-
- private long timeout;
-
- private String jmsUser;
-
- private String jmsPassword;
-
- public MDB_SNDQ_TestEJB() {
- }
-
- public void setup(Properties props) {
- TestUtil.logTrace("MDB_SNDQ_TestEJB.askMDBToSendAMessage()");
- p = props;
- try {
- TestUtil.init(props);
- // get props
- timeout = Long.parseLong(props.getProperty("jms_timeout"));
- jmsUser = props.getProperty("user");
- jmsPassword = props.getProperty("password");
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (jmsUser == null) {
- throw new Exception("'user' in ts.jte must not be null");
- }
- if (jmsPassword == null) {
- throw new Exception("'password' in ts.jte must not be null");
- }
- if (cf == null || Dest == null || receiveDest == null
- || sessionContext == null) {
- throw new Exception("@Resource injection failed");
- }
- } catch (Exception e) {
- throw new EJBException("@setup failed: ", e);
- }
- }
-
- public boolean askMDBToSendAMessage(String typeOfMessage) {
- TestUtil.logTrace("MDB_SNDQ_TestEJB.askMDBToSendAMessage()");
- boolean ok = true;
- String myMessage = "I want you to send a message";
- try {
- Conn = cf.createConnection(jmsUser, jmsPassword);
- Session session = Conn.createSession(true, 0);
- Conn.start();
-
- MessageProducer mSender = session.createProducer(Dest);
-
- // create a text message
- TextMessage msg = session.createTextMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.setText(myMessage);
- msg.setStringProperty("MessageType", typeOfMessage);
-
- // send the message
- mSender.send(msg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("@askMDBToSendAMessage: Error!", e);
- } finally {
- try {
- if (Conn != null) {
- Conn.close();
- }
- } catch (Exception e) {
- TestUtil.logErr("Error closing connection in askMDBToSendAMessage", e);
- }
- }
- return ok;
- }
-
- // Validate that a given message was sent by mdb
- // prop = validate string
- public boolean checkOnResponse(String prop) {
- boolean status = false;
- try {
- TestUtil.logTrace("MDB_SNDQ_TestEJB.checkOnResponse()");
- Conn = cf.createConnection(jmsUser, jmsPassword);
- Conn.start();
-
- Session session = Conn.createSession(true, 0);
- status = recvMessageInternal(session, prop);
- TestUtil.logTrace("Close the session");
- session.close();
- } catch (Exception e) {
- TestUtil.logErr("Error in checkOnResponse", e);
- } finally {
- try {
- if (Conn != null) {
- Conn.close();
- }
- } catch (Exception e) {
- TestUtil.logErr("Error closing connection in checkOnResponse", e);
- }
- }
- return status;
- }
-
- private boolean recvMessageInternal(Session session, String prop)
- throws JMSException {
- boolean retcode = false;
- TestUtil.logTrace("MDB_SNDQ_TestEJB.recvMessageInternal()");
-
- // Create a message producer.
- MessageConsumer rcvr = session.createConsumer(receiveDest);
-
- // remove the response from the mdb
- Message msgRec = null;
- for (int i = 0; i < 10; ++i) {
- TestUtil
- .logTrace("@recvMessageInternal trying to receive the message: " + i);
- msgRec = rcvr.receive(timeout);
- if (msgRec != null) {
- break;
- }
- } // end for loop
-
- if (msgRec != null) {
- if (msgRec.getStringProperty("MessageType").equals(prop)) {
- TestUtil.logTrace("Success: received Msg from Q! "
- + msgRec.getStringProperty("MessageType"));
- TestUtil.logTrace("Pass: we got the expected msg back! ");
- retcode = true;
- } else {
- TestUtil.logErr("Fail: we didnt get the expected msg back! ");
- TestUtil
- .logErr("Msg from Q: " + msgRec.getStringProperty("MessageType"));
- }
- } else {
- TestUtil.logErr("Fail: we didnt get the expected msg back! ");
- }
- return retcode;
- }
-
- public boolean isThereSomethingInTheQueue() {
- TestUtil.logTrace("MDB_SNDQ_TestEJB.isThereSomethingInTheQueue()");
- QueueBrowser qBrowser = null;
- Enumeration msgs = null;
- boolean ret = false;
- try {
- // Hopefully nothing is left in the Destination
- Conn = cf.createConnection(jmsUser, jmsPassword);
- Conn.start();
-
- Session session = Conn.createSession(true, 0);
- qBrowser = session.createBrowser((jakarta.jms.Queue) receiveDest);
- msgs = qBrowser.getEnumeration();
- if (msgs.hasMoreElements()) {
- ret = true;
- }
- qBrowser.close();
- session.close();
-
- } catch (Exception e) {
- TestUtil.logErr("Error in isThereSomethingInTheQueue", e);
- } finally {
- try {
- if (Conn != null) {
- Conn.close();
- }
- } catch (Exception e) {
- TestUtil.logErr(
- "Error closing connection in isThereSomethingInTheQueue", e);
- }
- }
- return ret;
- }
-
- public void cleanTheQueue() {
- TestUtil.logTrace("MDB_SNDQ_TestEJB.cleanTheQueue()");
-
- QueueBrowser qBrowser = null;
- Enumeration msgs = null;
- int numMsgs = 0;
- TextMessage msgRec = null;
- MessageConsumer rcvr = null;
-
- try {
- Conn = cf.createConnection(jmsUser, jmsPassword);
- Session session = Conn.createSession(true, 0);
- Conn.start();
-
- // delete anything left in the Destination
- qBrowser = session.createBrowser((Queue) receiveDest);
- // count the number of messages
- msgs = qBrowser.getEnumeration();
- while (msgs.hasMoreElements()) {
- msgs.nextElement();
- numMsgs++;
- }
- qBrowser.close();
-
- // Read messages until Destination is cleaned
- rcvr = session.createConsumer(receiveDest);
- for (int n = 0; n < numMsgs; n++) {
- for (int i = 0; i < 10; ++i) {
- msgRec = (TextMessage) rcvr.receive(timeout);
- if (msgRec != null) {
- TestUtil.logTrace("Removed message from Destination: " + n);
- break;
- }
- TestUtil
- .logTrace("Attempt no: " + i + " Trying to delete message: " + n);
- } // end of internal for loop
- }
- session.close();
- } catch (Exception e) {
- TestUtil.logErr("Error in cleanTheQueue", e);
- } finally {
- try {
- if (Conn != null) {
- Conn.close();
- }
- } catch (Exception e) {
- TestUtil.logErr("Error closing connection in cleanTheQueue", e);
- }
- }
- }
-
- @Remove
- public void remove() {
- TestUtil.logTrace("MDB_SNDQ_TestEJB.remove()");
- }
-
- @PostActivate
- public void activate() {
- TestUtil.logTrace("MDB_SNDQ_TestEJB.activate()");
- try {
- TSNamingContext context = new TSNamingContext();
- cf = (ConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- TestUtil.logTrace("looked up connection factory object");
-
- Dest = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
- TestUtil.logTrace("looked up the Destination");
- receiveDest = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- } catch (Exception e) {
- TestUtil.logErr(
- "Error looking up Queue, Reply Queue, and ConnectionFactory objects",
- e);
- throw new EJBException("@activate: Error!", e);
- }
- }
-
- @PrePassivate
- public void passivate() {
- TestUtil.logTrace("MDB_SNDQ_TestEJB.passivate()");
- receiveDest = null;
- Conn = null;
- Dest = null;
- cf = null;
- }
+ @Resource
+ private SessionContext sessionContext;
+
+ @Resource(name = "jms/MDB_QUEUE")
+ private transient Queue Dest;
+
+ @Resource(name = "jms/MDB_QUEUE_REPLY")
+ private transient Queue receiveDest;
+
+ @Resource(name = "jms/MyQueueConnectionFactory")
+ private transient ConnectionFactory cf;
+
+ private transient Connection Conn;
+
+ private Properties p = null;
+
+ private long timeout;
+
+ private String jmsUser;
+
+ private String jmsPassword;
+
+ private static final Logger logger = (Logger) System.getLogger(MDB_SNDQ_TestEJB.class.getName());
+
+ public MDB_SNDQ_TestEJB() {
+ }
+
+ public void setup(Properties props) {
+ logger.log(Logger.Level.TRACE, "MDB_SNDQ_TestEJB.askMDBToSendAMessage()");
+ p = props;
+ try {
+ TestUtil.init(props);
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (jmsUser == null) {
+ throw new Exception("'user' is null");
+ }
+ if (jmsPassword == null) {
+ throw new Exception("'password' is null");
+ }
+ if (cf == null || Dest == null || receiveDest == null || sessionContext == null) {
+ throw new Exception("@Resource injection failed");
+ }
+ } catch (Exception e) {
+ throw new EJBException("@setup failed: ", e);
+ }
+ }
+
+ public boolean askMDBToSendAMessage(String typeOfMessage) {
+ logger.log(Logger.Level.TRACE, "MDB_SNDQ_TestEJB.askMDBToSendAMessage()");
+ boolean ok = true;
+ String myMessage = "I want you to send a message";
+ try {
+ Conn = cf.createConnection(jmsUser, jmsPassword);
+ Session session = Conn.createSession(true, 0);
+ Conn.start();
+
+ MessageProducer mSender = session.createProducer(Dest);
+
+ // create a text message
+ TextMessage msg = session.createTextMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.setText(myMessage);
+ msg.setStringProperty("MessageType", typeOfMessage);
+
+ // send the message
+ mSender.send(msg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("@askMDBToSendAMessage: Error!", e);
+ } finally {
+ try {
+ if (Conn != null) {
+ Conn.close();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing connection in askMDBToSendAMessage", e);
+ }
+ }
+ return ok;
+ }
+
+ // Validate that a given message was sent by mdb
+ // prop = validate string
+ public boolean checkOnResponse(String prop) {
+ boolean status = false;
+ try {
+ logger.log(Logger.Level.TRACE, "MDB_SNDQ_TestEJB.checkOnResponse()");
+ Conn = cf.createConnection(jmsUser, jmsPassword);
+ Conn.start();
+
+ Session session = Conn.createSession(true, 0);
+ status = recvMessageInternal(session, prop);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ session.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error in checkOnResponse", e);
+ } finally {
+ try {
+ if (Conn != null) {
+ Conn.close();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing connection in checkOnResponse", e);
+ }
+ }
+ return status;
+ }
+
+ private boolean recvMessageInternal(Session session, String prop) throws JMSException {
+ boolean retcode = false;
+ logger.log(Logger.Level.TRACE, "MDB_SNDQ_TestEJB.recvMessageInternal()");
+
+ // Create a message producer.
+ MessageConsumer rcvr = session.createConsumer(receiveDest);
+
+ // remove the response from the mdb
+ Message msgRec = null;
+ for (int i = 0; i < 10; ++i) {
+ logger.log(Logger.Level.TRACE, "@recvMessageInternal trying to receive the message: " + i);
+ msgRec = rcvr.receive(timeout);
+ if (msgRec != null) {
+ break;
+ }
+ } // end for loop
+
+ if (msgRec != null) {
+ if (msgRec.getStringProperty("MessageType").equals(prop)) {
+ logger.log(Logger.Level.TRACE,
+ "Success: received Msg from Q! " + msgRec.getStringProperty("MessageType"));
+ logger.log(Logger.Level.TRACE, "Pass: we got the expected msg back! ");
+ retcode = true;
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: we didnt get the expected msg back! ");
+ logger.log(Logger.Level.ERROR, "Msg from Q: " + msgRec.getStringProperty("MessageType"));
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Fail: we didnt get the expected msg back! ");
+ }
+ return retcode;
+ }
+
+ public boolean isThereSomethingInTheQueue() {
+ logger.log(Logger.Level.TRACE, "MDB_SNDQ_TestEJB.isThereSomethingInTheQueue()");
+ QueueBrowser qBrowser = null;
+ Enumeration msgs = null;
+ boolean ret = false;
+ try {
+ // Hopefully nothing is left in the Destination
+ Conn = cf.createConnection(jmsUser, jmsPassword);
+ Conn.start();
+
+ Session session = Conn.createSession(true, 0);
+ qBrowser = session.createBrowser((jakarta.jms.Queue) receiveDest);
+ msgs = qBrowser.getEnumeration();
+ if (msgs.hasMoreElements()) {
+ ret = true;
+ }
+ qBrowser.close();
+ session.close();
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error in isThereSomethingInTheQueue", e);
+ } finally {
+ try {
+ if (Conn != null) {
+ Conn.close();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing connection in isThereSomethingInTheQueue", e);
+ }
+ }
+ return ret;
+ }
+
+ public void cleanTheQueue() {
+ logger.log(Logger.Level.TRACE, "MDB_SNDQ_TestEJB.cleanTheQueue()");
+
+ QueueBrowser qBrowser = null;
+ Enumeration msgs = null;
+ int numMsgs = 0;
+ TextMessage msgRec = null;
+ MessageConsumer rcvr = null;
+
+ try {
+ Conn = cf.createConnection(jmsUser, jmsPassword);
+ Session session = Conn.createSession(true, 0);
+ Conn.start();
+
+ // delete anything left in the Destination
+ qBrowser = session.createBrowser((Queue) receiveDest);
+ // count the number of messages
+ msgs = qBrowser.getEnumeration();
+ while (msgs.hasMoreElements()) {
+ msgs.nextElement();
+ numMsgs++;
+ }
+ qBrowser.close();
+
+ // Read messages until Destination is cleaned
+ rcvr = session.createConsumer(receiveDest);
+ for (int n = 0; n < numMsgs; n++) {
+ for (int i = 0; i < 10; ++i) {
+ msgRec = (TextMessage) rcvr.receive(timeout);
+ if (msgRec != null) {
+ logger.log(Logger.Level.TRACE, "Removed message from Destination: " + n);
+ break;
+ }
+ logger.log(Logger.Level.TRACE, "Attempt no: " + i + " Trying to delete message: " + n);
+ } // end of internal for loop
+ }
+ session.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error in cleanTheQueue", e);
+ } finally {
+ try {
+ if (Conn != null) {
+ Conn.close();
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing connection in cleanTheQueue", e);
+ }
+ }
+ }
+
+ @Remove
+ public void remove() {
+ logger.log(Logger.Level.TRACE, "MDB_SNDQ_TestEJB.remove()");
+ }
+
+ @PostActivate
+ public void activate() {
+ logger.log(Logger.Level.TRACE, "MDB_SNDQ_TestEJB.activate()");
+ try {
+ TSNamingContext context = new TSNamingContext();
+ cf = (ConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ logger.log(Logger.Level.TRACE, "looked up connection factory object");
+
+ Dest = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
+ logger.log(Logger.Level.TRACE, "looked up the Destination");
+ receiveDest = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error looking up Queue, Reply Queue, and ConnectionFactory objects", e);
+ throw new EJBException("@activate: Error!", e);
+ }
+ }
+
+ @PrePassivate
+ public void passivate() {
+ logger.log(Logger.Level.TRACE, "MDB_SNDQ_TestEJB.passivate()");
+ receiveDest = null;
+ Conn = null;
+ Dest = null;
+ cf = null;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MsgBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MsgBean.java
index f84cbcdbea..ddfef41e13 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MsgBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndQ/MsgBean.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_sndQ;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.RemoteLoggingInitException;
@@ -45,216 +46,216 @@
public class MsgBean implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- private MessageDrivenContext mdc = null;
-
- // JMS
- private ConnectionFactory cf = null;
-
- private Destination Dest = null;
-
- private MessageProducer mSender = null;
-
- private Session sess = null;
-
- public MsgBean() {
- TestUtil.logTrace("@MsgBean()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace("@MsgBean-ejbCreate() !!");
- try {
- context = new TSNamingContext();
-
- cf = (ConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- if (cf == null)
- TestUtil.logErr("error looking up ConnectionFactory");
- TestUtil.logTrace("got a ConnectionFactory!!");
-
- Dest = (Destination) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- if (Dest == null)
- TestUtil.logErr("Dest error");
- TestUtil.logTrace("got a Dest ");
-
- p = new Properties();
-
- } catch (Exception e) {
- TestUtil.logErr("MDB ejbCreate Error!", e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("@onMessage! " + msg);
-
- Connection Conn = null;
- try {
- if (msg.getObjectProperty("properties") != null) {
- initLogging((java.util.Properties) msg.getObjectProperty("properties"));
- }
-
- Conn = cf.createConnection();
- if (Conn == null)
- TestUtil.logErr("connection error");
- else {
- Conn.start();
- sess = Conn.createSession(true, 0);
- }
-
- TestUtil.logTrace("started the connection !!");
-
- // Send a message back to acknowledge that the mdb received the message.
- if (msg.getStringProperty("MessageType").equals("TextMessage")) {
- sendATextMessage();
- } else if (msg.getStringProperty("MessageType").equals("BytesMessage")) {
- sendABytesMessage();
- } else if (msg.getStringProperty("MessageType").equals("MapMessage")) {
- sendAMapMessage();
- } else if (msg.getStringProperty("MessageType").equals("StreamMessage")) {
- sendAStreamMessage();
- } else if (msg.getStringProperty("MessageType").equals("ObjectMessage")) {
- sendAnObjectMessage();
- } else {
- TestUtil.logTrace(
- "@onMessage - invalid message type found in StringProperty");
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Exception caught in onMessage!", e);
- } finally {
- if (Conn != null) {
- try {
- Conn.close();
- } catch (Exception e) {
- TestUtil.logErr("Error closing Connection", e);
- }
- }
- }
- }
-
- // message bean helper methods follow.
- // Each method will send a simple message of the type requested.
- // this will send a text message to a Destination
-
- // must call init for logging to be properly performed
- public void initLogging(java.util.Properties p) {
- try {
- TestUtil.init(p);
- TestUtil.logTrace("MsgBean initLogging OK.");
- } catch (RemoteLoggingInitException e) {
- TestUtil.printStackTrace(e);
- TestUtil.logMsg("MsgBean initLogging failed.");
- throw new EJBException(e.getMessage());
- }
- }
-
- private void sendATextMessage() {
- TestUtil.logTrace("@sendATextMessage");
- try {
- String myMsg = "I am sending a text message as requested";
-
- // send a text message as requested to MDB_QUEUE_REPLY
- mSender = sess.createProducer(Dest);
-
- TextMessage msg = sess.createTextMessage();
- msg.setText(myMsg);
- msg.setStringProperty("MessageType", "TextMessageFromMsgBean");
-
- mSender.send(msg);
- } catch (Exception e) {
- TestUtil.logErr("Exception caught sending a TextMessage!", e);
- }
- }
-
- private void sendABytesMessage() {
- TestUtil.logTrace("@sendABytesMessage");
- try {
- byte aByte = 10;
-
- // send a text message as requested to MDB_QUEUE_REPLY
- mSender = sess.createProducer(Dest);
-
- BytesMessage msg = sess.createBytesMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.writeByte(aByte);
- msg.setStringProperty("MessageType", "BytesMessageFromMsgBean");
-
- mSender.send(msg);
- } catch (Exception e) {
- TestUtil.logErr("Exception caught sending a BytesMessage!", e);
- }
- }
-
- private void sendAMapMessage() {
- TestUtil.logTrace("@sendAMapMessage");
- try {
- String myMsg = "I am sending a map message as requested";
-
- // send a text message as requested to MDB_QUEUE_REPLY
- mSender = sess.createProducer(Dest);
-
- MapMessage msg = sess.createMapMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.setString("MapMessage", myMsg);
- msg.setStringProperty("MessageType", "MapMessageFromMsgBean");
-
- mSender.send(msg);
- } catch (Exception e) {
- TestUtil.logErr("Exception caught sending a MapMessage!", e);
- }
- }
-
- private void sendAStreamMessage() {
- TestUtil.logTrace("@sendAStreamMessage");
- try {
- String myMsg = "I am sending a stream message as requested";
-
- // send a text message as requested to MDB_QUEUE_REPLY
- mSender = sess.createProducer(Dest);
-
- StreamMessage msg = sess.createStreamMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.writeString(myMsg);
- msg.setStringProperty("MessageType", "StreamMessageFromMsgBean");
-
- mSender.send(msg);
- } catch (Exception e) {
- TestUtil.logErr("Exception caught sending a StreamMessage!", e);
- }
- }
-
- private void sendAnObjectMessage() {
- TestUtil.logTrace("@sendAnObjectMessage");
- try {
- String myMsg = "I am sending a text message as requested";
-
- // send a text message as requested to MDB_QUEUE_REPLY
- mSender = sess.createProducer(Dest);
-
- ObjectMessage msg = sess.createObjectMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.setObject(myMsg);
- msg.setStringProperty("MessageType", "ObjectMessageFromMsgBean");
-
- mSender.send(msg);
- } catch (Exception e) {
- TestUtil.logErr("Exception caught sending an ObjectMessage!", e);
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace("In MsgBean::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil.logTrace("In MsgBean::remove()!!");
- }
+ // properties object needed for logging, get this from the message object
+ // passed into the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ private MessageDrivenContext mdc = null;
+
+ // JMS
+ private ConnectionFactory cf = null;
+
+ private Destination Dest = null;
+
+ private MessageProducer mSender = null;
+
+ private Session sess = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBean.class.getName());
+
+ public MsgBean() {
+ logger.log(Logger.Level.TRACE, "@MsgBean()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "@MsgBean-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+
+ cf = (ConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ if (cf == null)
+ logger.log(Logger.Level.ERROR, "error looking up ConnectionFactory");
+ logger.log(Logger.Level.TRACE, "got a ConnectionFactory!!");
+
+ Dest = (Destination) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ if (Dest == null)
+ logger.log(Logger.Level.ERROR, "Dest error");
+ logger.log(Logger.Level.TRACE, "got a Dest ");
+
+ p = new Properties();
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "MDB ejbCreate Error!", e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "@onMessage! " + msg);
+
+ Connection Conn = null;
+ try {
+ if (msg.getObjectProperty("properties") != null) {
+ initLogging((java.util.Properties) msg.getObjectProperty("properties"));
+ }
+
+ Conn = cf.createConnection();
+ if (Conn == null)
+ logger.log(Logger.Level.ERROR, "connection error");
+ else {
+ Conn.start();
+ sess = Conn.createSession(true, 0);
+ }
+
+ logger.log(Logger.Level.TRACE, "started the connection !!");
+
+ // Send a message back to acknowledge that the mdb received the message.
+ if (msg.getStringProperty("MessageType").equals("TextMessage")) {
+ sendATextMessage();
+ } else if (msg.getStringProperty("MessageType").equals("BytesMessage")) {
+ sendABytesMessage();
+ } else if (msg.getStringProperty("MessageType").equals("MapMessage")) {
+ sendAMapMessage();
+ } else if (msg.getStringProperty("MessageType").equals("StreamMessage")) {
+ sendAStreamMessage();
+ } else if (msg.getStringProperty("MessageType").equals("ObjectMessage")) {
+ sendAnObjectMessage();
+ } else {
+ logger.log(Logger.Level.TRACE, "@onMessage - invalid message type found in StringProperty");
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception caught in onMessage!", e);
+ } finally {
+ if (Conn != null) {
+ try {
+ Conn.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error closing Connection", e);
+ }
+ }
+ }
+ }
+
+ // message bean helper methods follow.
+ // Each method will send a simple message of the type requested.
+ // this will send a text message to a Destination
+
+ // must call init for logging to be properly performed
+ public void initLogging(java.util.Properties p) {
+ try {
+ TestUtil.init(p);
+ logger.log(Logger.Level.TRACE, "MsgBean initLogging OK.");
+ } catch (RemoteLoggingInitException e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "MsgBean initLogging failed.");
+ throw new EJBException(e.getMessage());
+ }
+ }
+
+ private void sendATextMessage() {
+ logger.log(Logger.Level.TRACE, "@sendATextMessage");
+ try {
+ String myMsg = "I am sending a text message as requested";
+
+ // send a text message as requested to MDB_QUEUE_REPLY
+ mSender = sess.createProducer(Dest);
+
+ TextMessage msg = sess.createTextMessage();
+ msg.setText(myMsg);
+ msg.setStringProperty("MessageType", "TextMessageFromMsgBean");
+
+ mSender.send(msg);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception caught sending a TextMessage!", e);
+ }
+ }
+
+ private void sendABytesMessage() {
+ logger.log(Logger.Level.TRACE, "@sendABytesMessage");
+ try {
+ byte aByte = 10;
+
+ // send a text message as requested to MDB_QUEUE_REPLY
+ mSender = sess.createProducer(Dest);
+
+ BytesMessage msg = sess.createBytesMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.writeByte(aByte);
+ msg.setStringProperty("MessageType", "BytesMessageFromMsgBean");
+
+ mSender.send(msg);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception caught sending a BytesMessage!", e);
+ }
+ }
+
+ private void sendAMapMessage() {
+ logger.log(Logger.Level.TRACE, "@sendAMapMessage");
+ try {
+ String myMsg = "I am sending a map message as requested";
+
+ // send a text message as requested to MDB_QUEUE_REPLY
+ mSender = sess.createProducer(Dest);
+
+ MapMessage msg = sess.createMapMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.setString("MapMessage", myMsg);
+ msg.setStringProperty("MessageType", "MapMessageFromMsgBean");
+
+ mSender.send(msg);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception caught sending a MapMessage!", e);
+ }
+ }
+
+ private void sendAStreamMessage() {
+ logger.log(Logger.Level.TRACE, "@sendAStreamMessage");
+ try {
+ String myMsg = "I am sending a stream message as requested";
+
+ // send a text message as requested to MDB_QUEUE_REPLY
+ mSender = sess.createProducer(Dest);
+
+ StreamMessage msg = sess.createStreamMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.writeString(myMsg);
+ msg.setStringProperty("MessageType", "StreamMessageFromMsgBean");
+
+ mSender.send(msg);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception caught sending a StreamMessage!", e);
+ }
+ }
+
+ private void sendAnObjectMessage() {
+ logger.log(Logger.Level.TRACE, "@sendAnObjectMessage");
+ try {
+ String myMsg = "I am sending a text message as requested";
+
+ // send a text message as requested to MDB_QUEUE_REPLY
+ mSender = sess.createProducer(Dest);
+
+ ObjectMessage msg = sess.createObjectMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.setObject(myMsg);
+ msg.setStringProperty("MessageType", "ObjectMessageFromMsgBean");
+
+ mSender.send(msg);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception caught sending an ObjectMessage!", e);
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "In MsgBean::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "In MsgBean::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToQueue/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToQueue/MDBClient.java
deleted file mode 100644
index dbd9abb328..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToQueue/MDBClient.java
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_sndToQueue;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.MDB_Q_Test;
-
-import jakarta.ejb.EJB;
-
-/**
- * The MDBClient class invokes a test session bean, which will ask the message
- * driven bean to send a text, byte, map, stream, and object message to a queue
- */
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_SNDToQueue_Test")
- private static MDB_Q_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
- // Tests mdb sending jms messages
- // Test with Queue
- // Test with Text,Stream,Byte,Map and Object messages
- //
- /*
- * @testName: mdbSendTextMsgToQueueTest
- *
- * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:270; JMS:JAVADOC:522;
- * JMS:JAVADOC:188; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JavaEE:SPEC:128;
- *
- * @test_Strategy: Instruct the mdb to send a text msg. Create a stateful
- * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send
- * a message to a Queue Destination. handled by a message-driven bean Tell the
- * mdb to send a text message with QueueSender. Verify that the text message
- * was sent.
- *
- */
- public void mdbSendTextMsgToQueueTest() throws Exception {
- String messageType = "TextMessage";
- String matchMe = "TextMessageFromMsgBean";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace("Call bean - have it tell mdb to send a text message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendTextMsgToQueueTest failed");
- }
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbSendBytesMsgToQueueTest
- *
- * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:270; JMS:JAVADOC:522;
- * JMS:JAVADOC:188; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:209; JMS:JAVADOC:562; JavaEE:SPEC:128;
- *
- * @test_Strategy: Instruct the mdb to send a bytes msg. Create a stateful
- * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send
- * a message to a Queue Destination. handled by a message-driven bean Tell the
- * mdb to send a bytes message with QueueSender. Verify that a Bytes message
- * was sent
- *
- */
- public void mdbSendBytesMsgToQueueTest() throws Exception {
- String messageType = "BytesMessage";
- String matchMe = "BytesMessageFromMsgBean";
- try {
- // Have the EJB invoke the MDB
- TestUtil
- .logTrace("Call bean - have it tell mdb to send a Bytes message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendBytesMsgToQueueTest failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbSendMapMsgToQueueTest
- *
- * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:270; JMS:JAVADOC:522;
- * JMS:JAVADOC:188; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:211; JMS:JAVADOC:473; JavaEE:SPEC:128;
- *
- * @test_Strategy: Instruct the mdb to send a map msg. Create a stateful
- * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send
- * a message to a Queue Destination. handled by a message-driven bean Tell the
- * mdb to send a map message with QueueSender. Verify that a Map message was
- * sent
- *
- */
- public void mdbSendMapMsgToQueueTest() throws Exception {
- String matchMe = "MapMessageFromMsgBean";
- String messageType = "MapMessage";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace("Call bean - have it tell mdb to send a map message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendMapMsgToQueueTest failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
-
- }
-
- /*
- * @testName: mdbSendStreamMsgToQueueTest
- *
- * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:270; JMS:JAVADOC:522;
- * JMS:JAVADOC:188; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:219; JMS:JAVADOC:166; JavaEE:SPEC:128;
- *
- * @test_Strategy: Instruct the mdb to send a stream msg. Create a stateful
- * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send
- * a message to a Queue Destination. handled by a message-driven bean Tell the
- * mdb to send a stream message with QueueSender. Verify that a Stream message
- * was sent
- *
- */
- public void mdbSendStreamMsgToQueueTest() throws Exception {
- String matchMe = "StreamMessageFromMsgBean";
- String messageType = "StreamMessage";
- try {
- // Have the EJB invoke the MDB
- TestUtil
- .logTrace("Call bean - have it tell mdb to send a stream message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendStreamMsgToQueueTest failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbSendObjectMsgToQueueTest
- *
- * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:270; JMS:JAVADOC:522;
- * JMS:JAVADOC:188; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:215; JMS:JAVADOC:289; JavaEE:SPEC:128;
- *
- * @test_Strategy: Instruct the mdb to send an object msg. Create a stateful
- * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send
- * a message to a Queue Destination. handled by a message-driven bean Tell the
- * mdb to send an Object message with QueueSender. Verify that an Object
- * message was sent
- *
- */
- public void mdbSendObjectMsgToQueueTest() throws Exception {
- String matchMe = "ObjectMessageFromMsgBean";
- String messageType = "ObjectMessage";
- try {
- // Have the EJB invoke the MDB
- TestUtil
- .logTrace("Call bean - have it tell mdb to send an object message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendObjectMsgToQueueTest failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- ;
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToQueue/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToQueue/MDBClientIT.java
new file mode 100644
index 0000000000..322fcd1835
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToQueue/MDBClientIT.java
@@ -0,0 +1,260 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_sndToQueue;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.commonee.MDB_Q_Test;
+
+import jakarta.ejb.EJB;
+
+/**
+ * The MDBClient class invokes a test session bean, which will ask the message
+ * driven bean to send a text, byte, map, stream, and object message to a queue
+ */
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_SNDToQueue_Test")
+ private static MDB_Q_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+ try {
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ hr.setup(props);
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+ // Tests mdb sending jms messages
+ // Test with Queue
+ // Test with Text,Stream,Byte,Map and Object messages
+ //
+ /*
+ * @testName: mdbSendTextMsgToQueueTest
+ *
+ * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:270; JMS:JAVADOC:522;
+ * JMS:JAVADOC:188; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JavaEE:SPEC:128;
+ *
+ * @test_Strategy: Instruct the mdb to send a text msg. Create a stateful
+ * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send a
+ * message to a Queue Destination. handled by a message-driven bean Tell the mdb
+ * to send a text message with QueueSender. Verify that the text message was
+ * sent.
+ *
+ */
+ @Test
+ public void mdbSendTextMsgToQueueTest() throws Exception {
+ String messageType = "TextMessage";
+ String matchMe = "TextMessageFromMsgBean";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send a text message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendTextMsgToQueueTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbSendBytesMsgToQueueTest
+ *
+ * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:270; JMS:JAVADOC:522;
+ * JMS:JAVADOC:188; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:209; JMS:JAVADOC:562; JavaEE:SPEC:128;
+ *
+ * @test_Strategy: Instruct the mdb to send a bytes msg. Create a stateful
+ * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send a
+ * message to a Queue Destination. handled by a message-driven bean Tell the mdb
+ * to send a bytes message with QueueSender. Verify that a Bytes message was
+ * sent
+ *
+ */
+ @Test
+ public void mdbSendBytesMsgToQueueTest() throws Exception {
+ String messageType = "BytesMessage";
+ String matchMe = "BytesMessageFromMsgBean";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send a Bytes message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendBytesMsgToQueueTest failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbSendMapMsgToQueueTest
+ *
+ * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:270; JMS:JAVADOC:522;
+ * JMS:JAVADOC:188; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:211; JMS:JAVADOC:473; JavaEE:SPEC:128;
+ *
+ * @test_Strategy: Instruct the mdb to send a map msg. Create a stateful Session
+ * EJB Bean. Deploy it on the J2EE server. Have the EJB component send a message
+ * to a Queue Destination. handled by a message-driven bean Tell the mdb to send
+ * a map message with QueueSender. Verify that a Map message was sent
+ *
+ */
+ @Test
+ public void mdbSendMapMsgToQueueTest() throws Exception {
+ String matchMe = "MapMessageFromMsgBean";
+ String messageType = "MapMessage";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send a map message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendMapMsgToQueueTest failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+
+ }
+
+ /*
+ * @testName: mdbSendStreamMsgToQueueTest
+ *
+ * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:270; JMS:JAVADOC:522;
+ * JMS:JAVADOC:188; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:219; JMS:JAVADOC:166; JavaEE:SPEC:128;
+ *
+ * @test_Strategy: Instruct the mdb to send a stream msg. Create a stateful
+ * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send a
+ * message to a Queue Destination. handled by a message-driven bean Tell the mdb
+ * to send a stream message with QueueSender. Verify that a Stream message was
+ * sent
+ *
+ */
+ @Test
+ public void mdbSendStreamMsgToQueueTest() throws Exception {
+ String matchMe = "StreamMessageFromMsgBean";
+ String messageType = "StreamMessage";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send a stream message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendStreamMsgToQueueTest failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbSendObjectMsgToQueueTest
+ *
+ * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:270; JMS:JAVADOC:522;
+ * JMS:JAVADOC:188; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:215; JMS:JAVADOC:289; JavaEE:SPEC:128;
+ *
+ * @test_Strategy: Instruct the mdb to send an object msg. Create a stateful
+ * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send a
+ * message to a Queue Destination. handled by a message-driven bean Tell the mdb
+ * to send an Object message with QueueSender. Verify that an Object message was
+ * sent
+ *
+ */
+ @Test
+ public void mdbSendObjectMsgToQueueTest() throws Exception {
+ String matchMe = "ObjectMessageFromMsgBean";
+ String messageType = "ObjectMessage";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send an object message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendObjectMsgToQueueTest failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ ;
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToQueue/MsgBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToQueue/MsgBean.java
index bc3e7f8fcd..768d3f2a48 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToQueue/MsgBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToQueue/MsgBean.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_sndToQueue;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.RemoteLoggingInitException;
@@ -45,212 +46,212 @@
public class MsgBean implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- private MessageDrivenContext mdc = null;
-
- // JMS
- private QueueConnectionFactory qFactory = null;
-
- private QueueConnection qConnection = null;
-
- private Queue queue = null;
-
- private QueueSender mSender = null;
-
- private QueueSession qSession = null;
-
- public MsgBean() {
- TestUtil.logTrace("@MsgBean()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace("@MsgBean-ejbCreate() !!");
- try {
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- if (qFactory == null)
- TestUtil.logErr("qFactory error");
- TestUtil.logTrace("got a qFactory !!");
-
- queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- if (queue == null)
- TestUtil.logErr("queue error");
-
- TestUtil.logTrace("got a queue ");
- p = new Properties();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("@onMessage! " + msg);
-
- try {
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null)
- TestUtil.logErr("connection error");
- else {
- qConnection.start();
- qSession = qConnection.createQueueSession(true, 0);
- }
- TestUtil.logTrace("started the connection !!");
-
- if (msg.getObjectProperty("properties") != null) {
- initLogging((java.util.Properties) msg.getObjectProperty("properties"));
- }
-
- // Send a message back to acknowledge that the mdb received the message.
- if (msg.getStringProperty("MessageType").equals("TextMessage")) {
- sendATextMessage();
- } else if (msg.getStringProperty("MessageType").equals("BytesMessage")) {
- sendABytesMessage();
- } else if (msg.getStringProperty("MessageType").equals("MapMessage")) {
- sendAMapMessage();
- } else if (msg.getStringProperty("MessageType").equals("StreamMessage")) {
- sendAStreamMessage();
- } else if (msg.getStringProperty("MessageType").equals("ObjectMessage")) {
- sendAnObjectMessage();
- } else {
- TestUtil.logTrace(
- "@onMessage - invalid message type found in StringProperty");
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Exception caught in onMessage!", e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
- }
-
- // message bean helper methods follow.
- // Each method will send a simple message of the type requested.
- // this will send a text message to a Queue
-
- // must call init for logging to be properly performed
- public void initLogging(java.util.Properties p) {
- try {
- TestUtil.init(p);
- TestUtil.logTrace("MsgBean initLogging OK.");
- } catch (RemoteLoggingInitException e) {
- TestUtil.printStackTrace(e);
- TestUtil.logMsg("MsgBean initLogging failed.");
- throw new EJBException(e.getMessage());
- }
- }
-
- private void sendATextMessage() {
- TestUtil.logTrace("@sendATextMessage");
- try {
- String myMsg = "I am sending a text message as requested";
-
- // send a text message as requested to MDB_QUEUE_REPLY
- mSender = qSession.createSender(queue);
-
- TextMessage msg = qSession.createTextMessage();
- msg.setText(myMsg);
- msg.setStringProperty("MessageType", "TextMessageFromMsgBean");
-
- mSender.send(msg);
- } catch (Exception e) {
- TestUtil.logErr("Exception caught sending a TextMessage!", e);
- }
- }
-
- private void sendABytesMessage() {
- TestUtil.logTrace("@sendABytesMessage");
- try {
- byte aByte = 10;
-
- // send a text message as requested to MDB_QUEUE_REPLY
- mSender = qSession.createSender(queue);
-
- BytesMessage msg = qSession.createBytesMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.writeByte(aByte);
- msg.setStringProperty("MessageType", "BytesMessageFromMsgBean");
-
- mSender.send(msg);
- } catch (Exception e) {
- TestUtil.logErr("Exception caught sending a BytesMessage!", e);
- }
- }
-
- private void sendAMapMessage() {
- TestUtil.logTrace("@sendAMapMessage");
- try {
- String myMsg = "I am sending a map message as requested";
-
- // send a text message as requested to MDB_QUEUE_REPLY
- mSender = qSession.createSender(queue);
-
- MapMessage msg = qSession.createMapMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.setString("MapMessage", myMsg);
- msg.setStringProperty("MessageType", "MapMessageFromMsgBean");
-
- mSender.send(msg);
- } catch (Exception e) {
- TestUtil.logErr("Exception caught sending a MapMessage!", e);
- }
- }
-
- private void sendAStreamMessage() {
- TestUtil.logTrace("@sendAStreamMessage");
- try {
- String myMsg = "I am sending a stream message as requested";
- // send a text message as requested to MDB_QUEUE_REPLY
- mSender = qSession.createSender(queue);
- StreamMessage msg = qSession.createStreamMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.writeString(myMsg);
- msg.setStringProperty("MessageType", "StreamMessageFromMsgBean");
- mSender.send(msg);
- } catch (Exception e) {
- TestUtil.logErr("Exception caught sending a StreamMessage!", e);
- }
- }
-
- private void sendAnObjectMessage() {
- TestUtil.logTrace("@sendAnObjectMessage");
- try {
- String myMsg = "I am sending a text message as requested";
-
- // send a text message as requested to MDB_QUEUE_REPLY
- mSender = qSession.createSender(queue);
-
- ObjectMessage msg = qSession.createObjectMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.setObject(myMsg);
- msg.setStringProperty("MessageType", "ObjectMessageFromMsgBean");
-
- mSender.send(msg);
- } catch (Exception e) {
- TestUtil.logErr("Exception caught sending an ObjectMessage!", e);
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace("In MsgBean::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil.logTrace("In MsgBean::remove()!!");
- }
+ // properties object needed for logging, get this from the message object
+ // passed into the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ private MessageDrivenContext mdc = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBean.class.getName());
+
+ // JMS
+ private QueueConnectionFactory qFactory = null;
+
+ private QueueConnection qConnection = null;
+
+ private Queue queue = null;
+
+ private QueueSender mSender = null;
+
+ private QueueSession qSession = null;
+
+ public MsgBean() {
+ logger.log(Logger.Level.TRACE, "@MsgBean()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "@MsgBean-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ if (qFactory == null)
+ logger.log(Logger.Level.ERROR, "qFactory error");
+ logger.log(Logger.Level.TRACE, "got a qFactory !!");
+
+ queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ if (queue == null)
+ logger.log(Logger.Level.ERROR, "queue error");
+
+ logger.log(Logger.Level.TRACE, "got a queue ");
+ p = new Properties();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "@onMessage! " + msg);
+
+ try {
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null)
+ logger.log(Logger.Level.ERROR, "connection error");
+ else {
+ qConnection.start();
+ qSession = qConnection.createQueueSession(true, 0);
+ }
+ logger.log(Logger.Level.TRACE, "started the connection !!");
+
+ if (msg.getObjectProperty("properties") != null) {
+ initLogging((java.util.Properties) msg.getObjectProperty("properties"));
+ }
+
+ // Send a message back to acknowledge that the mdb received the message.
+ if (msg.getStringProperty("MessageType").equals("TextMessage")) {
+ sendATextMessage();
+ } else if (msg.getStringProperty("MessageType").equals("BytesMessage")) {
+ sendABytesMessage();
+ } else if (msg.getStringProperty("MessageType").equals("MapMessage")) {
+ sendAMapMessage();
+ } else if (msg.getStringProperty("MessageType").equals("StreamMessage")) {
+ sendAStreamMessage();
+ } else if (msg.getStringProperty("MessageType").equals("ObjectMessage")) {
+ sendAnObjectMessage();
+ } else {
+ logger.log(Logger.Level.TRACE, "@onMessage - invalid message type found in StringProperty");
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception caught in onMessage!", e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+ }
+
+ // message bean helper methods follow.
+ // Each method will send a simple message of the type requested.
+ // this will send a text message to a Queue
+
+ // must call init for logging to be properly performed
+ public void initLogging(java.util.Properties p) {
+ try {
+ TestUtil.init(p);
+ logger.log(Logger.Level.TRACE, "MsgBean initLogging OK.");
+ } catch (RemoteLoggingInitException e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "MsgBean initLogging failed.");
+ throw new EJBException(e.getMessage());
+ }
+ }
+
+ private void sendATextMessage() {
+ logger.log(Logger.Level.TRACE, "@sendATextMessage");
+ try {
+ String myMsg = "I am sending a text message as requested";
+
+ // send a text message as requested to MDB_QUEUE_REPLY
+ mSender = qSession.createSender(queue);
+
+ TextMessage msg = qSession.createTextMessage();
+ msg.setText(myMsg);
+ msg.setStringProperty("MessageType", "TextMessageFromMsgBean");
+
+ mSender.send(msg);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception caught sending a TextMessage!", e);
+ }
+ }
+
+ private void sendABytesMessage() {
+ logger.log(Logger.Level.TRACE, "@sendABytesMessage");
+ try {
+ byte aByte = 10;
+
+ // send a text message as requested to MDB_QUEUE_REPLY
+ mSender = qSession.createSender(queue);
+
+ BytesMessage msg = qSession.createBytesMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.writeByte(aByte);
+ msg.setStringProperty("MessageType", "BytesMessageFromMsgBean");
+
+ mSender.send(msg);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception caught sending a BytesMessage!", e);
+ }
+ }
+
+ private void sendAMapMessage() {
+ logger.log(Logger.Level.TRACE, "@sendAMapMessage");
+ try {
+ String myMsg = "I am sending a map message as requested";
+
+ // send a text message as requested to MDB_QUEUE_REPLY
+ mSender = qSession.createSender(queue);
+
+ MapMessage msg = qSession.createMapMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.setString("MapMessage", myMsg);
+ msg.setStringProperty("MessageType", "MapMessageFromMsgBean");
+
+ mSender.send(msg);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception caught sending a MapMessage!", e);
+ }
+ }
+
+ private void sendAStreamMessage() {
+ logger.log(Logger.Level.TRACE, "@sendAStreamMessage");
+ try {
+ String myMsg = "I am sending a stream message as requested";
+ // send a text message as requested to MDB_QUEUE_REPLY
+ mSender = qSession.createSender(queue);
+ StreamMessage msg = qSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.writeString(myMsg);
+ msg.setStringProperty("MessageType", "StreamMessageFromMsgBean");
+ mSender.send(msg);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception caught sending a StreamMessage!", e);
+ }
+ }
+
+ private void sendAnObjectMessage() {
+ logger.log(Logger.Level.TRACE, "@sendAnObjectMessage");
+ try {
+ String myMsg = "I am sending a text message as requested";
+
+ // send a text message as requested to MDB_QUEUE_REPLY
+ mSender = qSession.createSender(queue);
+
+ ObjectMessage msg = qSession.createObjectMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.setObject(myMsg);
+ msg.setStringProperty("MessageType", "ObjectMessageFromMsgBean");
+
+ mSender.send(msg);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Exception caught sending an ObjectMessage!", e);
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "In MsgBean::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "In MsgBean::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MDBClient.java
deleted file mode 100644
index 35204c1a6a..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MDBClient.java
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_sndToTopic;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.commonee.MDB_T_Test;
-
-import jakarta.ejb.EJB;
-
-/**
- * The MDBClient class invokes a test session bean, which will ask and the
- * message driven bean to send a text, byte, map, stream, and object message to
- * a topic Sun's EJB Reference Implementation.
- */
-
-public class MDBClient extends EETest {
-
- @EJB(name = "ejb/MDB_SNDToTopic_Test")
- private static MDB_T_Test hr;
-
- private Properties props = null;
-
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.port;
- * harness.log.traceflag;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- try {
- if (hr == null) {
- throw new Exception("@EJB injection failed");
- }
- hr.setup(p);
- if (hr.isThereSomethingInTheQueue()) {
- TestUtil.logTrace("Error: message(s) left in Q");
- hr.cleanTheQueue();
- } else {
- TestUtil.logTrace("Nothing left in queue");
- }
- logMsg("Setup ok;");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
- // Tests mdb sending jms messages
- // Tests with Topic
- // Tests with Text,Stream,Byte,Map and Object messages
- //
- /*
- * @testName: mdbSendTextMsgToTopicTest
- *
- * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:109; JMS:JAVADOC:111;
- * JMS:JAVADOC:91; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:99; JMS:JAVADOC:270; JMS:JAVADOC:522; JMS:JAVADOC:188;
- * JMS:JAVADOC:198;
- *
- * @test_Strategy: Instruct the mdb to send a text msg. Create a stateful
- * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send
- * a message to a Topic Destination. handled by a message-driven bean Tell the
- * mdb (MsgBeanToTopic) to send a text message with TopicPublisher to a topic
- * that is handled by a second mdb(MsgBeanTopic). MsgBeanTopic verifies it
- * received the message by sending another message to a Queue -
- * MDB_QUEUE_REPLY.
- *
- */
- public void mdbSendTextMsgToTopicTest() throws Exception {
- String messageType = "TextMessage";
- String matchMe = "TextMessageFromMsgBean";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace("Call bean - have it tell mdb to send a text message;");
- // subscribe
- hr.askMDBToSendAMessage(messageType);
- // getMessage
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendBytesMsgToTopicTest failed");
- }
- TestUtil.logTrace("mdbSendTextMsgToTopicTest passed!");
-
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
-
- }
-
- /*
- * @testName: mdbSendBytesMsgToTopicTest
- *
- * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:109; JMS:JAVADOC:111;
- * JMS:JAVADOC:91; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:99; JMS:JAVADOC:270; JMS:JAVADOC:522; JMS:JAVADOC:188;
- * JMS:JAVADOC:198; JMS:JAVADOC:209; JMS:JAVADOC:562;
- *
- * @test_Strategy: Instruct the mdb to send a bytes msg. Create a stateful
- * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send
- * a message to a Topic Destination. handled by a message-driven bean Tell the
- * mdb (MsgBeanToTopic) to send a bytes message with TopicPublisher to a topic
- * that is handled by a second mdb(MsgBeanTopic). MsgBeanTopic verifies it
- * received the message by sending another message to a Queue -
- * MDB_QUEUE_REPLY.
- *
- */
- public void mdbSendBytesMsgToTopicTest() throws Exception {
- String messageType = "BytesMessage";
- String matchMe = "BytesMessageFromMsgBean";
- try {
- // Have the EJB invoke the MDB
- TestUtil
- .logTrace("Call bean - have it tell mdb to send a Bytes message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendBytesMsgToTopicTest failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbSendMapMsgToTopicTest
- *
- * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:109; JMS:JAVADOC:111;
- * JMS:JAVADOC:91; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:99; JMS:JAVADOC:270; JMS:JAVADOC:522; JMS:JAVADOC:188;
- * JMS:JAVADOC:198; JMS:JAVADOC:211; JMS:JAVADOC:473;
- *
- * @test_Strategy: Instruct the mdb to send a map msg. Create a stateful
- * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send
- * a message to a Topic Destination. handled by a message-driven bean Tell the
- * mdb (MsgBeanToTopic) to send a map message with TopicPublisher to a topic
- * that is handled by a second mdb(MsgBeanTopic). MsgBeanTopic verifies it
- * received the message by sending another message to a Queue -
- * MDB_QUEUE_REPLY.
- *
- */
- public void mdbSendMapMsgToTopicTest() throws Exception {
- String matchMe = "MapMessageFromMsgBean";
- String messageType = "MapMessage";
- try {
- // Have the EJB invoke the MDB
- TestUtil.logTrace("Call bean - have it tell mdb to send a map message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendMapMsgToTopicTest failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
-
- }
-
- /*
- * @testName: mdbSendStreamMsgToTopicTest
- *
- * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:109; JMS:JAVADOC:111;
- * JMS:JAVADOC:91; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:99; JMS:JAVADOC:270; JMS:JAVADOC:522; JMS:JAVADOC:188;
- * JMS:JAVADOC:198; JMS:JAVADOC:219; JMS:JAVADOC:166;
- *
- * @test_Strategy: Instruct the mdb to send a stream msg. Create a stateful
- * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send
- * a message to a Topic Destination. handled by a message-driven bean Tell the
- * mdb (MsgBeanToTopic) to send a stream message with TopicPublisher to a
- * topic that is handled by a second mdb(MsgBeanTopic). MsgBeanTopic verifies
- * it received the message by sending another message to a Queue -
- * MDB_QUEUE_REPLY.
- *
- */
- public void mdbSendStreamMsgToTopicTest() throws Exception {
- String matchMe = "StreamMessageFromMsgBean";
- String messageType = "StreamMessage";
- try {
- // Have the EJB invoke the MDB
- TestUtil
- .logTrace("Call bean - have it tell mdb to send a stream message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendStreamMsgToTopicTest failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: mdbSendObjectMsgToTopicTest
- *
- * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:109; JMS:JAVADOC:111;
- * JMS:JAVADOC:91; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:99; JMS:JAVADOC:270; JMS:JAVADOC:522; JMS:JAVADOC:188;
- * JMS:JAVADOC:198; JMS:JAVADOC:215; JMS:JAVADOC:289;
- *
- * @test_Strategy: Instruct the mdb to send an object msg. Create a stateful
- * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send
- * a message to a Topic Destination. handled by a message-driven bean Tell the
- * mdb (MsgBeanToTopic) to send an object message with TopicPublisher to a
- * topic that is handled by a second mdb(MsgBeanTopic). MsgBeanTopic verifies
- * it received the message by sending another message to a Queue -
- * MDB_QUEUE_REPLY.
- *
- */
- public void mdbSendObjectMsgToTopicTest() throws Exception {
- String matchMe = "ObjectMessageFromMsgBean";
- String messageType = "ObjectMessage";
- try {
- // Have the EJB invoke the MDB
- TestUtil
- .logTrace("Call bean - have it tell mdb to send an object message;");
- hr.askMDBToSendAMessage(messageType);
- if (!hr.checkOnResponse(matchMe)) {
- TestUtil.logTrace("Error: didn't get expected response from mdb");
- throw new Exception("ERROR: mdbSendObjectMsgToTopicTest failed");
- }
-
- TestUtil.logTrace("Test passed!");
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- logMsg("End of client cleanup;");
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MDBClientIT.java
new file mode 100644
index 0000000000..ec5f08e90b
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MDBClientIT.java
@@ -0,0 +1,266 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_sndToTopic;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.tests.jms.commonee.MDB_T_Test;
+
+import jakarta.ejb.EJB;
+
+/**
+ * The MDBClient class invokes a test session bean, which will ask and the
+ * message driven bean to send a text, byte, map, stream, and object message to
+ * a topic Sun's EJB Reference Implementation.
+ */
+
+
+public class MDBClientIT {
+
+ @EJB(name = "ejb/MDB_SNDToTopic_Test")
+ private static MDB_T_Test hr;
+
+ private Properties props = new Properties();
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /* Test setup: */
+ /*
+ * @class.setup_props: jms_timeout; user; password
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ if (hr == null) {
+ throw new Exception("@EJB injection failed");
+ }
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ hr.setup(props);
+
+ if (hr.isThereSomethingInTheQueue()) {
+ logger.log(Logger.Level.TRACE, "Error: message(s) left in Q");
+ hr.cleanTheQueue();
+ } else {
+ logger.log(Logger.Level.TRACE, "Nothing left in queue");
+ }
+ logger.log(Logger.Level.INFO, "Setup ok;");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+ // Tests mdb sending jms messages
+ // Tests with Topic
+ // Tests with Text,Stream,Byte,Map and Object messages
+ //
+ /*
+ * @testName: mdbSendTextMsgToTopicTest
+ *
+ * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:109; JMS:JAVADOC:111;
+ * JMS:JAVADOC:91; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:99; JMS:JAVADOC:270; JMS:JAVADOC:522; JMS:JAVADOC:188;
+ * JMS:JAVADOC:198;
+ *
+ * @test_Strategy: Instruct the mdb to send a text msg. Create a stateful
+ * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send a
+ * message to a Topic Destination. handled by a message-driven bean Tell the mdb
+ * (MsgBeanToTopic) to send a text message with TopicPublisher to a topic that
+ * is handled by a second mdb(MsgBeanTopic). MsgBeanTopic verifies it received
+ * the message by sending another message to a Queue - MDB_QUEUE_REPLY.
+ *
+ */
+ @Test
+ public void mdbSendTextMsgToTopicTest() throws Exception {
+ String messageType = "TextMessage";
+ String matchMe = "TextMessageFromMsgBean";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send a text message;");
+ // subscribe
+ hr.askMDBToSendAMessage(messageType);
+ // getMessage
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendBytesMsgToTopicTest failed");
+ }
+ logger.log(Logger.Level.TRACE, "mdbSendTextMsgToTopicTest passed!");
+
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+
+ }
+
+ /*
+ * @testName: mdbSendBytesMsgToTopicTest
+ *
+ * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:109; JMS:JAVADOC:111;
+ * JMS:JAVADOC:91; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:99; JMS:JAVADOC:270; JMS:JAVADOC:522; JMS:JAVADOC:188;
+ * JMS:JAVADOC:198; JMS:JAVADOC:209; JMS:JAVADOC:562;
+ *
+ * @test_Strategy: Instruct the mdb to send a bytes msg. Create a stateful
+ * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send a
+ * message to a Topic Destination. handled by a message-driven bean Tell the mdb
+ * (MsgBeanToTopic) to send a bytes message with TopicPublisher to a topic that
+ * is handled by a second mdb(MsgBeanTopic). MsgBeanTopic verifies it received
+ * the message by sending another message to a Queue - MDB_QUEUE_REPLY.
+ *
+ */
+ @Test
+ public void mdbSendBytesMsgToTopicTest() throws Exception {
+ String messageType = "BytesMessage";
+ String matchMe = "BytesMessageFromMsgBean";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send a Bytes message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendBytesMsgToTopicTest failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbSendMapMsgToTopicTest
+ *
+ * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:109; JMS:JAVADOC:111;
+ * JMS:JAVADOC:91; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:99; JMS:JAVADOC:270; JMS:JAVADOC:522; JMS:JAVADOC:188;
+ * JMS:JAVADOC:198; JMS:JAVADOC:211; JMS:JAVADOC:473;
+ *
+ * @test_Strategy: Instruct the mdb to send a map msg. Create a stateful Session
+ * EJB Bean. Deploy it on the J2EE server. Have the EJB component send a message
+ * to a Topic Destination. handled by a message-driven bean Tell the mdb
+ * (MsgBeanToTopic) to send a map message with TopicPublisher to a topic that is
+ * handled by a second mdb(MsgBeanTopic). MsgBeanTopic verifies it received the
+ * message by sending another message to a Queue - MDB_QUEUE_REPLY.
+ *
+ */
+ @Test
+ public void mdbSendMapMsgToTopicTest() throws Exception {
+ String matchMe = "MapMessageFromMsgBean";
+ String messageType = "MapMessage";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send a map message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendMapMsgToTopicTest failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+
+ }
+
+ /*
+ * @testName: mdbSendStreamMsgToTopicTest
+ *
+ * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:109; JMS:JAVADOC:111;
+ * JMS:JAVADOC:91; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:99; JMS:JAVADOC:270; JMS:JAVADOC:522; JMS:JAVADOC:188;
+ * JMS:JAVADOC:198; JMS:JAVADOC:219; JMS:JAVADOC:166;
+ *
+ * @test_Strategy: Instruct the mdb to send a stream msg. Create a stateful
+ * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send a
+ * message to a Topic Destination. handled by a message-driven bean Tell the mdb
+ * (MsgBeanToTopic) to send a stream message with TopicPublisher to a topic that
+ * is handled by a second mdb(MsgBeanTopic). MsgBeanTopic verifies it received
+ * the message by sending another message to a Queue - MDB_QUEUE_REPLY.
+ *
+ */
+ @Test
+ public void mdbSendStreamMsgToTopicTest() throws Exception {
+ String matchMe = "StreamMessageFromMsgBean";
+ String messageType = "StreamMessage";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send a stream message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendStreamMsgToTopicTest failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: mdbSendObjectMsgToTopicTest
+ *
+ * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:109; JMS:JAVADOC:111;
+ * JMS:JAVADOC:91; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:99; JMS:JAVADOC:270; JMS:JAVADOC:522; JMS:JAVADOC:188;
+ * JMS:JAVADOC:198; JMS:JAVADOC:215; JMS:JAVADOC:289;
+ *
+ * @test_Strategy: Instruct the mdb to send an object msg. Create a stateful
+ * Session EJB Bean. Deploy it on the J2EE server. Have the EJB component send a
+ * message to a Topic Destination. handled by a message-driven bean Tell the mdb
+ * (MsgBeanToTopic) to send an object message with TopicPublisher to a topic
+ * that is handled by a second mdb(MsgBeanTopic). MsgBeanTopic verifies it
+ * received the message by sending another message to a Queue - MDB_QUEUE_REPLY.
+ *
+ */
+ @Test
+ public void mdbSendObjectMsgToTopicTest() throws Exception {
+ String matchMe = "ObjectMessageFromMsgBean";
+ String messageType = "ObjectMessage";
+ try {
+ // Have the EJB invoke the MDB
+ logger.log(Logger.Level.TRACE, "Call bean - have it tell mdb to send an object message;");
+ hr.askMDBToSendAMessage(messageType);
+ if (!hr.checkOnResponse(matchMe)) {
+ logger.log(Logger.Level.TRACE, "Error: didn't get expected response from mdb");
+ throw new Exception("ERROR: mdbSendObjectMsgToTopicTest failed");
+ }
+
+ logger.log(Logger.Level.TRACE, "Test passed!");
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MsgBeanToTopic.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MsgBeanToTopic.java
index bb88d64d9f..38cd5d16a6 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MsgBeanToTopic.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MsgBeanToTopic.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_sndToTopic;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.RemoteLoggingInitException;
@@ -45,189 +46,189 @@
public class MsgBeanToTopic implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- private MessageDrivenContext mdc = null;
-
- // JMS
- private TopicConnectionFactory tFactory = null;
-
- private TopicConnection tConnection = null;
-
- private Topic topic = null;
-
- private TopicPublisher mPublisher = null;
-
- private TopicSession tSession = null;
-
- public MsgBeanToTopic() {
- TestUtil.logTrace("@MsgBeanToTopic()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace("@MsgBeanToTopic-ejbCreate() !!");
- try {
- context = new TSNamingContext();
- tFactory = (TopicConnectionFactory) context
- .lookup("java:comp/env/jms/MyTopicConnectionFactory");
- topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC_REPLY");
- p = new Properties();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("@MsgBeanToTopic - onMessage! " + msg);
-
- try {
- tConnection = tFactory.createTopicConnection();
- tConnection.start();
- TestUtil.logTrace("started the connection !!");
-
- // Send a message back to acknowledge that the mdb received the message.
- tSession = tConnection.createTopicSession(true, 0);
-
- if (msg.getStringProperty("MessageType").equals("TextMessage")) {
- sendATextMessage();
- } else if (msg.getStringProperty("MessageType").equals("BytesMessage")) {
- sendABytesMessage();
- } else if (msg.getStringProperty("MessageType").equals("MapMessage")) {
- sendAMapMessage();
- } else if (msg.getStringProperty("MessageType").equals("StreamMessage")) {
- sendAStreamMessage();
- } else if (msg.getStringProperty("MessageType").equals("ObjectMessage")) {
- sendAnObjectMessage();
- } else {
- TestUtil.logTrace(
- "@onMessage - invalid message type found in StringProperty");
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- try {
- if (tConnection != null) {
- tConnection.close();
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- }
-
- // message bean helper methods follow.
- // Each method will send a simple message of the type requested.
- // this will send a text message to a Topic
-
- // must call init for logging to be properly performed
- public void initLogging(java.util.Properties p) {
- try {
- TestUtil.init(p);
- TestUtil.logTrace("MsgBean initLogging OK.");
- } catch (RemoteLoggingInitException e) {
- TestUtil.printStackTrace(e);
- TestUtil.logMsg("MsgBean initLogging failed.");
- throw new EJBException(e.getMessage());
- }
- }
-
- private void sendATextMessage() {
- TestUtil.logTrace("@MsgBean - sendATextMessage");
- try {
- String myMsg = "I am sending a text message as requested";
- // send a text message as requested to MDB_TOPIC_REPLY
- mPublisher = tSession.createPublisher(topic);
- TextMessage msg = tSession.createTextMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.setText(myMsg);
- msg.setStringProperty("MessageType", "TextMessageFromMsgBean");
- mPublisher.publish(msg);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void sendABytesMessage() {
- TestUtil.logTrace("@MsgBean - sendABytesMessage");
- try {
- byte aByte = 10;
- // send a bytes message as requested to MDB_TOPIC_REPLY
- mPublisher = tSession.createPublisher(topic);
- BytesMessage msg = tSession.createBytesMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.writeByte(aByte);
- msg.setStringProperty("MessageType", "BytesMessageFromMsgBean");
- mPublisher.publish(msg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void sendAMapMessage() {
- TestUtil.logTrace("@MsgBean - sendAMapMessage");
- try {
- String myMsg = "I am sending a map message as requested";
- // send a map message as requested to MDB_TOPIC_REPLY
- mPublisher = tSession.createPublisher(topic);
- MapMessage msg = tSession.createMapMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.setString("MapMessage", myMsg);
- msg.setStringProperty("MessageType", "MapMessageFromMsgBean");
- mPublisher.publish(msg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void sendAStreamMessage() {
- TestUtil.logTrace("@MsgBean - sendAStreamMessage");
- try {
- String myMsg = "I am sending a stream message as requested";
- // send a stream message as requested to MDB_TOPIC_REPLY
- mPublisher = tSession.createPublisher(topic);
- StreamMessage msg = tSession.createStreamMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.writeString(myMsg);
- msg.setStringProperty("MessageType", "StreamMessageFromMsgBean");
- mPublisher.publish(msg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void sendAnObjectMessage() {
- TestUtil.logTrace("@MsgBean - sendAnObjectMessage");
- try {
- String myMsg = "I am sending a text message as requested";
- // send an object message as requested to MDB_TOPIC_REPLY
- mPublisher = tSession.createPublisher(topic);
-
- ObjectMessage msg = tSession.createObjectMessage();
- JmsUtil.addPropsToMessage(msg, p);
- msg.setObject(myMsg);
- msg.setStringProperty("MessageType", "ObjectMessageFromMsgBean");
- mPublisher.publish(msg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace("In MsgBean::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil.logTrace("In MsgBean::remove()!!");
- }
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ private MessageDrivenContext mdc = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanToTopic.class.getName());
+
+ // JMS
+ private TopicConnectionFactory tFactory = null;
+
+ private TopicConnection tConnection = null;
+
+ private Topic topic = null;
+
+ private TopicPublisher mPublisher = null;
+
+ private TopicSession tSession = null;
+
+ public MsgBeanToTopic() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanToTopic()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanToTopic-ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ tFactory = (TopicConnectionFactory) context.lookup("java:comp/env/jms/MyTopicConnectionFactory");
+ topic = (Topic) context.lookup("java:comp/env/jms/MDB_TOPIC_REPLY");
+ p = new Properties();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "@MsgBeanToTopic - onMessage! " + msg);
+
+ try {
+ tConnection = tFactory.createTopicConnection();
+ tConnection.start();
+ logger.log(Logger.Level.TRACE, "started the connection !!");
+
+ // Send a message back to acknowledge that the mdb received the message.
+ tSession = tConnection.createTopicSession(true, 0);
+
+ if (msg.getStringProperty("MessageType").equals("TextMessage")) {
+ sendATextMessage();
+ } else if (msg.getStringProperty("MessageType").equals("BytesMessage")) {
+ sendABytesMessage();
+ } else if (msg.getStringProperty("MessageType").equals("MapMessage")) {
+ sendAMapMessage();
+ } else if (msg.getStringProperty("MessageType").equals("StreamMessage")) {
+ sendAStreamMessage();
+ } else if (msg.getStringProperty("MessageType").equals("ObjectMessage")) {
+ sendAnObjectMessage();
+ } else {
+ logger.log(Logger.Level.TRACE, "@onMessage - invalid message type found in StringProperty");
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ try {
+ if (tConnection != null) {
+ tConnection.close();
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ }
+
+ // message bean helper methods follow.
+ // Each method will send a simple message of the type requested.
+ // this will send a text message to a Topic
+
+ // must call init for logging to be properly performed
+ public void initLogging(java.util.Properties p) {
+ try {
+ TestUtil.init(p);
+ logger.log(Logger.Level.TRACE, "MsgBean initLogging OK.");
+ } catch (RemoteLoggingInitException e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "MsgBean initLogging failed.");
+ throw new EJBException(e.getMessage());
+ }
+ }
+
+ private void sendATextMessage() {
+ logger.log(Logger.Level.TRACE, "@MsgBean - sendATextMessage");
+ try {
+ String myMsg = "I am sending a text message as requested";
+ // send a text message as requested to MDB_TOPIC_REPLY
+ mPublisher = tSession.createPublisher(topic);
+ TextMessage msg = tSession.createTextMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.setText(myMsg);
+ msg.setStringProperty("MessageType", "TextMessageFromMsgBean");
+ mPublisher.publish(msg);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void sendABytesMessage() {
+ logger.log(Logger.Level.TRACE, "@MsgBean - sendABytesMessage");
+ try {
+ byte aByte = 10;
+ // send a bytes message as requested to MDB_TOPIC_REPLY
+ mPublisher = tSession.createPublisher(topic);
+ BytesMessage msg = tSession.createBytesMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.writeByte(aByte);
+ msg.setStringProperty("MessageType", "BytesMessageFromMsgBean");
+ mPublisher.publish(msg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void sendAMapMessage() {
+ logger.log(Logger.Level.TRACE, "@MsgBean - sendAMapMessage");
+ try {
+ String myMsg = "I am sending a map message as requested";
+ // send a map message as requested to MDB_TOPIC_REPLY
+ mPublisher = tSession.createPublisher(topic);
+ MapMessage msg = tSession.createMapMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.setString("MapMessage", myMsg);
+ msg.setStringProperty("MessageType", "MapMessageFromMsgBean");
+ mPublisher.publish(msg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void sendAStreamMessage() {
+ logger.log(Logger.Level.TRACE, "@MsgBean - sendAStreamMessage");
+ try {
+ String myMsg = "I am sending a stream message as requested";
+ // send a stream message as requested to MDB_TOPIC_REPLY
+ mPublisher = tSession.createPublisher(topic);
+ StreamMessage msg = tSession.createStreamMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.writeString(myMsg);
+ msg.setStringProperty("MessageType", "StreamMessageFromMsgBean");
+ mPublisher.publish(msg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void sendAnObjectMessage() {
+ logger.log(Logger.Level.TRACE, "@MsgBean - sendAnObjectMessage");
+ try {
+ String myMsg = "I am sending a text message as requested";
+ // send an object message as requested to MDB_TOPIC_REPLY
+ mPublisher = tSession.createPublisher(topic);
+
+ ObjectMessage msg = tSession.createObjectMessage();
+ JmsUtil.addPropsToMessage(msg, p);
+ msg.setObject(myMsg);
+ msg.setStringProperty("MessageType", "ObjectMessageFromMsgBean");
+ mPublisher.publish(msg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "In MsgBean::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "In MsgBean::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MsgBeanTopic.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MsgBeanTopic.java
index 84877d85c6..1f4492189b 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MsgBeanTopic.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_sndToTopic/MsgBeanTopic.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_sndToTopic;
+import java.lang.System.Logger;
import java.util.Properties;
import javax.sql.DataSource;
@@ -42,100 +43,100 @@
public class MsgBeanTopic implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- private MessageDrivenContext mdc = null;
-
- // JMS
- private QueueConnectionFactory queueConFactory = null;
-
- private TopicConnectionFactory topicConFactory = null;
-
- private DataSource dataSource = null;
-
- private QueueConnectionFactory qcFactory = null;
-
- private QueueConnection connection = null;
-
- private Queue replyQueue = null;
-
- public MsgBeanTopic() {
- TestUtil.logTrace("@MsgBeanTopic - @MsgBean()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace("@MsgBeanTopic - @MsgBean-ejbCreate() !!");
- try {
- TSNamingContext context = new TSNamingContext();
- qcFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- replyQueue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- p = new Properties();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
-
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace("@MsgBeanTopic - MsgBeanTopic - onMessage! " + msg);
-
- try {
- TestUtil.logTrace("In MsgBeanForTopic::onMessage() : " + msg);
- TestUtil.logTrace("calling sendReply");
- sendReply(msg);
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
-
- }
-
- private void sendReply(Message msg) {
- try {
- connection = qcFactory.createQueueConnection();
-
- // get the reply to queue
- System.out.println("From sendReply");
- connection.start();
- System.out.println("started the connection");
-
- QueueSession session = connection.createQueueSession(true, 0);
- jakarta.jms.TextMessage reply = session.createTextMessage();
- QueueSender replier = session.createSender(replyQueue);
- reply.setText("MDB Responding to message receipt");
- reply.setStringProperty("MessageType",
- msg.getStringProperty("MessageType"));
-
- TestUtil.logTrace("sending a msg to MDB_QUEUE_REPLY");
- replier.send(reply);
- System.out.println("Sent the message");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (connection != null) {
- try {
- connection.close();
- } catch (Exception ee) {
- TestUtil.printStackTrace(ee);
- }
- }
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace("In MsgBean::setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil.logTrace("In MsgBean::remove()!!");
- }
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ private MessageDrivenContext mdc = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanTopic.class.getName());
+
+ // JMS
+ private QueueConnectionFactory queueConFactory = null;
+
+ private TopicConnectionFactory topicConFactory = null;
+
+ private DataSource dataSource = null;
+
+ private QueueConnectionFactory qcFactory = null;
+
+ private QueueConnection connection = null;
+
+ private Queue replyQueue = null;
+
+ public MsgBeanTopic() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanTopic - @MsgBean()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanTopic - @MsgBean-ejbCreate() !!");
+ try {
+ TSNamingContext context = new TSNamingContext();
+ qcFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ replyQueue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ p = new Properties();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "@MsgBeanTopic - MsgBeanTopic - onMessage! " + msg);
+
+ try {
+ logger.log(Logger.Level.TRACE, "In MsgBeanForTopic::onMessage() : " + msg);
+ logger.log(Logger.Level.TRACE, "calling sendReply");
+ sendReply(msg);
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+
+ }
+
+ private void sendReply(Message msg) {
+ try {
+ connection = qcFactory.createQueueConnection();
+
+ // get the reply to queue
+ System.out.println("From sendReply");
+ connection.start();
+ System.out.println("started the connection");
+
+ QueueSession session = connection.createQueueSession(true, 0);
+ jakarta.jms.TextMessage reply = session.createTextMessage();
+ QueueSender replier = session.createSender(replyQueue);
+ reply.setText("MDB Responding to message receipt");
+ reply.setStringProperty("MessageType", msg.getStringProperty("MessageType"));
+
+ logger.log(Logger.Level.TRACE, "sending a msg to MDB_QUEUE_REPLY");
+ replier.send(reply);
+ System.out.println("Sent the message");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (connection != null) {
+ try {
+ connection.close();
+ } catch (Exception ee) {
+ TestUtil.printStackTrace(ee);
+ }
+ }
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "In MsgBean::setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "In MsgBean::remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_synchrec/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_synchrec/MDBClient.java
deleted file mode 100644
index 87e3831661..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_synchrec/MDBClient.java
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.mdb_synchrec;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.util.TSNamingContext;
-import com.sun.ts.lib.util.TSNamingContextInterface;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsUtil;
-
-import jakarta.jms.JMSException;
-import jakarta.jms.Message;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueConnection;
-import jakarta.jms.QueueConnectionFactory;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueSender;
-import jakarta.jms.QueueSession;
-import jakarta.jms.Session;
-import jakarta.jms.TextMessage;
-
-public class MDBClient extends EETest {
-
- // Naming specific member variables
- private TSNamingContextInterface context = null;
-
- private Properties props = null;
-
- private Queue mdbRcvrQueue;
-
- private Queue rcvrQueue;
-
- private QueueConnection qConnect;
-
- private Queue cmtQ;
-
- private QueueSession session;
-
- private QueueConnectionFactory qFactory;
-
- private QueueSender qSender;
-
- private String jmsUser = null;
-
- private String jmsPassword = null;
-
- private TextMessage msg = null;
-
- // get this from ts.jte
- long timeout;
-
- /* Run test in standalone mode */
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * Test setup:
- *
- * @class.setup_props: jms_timeout, in milliseconds - how long to wait on
- * synchronous receive; user;password;harness.log.port; harness.log.traceflag;
- *
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- jmsUser = p.getProperty("user");
- jmsPassword = p.getProperty("password");
- try {
- timeout = Integer.parseInt(p.getProperty("jms_timeout"));
-
- TestUtil.logTrace("in client setup");
-
- context = new TSNamingContext();
- TestUtil.logTrace("Client: Do lookups!");
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- cmtQ = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
- rcvrQueue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- mdbRcvrQueue = (Queue) context.lookup("java:comp/env/jms/MY_QUEUE");
- qConnect = qFactory.createQueueConnection(jmsUser, jmsPassword);
- session = qConnect.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- qConnect.start();
- cleanTheQueue(rcvrQueue);
- cleanTheQueue(mdbRcvrQueue);
-
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
- /* Run tests */
-
- /*
- * @testName: test1
- *
- * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:270; JMS:JAVADOC:522;
- * JMS:JAVADOC:188; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
- * JMS:JAVADOC:198; JMS:JAVADOC:184; JMS:JAVADOC:334; JMS:JAVADOC:405;
- *
- * @test_Strategy: Verify synchronous receive in an mdb. send a msg to
- * MDB_QURUR_REPLY - mdb will do a synchronous rec on it Invoke a cmt mdb by
- * writing to MDB_QUEUE In onMessage mdb method, do a synchronous receive
- * Notify the client by sending a message to QUEUE_REPLY if mdb was able to
- * successfully receive the message
- *
- */
- public void test1() throws Exception {
- String TestCase = "syncRecTest1";
- int TestNum = 1;
- String mdbMessage = "my mdb message";
-
- try {
- // create a text message
- createTestMessage(TestCase, TestNum);
- // send a message to receiver queue that the mdb can synchronously receive
- qSender = session.createSender(mdbRcvrQueue);
- // send the message to invoke mdb
- JmsUtil.addPropsToMessage(msg, props);
- msg.setStringProperty("TestCase", mdbMessage);
- qSender.send(msg);
-
- msg.setStringProperty("COM_SUN_JMS_TESTNAME", TestCase);
- qSender = session.createSender(cmtQ);
- // send the message to invoke mdb
- qSender.send(msg);
-
- // verify that message was requeued and pass
- TestCase = "mdbResponse";
- if (!checkOnResponse(TestCase)) {
- throw new Exception("syncRecTest1 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /* cleanup -- none in this case */
- public void cleanup() throws Exception {
- try {
- msg = null;
- if (qConnect != null) {
- qConnect.close();
- }
- logMsg("End of client cleanup;");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void createTestMessage(String TestCase, int num) {
- String myMessage = "MDB synchronous receive test";
- try {
- msg = session.createTextMessage();
- msg.setStringProperty("user", jmsUser);
- msg.setStringProperty("password", jmsPassword);
- msg.setText(myMessage);
- msg.setIntProperty("TestCaseNum", num);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logMsg("Error setting user and password in jms msg");
- }
- }
-
- public boolean checkOnResponse(String prop) {
- boolean status = false;
- try {
- TestUtil.logTrace("@checkOnResponse");
- for (int i = 0; i < 10; i++) {
- status = getMessage(session, prop);
- if (status)
- break;
- }
- TestUtil.logTrace("Close the session");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- return status;
- }
-
- private boolean getMessage(QueueSession session, String prop)
- throws Exception {
- try {
- TestUtil.logTrace("top of getMessage");
- boolean gotit = false;
- String selector = "TestCase = 'mdbResponse'";
- QueueReceiver rcvr = session.createReceiver(rcvrQueue, selector);
- // dequeue the response from the mdb
- Message msgRec = null;
- msgRec = rcvr.receive(timeout);
- if (msgRec == null) {
- // not good
- TestUtil.logTrace("No message to receive!!!");
- } else {
- TestUtil.logTrace("Success: getMessage received a msg!!!");
- gotit = recvMessageInternal(msgRec, prop);
- }
-
- return gotit;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logErr("exception: ", e);
- throw new Exception("getMessage threw an exception!");
- }
-
- }
-
- private boolean recvMessageInternal(Message msgRec, String prop)
- throws JMSException {
- boolean retcode = false;
- TestUtil.logTrace("@recvMessageInternal");
- if (msgRec != null) {
-
- TestUtil.logTrace("Msg: " + msgRec.toString());
- TestUtil.logTrace("TestCase: " + msgRec.getStringProperty("TestCase"));
- TestUtil.logTrace("Status: " + msgRec.getStringProperty("Status"));
- TestUtil.logTrace("=================================================");
- TestUtil.logTrace("Msg: " + msgRec.toString());
-
- if (msgRec.getStringProperty("TestCase").equals(prop)
- && msgRec.getStringProperty("Status").equals("Pass")) {
- TestUtil.logTrace("TestCase: " + msgRec.getStringProperty("TestCase"));
- TestUtil
- .logTrace("Status from msg: " + msgRec.getStringProperty("Status"));
- TestUtil.logTrace("Pass: we got the expected msg back! ");
- retcode = true;
- } else if (msgRec.getStringProperty("Status").equals("Fail")) {
- TestUtil.logTrace("TestCase: " + msgRec.getStringProperty("TestCase"));
- TestUtil
- .logTrace("Status from msg: " + msgRec.getStringProperty("Status"));
- TestUtil.logTrace("Fail: Error(s) occurred! ");
- } else {
- TestUtil.logTrace("Fail: we didnt get the expected msg back! ");
- TestUtil.logTrace("TestCase: " + msgRec.getStringProperty("TestCase"));
- }
- } else if (msgRec == null) {
- TestUtil.logTrace("Fail: we didnt get the expected msg back! ");
- }
- return retcode;
- }
-
- private void cleanTheQueue(Queue q) {
-
- try {
- // make sure nothing is left in QUEUE_REPLY
- TestUtil.logTrace("Check if any messages left in queue");
- QueueReceiver qR = session.createReceiver(q);
- Message msg = qR.receive(timeout);
- while (msg != null) {
- TestUtil.logTrace("Cleaned up a message in QUEUE!");
- msg = qR.receive(timeout);
- }
- qR.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logTrace("Error in cleanTheQueue");
- }
-
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_synchrec/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_synchrec/MDBClientIT.java
new file mode 100644
index 0000000000..8c78a15581
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_synchrec/MDBClientIT.java
@@ -0,0 +1,278 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.mdb_synchrec;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TSNamingContext;
+import com.sun.ts.lib.util.TSNamingContextInterface;
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsUtil;
+
+import jakarta.jms.JMSException;
+import jakarta.jms.Message;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueConnection;
+import jakarta.jms.QueueConnectionFactory;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueSender;
+import jakarta.jms.QueueSession;
+import jakarta.jms.Session;
+import jakarta.jms.TextMessage;
+
+
+public class MDBClientIT {
+
+ // Naming specific member variables
+ private TSNamingContextInterface context = null;
+
+ private Properties props = new Properties();
+
+ private Queue mdbRcvrQueue;
+
+ private Queue rcvrQueue;
+
+ private QueueConnection qConnect;
+
+ private Queue cmtQ;
+
+ private QueueSession session;
+
+ private QueueConnectionFactory qFactory;
+
+ private QueueSender qSender;
+
+ private String jmsUser = null;
+
+ private String jmsPassword = null;
+
+ private TextMessage msg = null;
+
+ // get this from ts.jte
+ long timeout;
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /*
+ * Test setup:
+ *
+ * @class.setup_props: jms_timeout, in milliseconds - how long to wait on
+ * synchronous receive; user;password
+ *
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ jmsUser = System.getProperty("user");
+ jmsPassword = System.getProperty("password");
+ try {
+ timeout = Integer.parseInt(System.getProperty("jms_timeout"));
+
+ logger.log(Logger.Level.TRACE, "in client setup");
+
+ context = new TSNamingContext();
+ logger.log(Logger.Level.TRACE, "Client: Do lookups!");
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ cmtQ = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
+ rcvrQueue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ mdbRcvrQueue = (Queue) context.lookup("java:comp/env/jms/MY_QUEUE");
+ qConnect = qFactory.createQueueConnection(jmsUser, jmsPassword);
+ session = qConnect.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ qConnect.start();
+ cleanTheQueue(rcvrQueue);
+ cleanTheQueue(mdbRcvrQueue);
+
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+ /* Run tests */
+
+ /*
+ * @testName: test1
+ *
+ * @assertion_ids: JavaEE:SPEC:214; JMS:JAVADOC:270; JMS:JAVADOC:522;
+ * JMS:JAVADOC:188; JMS:JAVADOC:221; JMS:JAVADOC:120; JMS:JAVADOC:425;
+ * JMS:JAVADOC:198; JMS:JAVADOC:184; JMS:JAVADOC:334; JMS:JAVADOC:405;
+ *
+ * @test_Strategy: Verify synchronous receive in an mdb. send a msg to
+ * MDB_QURUR_REPLY - mdb will do a synchronous rec on it Invoke a cmt mdb by
+ * writing to MDB_QUEUE In onMessage mdb method, do a synchronous receive Notify
+ * the client by sending a message to QUEUE_REPLY if mdb was able to
+ * successfully receive the message
+ *
+ */
+ @Test
+ public void test1() throws Exception {
+ String TestCase = "syncRecTest1";
+ int TestNum = 1;
+ String mdbMessage = "my mdb message";
+
+ try {
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ // send a message to receiver queue that the mdb can synchronously receive
+ qSender = session.createSender(mdbRcvrQueue);
+ // send the message to invoke mdb
+ JmsUtil.addPropsToMessage(msg, props);
+ msg.setStringProperty("TestCase", mdbMessage);
+ qSender.send(msg);
+
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", TestCase);
+ qSender = session.createSender(cmtQ);
+ // send the message to invoke mdb
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ TestCase = "mdbResponse";
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("syncRecTest1 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /* cleanup -- none in this case */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ msg = null;
+ if (qConnect != null) {
+ qConnect.close();
+ }
+ logger.log(Logger.Level.INFO, "End of client cleanup;");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void createTestMessage(String TestCase, int num) {
+ String myMessage = "MDB synchronous receive test";
+ try {
+ msg = session.createTextMessage();
+ msg.setStringProperty("user", jmsUser);
+ msg.setStringProperty("password", jmsPassword);
+ msg.setText(myMessage);
+ msg.setIntProperty("TestCaseNum", num);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error setting user and password in jms msg");
+ }
+ }
+
+ public boolean checkOnResponse(String prop) {
+ boolean status = false;
+ try {
+ logger.log(Logger.Level.TRACE, "@checkOnResponse");
+ for (int i = 0; i < 10; i++) {
+ status = getMessage(session, prop);
+ if (status)
+ break;
+ }
+ logger.log(Logger.Level.TRACE, "Close the session");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ return status;
+ }
+
+ private boolean getMessage(QueueSession session, String prop) throws Exception {
+ try {
+ logger.log(Logger.Level.TRACE, "top of getMessage");
+ boolean gotit = false;
+ String selector = "TestCase = 'mdbResponse'";
+ QueueReceiver rcvr = session.createReceiver(rcvrQueue, selector);
+ // dequeue the response from the mdb
+ Message msgRec = null;
+ msgRec = rcvr.receive(timeout);
+ if (msgRec == null) {
+ // not good
+ logger.log(Logger.Level.TRACE, "No message to receive!!!");
+ } else {
+ logger.log(Logger.Level.TRACE, "Success: getMessage received a msg!!!");
+ gotit = recvMessageInternal(msgRec, prop);
+ }
+
+ return gotit;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.ERROR, "exception: ", e);
+ throw new Exception("getMessage threw an exception!");
+ }
+
+ }
+
+ private boolean recvMessageInternal(Message msgRec, String prop) throws JMSException {
+ boolean retcode = false;
+ logger.log(Logger.Level.TRACE, "@recvMessageInternal");
+ if (msgRec != null) {
+
+ logger.log(Logger.Level.TRACE, "Msg: " + msgRec.toString());
+ logger.log(Logger.Level.TRACE, "TestCase: " + msgRec.getStringProperty("TestCase"));
+ logger.log(Logger.Level.TRACE, "Status: " + msgRec.getStringProperty("Status"));
+ logger.log(Logger.Level.TRACE, "=================================================");
+ logger.log(Logger.Level.TRACE, "Msg: " + msgRec.toString());
+
+ if (msgRec.getStringProperty("TestCase").equals(prop)
+ && msgRec.getStringProperty("Status").equals("Pass")) {
+ logger.log(Logger.Level.TRACE, "TestCase: " + msgRec.getStringProperty("TestCase"));
+ logger.log(Logger.Level.TRACE, "Status from msg: " + msgRec.getStringProperty("Status"));
+ logger.log(Logger.Level.TRACE, "Pass: we got the expected msg back! ");
+ retcode = true;
+ } else if (msgRec.getStringProperty("Status").equals("Fail")) {
+ logger.log(Logger.Level.TRACE, "TestCase: " + msgRec.getStringProperty("TestCase"));
+ logger.log(Logger.Level.TRACE, "Status from msg: " + msgRec.getStringProperty("Status"));
+ logger.log(Logger.Level.TRACE, "Fail: Error(s) occurred! ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: we didnt get the expected msg back! ");
+ logger.log(Logger.Level.TRACE, "TestCase: " + msgRec.getStringProperty("TestCase"));
+ }
+ } else if (msgRec == null) {
+ logger.log(Logger.Level.TRACE, "Fail: we didnt get the expected msg back! ");
+ }
+ return retcode;
+ }
+
+ private void cleanTheQueue(Queue q) {
+
+ try {
+ // make sure nothing is left in QUEUE_REPLY
+ logger.log(Logger.Level.TRACE, "Check if any messages left in queue");
+ QueueReceiver qR = session.createReceiver(q);
+ Message msg = qR.receive(timeout);
+ while (msg != null) {
+ logger.log(Logger.Level.TRACE, "Cleaned up a message in QUEUE!");
+ msg = qR.receive(timeout);
+ }
+ qR.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.TRACE, "Error in cleanTheQueue");
+ }
+
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_synchrec/MsgBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_synchrec/MsgBean.java
index 0c57742b23..ceaa1390b3 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_synchrec/MsgBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/mdb_synchrec/MsgBean.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.mdb_synchrec;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.TSNamingContext;
@@ -41,115 +42,113 @@
public class MsgBean implements MessageDrivenBean, MessageListener {
- // properties object needed for logging,
- // get this from the message object passed into
- // the onMessage method.
- private java.util.Properties p = null;
-
- // Contexts
- private TSNamingContext context = null;
-
- protected MessageDrivenContext mdc = null;
-
- // JMS PTP
- private QueueConnectionFactory qFactory;
-
- private QueueConnection qConnection = null;
-
- private Queue queueR = null;
-
- private Queue queueS = null;
-
- private QueueSender mSender = null;
-
- private boolean result = false;
-
- public MsgBean() {
- TestUtil.logTrace("@MsgBean()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace(
- "In Message Bean ======================================EJBCreate");
- try {
-
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- queueR = (Queue) context.lookup("java:comp/env/jms/MY_QUEUE");
- queueS = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- p = new Properties();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error", e);
- }
- }
-
- public void onMessage(Message msg) {
- long timeout = 10000;
- QueueSession qSession = null;
- TextMessage messageSent = null;
- TextMessage msgRec = null;
- String mdbMessage = "my mdb message";
- String testName = null;
- QueueSender qSender = null;
- QueueReceiver rcvr = null;
- boolean result = false;
-
- JmsUtil.initHarnessProps(msg, p);
- TestUtil.logTrace(
- "In Message Bean ======================================onMessage");
- try {
- testName = "mdbResponse";
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null)
- throw new EJBException("MDB connection Error!");
-
- qConnection.start();
-
- qSession = qConnection.createQueueSession(true, 0);
- TestUtil.logTrace("will run TestCase: " + testName);
-
- rcvr = qSession.createReceiver(queueR);
-
- TestUtil.logTrace("Verify the synchronous receive");
- TestUtil.logTrace(
- "HHHHHHHHHHHHH+++++++++ Trying to receive message from the Queue: ");
- msgRec = (TextMessage) rcvr.receive(timeout);
-
- if (msgRec != null) {
- //
- TestUtil.logTrace("mdb received a msg from MY_QUEUE");
- if (msgRec.getStringProperty("TestCase").equals(mdbMessage)) {
- TestUtil.logTrace("Success: Correct msg recvd from MY_QUEUE");
- result = true;
- }
- }
- // send results to QUEUE_REPLY
-
- JmsUtil.sendTestResults(testName, result, qSession, queueS);
- TestUtil.logTrace("Mdb test results send to queue reply");
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace("@MsgBean:setMessageDrivenContext()!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil.logTrace("@ejbRemove()");
- }
+ // properties object needed for logging,
+ // get this from the message object passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
+
+ // Contexts
+ private TSNamingContext context = null;
+
+ protected MessageDrivenContext mdc = null;
+
+ // JMS PTP
+ private QueueConnectionFactory qFactory;
+
+ private QueueConnection qConnection = null;
+
+ private Queue queueR = null;
+
+ private Queue queueS = null;
+
+ private QueueSender mSender = null;
+
+ private boolean result = false;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBean.class.getName());
+
+ public MsgBean() {
+ logger.log(Logger.Level.TRACE, "@MsgBean()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "In Message Bean ======================================EJBCreate");
+ try {
+
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ queueR = (Queue) context.lookup("java:comp/env/jms/MY_QUEUE");
+ queueS = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ p = new Properties();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+ long timeout = 10000;
+ QueueSession qSession = null;
+ TextMessage messageSent = null;
+ TextMessage msgRec = null;
+ String mdbMessage = "my mdb message";
+ String testName = null;
+ QueueSender qSender = null;
+ QueueReceiver rcvr = null;
+ boolean result = false;
+
+ JmsUtil.initHarnessProps(msg, p);
+ logger.log(Logger.Level.TRACE, "In Message Bean ======================================onMessage");
+ try {
+ testName = "mdbResponse";
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null)
+ throw new EJBException("MDB connection Error!");
+
+ qConnection.start();
+
+ qSession = qConnection.createQueueSession(true, 0);
+ logger.log(Logger.Level.TRACE, "will run TestCase: " + testName);
+
+ rcvr = qSession.createReceiver(queueR);
+
+ logger.log(Logger.Level.TRACE, "Verify the synchronous receive");
+ logger.log(Logger.Level.TRACE, "HHHHHHHHHHHHH+++++++++ Trying to receive message from the Queue: ");
+ msgRec = (TextMessage) rcvr.receive(timeout);
+
+ if (msgRec != null) {
+ //
+ logger.log(Logger.Level.TRACE, "mdb received a msg from MY_QUEUE");
+ if (msgRec.getStringProperty("TestCase").equals(mdbMessage)) {
+ logger.log(Logger.Level.TRACE, "Success: Correct msg recvd from MY_QUEUE");
+ result = true;
+ }
+ }
+ // send results to QUEUE_REPLY
+
+ JmsUtil.sendTestResults(testName, result, qSession, queueS);
+ logger.log(Logger.Level.TRACE, "Mdb test results send to queue reply");
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "@MsgBean:setMessageDrivenContext()!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "@ejbRemove()");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/xa/MDBClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/xa/MDBClient.java
deleted file mode 100644
index b42b9981aa..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/xa/MDBClient.java
+++ /dev/null
@@ -1,475 +0,0 @@
-/*
- * Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee.mdb.xa;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.util.TestUtil;
-import com.sun.ts.tests.jms.common.JmsUtil;
-import com.sun.ts.tests.jms.commonee.Client;
-
-import jakarta.jms.JMSException;
-import jakarta.jms.Message;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueReceiver;
-import jakarta.jms.QueueSession;
-import jakarta.jms.Topic;
-
-public class MDBClient extends Client {
-
- private Queue cmtQ;
-
- private Queue bmtQ;
-
- private Topic bmtT;
-
- private Topic cmtT;
-
- /* Run test in standalone mode */
- public static void main(String[] args) {
- MDBClient theTests = new MDBClient();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * Test setup:
- *
- * @class.setup_props: jms_timeout, in milliseconds - how long to wait on
- * synchronous receive; user; password;
- */
- public void setup(String[] args, Properties p) throws Exception {
-
- props = p;
- super.setup(args, p);
-
- try {
- cmtQ = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_CMT");
- bmtQ = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_BMT");
- rcvrQueue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
-
- bmtT = (Topic) context.lookup("java:comp/env/jms/MDB_DURABLE_BMT");
- cmtT = (Topic) context.lookup("java:comp/env/jms/MDB_DURABLE_CMT");
- } catch (Exception e) {
- throw new Exception("Setup Failed!", e);
- }
- }
-
- /* Run tests */
-
- /*
- * @testName: Test1
- *
- * @assertion_ids: JMS:SPEC:13; JMS:SPEC:129; JMS:SPEC:246.10;
- * JMS:JAVADOC:371; EJB:SPEC:586.1; EJB:SPEC:586.1.1; EJB:SPEC:583.2;
- * EJB:SPEC:583.2.1;
- *
- * @test_Strategy: Send a test message to a container managed queue. The mdb
- * tests if this is the first time this message was received by checking the
- * JMSRedelivered flag. Rollback the msg. Second time the msg is received is a
- * pass! If the message is not requeued and received again this is a failure.
- */
-
- public void Test1() throws Exception {
- String TestCase = "xaTest1";
- int TestNum = 1;
- try {
- // construct a message for this test case
- qSender = session.createSender(cmtQ);
- // set up password and username
- createTestMessage(TestCase, TestNum);
- JmsUtil.addPropsToMessage(msg, props);
- System.out.println("Client: sending test message");
- // send the message
- qSender.send(msg);
- // verify that message was requeued and pass
- System.out.println("Client: response message");
- if (!checkOnResponse(TestCase)) {
- throw new Exception("oops! error!");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test2
- *
- * @assertion_ids: EJB:SPEC:586.1; EJB:SPEC:586.1.1; EJB:SPEC:583.2;
- * EJB:SPEC:583.2.1; JMS:SPEC:13; JMS:SPEC:129; JMS:SPEC:246.10;
- * JMS:JAVADOC:371;
- *
- * @test_Strategy: Send a test message to a container managed topic. The mdb
- * tests if this is the first time this message was received by checking the
- * JMSRedelivered flag. Send a msg, rollback. Second time the msg is received
- * is a pass! If the message is not requeued and received again this is a
- * failure.
- */
- public void Test2() throws Exception {
- String TestCase = "xaTest2";
- int TestNum = 2;
- try {
-
- // construct a message for this test case
- tPub = tSession.createPublisher(cmtT);
- // create a text message
- createTestMessage(TestCase, TestNum);
- JmsUtil.addPropsToMessage(msg, props);
- // send the message
- tPub.publish(msg);
- // verify that message was requeued and pass
- System.out.println("Client: response message");
- if (!checkOnResponse(TestCase)) {
- throw new Exception("oops! error!");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test3
- *
- * @assertion_ids: EJB:SPEC:509; EJB:SPEC:510;
- *
- * @test_Strategy: Send a test message to a container managed queue. Check
- * rollback status with getRollbackOnly Should be false for not set for
- * rollback! If not test fails
- *
- */
- public void Test3() throws Exception {
- String TestCase = "xaTest3";
- int TestNum = 3;
- try {
- qSender = session.createSender(cmtQ);
- // create a text message
- createTestMessage(TestCase, TestNum);
- JmsUtil.addPropsToMessage(msg, props);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test3 - getRollbackOnly returned wrong value");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test4
- *
- * @assertion_ids: EJB:SPEC:511;
- *
- * @test_Strategy: Send a test message to a bean managed queue. Check the
- * transaction status.
- *
- */
- public void Test4() throws Exception {
- String TestCase = "xaTest4";
- int TestNum = 4;
- try {
-
- qSender = session.createSender(bmtQ);
- // create a text message
- createTestMessage(TestCase, TestNum);
- JmsUtil.addPropsToMessage(msg, props);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test4 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test5
- *
- * @assertion_ids: EJB:SPEC:543; EJB:SPEC:543.1;
- *
- * @test_Strategy: Invoke an bmt mdb by writing to MDB_QUEUE_BMT. mdb begins a
- * transaction, sends a msg to MDB_QUEUE. mdb commits. Verify that MDB_QUEUE
- * has the msg sent. .
- *
- */
- public void Test5() throws Exception {
- String TestCase = "xaTest5";
- int TestNum = 5;
- try {
-
- qSender = session.createSender(bmtQ);
- // create a text message
- createTestMessage(TestCase, TestNum);
- JmsUtil.addPropsToMessage(msg, props);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test5 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test6
- *
- * @assertion_ids: EJB:SPEC:543; EJB:SPEC:543.1;
- *
- * @test_Strategy: Invoke an bmt mdb by writing to MDB_DURABLE_BMT. mdb begins
- * a transaction, sends a msg to MDB_QUEUE_REPLY. mdb commits. Verify that
- * MDB_QUEUE_REPLY has the msg sent.
- *
- */
- public void Test6() throws Exception {
- String TestCase = "xaTest6";
- int TestNum = 6;
- try {
- tPub = tSession.createPublisher(bmtT);
- // create a text message
- createTestMessage(TestCase, TestNum);
- JmsUtil.addPropsToMessage(msg, props);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test6 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test7
- *
- * @assertion_ids: JMS:SPEC:13; JMS:SPEC:129; JMS:SPEC:246.10;
- * JMS:JAVADOC:371; EJB:SPEC:586.1; EJB:SPEC:586.1.1; EJB:SPEC:583.2;
- * EJB:SPEC:583.2.1;
- *
- * @test_Strategy: Send a test message to a container managed topic. The mdb
- * tests if this is the first time this message was received by checking the
- * JMSRedelivered flag. Second time the msg is received is a a pass! If the
- * message is not requeued and received again this is a failure.
- */
- public void Test7() throws Exception {
- String TestCase = "xaTest7";
- int TestNum = 7;
- try {
- // construct a message for this test case
- tPub = tSession.createPublisher(cmtT);
- // create a text message
- createTestMessage(TestCase, TestNum);
- JmsUtil.addPropsToMessage(msg, props);
- msg.setStringProperty("TestCase", TestCase);
- // send the message
- tPub.publish(msg);
- // verify that message was requeued and pass
- System.out.println("Client: response message");
- if (!checkOnResponse(TestCase)) {
- throw new Exception("oops! error!");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test8
- *
- * @assertion_ids: EJB:SPEC:547.2;
- *
- * @test_Strategy: Invoke an bmt mdb by writing to MDB_QUEUE_BMT. mdb begins a
- * transaction, sends a msg to MDB_QUEUE. then rollsback. Verify the 2nd msg
- * is received.
- *
- *
- */
- public void Test8() throws Exception {
- String TestCase = "xaTest8";
- int TestNum = 8;
- try {
-
- qSender = session.createSender(bmtQ);
- // create a text message
- createTestMessage(TestCase, TestNum);
- JmsUtil.addPropsToMessage(msg, props);
- // send the message
- qSender.send(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test8 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test9
- *
- * @assertion_ids: EJB:SPEC:547.2;
- *
- * @test_Strategy: Invoke an bmt mdb by writing to MDB_DURABLE_BMT. mdb begins
- * a transaction, sends a msg to MDB_QUEUE_REPLY. then rollsback. Send msg and
- * commits. Verify the 2nd msg is received.
- *
- *
- */
- public void Test9() throws Exception {
- String TestCase = "xaTest9";
- int TestNum = 9;
- try {
-
- tPub = tSession.createPublisher(bmtT);
- // create a text message
- createTestMessage(TestCase, TestNum);
- JmsUtil.addPropsToMessage(msg, props);
- // send the message
- tPub.publish(msg);
-
- // verify that message was requeued and pass
- if (!checkOnResponse(TestCase)) {
- throw new Exception("Test9 - ");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- /*
- * @testName: Test10
- *
- * @assertion_ids: JMS:SPEC:13; JMS:SPEC:129; JMS:SPEC:246.10;
- * JMS:JAVADOC:371; EJB:SPEC:586.1; EJB:SPEC:586.1.1; EJB:SPEC:583.2;
- * EJB:SPEC:583.2.1;
- *
- * @test_Strategy: Send a test message to a container managed queue. The mdb
- * tests if this is the first time this message was received by checking the
- * JMSRedelivered flag. Send a msg, rollback. send a second message, pass if
- * 2nd msg received.
- *
- *
- */
- public void Test10() throws Exception {
- String TestCase = "xaTest10";
- int TestNum = 10;
- try {
-
- // construct a message for this test case
- qSender = session.createSender(cmtQ);
- // create a text message
- createTestMessage(TestCase, TestNum);
- JmsUtil.addPropsToMessage(msg, props);
- // send the message
- qSender.send(msg);
- // verify that message was requeued and pass
- System.out.println("Client: response message");
- if (!checkOnResponse(TestCase)) {
- throw new Exception("oops! error!");
- }
- } catch (Exception e) {
- throw new Exception("Test Failed!", e);
- }
- }
-
- public void createTestMessage(String TestCase, int num) {
- String myMessage = "Transaction tests";
- try {
- msg = session.createTextMessage();
- msg.setStringProperty("user", jmsUser);
- msg.setStringProperty("password", jmsPassword);
- msg.setText(myMessage);
- msg.setIntProperty("TestCaseNum", num);
- msg.setStringProperty("COM_SUN_JMS_TESTNAME", TestCase);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- TestUtil.logMsg("Error setting user and password in jms msg");
- }
- }
-
- public boolean checkOnResponse(String prop) {
- boolean status = false;
- try {
- TestUtil.logTrace("@checkOnResponse");
- status = recvMessageInternal(session, prop);
- TestUtil.logTrace("Close the session");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- return status;
- }
-
- public boolean recvMessageInternal(QueueSession session, String prop)
- throws JMSException {
- boolean retcode = false;
- TestUtil.logTrace("@recvMessageInternal");
- // Create a message producer.
- QueueReceiver rcvr = session.createReceiver(rcvrQueue);
- // dequeue the response from the mdb
- Message msgRec = null;
-
- for (int i = 0; i < 10; ++i) {
- TestUtil
- .logTrace("@recvMessageInternal trying to receive the message: " + i);
- msgRec = rcvr.receive(timeout);
- if (msgRec != null) {
- break;
- }
- } // end for loop
- if (msgRec != null) {
- if (msgRec.getStringProperty("TestCase").equals(prop)
- && msgRec.getStringProperty("Status").equals("Pass")) {
- TestUtil.logTrace("TestCase: " + msgRec.getStringProperty("TestCase"));
- TestUtil
- .logTrace("Status from msg: " + msgRec.getStringProperty("Status"));
- TestUtil.logTrace("Pass: we got the expected msg back! ");
- retcode = true;
- } else if (msgRec.getStringProperty("Status").equals("Fail")) {
- TestUtil.logTrace("TestCase: " + msgRec.getStringProperty("TestCase"));
- TestUtil
- .logTrace("Status from msg: " + msgRec.getStringProperty("Status"));
- TestUtil.logTrace("Fail: Error(s) occurred! ");
- } else {
- TestUtil.logTrace("Fail: we didnt get the expected msg back! ");
- TestUtil.logTrace("TestCase: " + msgRec.getStringProperty("TestCase"));
- }
- } else if (msgRec == null) {
- TestUtil.logTrace("Fail: we didnt get the expected msg back! ");
- }
- return retcode;
- }
-
- private void cleanTheQueue() {
- // make sure nothing is left in QUEUE_REPLY
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/xa/MDBClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/xa/MDBClientIT.java
new file mode 100644
index 0000000000..e7c2e2c532
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/xa/MDBClientIT.java
@@ -0,0 +1,480 @@
+/*
+ * Copyright (c) 2007, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee.mdb.xa;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TestUtil;
+import com.sun.ts.tests.jms.common.JmsUtil;
+import com.sun.ts.tests.jms.commonee.Client;
+
+import jakarta.jms.JMSException;
+import jakarta.jms.Message;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueReceiver;
+import jakarta.jms.QueueSession;
+import jakarta.jms.Topic;
+
+
+public class MDBClientIT extends Client {
+
+ private Queue cmtQ;
+
+ private Queue bmtQ;
+
+ private Topic bmtT;
+
+ private Topic cmtT;
+
+ private static final Logger logger = (Logger) System.getLogger(MDBClientIT.class.getName());
+
+ /*
+ * Test setup:
+ *
+ * @class.setup_props: jms_timeout, in milliseconds - how long to wait on
+ * synchronous receive; user; password;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ props = new Properties();
+
+ props.put("jms_timeout", System.getProperty("jms_property"));
+ props.put("user", System.getProperty("user"));
+ props.put("password", System.getProperty("password"));
+
+ super.setup(new String[0], props);
+
+ try {
+ cmtQ = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_CMT");
+ bmtQ = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_BMT");
+ rcvrQueue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+
+ bmtT = (Topic) context.lookup("java:comp/env/jms/MDB_DURABLE_BMT");
+ cmtT = (Topic) context.lookup("java:comp/env/jms/MDB_DURABLE_CMT");
+ } catch (Exception e) {
+ throw new Exception("Setup Failed!", e);
+ }
+ }
+
+ /* Run tests */
+
+ /*
+ * @testName: Test1
+ *
+ * @assertion_ids: JMS:SPEC:13; JMS:SPEC:129; JMS:SPEC:246.10; JMS:JAVADOC:371;
+ * EJB:SPEC:586.1; EJB:SPEC:586.1.1; EJB:SPEC:583.2; EJB:SPEC:583.2.1;
+ *
+ * @test_Strategy: Send a test message to a container managed queue. The mdb
+ * tests if this is the first time this message was received by checking the
+ * JMSRedelivered flag. Rollback the msg. Second time the msg is received is a
+ * pass! If the message is not requeued and received again this is a failure.
+ */
+ @Test
+ public void Test1() throws Exception {
+ String TestCase = "xaTest1";
+ int TestNum = 1;
+ try {
+ // construct a message for this test case
+ qSender = session.createSender(cmtQ);
+ // set up password and username
+ createTestMessage(TestCase, TestNum);
+ JmsUtil.addPropsToMessage(msg, props);
+ System.out.println("Client: sending test message");
+ // send the message
+ qSender.send(msg);
+ // verify that message was requeued and pass
+ System.out.println("Client: response message");
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("oops! error!");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test2
+ *
+ * @assertion_ids: EJB:SPEC:586.1; EJB:SPEC:586.1.1; EJB:SPEC:583.2;
+ * EJB:SPEC:583.2.1; JMS:SPEC:13; JMS:SPEC:129; JMS:SPEC:246.10;
+ * JMS:JAVADOC:371;
+ *
+ * @test_Strategy: Send a test message to a container managed topic. The mdb
+ * tests if this is the first time this message was received by checking the
+ * JMSRedelivered flag. Send a msg, rollback. Second time the msg is received is
+ * a pass! If the message is not requeued and received again this is a failure.
+ */
+ @Test
+ public void Test2() throws Exception {
+ String TestCase = "xaTest2";
+ int TestNum = 2;
+ try {
+
+ // construct a message for this test case
+ tPub = tSession.createPublisher(cmtT);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ JmsUtil.addPropsToMessage(msg, props);
+ // send the message
+ tPub.publish(msg);
+ // verify that message was requeued and pass
+ System.out.println("Client: response message");
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("oops! error!");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test3
+ *
+ * @assertion_ids: EJB:SPEC:509; EJB:SPEC:510;
+ *
+ * @test_Strategy: Send a test message to a container managed queue. Check
+ * rollback status with getRollbackOnly Should be false for not set for
+ * rollback! If not test fails
+ *
+ */
+ @Test
+ public void Test3() throws Exception {
+ String TestCase = "xaTest3";
+ int TestNum = 3;
+ try {
+ qSender = session.createSender(cmtQ);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ JmsUtil.addPropsToMessage(msg, props);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test3 - getRollbackOnly returned wrong value");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test4
+ *
+ * @assertion_ids: EJB:SPEC:511;
+ *
+ * @test_Strategy: Send a test message to a bean managed queue. Check the
+ * transaction status.
+ *
+ */
+ @Test
+ public void Test4() throws Exception {
+ String TestCase = "xaTest4";
+ int TestNum = 4;
+ try {
+
+ qSender = session.createSender(bmtQ);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ JmsUtil.addPropsToMessage(msg, props);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test4 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test5
+ *
+ * @assertion_ids: EJB:SPEC:543; EJB:SPEC:543.1;
+ *
+ * @test_Strategy: Invoke an bmt mdb by writing to MDB_QUEUE_BMT. mdb begins a
+ * transaction, sends a msg to MDB_QUEUE. mdb commits. Verify that MDB_QUEUE has
+ * the msg sent. .
+ *
+ */
+ @Test
+ public void Test5() throws Exception {
+ String TestCase = "xaTest5";
+ int TestNum = 5;
+ try {
+
+ qSender = session.createSender(bmtQ);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ JmsUtil.addPropsToMessage(msg, props);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test5 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test6
+ *
+ * @assertion_ids: EJB:SPEC:543; EJB:SPEC:543.1;
+ *
+ * @test_Strategy: Invoke an bmt mdb by writing to MDB_DURABLE_BMT. mdb begins a
+ * transaction, sends a msg to MDB_QUEUE_REPLY. mdb commits. Verify that
+ * MDB_QUEUE_REPLY has the msg sent.
+ *
+ */
+ @Test
+ public void Test6() throws Exception {
+ String TestCase = "xaTest6";
+ int TestNum = 6;
+ try {
+ tPub = tSession.createPublisher(bmtT);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ JmsUtil.addPropsToMessage(msg, props);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test6 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test7
+ *
+ * @assertion_ids: JMS:SPEC:13; JMS:SPEC:129; JMS:SPEC:246.10; JMS:JAVADOC:371;
+ * EJB:SPEC:586.1; EJB:SPEC:586.1.1; EJB:SPEC:583.2; EJB:SPEC:583.2.1;
+ *
+ * @test_Strategy: Send a test message to a container managed topic. The mdb
+ * tests if this is the first time this message was received by checking the
+ * JMSRedelivered flag. Second time the msg is received is a a pass! If the
+ * message is not requeued and received again this is a failure.
+ */
+ @Test
+ public void Test7() throws Exception {
+ String TestCase = "xaTest7";
+ int TestNum = 7;
+ try {
+ // construct a message for this test case
+ tPub = tSession.createPublisher(cmtT);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ JmsUtil.addPropsToMessage(msg, props);
+ msg.setStringProperty("TestCase", TestCase);
+ // send the message
+ tPub.publish(msg);
+ // verify that message was requeued and pass
+ System.out.println("Client: response message");
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("oops! error!");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test8
+ *
+ * @assertion_ids: EJB:SPEC:547.2;
+ *
+ * @test_Strategy: Invoke an bmt mdb by writing to MDB_QUEUE_BMT. mdb begins a
+ * transaction, sends a msg to MDB_QUEUE. then rollsback. Verify the 2nd msg is
+ * received.
+ *
+ *
+ */
+ @Test
+ public void Test8() throws Exception {
+ String TestCase = "xaTest8";
+ int TestNum = 8;
+ try {
+
+ qSender = session.createSender(bmtQ);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ JmsUtil.addPropsToMessage(msg, props);
+ // send the message
+ qSender.send(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test8 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test9
+ *
+ * @assertion_ids: EJB:SPEC:547.2;
+ *
+ * @test_Strategy: Invoke an bmt mdb by writing to MDB_DURABLE_BMT. mdb begins a
+ * transaction, sends a msg to MDB_QUEUE_REPLY. then rollsback. Send msg and
+ * commits. Verify the 2nd msg is received.
+ *
+ *
+ */
+ @Test
+ public void Test9() throws Exception {
+ String TestCase = "xaTest9";
+ int TestNum = 9;
+ try {
+
+ tPub = tSession.createPublisher(bmtT);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ JmsUtil.addPropsToMessage(msg, props);
+ // send the message
+ tPub.publish(msg);
+
+ // verify that message was requeued and pass
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("Test9 - ");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ /*
+ * @testName: Test10
+ *
+ * @assertion_ids: JMS:SPEC:13; JMS:SPEC:129; JMS:SPEC:246.10; JMS:JAVADOC:371;
+ * EJB:SPEC:586.1; EJB:SPEC:586.1.1; EJB:SPEC:583.2; EJB:SPEC:583.2.1;
+ *
+ * @test_Strategy: Send a test message to a container managed queue. The mdb
+ * tests if this is the first time this message was received by checking the
+ * JMSRedelivered flag. Send a msg, rollback. send a second message, pass if 2nd
+ * msg received.
+ *
+ *
+ */
+ @Test
+ public void Test10() throws Exception {
+ String TestCase = "xaTest10";
+ int TestNum = 10;
+ try {
+
+ // construct a message for this test case
+ qSender = session.createSender(cmtQ);
+ // create a text message
+ createTestMessage(TestCase, TestNum);
+ JmsUtil.addPropsToMessage(msg, props);
+ // send the message
+ qSender.send(msg);
+ // verify that message was requeued and pass
+ System.out.println("Client: response message");
+ if (!checkOnResponse(TestCase)) {
+ throw new Exception("oops! error!");
+ }
+ } catch (Exception e) {
+ throw new Exception("Test Failed!", e);
+ }
+ }
+
+ public void createTestMessage(String TestCase, int num) {
+ String myMessage = "Transaction tests";
+ try {
+ msg = session.createTextMessage();
+ msg.setStringProperty("user", jmsUser);
+ msg.setStringProperty("password", jmsPassword);
+ msg.setText(myMessage);
+ msg.setIntProperty("TestCaseNum", num);
+ msg.setStringProperty("COM_SUN_JMS_TESTNAME", TestCase);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ logger.log(Logger.Level.INFO, "Error setting user and password in jms msg");
+ }
+ }
+
+ public boolean checkOnResponse(String prop) {
+ boolean status = false;
+ try {
+ logger.log(Logger.Level.TRACE, "@checkOnResponse");
+ status = recvMessageInternal(session, prop);
+ logger.log(Logger.Level.TRACE, "Close the session");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ return status;
+ }
+
+ public boolean recvMessageInternal(QueueSession session, String prop) throws JMSException {
+ boolean retcode = false;
+ logger.log(Logger.Level.TRACE, "@recvMessageInternal");
+ // Create a message producer.
+ QueueReceiver rcvr = session.createReceiver(rcvrQueue);
+ // dequeue the response from the mdb
+ Message msgRec = null;
+
+ for (int i = 0; i < 10; ++i) {
+ logger.log(Logger.Level.TRACE, "@recvMessageInternal trying to receive the message: " + i);
+ msgRec = rcvr.receive(timeout);
+ if (msgRec != null) {
+ break;
+ }
+ } // end for loop
+ if (msgRec != null) {
+ if (msgRec.getStringProperty("TestCase").equals(prop)
+ && msgRec.getStringProperty("Status").equals("Pass")) {
+ logger.log(Logger.Level.TRACE, "TestCase: " + msgRec.getStringProperty("TestCase"));
+ logger.log(Logger.Level.TRACE, "Status from msg: " + msgRec.getStringProperty("Status"));
+ logger.log(Logger.Level.TRACE, "Pass: we got the expected msg back! ");
+ retcode = true;
+ } else if (msgRec.getStringProperty("Status").equals("Fail")) {
+ logger.log(Logger.Level.TRACE, "TestCase: " + msgRec.getStringProperty("TestCase"));
+ logger.log(Logger.Level.TRACE, "Status from msg: " + msgRec.getStringProperty("Status"));
+ logger.log(Logger.Level.TRACE, "Fail: Error(s) occurred! ");
+ } else {
+ logger.log(Logger.Level.TRACE, "Fail: we didnt get the expected msg back! ");
+ logger.log(Logger.Level.TRACE, "TestCase: " + msgRec.getStringProperty("TestCase"));
+ }
+ } else if (msgRec == null) {
+ logger.log(Logger.Level.TRACE, "Fail: we didnt get the expected msg back! ");
+ }
+ return retcode;
+ }
+
+ private void cleanTheQueue() {
+ // make sure nothing is left in QUEUE_REPLY
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/xa/MsgBeanxa.java b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/xa/MsgBeanxa.java
index e6f6eae1bc..7cfa295b54 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/xa/MsgBeanxa.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee/mdb/xa/MsgBeanxa.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee.mdb.xa;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.TSNamingContext;
@@ -43,340 +44,335 @@
public class MsgBeanxa implements MessageDrivenBean, MessageListener {
- // properties object needed for logging, get this from the message object
- // passed into
- // the onMessage method.
- private java.util.Properties p = null;
-
- private TSNamingContext context = null;
-
- protected MessageDrivenContext mdc = null;
-
- // JMS
- private QueueConnectionFactory qFactory = null;
-
- private QueueConnection qConnection = null;
-
- private Queue queueR = null;
-
- private Queue queue = null;
-
- private QueueSender mSender = null;
-
- public MsgBeanxa() {
- TestUtil.logTrace("@MsgBeanMsgTestPropsQ()!");
- };
-
- public void ejbCreate() {
- TestUtil.logTrace("mdb -ejbCreate() !!");
- try {
- context = new TSNamingContext();
- qFactory = (QueueConnectionFactory) context
- .lookup("java:comp/env/jms/MyQueueConnectionFactory");
- queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
- // queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
- p = new Properties();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("MDB ejbCreate Error!", e);
- }
- }
-
- public void onMessage(Message msg) {
- QueueSession qSession = null;
-
- JmsUtil.initHarnessProps(msg, p);
-
- TestUtil.logTrace(" @onMessage!" + msg);
- TextMessage messageSent = null;
- try {
- TestUtil.logTrace("TestCase:====================="
- + msg.getStringProperty("COM_SUN_JMS_TESTNAME"));
- //
- qConnection = qFactory.createQueueConnection();
- if (qConnection == null) {
- TestUtil.logTrace("connection error");
- } else {
- // qConnection.start();
- qSession = qConnection.createQueueSession(false,
- Session.AUTO_ACKNOWLEDGE);
- }
-
- TestUtil.logTrace("will run TestCase: "
- + msg.getStringProperty("COM_SUN_JMS_TESTNAME"));
- runTests(msg, qSession);
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
- }
-
- }
-
- private void runTests(Message msg, QueueSession qSession) {
- try {
- // test to see if this is the first message
- if (msg.getIntProperty("TestCaseNum") > 0) {
- switch (msg.getIntProperty("TestCaseNum")) {
- case 1:
- runTest1(msg, qSession);
- break;
- case 2:
- runTest2(msg, qSession);
- break;
- case 3:
- runTest3(msg, qSession);
- break;
- case 4:
- runTest4(msg, qSession);
- break;
- case 5:
- runTest5(msg, qSession);
- break;
- case 6:
- runTest6(msg, qSession);
- break;
- case 7:
- runTest7(msg, qSession);
- break;
- case 8:
- runTest8(msg, qSession);
- break;
- case 9:
- runTest9(msg, qSession);
- break;
- case 10:
- runTest10(msg, qSession);
- break;
- default:
- TestUtil.logTrace("Error in mdb - No test match for TestCaseNum: "
- + msg.getIntProperty("TestCaseNum"));
- break;
- }
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }// runTests
-
- /*
- *
- */
- private void runTest1(Message msg, QueueSession qSession) {
- try {
- TestUtil.logTrace("Second time? = " + isJmsRedelivered(msg));
- // check redelivered flag
- if (!isJmsRedelivered(msg)) {
- TestUtil.logTrace("Test1 message: first time thru");
- TestUtil
- .logTrace("Message Number: " + msg.getIntProperty("TestCaseNum"));
- mdc.setRollbackOnly();
- } else {
- TestUtil.logTrace("Test1 message: again - Pass!");
- // the rollback requeued the message - so this test passed!
- JmsUtil.sendTestResults("xaTest1", true, qSession, queueR);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- */
- private void runTest2(Message msg, QueueSession qSession) {
- try {
- if (!isJmsRedelivered(msg)) {
- TestUtil.logTrace("Test2 message: first time thru");
- TestUtil
- .logTrace("Message Number: " + msg.getIntProperty("TestCaseNum"));
- JmsUtil.sendTestResults("xaTest2", false, qSession, queueR);
- mdc.setRollbackOnly();
- } else {
- TestUtil.logTrace("Test2 message: again - Pass!");
- // the rollback requeued the message - so this test passed!
- JmsUtil.sendTestResults("xaTest2", true, qSession, queueR);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void runTest3(Message msg, QueueSession qSession) {
- if (mdc.getRollbackOnly()) {
- TestUtil.logTrace("runTest3! ===== FAIL!");
- JmsUtil.sendTestResults("xaTest3", false, qSession, queueR);
- } else {
- TestUtil.logTrace("runTest3 ===== PASS!");
- JmsUtil.sendTestResults("xaTest3", true, qSession, queueR);
- }
- }// runTest3
-
- private void runTest4(Message msg, QueueSession qSession) {
- int status;
- try {
- // Obtain the transaction demarcation interface.
- UserTransaction ut = mdc.getUserTransaction();
- status = ut.getStatus();
- // There is no transaction associated with this.
- if (status != Status.STATUS_NO_TRANSACTION) {
- JmsUtil.sendTestResults("xaTest4", false, qSession, queueR);
- TestUtil.logTrace("runTest4 ===== FAIL!");
- } else {
- TestUtil.logTrace("runTest4 ===== PASS!");
- JmsUtil.sendTestResults("xaTest4", true, qSession, queueR);
- }
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void runTest5(Message msg, QueueSession qSession) {
- TextMessage newMsg;
- try {
- // Obtain the transaction demarcation interface.
- UserTransaction ut = mdc.getUserTransaction();
- // start a transaction
- ut.begin();
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults("xaTest5", true, qSession, queueR);
- // commit the transaction
- ut.commit();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void runTest6(Message msg, QueueSession session) {
- try {
- // Obtain the transaction demarcation interface.
- UserTransaction ut = mdc.getUserTransaction();
- // start a transaction
- ut.begin();
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults("xaTest6", true, session, queueR);
- // commit the transaction
- ut.commit();
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- */
- private void runTest7(Message msg, QueueSession qSession) {
- try {
- TestUtil.logTrace("JmsRedelivered flag = " + isJmsRedelivered(msg));
- if (!isJmsRedelivered(msg)) {
- TestUtil.logTrace("Test7 message: first time thru");
- TestUtil
- .logTrace("Message Number: " + msg.getIntProperty("TestCaseNum"));
- mdc.setRollbackOnly();
- } else {
- TestUtil.logTrace("Test7 message: again - Pass!");
- // the rollback requeued the message - so this test passed!
- JmsUtil.sendTestResults("xaTest7", true, qSession, queueR);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void runTest8(Message msg, QueueSession qSession) {
- try {
- // Obtain the transaction demarcation interface.
- UserTransaction ut = mdc.getUserTransaction();
- // start a transaction
- ut.begin();
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults("xaTest8", false, qSession, queueR);
- // rollback the message
- ut.rollback();
- ut.begin();
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults("xaTest8", true, qSession, queueR);
- // rollback the message
- ut.commit();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private void runTest9(Message msg, QueueSession qSession) {
- try {
- // Obtain the transaction demarcation interface.
- UserTransaction ut = mdc.getUserTransaction();
- // start a transaction
- ut.begin();
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults("xaTest9", false, qSession, queueR);
- // rollback the message
- ut.rollback();
- // start a transaction
- ut.begin();
- // send a message to MDB_QUEUE_REPLY.
- JmsUtil.sendTestResults("xaTest9", true, qSession, queueR);
- // commit the message
- ut.commit();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- /*
- *
- */
- private void runTest10(Message msg, QueueSession qSession) {
- try {
- TestUtil.logTrace("Second time? = " + isJmsRedelivered(msg));
- // check redelivered flag
- if (!isJmsRedelivered(msg)) {
- TestUtil.logTrace("Test10 message: first time thru");
- TestUtil
- .logTrace("Message Number: " + msg.getIntProperty("TestCaseNum"));
- JmsUtil.sendTestResults("xaTest10", false, qSession, queueR);
- mdc.setRollbackOnly();
- } else {
- TestUtil.logTrace("Test10 message: again - Pass!");
- // the rollback requeued the message - so this test passed!
- JmsUtil.sendTestResults("xaTest10", true, qSession, queueR);
- }
-
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- }
-
- private boolean isJmsRedelivered(Message msg) {
- boolean redelivered = false;
- try {
- redelivered = msg.getJMSRedelivered();
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- }
- return redelivered;
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- TestUtil.logTrace("setMessageDrivenContext()!!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- TestUtil.logTrace("remove()!!");
- }
+ // properties object needed for logging, get this from the message object
+ // passed into
+ // the onMessage method.
+ private java.util.Properties p = null;
+
+ private TSNamingContext context = null;
+
+ protected MessageDrivenContext mdc = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanxa.class.getName());
+
+ // JMS
+ private QueueConnectionFactory qFactory = null;
+
+ private QueueConnection qConnection = null;
+
+ private Queue queueR = null;
+
+ private Queue queue = null;
+
+ private QueueSender mSender = null;
+
+ public MsgBeanxa() {
+ logger.log(Logger.Level.TRACE, "@MsgBeanMsgTestPropsQ()!");
+ };
+
+ public void ejbCreate() {
+ logger.log(Logger.Level.TRACE, "mdb -ejbCreate() !!");
+ try {
+ context = new TSNamingContext();
+ qFactory = (QueueConnectionFactory) context.lookup("java:comp/env/jms/MyQueueConnectionFactory");
+ queueR = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE_REPLY");
+ // queue = (Queue) context.lookup("java:comp/env/jms/MDB_QUEUE");
+ p = new Properties();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("MDB ejbCreate Error!", e);
+ }
+ }
+
+ public void onMessage(Message msg) {
+ QueueSession qSession = null;
+
+ JmsUtil.initHarnessProps(msg, p);
+
+ logger.log(Logger.Level.TRACE, " @onMessage!" + msg);
+ TextMessage messageSent = null;
+ try {
+ logger.log(Logger.Level.TRACE,
+ "TestCase:=====================" + msg.getStringProperty("COM_SUN_JMS_TESTNAME"));
+ //
+ qConnection = qFactory.createQueueConnection();
+ if (qConnection == null) {
+ logger.log(Logger.Level.TRACE, "connection error");
+ } else {
+ // qConnection.start();
+ qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ }
+
+ logger.log(Logger.Level.TRACE, "will run TestCase: " + msg.getStringProperty("COM_SUN_JMS_TESTNAME"));
+ runTests(msg, qSession);
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+ }
+
+ }
+
+ private void runTests(Message msg, QueueSession qSession) {
+ try {
+ // test to see if this is the first message
+ if (msg.getIntProperty("TestCaseNum") > 0) {
+ switch (msg.getIntProperty("TestCaseNum")) {
+ case 1:
+ runTest1(msg, qSession);
+ break;
+ case 2:
+ runTest2(msg, qSession);
+ break;
+ case 3:
+ runTest3(msg, qSession);
+ break;
+ case 4:
+ runTest4(msg, qSession);
+ break;
+ case 5:
+ runTest5(msg, qSession);
+ break;
+ case 6:
+ runTest6(msg, qSession);
+ break;
+ case 7:
+ runTest7(msg, qSession);
+ break;
+ case 8:
+ runTest8(msg, qSession);
+ break;
+ case 9:
+ runTest9(msg, qSession);
+ break;
+ case 10:
+ runTest10(msg, qSession);
+ break;
+ default:
+ logger.log(Logger.Level.TRACE,
+ "Error in mdb - No test match for TestCaseNum: " + msg.getIntProperty("TestCaseNum"));
+ break;
+ }
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }// runTests
+
+ /*
+ *
+ */
+ private void runTest1(Message msg, QueueSession qSession) {
+ try {
+ logger.log(Logger.Level.TRACE, "Second time? = " + isJmsRedelivered(msg));
+ // check redelivered flag
+ if (!isJmsRedelivered(msg)) {
+ logger.log(Logger.Level.TRACE, "Test1 message: first time thru");
+ logger.log(Logger.Level.TRACE, "Message Number: " + msg.getIntProperty("TestCaseNum"));
+ mdc.setRollbackOnly();
+ } else {
+ logger.log(Logger.Level.TRACE, "Test1 message: again - Pass!");
+ // the rollback requeued the message - so this test passed!
+ JmsUtil.sendTestResults("xaTest1", true, qSession, queueR);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ */
+ private void runTest2(Message msg, QueueSession qSession) {
+ try {
+ if (!isJmsRedelivered(msg)) {
+ logger.log(Logger.Level.TRACE, "Test2 message: first time thru");
+ logger.log(Logger.Level.TRACE, "Message Number: " + msg.getIntProperty("TestCaseNum"));
+ JmsUtil.sendTestResults("xaTest2", false, qSession, queueR);
+ mdc.setRollbackOnly();
+ } else {
+ logger.log(Logger.Level.TRACE, "Test2 message: again - Pass!");
+ // the rollback requeued the message - so this test passed!
+ JmsUtil.sendTestResults("xaTest2", true, qSession, queueR);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void runTest3(Message msg, QueueSession qSession) {
+ if (mdc.getRollbackOnly()) {
+ logger.log(Logger.Level.TRACE, "runTest3! ===== FAIL!");
+ JmsUtil.sendTestResults("xaTest3", false, qSession, queueR);
+ } else {
+ logger.log(Logger.Level.TRACE, "runTest3 ===== PASS!");
+ JmsUtil.sendTestResults("xaTest3", true, qSession, queueR);
+ }
+ }// runTest3
+
+ private void runTest4(Message msg, QueueSession qSession) {
+ int status;
+ try {
+ // Obtain the transaction demarcation interface.
+ UserTransaction ut = mdc.getUserTransaction();
+ status = ut.getStatus();
+ // There is no transaction associated with this.
+ if (status != Status.STATUS_NO_TRANSACTION) {
+ JmsUtil.sendTestResults("xaTest4", false, qSession, queueR);
+ logger.log(Logger.Level.TRACE, "runTest4 ===== FAIL!");
+ } else {
+ logger.log(Logger.Level.TRACE, "runTest4 ===== PASS!");
+ JmsUtil.sendTestResults("xaTest4", true, qSession, queueR);
+ }
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void runTest5(Message msg, QueueSession qSession) {
+ TextMessage newMsg;
+ try {
+ // Obtain the transaction demarcation interface.
+ UserTransaction ut = mdc.getUserTransaction();
+ // start a transaction
+ ut.begin();
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults("xaTest5", true, qSession, queueR);
+ // commit the transaction
+ ut.commit();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void runTest6(Message msg, QueueSession session) {
+ try {
+ // Obtain the transaction demarcation interface.
+ UserTransaction ut = mdc.getUserTransaction();
+ // start a transaction
+ ut.begin();
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults("xaTest6", true, session, queueR);
+ // commit the transaction
+ ut.commit();
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ */
+ private void runTest7(Message msg, QueueSession qSession) {
+ try {
+ logger.log(Logger.Level.TRACE, "JmsRedelivered flag = " + isJmsRedelivered(msg));
+ if (!isJmsRedelivered(msg)) {
+ logger.log(Logger.Level.TRACE, "Test7 message: first time thru");
+ logger.log(Logger.Level.TRACE, "Message Number: " + msg.getIntProperty("TestCaseNum"));
+ mdc.setRollbackOnly();
+ } else {
+ logger.log(Logger.Level.TRACE, "Test7 message: again - Pass!");
+ // the rollback requeued the message - so this test passed!
+ JmsUtil.sendTestResults("xaTest7", true, qSession, queueR);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void runTest8(Message msg, QueueSession qSession) {
+ try {
+ // Obtain the transaction demarcation interface.
+ UserTransaction ut = mdc.getUserTransaction();
+ // start a transaction
+ ut.begin();
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults("xaTest8", false, qSession, queueR);
+ // rollback the message
+ ut.rollback();
+ ut.begin();
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults("xaTest8", true, qSession, queueR);
+ // rollback the message
+ ut.commit();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private void runTest9(Message msg, QueueSession qSession) {
+ try {
+ // Obtain the transaction demarcation interface.
+ UserTransaction ut = mdc.getUserTransaction();
+ // start a transaction
+ ut.begin();
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults("xaTest9", false, qSession, queueR);
+ // rollback the message
+ ut.rollback();
+ // start a transaction
+ ut.begin();
+ // send a message to MDB_QUEUE_REPLY.
+ JmsUtil.sendTestResults("xaTest9", true, qSession, queueR);
+ // commit the message
+ ut.commit();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ /*
+ *
+ */
+ private void runTest10(Message msg, QueueSession qSession) {
+ try {
+ logger.log(Logger.Level.TRACE, "Second time? = " + isJmsRedelivered(msg));
+ // check redelivered flag
+ if (!isJmsRedelivered(msg)) {
+ logger.log(Logger.Level.TRACE, "Test10 message: first time thru");
+ logger.log(Logger.Level.TRACE, "Message Number: " + msg.getIntProperty("TestCaseNum"));
+ JmsUtil.sendTestResults("xaTest10", false, qSession, queueR);
+ mdc.setRollbackOnly();
+ } else {
+ logger.log(Logger.Level.TRACE, "Test10 message: again - Pass!");
+ // the rollback requeued the message - so this test passed!
+ JmsUtil.sendTestResults("xaTest10", true, qSession, queueR);
+ }
+
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ }
+
+ private boolean isJmsRedelivered(Message msg) {
+ boolean redelivered = false;
+ try {
+ redelivered = msg.getJMSRedelivered();
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ }
+ return redelivered;
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ logger.log(Logger.Level.TRACE, "setMessageDrivenContext()!!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ logger.log(Logger.Level.TRACE, "remove()!!");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/Client.java
deleted file mode 100644
index a87a81e17a..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/Client.java
+++ /dev/null
@@ -1,702 +0,0 @@
-/*
- * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-package com.sun.ts.tests.jms.ee20.cditests.ejbweb;
-
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.porting.TSURL;
-import com.sun.ts.lib.util.TestUtil;
-
-import jakarta.ejb.EJB;
-
-public class Client extends EETest {
- // The webserver defaults (overidden by harness properties)
- private static final String PROTOCOL = "http";
-
- private static final String HOSTNAME = "localhost";
-
- private static final int PORTNUM = 8000;
-
- private TSURL ctsurl = new TSURL();
-
- private Properties props = null;
-
- private String hostname = HOSTNAME;
-
- private int portnum = PORTNUM;
-
- // URL properties used by the test
- private URL url = null;
-
- private URLConnection urlConn = null;
-
- private String SERVLET = "/cditestsejbweb_web/ServletTest";
-
- @EJB(name = "ejb/CDITestsEjbWebClntBean")
- static EjbClientIF ejbclient;
-
- private static final long serialVersionUID = 1L;
-
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup */
-
- /*
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- * webServerHost; webServerPort;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- boolean pass = true;
- try {
- // get props
- timeout = Integer.parseInt(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- hostname = p.getProperty("webServerHost");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- if (hostname == null) {
- throw new Exception("'webServerHost' in ts.jte must not be null");
- }
- try {
- portnum = Integer.parseInt(p.getProperty("webServerPort"));
- } catch (Exception e) {
- throw new Exception("'webServerPort' in ts.jte must be a number");
- }
- TestUtil.logMsg("AppClient DEBUG: ejbclient=" + ejbclient);
- if (ejbclient == null) {
- throw new Exception("setup failed: ejbclient injection failure");
- } else {
- ejbclient.init(p);
- }
- } catch (Exception e) {
- throw new Exception("setup failed:", e);
- }
- ejbclient.init(p);
- TestUtil.logMsg("setup ok");
- }
-
- public void cleanup() throws Exception {
- TestUtil.logMsg("cleanup ok");
- }
-
- /*
- * @testName: sendRecvQueueTestUsingCDIFromServlet
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
- *
- * @test_Strategy: Send and receive single message to verify that Queue is
- * working. Uses CDI and resource injection to inject the JMSContext. Uses
- * Resource injection to inject the ConnectionFactory, and Queue destination.
- *
- * @Inject
- *
- * @JMSConnectionFactory("jms/QueueConnectionFactory") JMSContext context1;
- *
- * ConnectionFactory --> jms/QueueConnectionFactory Queue --> jms/MY_QUEUE
- * JMSContext --> context1 [Variables injected: --> qcfactory, context1,
- * queue]
- */
- public void sendRecvQueueTestUsingCDIFromServlet() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------------------------------");
- TestUtil.logMsg("sendRecvQueueTestUsingCDIFromServlet");
- TestUtil.logMsg("------------------------------------");
- url = ctsurl.getURL("http", hostname, portnum, SERVLET);
- TestUtil.logMsg("Servlet URL: " + url);
- props.setProperty("TEST", "sendRecvQueueTestUsingCDIFromServlet");
- urlConn = TestUtil.sendPostData(props, url);
- Properties p = TestUtil.getResponseProperties(urlConn);
- String passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Servlet");
- } else {
- TestUtil.logMsg("CDI injection test passed from Servlet");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Servlet");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendRecvQueueTestUsingCDIFromServlet failed");
- }
- }
-
- /*
- * @testName: sendRecvTopicTestUsingCDIFromServlet
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
- *
- * @test_Strategy: Send and receive single message to verify that Topic is
- * working. Uses CDI and resource injection to inject the JMSContext. Uses
- * Resource injection to inject the ConnectionFactory, and Queue destination.
- *
- * @Inject
- *
- * @JMSConnectionFactory("jms/TopicConnectionFactory") JMSContext context2;
- *
- * ConnectionFactory --> jms/TopicConnectionFactory Topic --> jms/MY_TOPIC
- * JMSContext --> context1 [Variables injected: --> tcfactory, context2,
- * topic]
- */
- public void sendRecvTopicTestUsingCDIFromServlet() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------------------------------");
- TestUtil.logMsg("sendRecvTopicTestUsingCDIFromServlet");
- TestUtil.logMsg("------------------------------------");
- url = ctsurl.getURL("http", hostname, portnum, SERVLET);
- TestUtil.logMsg("Servlet URL: " + url);
- props.setProperty("TEST", "sendRecvTopicTestUsingCDIFromServlet");
- urlConn = TestUtil.sendPostData(props, url);
- Properties p = TestUtil.getResponseProperties(urlConn);
- String passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Servlet");
- } else {
- TestUtil.logMsg("CDI injection test passed from Servlet");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Servlet");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendRecvTopicTestUsingCDIFromServlet failed");
- }
- }
-
- /*
- * @testName: sendRecvUsingCDIDefaultFactoryFromServlet
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
- *
- * @test_Strategy: Send and receive single message to/from Queue/Topic using
- * CDI with the system default connection factory.
- *
- * @Inject JMSContext context4;
- *
- * ConnectionFactory --> jms/ConnectionFactory Topic --> jms/MY_TOPIC Queue
- * --> jms/MY_QUEUE JMSContext --> context4 [Variables injected: --> cfactory,
- * context4, topic, queue]
- */
- public void sendRecvUsingCDIDefaultFactoryFromServlet() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("-----------------------------------------");
- TestUtil.logMsg("sendRecvUsingCDIDefaultFactoryFromServlet");
- TestUtil.logMsg("-----------------------------------------");
- url = ctsurl.getURL("http", hostname, portnum, SERVLET);
- TestUtil.logMsg("Servlet URL: " + url);
- props.setProperty("TEST", "sendRecvUsingCDIDefaultFactoryFromServlet");
- urlConn = TestUtil.sendPostData(props, url);
- Properties p = TestUtil.getResponseProperties(urlConn);
- String passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Servlet");
- } else {
- TestUtil.logMsg("CDI injection test passed from Servlet");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Servlet");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendRecvUsingCDIDefaultFactoryFromServlet failed");
- }
- }
-
- /*
- * @testName: verifySessionModeOnCDIJMSContextFromServlet
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
- *
- * @test_Strategy: Check the Session Mode on JMSContext for correctness.
- * Checks the session mode of the 3 context injections.
- *
- * @Inject
- *
- * @JMSConnectionFactory("jms/QueueConnectionFactory") JMSContext context1;
- *
- * @Inject
- *
- * @JMSConnectionFactory("jms/TopicConnectionFactory") JMSContext context2;
- *
- * @Inject
- *
- * @JMSConnectionFactory("jms/ConnectionFactory")
- *
- * @JMSPasswordCredential(userName="j2ee", password="j2ee")
- *
- * @JMSSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE) JMSContext context3;
- */
- public void verifySessionModeOnCDIJMSContextFromServlet() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("-------------------------------------------");
- TestUtil.logMsg("verifySessionModeOnCDIJMSContextFromServlet");
- TestUtil.logMsg("-------------------------------------------");
- url = ctsurl.getURL("http", hostname, portnum, SERVLET);
- TestUtil.logMsg("Servlet URL: " + url);
- props.setProperty("TEST", "verifySessionModeOnCDIJMSContextFromServlet");
- urlConn = TestUtil.sendPostData(props, url);
- Properties p = TestUtil.getResponseProperties(urlConn);
- String passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Servlet");
- } else {
- TestUtil.logMsg("CDI injection test passed from Servlet");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Servlet");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("verifySessionModeOnCDIJMSContextFromServlet failed");
- }
- }
-
- /*
- * @testName: testRestrictionsOnCDIJMSContextFromServlet
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:281; JMS:JAVADOC:1366; JMS:JAVADOC:1367;
- * JMS:JAVADOC:1368; JMS:JAVADOC:1353; JMS:JAVADOC:1354; JMS:JAVADOC:917;
- * JMS:JAVADOC:997; JMS:JAVADOC:1043;
- *
- * @test_Strategy: Test restrictions on a CDI injected JMSContext. The
- * following API calls MUST throw a JMSRuntimeException or
- * IllegalStateRuntimeException if called on an injected CDI JMSContext.
- * JMSContext.setClientID() JMSContext.setExceptionListener()
- * JMSContext.stop() JMSContext.acknowledge() JMSContext.commit()
- * JMSContext.rollback() JMSContext.recover() JMSContext.setAutoStart()
- * JMSContext.start() JMSContext.close()
- */
- public void testRestrictionsOnCDIJMSContextFromServlet() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------------------------------------");
- TestUtil.logMsg("testRestrictionsOnCDIJMSContextFromServlet");
- TestUtil.logMsg("------------------------------------------");
- url = ctsurl.getURL("http", hostname, portnum, SERVLET);
- TestUtil.logMsg("Servlet URL: " + url);
- props.setProperty("TEST", "testRestrictionsOnCDIJMSContextFromServlet");
- urlConn = TestUtil.sendPostData(props, url);
- Properties p = TestUtil.getResponseProperties(urlConn);
- String passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Servlet");
- } else {
- TestUtil.logMsg("CDI injection test passed from Servlet");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Servlet");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("testRestrictionsOnCDIJMSContextFromServlet failed");
- }
- }
-
- /*
- * @testName: sendRecvQueueTestUsingCDIFromEjb
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
- *
- * @test_Strategy: Send and receive single message to verify that Queue is
- * working. Uses CDI and resource injection to inject the JMSContext. Uses
- * Resource injection to inject the ConnectionFactory, and Queue destination.
- *
- * @Inject
- *
- * @JMSConnectionFactory("jms/QueueConnectionFactory") JMSContext context1;
- *
- * ConnectionFactory --> jms/QueueConnectionFactory Queue --> jms/MY_QUEUE
- * JMSContext --> context1 [Variables injected: --> qcfactory, context1,
- * queue]
- */
- public void sendRecvQueueTestUsingCDIFromEjb() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("--------------------------------");
- TestUtil.logMsg("sendRecvQueueTestUsingCDIFromEjb");
- TestUtil.logMsg("--------------------------------");
- boolean passEjb = ejbclient.echo("sendRecvQueueTestUsingCDIFromEjb");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Ejb");
- } else {
- TestUtil.logMsg("CDI injection test passed from Ejb");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Ejb");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendRecvQueueTestUsingCDIFromEjb failed");
- }
- }
-
- /*
- * @testName: sendRecvTopicTestUsingCDIFromEjb
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
- *
- * @test_Strategy: Send and receive single message to verify that Topic is
- * working. Uses CDI and resource injection to inject the JMSContext. Uses
- * Resource injection to inject the ConnectionFactory, and Queue destination.
- *
- * @Inject
- *
- * @JMSConnectionFactory("jms/TopicConnectionFactory") JMSContext context2;
- *
- * ConnectionFactory --> jms/TopicConnectionFactory Topic --> jms/MY_TOPIC
- * JMSContext --> context2 [Variables injected: --> tcfactory, context2,
- * topic]
- */
- public void sendRecvTopicTestUsingCDIFromEjb() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("--------------------------------");
- TestUtil.logMsg("sendRecvTopicTestUsingCDIFromEjb");
- TestUtil.logMsg("--------------------------------");
- boolean passEjb = ejbclient.echo("sendRecvTopicTestUsingCDIFromEjb");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Ejb");
- } else {
- TestUtil.logMsg("CDI injection test passed from Ejb");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Ejb");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendRecvTopicTestUsingCDIFromEjb failed");
- }
- }
-
- /*
- * @testName: sendRecvUsingCDIDefaultFactoryFromEjb
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
- *
- * @test_Strategy: Send and receive single message to/from Queue/Topic using
- * CDI with the system default connection factory.
- *
- * @Inject JMSContext context4;
- *
- * ConnectionFactory --> jms/ConnectionFactory Topic --> jms/MY_TOPIC Queue
- * --> jms/MY_QUEUE JMSContext --> context4 [Variables injected: --> cfactory,
- * context4, topic, queue]
- */
- public void sendRecvUsingCDIDefaultFactoryFromEjb() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("-------------------------------------");
- TestUtil.logMsg("sendRecvUsingCDIDefaultFactoryFromEjb");
- TestUtil.logMsg("-------------------------------------");
- boolean passEjb = ejbclient.echo("sendRecvUsingCDIDefaultFactoryFromEjb");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Ejb");
- } else {
- TestUtil.logMsg("CDI injection test passed from Ejb");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Ejb");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendRecvUsingCDIDefaultFactoryFromServlet failed");
- }
- }
-
- /*
- * @testName: verifySessionModeOnCDIJMSContextFromEjb
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
- *
- * @test_Strategy: Check the Session Mode on JMSContext for correctness.
- * Checks the session mode of the 3 context injections.
- *
- * @Inject
- *
- * @JMSConnectionFactory("jms/QueueConnectionFactory") JMSContext context1;
- *
- * @Inject
- *
- * @JMSConnectionFactory("jms/TopicConnectionFactory") JMSContext context2;
- *
- * @Inject
- *
- * @JMSConnectionFactory("jms/ConnectionFactory")
- *
- * @JMSPasswordCredential(userName="j2ee", password="j2ee")
- *
- * @JMSSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE) JMSContext context3;
- */
- public void verifySessionModeOnCDIJMSContextFromEjb() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("---------------------------------------");
- TestUtil.logMsg("verifySessionModeOnCDIJMSContextFromEjb");
- TestUtil.logMsg("---------------------------------------");
- boolean passEjb = ejbclient
- .echo("verifySessionModeOnCDIJMSContextFromEjb");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Ejb");
- } else {
- TestUtil.logMsg("CDI injection test passed from Ejb");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Ejb");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("verifySessionModeOnCDIJMSContextFromEjb failed");
- }
- }
-
- /*
- * @testName: testRestrictionsOnCDIJMSContextFromEjb
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:281; JMS:JAVADOC:1366; JMS:JAVADOC:1367;
- * JMS:JAVADOC:1368; JMS:JAVADOC:1353; JMS:JAVADOC:1354; JMS:JAVADOC:917;
- * JMS:JAVADOC:997; JMS:JAVADOC:1043;
- *
- * @test_Strategy: Test restrictions on a CDI injected JMSContext. The
- * following API calls MUST throw a JMSRuntimeException or
- * IllegalStateRuntimeException if called on an injected CDI JMSContext.
- * JMSContext.setClientID() JMSContext.setExceptionListener()
- * JMSContext.stop() JMSContext.acknowledge() JMSContext.commit()
- * JMSContext.rollback() JMSContext.recover() JMSContext.setAutoStart()
- * JMSContext.start() JMSContext.close()
- */
- public void testRestrictionsOnCDIJMSContextFromEjb() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("--------------------------------------");
- TestUtil.logMsg("testRestrictionsOnCDIJMSContextFromEjb");
- TestUtil.logMsg("--------------------------------------");
- boolean passEjb = ejbclient
- .echo("testRestrictionsOnCDIJMSContextFromEjb");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Ejb");
- } else {
- TestUtil.logMsg("CDI injection test passed from Ejb");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Ejb");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("testRestrictionsOnCDIJMSContextFromEjb failed");
- }
- }
-
- /*
- * @testName: testActiveJTAUsingCDIAcross2MethodsFromEjb
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:280;
- *
- * @test_Strategy: Test active JTA transaction on CDI injected JMSContext
- * across 2 methods.
- */
- public void testActiveJTAUsingCDIAcross2MethodsFromEjb() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------------------------------------");
- TestUtil.logMsg("testActiveJTAUsingCDIAcross2MethodsFromEjb");
- TestUtil.logMsg("------------------------------------------");
- boolean passEjb = ejbclient
- .echo("testActiveJTAUsingCDICallMethod1FromEjb");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Ejb");
- } else {
- TestUtil.logMsg("CDI injection test passed from Ejb");
- }
- passEjb = ejbclient.echo("testActiveJTAUsingCDICallMethod2FromEjb");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Ejb");
- } else {
- TestUtil.logMsg("CDI injection test passed from Ejb");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Ejb");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("testActiveJTAUsingCDIAcross2MethodsFromEjb failed");
- }
- }
-
- /*
- * @testName: sendRecvQueueTestUsingCDIFromManagedBean
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
- *
- * @test_Strategy: Send and receive single message to verify that Queue is
- * working. Uses CDI and resource injection to inject the JMSContext. Uses
- * Resource injection to inject the ConnectionFactory, and Queue destination.
- * Verifies CDI injection from a CDI Managed Bean.
- *
- * @Inject
- *
- * @JMSConnectionFactory("jms/QueueConnectionFactory") JMSContext context1;
- *
- * ConnectionFactory --> jms/QueueConnectionFactory Queue --> jms/MY_QUEUE
- * JMSContext --> context1 [Variables injected: --> qcfactory, context1,
- * queue]
- */
- public void sendRecvQueueTestUsingCDIFromManagedBean() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("----------------------------------------");
- TestUtil.logMsg("sendRecvQueueTestUsingCDIFromManagedBean");
- TestUtil.logMsg("----------------------------------------");
- url = ctsurl.getURL("http", hostname, portnum, SERVLET);
- TestUtil.logMsg("Servlet URL: " + url);
- props.setProperty("TEST", "sendRecvQueueTestUsingCDIFromManagedBean");
- urlConn = TestUtil.sendPostData(props, url);
- Properties p = TestUtil.getResponseProperties(urlConn);
- String passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from ManagedBean");
- } else {
- TestUtil.logMsg("CDI injection test passed from ManagedBean");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from ManagedBean");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendRecvQueueTestUsingCDIFromManagedBean failed");
- }
- }
-
- /*
- * @testName: sendRecvTopicTestUsingCDIFromManagedBean
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
- *
- * @test_Strategy: Send and receive single message to verify that Topic is
- * working. Uses CDI and resource injection to inject the JMSContext. Uses
- * Resource injection to inject the ConnectionFactory, and Topic destination.
- * Verifies CDI injection from a CDI Managed Bean.
- *
- * @Inject
- *
- * @JMSConnectionFactory("jms/TopicConnectionFactory") JMSContext context1;
- *
- * ConnectionFactory --> jms/TopicConnectionFactory Topic --> jms/MY_TOPIC
- * JMSContext --> context2 [Variables injected: --> tcfactory, context2,
- * topic]
- */
- public void sendRecvTopicTestUsingCDIFromManagedBean() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("----------------------------------------");
- TestUtil.logMsg("sendRecvTopicTestUsingCDIFromManagedBean");
- TestUtil.logMsg("----------------------------------------");
- url = ctsurl.getURL("http", hostname, portnum, SERVLET);
- TestUtil.logMsg("Servlet URL: " + url);
- props.setProperty("TEST", "sendRecvTopicTestUsingCDIFromManagedBean");
- urlConn = TestUtil.sendPostData(props, url);
- Properties p = TestUtil.getResponseProperties(urlConn);
- String passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from ManagedBean");
- } else {
- TestUtil.logMsg("CDI injection test passed from ManagedBean");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from ManagedBean");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendRecvTopicTestUsingCDIFromManagedBean failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/ClientIT.java
new file mode 100644
index 0000000000..191dbccded
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/ClientIT.java
@@ -0,0 +1,704 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package com.sun.ts.tests.jms.ee20.cditests.ejbweb;
+
+import java.lang.System.Logger;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.porting.TSURL;
+import com.sun.ts.lib.util.TestUtil;
+
+import jakarta.ejb.EJB;
+
+
+public class ClientIT {
+ // The webserver defaults (overidden by harness properties)
+ private static final String PROTOCOL = "http";
+
+ private static final String HOSTNAME = "localhost";
+
+ private static final int PORTNUM = 8000;
+
+ private TSURL ctsurl = new TSURL();
+
+ private Properties props = null;
+
+ private String hostname = HOSTNAME;
+
+ private int portnum = PORTNUM;
+
+ // URL properties used by the test
+ private URL url = null;
+
+ private URLConnection urlConn = null;
+
+ private String SERVLET = "/cditestsejbweb_web/ServletTest";
+
+ @EJB(name = "ejb/CDITestsEjbWebClntBean")
+ static EjbClientIF ejbclient;
+
+ private static final long serialVersionUID = 1L;
+
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /* Test setup */
+
+ /*
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ * webServerHost; webServerPort;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ boolean pass = true;
+ try {
+ // get props
+ timeout = Integer.parseInt(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ hostname = System.getProperty("webServerHost");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ if (hostname == null) {
+ throw new Exception("'webServerHost' is null");
+ }
+ try {
+ portnum = Integer.parseInt(System.getProperty("webServerPort"));
+ } catch (Exception e) {
+ throw new Exception("'webServerPort' in must be a number");
+ }
+ logger.log(Logger.Level.INFO, "AppClient DEBUG: ejbclient=" + ejbclient);
+ if (ejbclient == null) {
+ throw new Exception("setup failed: ejbclient injection failure");
+ } else {
+ // ejbclient.init(p);
+ }
+ } catch (Exception e) {
+ throw new Exception("setup failed:", e);
+ }
+ // ejbclient.init(p);
+ logger.log(Logger.Level.INFO, "setup ok");
+ }
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ logger.log(Logger.Level.INFO, "cleanup ok");
+ }
+
+ /*
+ * @testName: sendRecvQueueTestUsingCDIFromServlet
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
+ *
+ * @test_Strategy: Send and receive single message to verify that Queue is
+ * working. Uses CDI and resource injection to inject the JMSContext. Uses
+ * Resource injection to inject the ConnectionFactory, and Queue destination.
+ *
+ * @Inject
+ *
+ * @JMSConnectionFactory("jms/QueueConnectionFactory") JMSContext context1;
+ *
+ * ConnectionFactory --> jms/QueueConnectionFactory Queue --> jms/MY_QUEUE
+ * JMSContext --> context1 [Variables injected: --> qcfactory, context1, queue]
+ */
+ @Test
+ public void sendRecvQueueTestUsingCDIFromServlet() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------------------------------");
+ logger.log(Logger.Level.INFO, "sendRecvQueueTestUsingCDIFromServlet");
+ logger.log(Logger.Level.INFO, "------------------------------------");
+ url = ctsurl.getURL("http", hostname, portnum, SERVLET);
+ logger.log(Logger.Level.INFO, "Servlet URL: " + url);
+ props.setProperty("TEST", "sendRecvQueueTestUsingCDIFromServlet");
+ urlConn = TestUtil.sendPostData(props, url);
+ Properties p = TestUtil.getResponseProperties(urlConn);
+ String passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Servlet");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Servlet");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Servlet");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendRecvQueueTestUsingCDIFromServlet failed");
+ }
+ }
+
+ /*
+ * @testName: sendRecvTopicTestUsingCDIFromServlet
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
+ *
+ * @test_Strategy: Send and receive single message to verify that Topic is
+ * working. Uses CDI and resource injection to inject the JMSContext. Uses
+ * Resource injection to inject the ConnectionFactory, and Queue destination.
+ *
+ * @Inject
+ *
+ * @JMSConnectionFactory("jms/TopicConnectionFactory") JMSContext context2;
+ *
+ * ConnectionFactory --> jms/TopicConnectionFactory Topic --> jms/MY_TOPIC
+ * JMSContext --> context1 [Variables injected: --> tcfactory, context2, topic]
+ */
+ @Test
+ public void sendRecvTopicTestUsingCDIFromServlet() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------------------------------");
+ logger.log(Logger.Level.INFO, "sendRecvTopicTestUsingCDIFromServlet");
+ logger.log(Logger.Level.INFO, "------------------------------------");
+ url = ctsurl.getURL("http", hostname, portnum, SERVLET);
+ logger.log(Logger.Level.INFO, "Servlet URL: " + url);
+ props.setProperty("TEST", "sendRecvTopicTestUsingCDIFromServlet");
+ urlConn = TestUtil.sendPostData(props, url);
+ Properties p = TestUtil.getResponseProperties(urlConn);
+ String passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Servlet");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Servlet");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Servlet");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendRecvTopicTestUsingCDIFromServlet failed");
+ }
+ }
+
+ /*
+ * @testName: sendRecvUsingCDIDefaultFactoryFromServlet
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
+ *
+ * @test_Strategy: Send and receive single message to/from Queue/Topic using CDI
+ * with the system default connection factory.
+ *
+ * @Inject JMSContext context4;
+ *
+ * ConnectionFactory --> jms/ConnectionFactory Topic --> jms/MY_TOPIC Queue -->
+ * jms/MY_QUEUE JMSContext --> context4 [Variables injected: --> cfactory,
+ * context4, topic, queue]
+ */
+ @Test
+ public void sendRecvUsingCDIDefaultFactoryFromServlet() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "-----------------------------------------");
+ logger.log(Logger.Level.INFO, "sendRecvUsingCDIDefaultFactoryFromServlet");
+ logger.log(Logger.Level.INFO, "-----------------------------------------");
+ url = ctsurl.getURL("http", hostname, portnum, SERVLET);
+ logger.log(Logger.Level.INFO, "Servlet URL: " + url);
+ props.setProperty("TEST", "sendRecvUsingCDIDefaultFactoryFromServlet");
+ urlConn = TestUtil.sendPostData(props, url);
+ Properties p = TestUtil.getResponseProperties(urlConn);
+ String passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Servlet");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Servlet");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Servlet");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendRecvUsingCDIDefaultFactoryFromServlet failed");
+ }
+ }
+
+ /*
+ * @testName: verifySessionModeOnCDIJMSContextFromServlet
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
+ *
+ * @test_Strategy: Check the Session Mode on JMSContext for correctness. Checks
+ * the session mode of the 3 context injections.
+ *
+ * @Inject
+ *
+ * @JMSConnectionFactory("jms/QueueConnectionFactory") JMSContext context1;
+ *
+ * @Inject
+ *
+ * @JMSConnectionFactory("jms/TopicConnectionFactory") JMSContext context2;
+ *
+ * @Inject
+ *
+ * @JMSConnectionFactory("jms/ConnectionFactory")
+ *
+ * @JMSPasswordCredential(userName="j2ee", password="j2ee")
+ *
+ * @JMSSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE) JMSContext context3;
+ */
+ @Test
+ public void verifySessionModeOnCDIJMSContextFromServlet() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "-------------------------------------------");
+ logger.log(Logger.Level.INFO, "verifySessionModeOnCDIJMSContextFromServlet");
+ logger.log(Logger.Level.INFO, "-------------------------------------------");
+ url = ctsurl.getURL("http", hostname, portnum, SERVLET);
+ logger.log(Logger.Level.INFO, "Servlet URL: " + url);
+ props.setProperty("TEST", "verifySessionModeOnCDIJMSContextFromServlet");
+ urlConn = TestUtil.sendPostData(props, url);
+ Properties p = TestUtil.getResponseProperties(urlConn);
+ String passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Servlet");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Servlet");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Servlet");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("verifySessionModeOnCDIJMSContextFromServlet failed");
+ }
+ }
+
+ /*
+ * @testName: testRestrictionsOnCDIJMSContextFromServlet
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:281; JMS:JAVADOC:1366; JMS:JAVADOC:1367;
+ * JMS:JAVADOC:1368; JMS:JAVADOC:1353; JMS:JAVADOC:1354; JMS:JAVADOC:917;
+ * JMS:JAVADOC:997; JMS:JAVADOC:1043;
+ *
+ * @test_Strategy: Test restrictions on a CDI injected JMSContext. The following
+ * API calls MUST throw a JMSRuntimeException or IllegalStateRuntimeException if
+ * called on an injected CDI JMSContext. JMSContext.setClientID()
+ * JMSContext.setExceptionListener() JMSContext.stop() JMSContext.acknowledge()
+ * JMSContext.commit() JMSContext.rollback() JMSContext.recover()
+ * JMSContext.setAutoStart() JMSContext.start() JMSContext.close()
+ */
+ @Test
+ public void testRestrictionsOnCDIJMSContextFromServlet() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------------------------------------");
+ logger.log(Logger.Level.INFO, "testRestrictionsOnCDIJMSContextFromServlet");
+ logger.log(Logger.Level.INFO, "------------------------------------------");
+ url = ctsurl.getURL("http", hostname, portnum, SERVLET);
+ logger.log(Logger.Level.INFO, "Servlet URL: " + url);
+ props.setProperty("TEST", "testRestrictionsOnCDIJMSContextFromServlet");
+ urlConn = TestUtil.sendPostData(props, url);
+ Properties p = TestUtil.getResponseProperties(urlConn);
+ String passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Servlet");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Servlet");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Servlet");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("testRestrictionsOnCDIJMSContextFromServlet failed");
+ }
+ }
+
+ /*
+ * @testName: sendRecvQueueTestUsingCDIFromEjb
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
+ *
+ * @test_Strategy: Send and receive single message to verify that Queue is
+ * working. Uses CDI and resource injection to inject the JMSContext. Uses
+ * Resource injection to inject the ConnectionFactory, and Queue destination.
+ *
+ * @Inject
+ *
+ * @JMSConnectionFactory("jms/QueueConnectionFactory") JMSContext context1;
+ *
+ * ConnectionFactory --> jms/QueueConnectionFactory Queue --> jms/MY_QUEUE
+ * JMSContext --> context1 [Variables injected: --> qcfactory, context1, queue]
+ */
+ @Test
+ public void sendRecvQueueTestUsingCDIFromEjb() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "--------------------------------");
+ logger.log(Logger.Level.INFO, "sendRecvQueueTestUsingCDIFromEjb");
+ logger.log(Logger.Level.INFO, "--------------------------------");
+ boolean passEjb = ejbclient.echo("sendRecvQueueTestUsingCDIFromEjb");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Ejb");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendRecvQueueTestUsingCDIFromEjb failed");
+ }
+ }
+
+ /*
+ * @testName: sendRecvTopicTestUsingCDIFromEjb
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
+ *
+ * @test_Strategy: Send and receive single message to verify that Topic is
+ * working. Uses CDI and resource injection to inject the JMSContext. Uses
+ * Resource injection to inject the ConnectionFactory, and Queue destination.
+ *
+ * @Inject
+ *
+ * @JMSConnectionFactory("jms/TopicConnectionFactory") JMSContext context2;
+ *
+ * ConnectionFactory --> jms/TopicConnectionFactory Topic --> jms/MY_TOPIC
+ * JMSContext --> context2 [Variables injected: --> tcfactory, context2, topic]
+ */
+ @Test
+ public void sendRecvTopicTestUsingCDIFromEjb() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "--------------------------------");
+ logger.log(Logger.Level.INFO, "sendRecvTopicTestUsingCDIFromEjb");
+ logger.log(Logger.Level.INFO, "--------------------------------");
+ boolean passEjb = ejbclient.echo("sendRecvTopicTestUsingCDIFromEjb");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Ejb");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendRecvTopicTestUsingCDIFromEjb failed");
+ }
+ }
+
+ /*
+ * @testName: sendRecvUsingCDIDefaultFactoryFromEjb
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
+ *
+ * @test_Strategy: Send and receive single message to/from Queue/Topic using CDI
+ * with the system default connection factory.
+ *
+ * @Inject JMSContext context4;
+ *
+ * ConnectionFactory --> jms/ConnectionFactory Topic --> jms/MY_TOPIC Queue -->
+ * jms/MY_QUEUE JMSContext --> context4 [Variables injected: --> cfactory,
+ * context4, topic, queue]
+ */
+ @Test
+ public void sendRecvUsingCDIDefaultFactoryFromEjb() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "-------------------------------------");
+ logger.log(Logger.Level.INFO, "sendRecvUsingCDIDefaultFactoryFromEjb");
+ logger.log(Logger.Level.INFO, "-------------------------------------");
+ boolean passEjb = ejbclient.echo("sendRecvUsingCDIDefaultFactoryFromEjb");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Ejb");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendRecvUsingCDIDefaultFactoryFromServlet failed");
+ }
+ }
+
+ /*
+ * @testName: verifySessionModeOnCDIJMSContextFromEjb
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
+ *
+ * @test_Strategy: Check the Session Mode on JMSContext for correctness. Checks
+ * the session mode of the 3 context injections.
+ *
+ * @Inject
+ *
+ * @JMSConnectionFactory("jms/QueueConnectionFactory") JMSContext context1;
+ *
+ * @Inject
+ *
+ * @JMSConnectionFactory("jms/TopicConnectionFactory") JMSContext context2;
+ *
+ * @Inject
+ *
+ * @JMSConnectionFactory("jms/ConnectionFactory")
+ *
+ * @JMSPasswordCredential(userName="j2ee", password="j2ee")
+ *
+ * @JMSSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE) JMSContext context3;
+ */
+ @Test
+ public void verifySessionModeOnCDIJMSContextFromEjb() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "---------------------------------------");
+ logger.log(Logger.Level.INFO, "verifySessionModeOnCDIJMSContextFromEjb");
+ logger.log(Logger.Level.INFO, "---------------------------------------");
+ boolean passEjb = ejbclient.echo("verifySessionModeOnCDIJMSContextFromEjb");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Ejb");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("verifySessionModeOnCDIJMSContextFromEjb failed");
+ }
+ }
+
+ /*
+ * @testName: testRestrictionsOnCDIJMSContextFromEjb
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:281; JMS:JAVADOC:1366; JMS:JAVADOC:1367;
+ * JMS:JAVADOC:1368; JMS:JAVADOC:1353; JMS:JAVADOC:1354; JMS:JAVADOC:917;
+ * JMS:JAVADOC:997; JMS:JAVADOC:1043;
+ *
+ * @test_Strategy: Test restrictions on a CDI injected JMSContext. The following
+ * API calls MUST throw a JMSRuntimeException or IllegalStateRuntimeException if
+ * called on an injected CDI JMSContext. JMSContext.setClientID()
+ * JMSContext.setExceptionListener() JMSContext.stop() JMSContext.acknowledge()
+ * JMSContext.commit() JMSContext.rollback() JMSContext.recover()
+ * JMSContext.setAutoStart() JMSContext.start() JMSContext.close()
+ */
+ @Test
+ public void testRestrictionsOnCDIJMSContextFromEjb() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "--------------------------------------");
+ logger.log(Logger.Level.INFO, "testRestrictionsOnCDIJMSContextFromEjb");
+ logger.log(Logger.Level.INFO, "--------------------------------------");
+ boolean passEjb = ejbclient.echo("testRestrictionsOnCDIJMSContextFromEjb");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Ejb");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("testRestrictionsOnCDIJMSContextFromEjb failed");
+ }
+ }
+
+ /*
+ * @testName: testActiveJTAUsingCDIAcross2MethodsFromEjb
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:280;
+ *
+ * @test_Strategy: Test active JTA transaction on CDI injected JMSContext across
+ * 2 methods.
+ */
+ @Test
+ public void testActiveJTAUsingCDIAcross2MethodsFromEjb() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------------------------------------");
+ logger.log(Logger.Level.INFO, "testActiveJTAUsingCDIAcross2MethodsFromEjb");
+ logger.log(Logger.Level.INFO, "------------------------------------------");
+ boolean passEjb = ejbclient.echo("testActiveJTAUsingCDICallMethod1FromEjb");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Ejb");
+ }
+ passEjb = ejbclient.echo("testActiveJTAUsingCDICallMethod2FromEjb");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Ejb");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("testActiveJTAUsingCDIAcross2MethodsFromEjb failed");
+ }
+ }
+
+ /*
+ * @testName: sendRecvQueueTestUsingCDIFromManagedBean
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
+ *
+ * @test_Strategy: Send and receive single message to verify that Queue is
+ * working. Uses CDI and resource injection to inject the JMSContext. Uses
+ * Resource injection to inject the ConnectionFactory, and Queue destination.
+ * Verifies CDI injection from a CDI Managed Bean.
+ *
+ * @Inject
+ *
+ * @JMSConnectionFactory("jms/QueueConnectionFactory") JMSContext context1;
+ *
+ * ConnectionFactory --> jms/QueueConnectionFactory Queue --> jms/MY_QUEUE
+ * JMSContext --> context1 [Variables injected: --> qcfactory, context1, queue]
+ */
+ @Test
+ public void sendRecvQueueTestUsingCDIFromManagedBean() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "----------------------------------------");
+ logger.log(Logger.Level.INFO, "sendRecvQueueTestUsingCDIFromManagedBean");
+ logger.log(Logger.Level.INFO, "----------------------------------------");
+ url = ctsurl.getURL("http", hostname, portnum, SERVLET);
+ logger.log(Logger.Level.INFO, "Servlet URL: " + url);
+ props.setProperty("TEST", "sendRecvQueueTestUsingCDIFromManagedBean");
+ urlConn = TestUtil.sendPostData(props, url);
+ Properties p = TestUtil.getResponseProperties(urlConn);
+ String passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from ManagedBean");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from ManagedBean");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from ManagedBean");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendRecvQueueTestUsingCDIFromManagedBean failed");
+ }
+ }
+
+ /*
+ * @testName: sendRecvTopicTestUsingCDIFromManagedBean
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:277; JMS:SPEC:278; JMS:SPEC:279;
+ *
+ * @test_Strategy: Send and receive single message to verify that Topic is
+ * working. Uses CDI and resource injection to inject the JMSContext. Uses
+ * Resource injection to inject the ConnectionFactory, and Topic destination.
+ * Verifies CDI injection from a CDI Managed Bean.
+ *
+ * @Inject
+ *
+ * @JMSConnectionFactory("jms/TopicConnectionFactory") JMSContext context1;
+ *
+ * ConnectionFactory --> jms/TopicConnectionFactory Topic --> jms/MY_TOPIC
+ * JMSContext --> context2 [Variables injected: --> tcfactory, context2, topic]
+ */
+ @Test
+ public void sendRecvTopicTestUsingCDIFromManagedBean() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "----------------------------------------");
+ logger.log(Logger.Level.INFO, "sendRecvTopicTestUsingCDIFromManagedBean");
+ logger.log(Logger.Level.INFO, "----------------------------------------");
+ url = ctsurl.getURL("http", hostname, portnum, SERVLET);
+ logger.log(Logger.Level.INFO, "Servlet URL: " + url);
+ props.setProperty("TEST", "sendRecvTopicTestUsingCDIFromManagedBean");
+ urlConn = TestUtil.sendPostData(props, url);
+ Properties p = TestUtil.getResponseProperties(urlConn);
+ String passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from ManagedBean");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from ManagedBean");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from ManagedBean");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendRecvTopicTestUsingCDIFromManagedBean failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/EjbClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/EjbClient.java
index 6f235a8c52..0e6beb8597 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/EjbClient.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/EjbClient.java
@@ -16,6 +16,7 @@
package com.sun.ts.tests.jms.ee20.cditests.ejbweb;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.RemoteLoggingInitException;
@@ -46,552 +47,529 @@
@Remote({ EjbClientIF.class })
public class EjbClient implements EjbClientIF {
- private static final boolean debug = false;
-
- private static final long serialVersionUID = 1L;
-
- long timeout;
-
- private static int testsExecuted = 0;
-
- // JMSContext CDI injection specifying QueueConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/QueueConnectionFactory")
- transient JMSContext context1;
-
- // JMSContext CDI injection specifying TopicConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/TopicConnectionFactory")
- transient JMSContext context2;
-
- // JMSContext CDI injection specifying ConnectionFactory,
- // Password Credentials, and Session Mode
- @Inject
- @JMSConnectionFactory("jms/ConnectionFactory")
- @JMSPasswordCredential(userName = "j2ee", password = "j2ee")
- @JMSSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE)
- transient JMSContext context3;
-
- // JMSContext CDI injection for default Connection Factory
- @Inject
- transient JMSContext context4;
-
- @Resource(name = "jms/MyConnectionFactory")
- private transient ConnectionFactory cfactory;
-
- @Resource(name = "jms/MyQueueConnectionFactory")
- private transient QueueConnectionFactory qcfactory;
-
- @Resource(name = "jms/MyTopicConnectionFactory")
- private transient TopicConnectionFactory tcfactory;
-
- @Resource(name = "jms/MY_QUEUE")
- private transient Queue queue;
-
- @Resource(name = "jms/MY_TOPIC")
- private transient Topic topic;
-
- /*
- * Utility method to return the session mode as a String
- */
- private String printSessionMode(int sessionMode) {
- switch (sessionMode) {
- case JMSContext.SESSION_TRANSACTED:
- return "SESSION_TRANSACTED";
- case JMSContext.AUTO_ACKNOWLEDGE:
- return "AUTO_ACKNOWLEDGE";
- case JMSContext.CLIENT_ACKNOWLEDGE:
- return "CLIENT_ACKNOWLEDGE";
- case JMSContext.DUPS_OK_ACKNOWLEDGE:
- return "DUPS_OK_ACKNOWLEDGE";
- default:
- return "UNEXPECTED_SESSIONMODE";
- }
- }
-
- private void cleanup() {
- TestUtil.logMsg("cleanup");
- }
-
- @PostConstruct
- public void postConstruct() {
- System.out.println("EjbClient:postConstruct()");
- System.out.println("queue=" + queue);
- System.out.println("topic=" + topic);
- System.out.println("cfactory=" + cfactory);
- System.out.println("qcfactory=" + qcfactory);
- System.out.println("tcfactory=" + tcfactory);
- if (queue == null || topic == null || context1 == null || context2 == null
- || context3 == null || context4 == null || cfactory == null
- || qcfactory == null || tcfactory == null) {
- throw new EJBException("postConstruct failed: injection failure");
- }
- }
-
- public void init(Properties p) {
- try {
- TestUtil.init(p);
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- } catch (RemoteLoggingInitException e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("init: failed");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("init: failed");
- }
- }
-
- public boolean echo(String testName) {
- boolean pass = false;
-
- if (testName.equals("sendRecvQueueTestUsingCDIFromEjb"))
- pass = sendRecvQueueTestUsingCDIFromEjb();
- else if (testName.equals("sendRecvTopicTestUsingCDIFromEjb"))
- pass = sendRecvTopicTestUsingCDIFromEjb();
- else if (testName.equals("sendRecvUsingCDIDefaultFactoryFromEjb"))
- pass = sendRecvUsingCDIDefaultFactoryFromEjb();
- else if (testName.equals("verifySessionModeOnCDIJMSContextFromEjb"))
- pass = verifySessionModeOnCDIJMSContextFromEjb();
- else if (testName.equals("testRestrictionsOnCDIJMSContextFromEjb"))
- pass = testRestrictionsOnCDIJMSContextFromEjb();
- else if (testName.equals("testActiveJTAUsingCDICallMethod1FromEjb"))
- pass = testActiveJTAUsingCDICallMethod1FromEjb();
- else if (testName.equals("testActiveJTAUsingCDICallMethod2FromEjb"))
- pass = testActiveJTAUsingCDICallMethod2FromEjb();
- cleanup();
- return pass;
- }
-
- public boolean sendRecvQueueTestUsingCDIFromEjb() {
- boolean pass = true;
- JMSConsumer consumer = null;
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- TestUtil.logMsg(
- "Using CDI injected context1 specifying QueueConnectionFactory");
-
- // Create JMSConsumer from JMSContext
- consumer = context1.createConsumer(queue);
-
- TestUtil.logMsg("Creating TextMessage");
- messageSent = context1.createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvQueueTestUsingCDIFromEjb");
- TestUtil.logMsg("Sending TextMessage");
- context1.createProducer().send(queue, messageSent);
- TestUtil.logMsg("Receiving TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived == null) {
- TestUtil.logErr("No message was received");
- pass = false;
- } else {
- TestUtil.logMsg("Message Sent: \"" + messageSent.getText() + "\"");
- TestUtil
- .logMsg("Message Received: \"" + messageReceived.getText() + "\"");
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message");
- } else {
- TestUtil.logErr("Received incorrect message");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- consumer.receive(timeout);
- while (consumer.receiveNoWait() != null)
- ;
- consumer.close();
- } catch (Exception e) {
- }
- }
- return pass;
- }
-
- public boolean sendRecvTopicTestUsingCDIFromEjb() {
- boolean pass = true;
- JMSConsumer consumer = null;
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- TestUtil.logMsg(
- "Using CDI injected context2 specifying TopicConnectionFactory");
-
- // Create JMSConsumer from JMSContext
- consumer = context2.createConsumer(topic);
-
- TestUtil.logMsg("Creating TextMessage");
- messageSent = context2.createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvTopicTestUsingCDIFromEjb");
- TestUtil.logMsg("Sending TextMessage");
- context2.createProducer().send(topic, messageSent);
- TestUtil.logMsg("Receiving TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived == null) {
- TestUtil.logErr("No message was received");
- pass = false;
- } else {
- TestUtil.logMsg("Message Sent: \"" + messageSent.getText() + "\"");
- TestUtil
- .logMsg("Message Received: \"" + messageReceived.getText() + "\"");
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message");
- } else {
- TestUtil.logErr("Received incorrect message");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- consumer.close();
- } catch (Exception e) {
- }
- }
- return pass;
- }
-
- public boolean sendRecvUsingCDIDefaultFactoryFromEjb() {
- boolean pass = true;
- JMSConsumer consumer = null;
- JMSConsumer consumer2 = null;
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TextMessage messageReceived2 = null;
-
- TestUtil.logMsg(
- "Using CDI injected context4 using default system connection factory");
-
- // Create JMSConsumer from JMSContext for Queue
- TestUtil.logMsg("Creating Consumer for Queue");
- consumer = context4.createConsumer(queue);
-
- // Create JMSConsumer from JMSContext for Topic
- TestUtil.logMsg("Creating Consumer for Topic");
- consumer2 = context4.createConsumer(topic);
-
- TestUtil.logMsg("Creating TextMessage");
- messageSent = context4.createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvUsingCDIDefaultFactoryFromEjb");
- TestUtil.logMsg("Sending TextMessage to Queue");
- context4.createProducer().send(queue, messageSent);
- TestUtil.logMsg("Sending TextMessage to Topic");
- context4.createProducer().send(topic, messageSent);
- TestUtil.logMsg("Receiving TextMessage from Queue consumer");
- messageReceived = (TextMessage) consumer.receive(timeout);
- TestUtil.logMsg("Receiving TextMessage from Topic consumer");
- messageReceived2 = (TextMessage) consumer2.receive(timeout);
-
- // Check to see if correct message received from Queue consumer
- TestUtil.logMsg("Check received message from Queue consumer");
- if (messageReceived == null) {
- TestUtil.logErr("No message was received");
- pass = false;
- } else {
- TestUtil.logMsg("Message Sent: \"" + messageSent.getText() + "\"");
- TestUtil
- .logMsg("Message Received: \"" + messageReceived.getText() + "\"");
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message");
- } else {
- TestUtil.logErr("Received incorrect message");
- pass = false;
- }
- }
-
- // Check to see if correct message received from Queue consumer
- TestUtil.logMsg("Check received message from Topic consumer");
- if (messageReceived2 == null) {
- TestUtil.logErr("No message was received");
- pass = false;
- } else {
- TestUtil.logMsg("Message Sent: \"" + messageSent.getText() + "\"");
- TestUtil
- .logMsg("Message Received: \"" + messageReceived2.getText() + "\"");
- if (messageReceived2.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message");
- } else {
- TestUtil.logErr("Received incorrect message");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- consumer.receive(timeout);
- while (consumer.receiveNoWait() != null)
- ;
- consumer.close();
- consumer2.receive(timeout);
- while (consumer2.receiveNoWait() != null)
- ;
- consumer2.close();
- } catch (Exception e) {
- }
- }
- return pass;
- }
-
- public boolean verifySessionModeOnCDIJMSContextFromEjb() {
- boolean pass = true;
- System.out.println("verifySessionModeOnCDIJMSContextFromEjb");
- try {
- TestUtil.logMsg("Checking session mode of context3 should be "
- + printSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE));
- if (context3.getSessionMode() != JMSContext.DUPS_OK_ACKNOWLEDGE) {
- TestUtil.logErr("Incorrect session mode returned: "
- + printSessionMode(context3.getSessionMode()) + " expected: "
- + printSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE));
- pass = false;
- } else {
- TestUtil.logMsg("Returned correct session mode: "
- + printSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE));
- }
-
- TestUtil.logMsg("Checking session mode of context2 should be "
- + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
- if (context2.getSessionMode() != JMSContext.AUTO_ACKNOWLEDGE) {
- TestUtil.logErr("Incorrect session mode returned: "
- + printSessionMode(context2.getSessionMode()) + " expected: "
- + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
- pass = false;
- } else {
- TestUtil.logMsg("Returned correct session mode: "
- + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
- }
-
- TestUtil.logMsg("Checking session mode of context1 should be "
- + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
- if (context1.getSessionMode() != JMSContext.AUTO_ACKNOWLEDGE) {
- TestUtil.logErr("Incorrect session mode returned: "
- + printSessionMode(context1.getSessionMode()) + " expected: "
- + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
- pass = false;
- } else {
- TestUtil.logMsg("Returned correct session mode: "
- + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
- return pass;
- }
-
- public boolean testRestrictionsOnCDIJMSContextFromEjb() {
- boolean pass = true;
- System.out.println("testRestrictionsOnCDIJMSContextFromEjb");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.acknowledge() MUST throw IllegalStateRuntimeException");
- try {
- context1.acknowledge();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.setClientID(String) MUST throw IllegalStateRuntimeException");
- try {
- context1.setClientID("test");
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.setExceptionListener(ExceptionListener) MUST throw IllegalStateRuntimeException");
- try {
- context1.setExceptionListener(null);
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.start() MUST throw IllegalStateRuntimeException");
- try {
- context1.start();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.stop() MUST throw IllegalStateRuntimeException");
- try {
- context1.stop();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.commit() MUST throw IllegalStateRuntimeException");
- try {
- context1.commit();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.rollback() MUST throw IllegalStateRuntimeException");
- try {
- context1.rollback();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.recover() MUST throw IllegalStateRuntimeException");
- try {
- context1.recover();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.setAutoStart(boolean) MUST throw IllegalStateRuntimeException");
- try {
- context1.setAutoStart(true);
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.close() MUST throw IllegalStateRuntimeException");
- try {
- context1.close();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
- return pass;
- }
-
- public boolean testActiveJTAUsingCDICallMethod1FromEjb() {
- boolean pass = true;
- JMSConsumer consumer = null;
-
- try {
- TestUtil.logMsg("Enter testActiveJTAUsingCDICallMethod1FromEjb");
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TSNamingContext nctx = new TSNamingContext();
- UserTransaction ut = (UserTransaction) nctx
- .lookup("java:comp/UserTransaction");
-
- TestUtil.logMsg("Start a JTA transaction");
- ut.begin();
- TestUtil.logMsg("Create TextMessage");
- messageSent = context4.createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "testActiveJTAUsingCDICallMethod1FromEjb");
- TestUtil.logMsg("Send TextMessage");
- context4.createProducer().send(queue, messageSent);
- TestUtil.logMsg(
- "Exit method and let the next method call complete the JTA transaction");
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
- return pass;
- }
-
- public boolean testActiveJTAUsingCDICallMethod2FromEjb() {
- boolean pass = true;
- JMSConsumer consumer = null;
-
- try {
- TestUtil.logMsg("Enter testActiveJTAUsingCDICallMethod2FromEjb");
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TSNamingContext nctx = new TSNamingContext();
- UserTransaction ut = (UserTransaction) nctx
- .lookup("java:comp/UserTransaction");
-
- TestUtil.logMsg("Commit the JTA transaction from previous method");
- ut.commit();
-
- // Create JMSConsumer from JMSContext
- TestUtil.logMsg(
- "Create JMSConsumer to consume TextMessage sent in previous method");
- consumer = context4.createConsumer(queue);
-
- messageSent = context4.createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "testActiveJTAUsingCDICallMethod2FromEjb");
- TestUtil.logMsg("Receiving TextMessage sent in previous method");
- messageReceived = (TextMessage) consumer.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived == null) {
- TestUtil.logErr("No message was received");
- pass = false;
- } else {
- TestUtil.logMsg("Message Sent: \"" + messageSent.getText() + "\"");
- TestUtil
- .logMsg("Message Received: \"" + messageReceived.getText() + "\"");
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message");
- } else {
- TestUtil.logErr("Received incorrect message");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- consumer.receive(timeout);
- while (consumer.receiveNoWait() != null)
- ;
- consumer.close();
- } catch (Exception e) {
- }
- }
- return pass;
- }
+ private static final boolean debug = false;
+
+ private static final long serialVersionUID = 1L;
+
+ long timeout;
+
+ private static final Logger logger = (Logger) System.getLogger(EjbClient.class.getName());
+
+ private static int testsExecuted = 0;
+
+ // JMSContext CDI injection specifying QueueConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/QueueConnectionFactory")
+ transient JMSContext context1;
+
+ // JMSContext CDI injection specifying TopicConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/TopicConnectionFactory")
+ transient JMSContext context2;
+
+ // JMSContext CDI injection specifying ConnectionFactory,
+ // Password Credentials, and Session Mode
+ @Inject
+ @JMSConnectionFactory("jms/ConnectionFactory")
+ @JMSPasswordCredential(userName = "j2ee", password = "j2ee")
+ @JMSSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE)
+ transient JMSContext context3;
+
+ // JMSContext CDI injection for default Connection Factory
+ @Inject
+ transient JMSContext context4;
+
+ @Resource(name = "jms/MyConnectionFactory")
+ private transient ConnectionFactory cfactory;
+
+ @Resource(name = "jms/MyQueueConnectionFactory")
+ private transient QueueConnectionFactory qcfactory;
+
+ @Resource(name = "jms/MyTopicConnectionFactory")
+ private transient TopicConnectionFactory tcfactory;
+
+ @Resource(name = "jms/MY_QUEUE")
+ private transient Queue queue;
+
+ @Resource(name = "jms/MY_TOPIC")
+ private transient Topic topic;
+
+ /*
+ * Utility method to return the session mode as a String
+ */
+ private String printSessionMode(int sessionMode) {
+ switch (sessionMode) {
+ case JMSContext.SESSION_TRANSACTED:
+ return "SESSION_TRANSACTED";
+ case JMSContext.AUTO_ACKNOWLEDGE:
+ return "AUTO_ACKNOWLEDGE";
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ return "CLIENT_ACKNOWLEDGE";
+ case JMSContext.DUPS_OK_ACKNOWLEDGE:
+ return "DUPS_OK_ACKNOWLEDGE";
+ default:
+ return "UNEXPECTED_SESSIONMODE";
+ }
+ }
+
+ private void cleanup() {
+ logger.log(Logger.Level.INFO, "cleanup");
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ System.out.println("EjbClient:postConstruct()");
+ System.out.println("queue=" + queue);
+ System.out.println("topic=" + topic);
+ System.out.println("cfactory=" + cfactory);
+ System.out.println("qcfactory=" + qcfactory);
+ System.out.println("tcfactory=" + tcfactory);
+ if (queue == null || topic == null || context1 == null || context2 == null || context3 == null
+ || context4 == null || cfactory == null || qcfactory == null || tcfactory == null) {
+ throw new EJBException("postConstruct failed: injection failure");
+ }
+ }
+
+ public void init(Properties p) {
+ try {
+ TestUtil.init(p);
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ } catch (RemoteLoggingInitException e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("init: failed");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("init: failed");
+ }
+ }
+
+ public boolean echo(String testName) {
+ boolean pass = false;
+
+ if (testName.equals("sendRecvQueueTestUsingCDIFromEjb"))
+ pass = sendRecvQueueTestUsingCDIFromEjb();
+ else if (testName.equals("sendRecvTopicTestUsingCDIFromEjb"))
+ pass = sendRecvTopicTestUsingCDIFromEjb();
+ else if (testName.equals("sendRecvUsingCDIDefaultFactoryFromEjb"))
+ pass = sendRecvUsingCDIDefaultFactoryFromEjb();
+ else if (testName.equals("verifySessionModeOnCDIJMSContextFromEjb"))
+ pass = verifySessionModeOnCDIJMSContextFromEjb();
+ else if (testName.equals("testRestrictionsOnCDIJMSContextFromEjb"))
+ pass = testRestrictionsOnCDIJMSContextFromEjb();
+ else if (testName.equals("testActiveJTAUsingCDICallMethod1FromEjb"))
+ pass = testActiveJTAUsingCDICallMethod1FromEjb();
+ else if (testName.equals("testActiveJTAUsingCDICallMethod2FromEjb"))
+ pass = testActiveJTAUsingCDICallMethod2FromEjb();
+ cleanup();
+ return pass;
+ }
+
+ public boolean sendRecvQueueTestUsingCDIFromEjb() {
+ boolean pass = true;
+ JMSConsumer consumer = null;
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ logger.log(Logger.Level.INFO, "Using CDI injected context1 specifying QueueConnectionFactory");
+
+ // Create JMSConsumer from JMSContext
+ consumer = context1.createConsumer(queue);
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ messageSent = context1.createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvQueueTestUsingCDIFromEjb");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ context1.createProducer().send(queue, messageSent);
+ logger.log(Logger.Level.INFO, "Receiving TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "No message was received");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message Sent: \"" + messageSent.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Message Received: \"" + messageReceived.getText() + "\"");
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ consumer.receive(timeout);
+ while (consumer.receiveNoWait() != null)
+ ;
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+ return pass;
+ }
+
+ public boolean sendRecvTopicTestUsingCDIFromEjb() {
+ boolean pass = true;
+ JMSConsumer consumer = null;
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ logger.log(Logger.Level.INFO, "Using CDI injected context2 specifying TopicConnectionFactory");
+
+ // Create JMSConsumer from JMSContext
+ consumer = context2.createConsumer(topic);
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ messageSent = context2.createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvTopicTestUsingCDIFromEjb");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ context2.createProducer().send(topic, messageSent);
+ logger.log(Logger.Level.INFO, "Receiving TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "No message was received");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message Sent: \"" + messageSent.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Message Received: \"" + messageReceived.getText() + "\"");
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+ return pass;
+ }
+
+ public boolean sendRecvUsingCDIDefaultFactoryFromEjb() {
+ boolean pass = true;
+ JMSConsumer consumer = null;
+ JMSConsumer consumer2 = null;
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TextMessage messageReceived2 = null;
+
+ logger.log(Logger.Level.INFO, "Using CDI injected context4 using default system connection factory");
+
+ // Create JMSConsumer from JMSContext for Queue
+ logger.log(Logger.Level.INFO, "Creating Consumer for Queue");
+ consumer = context4.createConsumer(queue);
+
+ // Create JMSConsumer from JMSContext for Topic
+ logger.log(Logger.Level.INFO, "Creating Consumer for Topic");
+ consumer2 = context4.createConsumer(topic);
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ messageSent = context4.createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvUsingCDIDefaultFactoryFromEjb");
+ logger.log(Logger.Level.INFO, "Sending TextMessage to Queue");
+ context4.createProducer().send(queue, messageSent);
+ logger.log(Logger.Level.INFO, "Sending TextMessage to Topic");
+ context4.createProducer().send(topic, messageSent);
+ logger.log(Logger.Level.INFO, "Receiving TextMessage from Queue consumer");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ logger.log(Logger.Level.INFO, "Receiving TextMessage from Topic consumer");
+ messageReceived2 = (TextMessage) consumer2.receive(timeout);
+
+ // Check to see if correct message received from Queue consumer
+ logger.log(Logger.Level.INFO, "Check received message from Queue consumer");
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "No message was received");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message Sent: \"" + messageSent.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Message Received: \"" + messageReceived.getText() + "\"");
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ pass = false;
+ }
+ }
+
+ // Check to see if correct message received from Queue consumer
+ logger.log(Logger.Level.INFO, "Check received message from Topic consumer");
+ if (messageReceived2 == null) {
+ logger.log(Logger.Level.ERROR, "No message was received");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message Sent: \"" + messageSent.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Message Received: \"" + messageReceived2.getText() + "\"");
+ if (messageReceived2.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ consumer.receive(timeout);
+ while (consumer.receiveNoWait() != null)
+ ;
+ consumer.close();
+ consumer2.receive(timeout);
+ while (consumer2.receiveNoWait() != null)
+ ;
+ consumer2.close();
+ } catch (Exception e) {
+ }
+ }
+ return pass;
+ }
+
+ public boolean verifySessionModeOnCDIJMSContextFromEjb() {
+ boolean pass = true;
+ System.out.println("verifySessionModeOnCDIJMSContextFromEjb");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Checking session mode of context3 should be " + printSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE));
+ if (context3.getSessionMode() != JMSContext.DUPS_OK_ACKNOWLEDGE) {
+ logger.log(Logger.Level.ERROR,
+ "Incorrect session mode returned: " + printSessionMode(context3.getSessionMode())
+ + " expected: " + printSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE));
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Returned correct session mode: " + printSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE));
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Checking session mode of context2 should be " + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
+ if (context2.getSessionMode() != JMSContext.AUTO_ACKNOWLEDGE) {
+ logger.log(Logger.Level.ERROR,
+ "Incorrect session mode returned: " + printSessionMode(context2.getSessionMode())
+ + " expected: " + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Returned correct session mode: " + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Checking session mode of context1 should be " + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
+ if (context1.getSessionMode() != JMSContext.AUTO_ACKNOWLEDGE) {
+ logger.log(Logger.Level.ERROR,
+ "Incorrect session mode returned: " + printSessionMode(context1.getSessionMode())
+ + " expected: " + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Returned correct session mode: " + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+ return pass;
+ }
+
+ public boolean testRestrictionsOnCDIJMSContextFromEjb() {
+ boolean pass = true;
+ System.out.println("testRestrictionsOnCDIJMSContextFromEjb");
+ try {
+ logger.log(Logger.Level.INFO, "Calling JMSContext.acknowledge() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.acknowledge();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.setClientID(String) MUST throw IllegalStateRuntimeException");
+ try {
+ context1.setClientID("test");
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.setExceptionListener(ExceptionListener) MUST throw IllegalStateRuntimeException");
+ try {
+ context1.setExceptionListener(null);
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling JMSContext.start() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.start();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling JMSContext.stop() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.stop();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling JMSContext.commit() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.commit();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling JMSContext.rollback() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.rollback();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling JMSContext.recover() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.recover();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.setAutoStart(boolean) MUST throw IllegalStateRuntimeException");
+ try {
+ context1.setAutoStart(true);
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling JMSContext.close() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.close();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+ return pass;
+ }
+
+ public boolean testActiveJTAUsingCDICallMethod1FromEjb() {
+ boolean pass = true;
+ JMSConsumer consumer = null;
+
+ try {
+ logger.log(Logger.Level.INFO, "Enter testActiveJTAUsingCDICallMethod1FromEjb");
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TSNamingContext nctx = new TSNamingContext();
+ UserTransaction ut = (UserTransaction) nctx.lookup("java:comp/UserTransaction");
+
+ logger.log(Logger.Level.INFO, "Start a JTA transaction");
+ ut.begin();
+ logger.log(Logger.Level.INFO, "Create TextMessage");
+ messageSent = context4.createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "testActiveJTAUsingCDICallMethod1FromEjb");
+ logger.log(Logger.Level.INFO, "Send TextMessage");
+ context4.createProducer().send(queue, messageSent);
+ logger.log(Logger.Level.INFO, "Exit method and let the next method call complete the JTA transaction");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+ return pass;
+ }
+
+ public boolean testActiveJTAUsingCDICallMethod2FromEjb() {
+ boolean pass = true;
+ JMSConsumer consumer = null;
+
+ try {
+ logger.log(Logger.Level.INFO, "Enter testActiveJTAUsingCDICallMethod2FromEjb");
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TSNamingContext nctx = new TSNamingContext();
+ UserTransaction ut = (UserTransaction) nctx.lookup("java:comp/UserTransaction");
+
+ logger.log(Logger.Level.INFO, "Commit the JTA transaction from previous method");
+ ut.commit();
+
+ // Create JMSConsumer from JMSContext
+ logger.log(Logger.Level.INFO, "Create JMSConsumer to consume TextMessage sent in previous method");
+ consumer = context4.createConsumer(queue);
+
+ messageSent = context4.createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "testActiveJTAUsingCDICallMethod2FromEjb");
+ logger.log(Logger.Level.INFO, "Receiving TextMessage sent in previous method");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "No message was received");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message Sent: \"" + messageSent.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Message Received: \"" + messageReceived.getText() + "\"");
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ consumer.receive(timeout);
+ while (consumer.receiveNoWait() != null)
+ ;
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+ return pass;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/EjbClientIF.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/EjbClientIF.java
index 5f692a6a5c..2d5617f6c7 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/EjbClientIF.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/EjbClientIF.java
@@ -18,7 +18,7 @@
public interface EjbClientIF {
- public void init(java.util.Properties p);
+ public void init(java.util.Properties p);
- public boolean echo(String testName);
+ public boolean echo(String testName);
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/MyManagedBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/MyManagedBean.java
index ac2a31206c..6e07f26624 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/MyManagedBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/MyManagedBean.java
@@ -20,6 +20,7 @@
package com.sun.ts.tests.jms.ee20.cditests.ejbweb;
import java.io.Serializable;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.RemoteLoggingInitException;
@@ -38,149 +39,147 @@
@ManagedBean(value = "mybean")
public class MyManagedBean implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private Properties p = new Properties();
-
- private long timeout;
-
- // JMSContext CDI injection specifying ConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/ConnectionFactory")
- private transient JMSContext context;
-
- @Resource(name = "jms/MY_QUEUE")
- private transient Queue queue;
-
- @Resource(name = "jms/MY_TOPIC")
- private transient Topic topic;
-
- public MyManagedBean() {
- }
-
- @PostConstruct
- public void postConstruct() {
- System.out.println("MyManageBean:postConstruct()");
- System.out.println("queue=" + queue);
- System.out.println("topic=" + topic);
- if (queue == null || topic == null || context == null) {
- throw new RuntimeException("postConstruct failed: injection failure");
- }
- }
-
- public void init(Properties p) {
- System.out.println("MyManageBean:init()");
- try {
- TestUtil.init(p);
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- } catch (RemoteLoggingInitException e) {
- TestUtil.printStackTrace(e);
- throw new RuntimeException("init: failed");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new RuntimeException("init: failed");
- }
- }
-
- public boolean sendRecvQueueTestUsingCDIFromManagedBean() {
- boolean pass = true;
- JMSConsumer consumer = null;
- TestUtil.logMsg("sendRecvQueueTestUsingCDIFromManagedBean");
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // Create JMSConsumer from JMSContext
- consumer = context.createConsumer(queue);
-
- TestUtil.logMsg("Creating TextMessage");
- messageSent = context.createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvQueueTestUsingCDIFromManagedBean");
- TestUtil.logMsg("Sending TextMessage");
- context.createProducer().send(queue, messageSent);
- TestUtil.logMsg("Receiving TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived == null) {
- TestUtil.logErr("No message was received");
- pass = false;
- } else {
- TestUtil.logMsg("Message Sent: \"" + messageSent.getText() + "\"");
- TestUtil
- .logMsg("Message Received: \"" + messageReceived.getText() + "\"");
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message");
- } else {
- TestUtil.logErr("Received incorrect message");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- consumer.receive(timeout);
- while (consumer.receiveNoWait() != null)
- ;
- consumer.close();
- } catch (Exception e) {
- }
- }
- return pass;
- }
-
- public boolean sendRecvTopicTestUsingCDIFromManagedBean() {
- boolean pass = true;
- JMSConsumer consumer = null;
- TestUtil.logMsg("sendRecvTopicTestUsingCDIFromManagedBean");
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- // Create JMSConsumer from JMSContext
- consumer = context.createConsumer(queue);
-
- TestUtil.logMsg("Creating TextMessage");
- messageSent = context.createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvTopicTestUsingCDIFromManagedBean");
- TestUtil.logMsg("Sending TextMessage");
- context.createProducer().send(queue, messageSent);
- TestUtil.logMsg("Receiving TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived == null) {
- TestUtil.logErr("No message was received");
- pass = false;
- } else {
- TestUtil.logMsg("Message Sent: \"" + messageSent.getText() + "\"");
- TestUtil
- .logMsg("Message Received: \"" + messageReceived.getText() + "\"");
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message");
- } else {
- TestUtil.logErr("Received incorrect message");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- consumer.receive(timeout);
- while (consumer.receiveNoWait() != null)
- ;
- consumer.close();
- } catch (Exception e) {
- }
- }
- return pass;
- }
+ private static final long serialVersionUID = 1L;
+
+ private Properties p = new Properties();
+
+ private long timeout;
+
+ private static final Logger logger = (Logger) System.getLogger(MyManagedBean.class.getName());
+
+ // JMSContext CDI injection specifying ConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/ConnectionFactory")
+ private transient JMSContext context;
+
+ @Resource(name = "jms/MY_QUEUE")
+ private transient Queue queue;
+
+ @Resource(name = "jms/MY_TOPIC")
+ private transient Topic topic;
+
+ public MyManagedBean() {
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ System.out.println("MyManageBean:postConstruct()");
+ System.out.println("queue=" + queue);
+ System.out.println("topic=" + topic);
+ if (queue == null || topic == null || context == null) {
+ throw new RuntimeException("postConstruct failed: injection failure");
+ }
+ }
+
+ public void init(Properties p) {
+ System.out.println("MyManageBean:init()");
+ try {
+ TestUtil.init(p);
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ } catch (RemoteLoggingInitException e) {
+ TestUtil.printStackTrace(e);
+ throw new RuntimeException("init: failed");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new RuntimeException("init: failed");
+ }
+ }
+
+ public boolean sendRecvQueueTestUsingCDIFromManagedBean() {
+ boolean pass = true;
+ JMSConsumer consumer = null;
+ logger.log(Logger.Level.INFO, "sendRecvQueueTestUsingCDIFromManagedBean");
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // Create JMSConsumer from JMSContext
+ consumer = context.createConsumer(queue);
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ messageSent = context.createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvQueueTestUsingCDIFromManagedBean");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ context.createProducer().send(queue, messageSent);
+ logger.log(Logger.Level.INFO, "Receiving TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "No message was received");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message Sent: \"" + messageSent.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Message Received: \"" + messageReceived.getText() + "\"");
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ consumer.receive(timeout);
+ while (consumer.receiveNoWait() != null)
+ ;
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+ return pass;
+ }
+
+ public boolean sendRecvTopicTestUsingCDIFromManagedBean() {
+ boolean pass = true;
+ JMSConsumer consumer = null;
+ logger.log(Logger.Level.INFO, "sendRecvTopicTestUsingCDIFromManagedBean");
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ // Create JMSConsumer from JMSContext
+ consumer = context.createConsumer(queue);
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ messageSent = context.createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvTopicTestUsingCDIFromManagedBean");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ context.createProducer().send(queue, messageSent);
+ logger.log(Logger.Level.INFO, "Receiving TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "No message was received");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message Sent: \"" + messageSent.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Message Received: \"" + messageReceived.getText() + "\"");
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ consumer.receive(timeout);
+ while (consumer.receiveNoWait() != null)
+ ;
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+ return pass;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/ServletClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/ServletClient.java
index 1a628e1b7d..6eef1451ad 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/ServletClient.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/ejbweb/ServletClient.java
@@ -18,6 +18,7 @@
import java.io.IOException;
import java.io.PrintWriter;
+import java.lang.System.Logger;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Properties;
@@ -45,543 +46,525 @@
import jakarta.servlet.http.HttpServletResponse;
public class ServletClient extends HttpServlet {
- private static final long serialVersionUID = 1L;
-
- private Properties harnessProps = null;
-
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- ArrayList queues = null;
-
- ArrayList connections = null;
-
- private static final int numMessages = 3;
-
- private static final int iterations = 5;
-
- private static int testsExecuted = 0;
-
- // JMSContext CDI injection specifying QueueConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/QueueConnectionFactory")
- transient JMSContext context1;
-
- // JMSContext CDI injection specifying TopicConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/TopicConnectionFactory")
- transient JMSContext context2;
-
- // JMSContext CDI injection specifying ConnectionFactory,
- // Password Credentials, and Session Mode
- @Inject
- @JMSConnectionFactory("jms/ConnectionFactory")
- @JMSPasswordCredential(userName = "j2ee", password = "j2ee")
- @JMSSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE)
- transient JMSContext context3;
-
- // JMSContext CDI injection for default Connection Factory
- @Inject
- transient JMSContext context4;
-
- @Resource(name = "jms/MyConnectionFactory")
- private transient ConnectionFactory cfactory;
-
- @Resource(name = "jms/MyQueueConnectionFactory")
- private transient QueueConnectionFactory qcfactory;
-
- @Resource(name = "jms/MyTopicConnectionFactory")
- private transient TopicConnectionFactory tcfactory;
-
- @Resource(name = "jms/MY_QUEUE")
- private transient Queue queue;
-
- @Resource(name = "jms/MY_TOPIC")
- private transient Topic topic;
-
- @Resource(name = "mybean")
- private MyManagedBean mybean;
-
- /*
- * Utility method to return the session mode as a String
- */
- private String printSessionMode(int sessionMode) {
- switch (sessionMode) {
- case JMSContext.SESSION_TRANSACTED:
- return "SESSION_TRANSACTED";
- case JMSContext.AUTO_ACKNOWLEDGE:
- return "AUTO_ACKNOWLEDGE";
- case JMSContext.CLIENT_ACKNOWLEDGE:
- return "CLIENT_ACKNOWLEDGE";
- case JMSContext.DUPS_OK_ACKNOWLEDGE:
- return "DUPS_OK_ACKNOWLEDGE";
- default:
- return "UNEXPECTED_SESSIONMODE";
- }
- }
-
- private void cleanup() {
- TestUtil.logMsg("cleanup");
- }
-
- public void init(ServletConfig config) throws ServletException {
- super.init(config);
- System.out.println("ServletClient:init() Entering");
- System.out.println("queue=" + queue);
- System.out.println("topic=" + topic);
- System.out.println("cfactory=" + cfactory);
- System.out.println("qcfactory=" + qcfactory);
- System.out.println("tcfactory=" + tcfactory);
- System.out.println("mybean=" + mybean);
- if (queue == null || topic == null || context1 == null || context2 == null
- || context3 == null || context4 == null || cfactory == null
- || qcfactory == null || tcfactory == null || mybean == null) {
- throw new ServletException("init() failed: port injection failed");
- }
- System.out.println("ServletClient:init() Leaving");
- }
-
- public void doGet(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, IOException {
- boolean pass = true;
- Properties p = new Properties();
- res.setContentType("text/plain");
- PrintWriter out = res.getWriter();
-
- try {
- String test = harnessProps.getProperty("TEST");
- System.out.println("doGet: test to execute is: " + test);
- if (test.equals("sendRecvQueueTestUsingCDIFromServlet")) {
- if (sendRecvQueueTestUsingCDIFromServlet())
- p.setProperty("TESTRESULT", "pass");
- else
- p.setProperty("TESTRESULT", "fail");
- } else if (test.equals("sendRecvTopicTestUsingCDIFromServlet")) {
- if (sendRecvTopicTestUsingCDIFromServlet())
- p.setProperty("TESTRESULT", "pass");
- else
- p.setProperty("TESTRESULT", "fail");
- } else if (test.equals("sendRecvUsingCDIDefaultFactoryFromServlet")) {
- if (sendRecvUsingCDIDefaultFactoryFromServlet())
- p.setProperty("TESTRESULT", "pass");
- else
- p.setProperty("TESTRESULT", "fail");
- } else if (test.equals("verifySessionModeOnCDIJMSContextFromServlet")) {
- if (verifySessionModeOnCDIJMSContextFromServlet())
- p.setProperty("TESTRESULT", "pass");
- else
- p.setProperty("TESTRESULT", "fail");
- } else if (test.equals("testRestrictionsOnCDIJMSContextFromServlet")) {
- if (testRestrictionsOnCDIJMSContextFromServlet())
- p.setProperty("TESTRESULT", "pass");
- else
- p.setProperty("TESTRESULT", "fail");
- } else if (test.equals("sendRecvQueueTestUsingCDIFromManagedBean")) {
- if (sendRecvQueueTestUsingCDIFromManagedBean())
- p.setProperty("TESTRESULT", "pass");
- else
- p.setProperty("TESTRESULT", "fail");
- } else if (test.equals("sendRecvTopicTestUsingCDIFromManagedBean")) {
- if (sendRecvTopicTestUsingCDIFromManagedBean())
- p.setProperty("TESTRESULT", "pass");
- else
- p.setProperty("TESTRESULT", "fail");
- } else {
- p.setProperty("TESTRESULT", "fail");
- }
- cleanup();
- p.list(out);
- } catch (Exception e) {
- TestUtil.logErr("doGet: Exception: " + e);
- System.out.println("doGet: Exception: " + e);
- p.setProperty("TESTRESULT", "fail");
- p.list(out);
- }
- out.close();
- }
-
- public void doPost(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, IOException {
- harnessProps = new Properties();
- Enumeration enumlist = req.getParameterNames();
- while (enumlist.hasMoreElements()) {
- String name = (String) enumlist.nextElement();
- String value = req.getParameter(name);
- harnessProps.setProperty(name, value);
- }
-
- try {
- TestUtil.init(harnessProps);
- mybean.init(harnessProps);
- timeout = Long.parseLong(harnessProps.getProperty("jms_timeout"));
- user = harnessProps.getProperty("user");
- password = harnessProps.getProperty("password");
- } catch (Exception e) {
- System.out.println("doPost: Exception: " + e);
- e.printStackTrace();
- throw new ServletException("unable to initialize remote logging");
- }
- doGet(req, res);
- harnessProps = null;
- }
-
- public boolean sendRecvQueueTestUsingCDIFromServlet() {
- boolean pass = true;
- JMSConsumer consumer = null;
- System.out.println("sendRecvQueueTestUsingCDIFromServlet");
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- TestUtil.logMsg(
- "Using CDI injected context1 specifying QueueConnectionFactory");
-
- // Create JMSConsumer from JMSContext
- consumer = context1.createConsumer(queue);
-
- TestUtil.logMsg("Creating TextMessage");
- messageSent = context1.createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvQueueTestUsingCDIFromServlet");
- TestUtil.logMsg("Sending TextMessage");
- context1.createProducer().send(queue, messageSent);
- TestUtil.logMsg("Receiving TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived == null) {
- TestUtil.logErr("No message was received");
- pass = false;
- } else {
- TestUtil.logMsg("Message Sent: \"" + messageSent.getText() + "\"");
- TestUtil
- .logMsg("Message Received: \"" + messageReceived.getText() + "\"");
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message");
- } else {
- TestUtil.logErr("Received incorrect message");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- consumer.receive(timeout);
- while (consumer.receiveNoWait() != null)
- ;
- consumer.close();
- } catch (Exception e) {
- }
- }
- return pass;
- }
-
- public boolean sendRecvTopicTestUsingCDIFromServlet() {
- boolean pass = true;
- JMSConsumer consumer = null;
- System.out.println("sendRecvTopicTestUsingCDIFromServlet");
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
-
- TestUtil.logMsg(
- "Using CDI injected context2 specifying TopicConnectionFactory");
-
- // Create JMSConsumer from JMSContext
- consumer = context2.createConsumer(topic);
-
- TestUtil.logMsg("Creating TextMessage");
- messageSent = context2.createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvTopicTestUsingCDIFromServlet");
- TestUtil.logMsg("Sending TextMessage");
- context2.createProducer().send(topic, messageSent);
- TestUtil.logMsg("Receiving TextMessage");
- messageReceived = (TextMessage) consumer.receive(timeout);
-
- // Check to see if correct message received
- if (messageReceived == null) {
- TestUtil.logErr("No message was received");
- pass = false;
- } else {
- TestUtil.logMsg("Message Sent: \"" + messageSent.getText() + "\"");
- TestUtil
- .logMsg("Message Received: \"" + messageReceived.getText() + "\"");
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message");
- } else {
- TestUtil.logErr("Received incorrect message");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- consumer.close();
- } catch (Exception e) {
- }
- }
- return pass;
- }
-
- public boolean sendRecvUsingCDIDefaultFactoryFromServlet() {
- boolean pass = true;
- JMSConsumer consumer = null;
- JMSConsumer consumer2 = null;
- try {
- TextMessage messageSent = null;
- TextMessage messageReceived = null;
- TextMessage messageReceived2 = null;
-
- TestUtil.logMsg(
- "Using CDI injected context4 using default system connection factory");
-
- // Create JMSConsumer from JMSContext for Queue
- TestUtil.logMsg("Creating Consumer for Queue");
- consumer = context4.createConsumer(queue);
-
- // Create JMSConsumer from JMSContext for Topic
- TestUtil.logMsg("Creating Consumer for Topic");
- consumer2 = context4.createConsumer(topic);
-
- TestUtil.logMsg("Creating TextMessage");
- messageSent = context4.createTextMessage();
- messageSent.setText("just a test");
- messageSent.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendRecvUsingCDIDefaultFactoryFromServlet");
- TestUtil.logMsg("Sending TextMessage to Queue");
- context4.createProducer().send(queue, messageSent);
- TestUtil.logMsg("Sending TextMessage to Topic");
- context4.createProducer().send(topic, messageSent);
- TestUtil.logMsg("Receiving TextMessage from Queue consumer");
- messageReceived = (TextMessage) consumer.receive(timeout);
- TestUtil.logMsg("Receiving TextMessage from Topic consumer");
- messageReceived2 = (TextMessage) consumer2.receive(timeout);
-
- // Check to see if correct message received from Queue consumer
- TestUtil.logMsg("Check received message from Queue consumer");
- if (messageReceived == null) {
- TestUtil.logErr("No message was received");
- pass = false;
- } else {
- TestUtil.logMsg("Message Sent: \"" + messageSent.getText() + "\"");
- TestUtil
- .logMsg("Message Received: \"" + messageReceived.getText() + "\"");
- if (messageReceived.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message");
- } else {
- TestUtil.logErr("Received incorrect message");
- pass = false;
- }
- }
-
- // Check to see if correct message received from Queue consumer
- TestUtil.logMsg("Check received message from Topic consumer");
- if (messageReceived2 == null) {
- TestUtil.logErr("No message was received");
- pass = false;
- } else {
- TestUtil.logMsg("Message Sent: \"" + messageSent.getText() + "\"");
- TestUtil
- .logMsg("Message Received: \"" + messageReceived2.getText() + "\"");
- if (messageReceived2.getText().equals(messageSent.getText())) {
- TestUtil.logMsg("Received correct message");
- } else {
- TestUtil.logErr("Received incorrect message");
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- consumer.receive(timeout);
- while (consumer.receiveNoWait() != null)
- ;
- consumer.close();
- consumer2.close();
- } catch (Exception e) {
- }
- }
- return pass;
- }
-
- public boolean verifySessionModeOnCDIJMSContextFromServlet() {
- boolean pass = true;
- System.out.println("verifySessionModeOnCDIJMSContextFromServlet");
- try {
- TestUtil.logMsg("Checking session mode of context3 should be "
- + printSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE));
- if (context3.getSessionMode() != JMSContext.DUPS_OK_ACKNOWLEDGE) {
- TestUtil.logErr("Incorrect session mode returned: "
- + printSessionMode(context3.getSessionMode()) + " expected: "
- + printSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE));
- pass = false;
- } else {
- TestUtil.logMsg("Returned correct session mode: "
- + printSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE));
- }
-
- TestUtil.logMsg("Checking session mode of context2 should be "
- + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
- if (context2.getSessionMode() != JMSContext.AUTO_ACKNOWLEDGE) {
- TestUtil.logErr("Incorrect session mode returned: "
- + printSessionMode(context2.getSessionMode()) + " expected: "
- + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
- pass = false;
- } else {
- TestUtil.logMsg("Returned correct session mode: "
- + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
- }
-
- TestUtil.logMsg("Checking session mode of context1 should be "
- + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
- if (context1.getSessionMode() != JMSContext.AUTO_ACKNOWLEDGE) {
- TestUtil.logErr("Incorrect session mode returned: "
- + printSessionMode(context1.getSessionMode()) + " expected: "
- + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
- pass = false;
- } else {
- TestUtil.logMsg("Returned correct session mode: "
- + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
- return pass;
- }
-
- public boolean testRestrictionsOnCDIJMSContextFromServlet() {
- boolean pass = true;
- System.out.println("testRestrictionsOnCDIJMSContextFromServlet");
- try {
- TestUtil.logMsg(
- "Calling JMSContext.acknowledge() MUST throw IllegalStateRuntimeException");
- try {
- context1.acknowledge();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.setClientID(String) MUST throw IllegalStateRuntimeException");
- try {
- context1.setClientID("test");
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.setExceptionListener(ExceptionListener) MUST throw IllegalStateRuntimeException");
- try {
- context1.setExceptionListener(null);
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.start() MUST throw IllegalStateRuntimeException");
- try {
- context1.start();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.stop() MUST throw IllegalStateRuntimeException");
- try {
- context1.stop();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.commit() MUST throw IllegalStateRuntimeException");
- try {
- context1.commit();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.rollback() MUST throw IllegalStateRuntimeException");
- try {
- context1.rollback();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.recover() MUST throw IllegalStateRuntimeException");
- try {
- context1.recover();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.setAutoStart(boolean) MUST throw IllegalStateRuntimeException");
- try {
- context1.setAutoStart(true);
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- TestUtil.logMsg(
- "Calling JMSContext.close() MUST throw IllegalStateRuntimeException");
- try {
- context1.close();
- } catch (IllegalStateRuntimeException e) {
- TestUtil.logMsg("Caught expected IllegalStateRuntimeException");
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected Exception: " + e);
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
- return pass;
- }
-
- public boolean sendRecvQueueTestUsingCDIFromManagedBean() {
- TestUtil.logMsg("DEBUG: sendRecvQueueTestUsingCDIFromManagedBean");
- return mybean.sendRecvQueueTestUsingCDIFromManagedBean();
- }
-
- public boolean sendRecvTopicTestUsingCDIFromManagedBean() {
- TestUtil.logMsg("DEBUG: sendRecvTopicTestUsingCDIFromManagedBean");
- return mybean.sendRecvTopicTestUsingCDIFromManagedBean();
- }
+ private static final long serialVersionUID = 1L;
+
+ private Properties harnessProps = null;
+
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ ArrayList queues = null;
+
+ ArrayList connections = null;
+
+ private static final int numMessages = 3;
+
+ private static final int iterations = 5;
+
+ private static int testsExecuted = 0;
+
+ private static final Logger logger = (Logger) System.getLogger(ServletClient.class.getName());
+
+ // JMSContext CDI injection specifying QueueConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/QueueConnectionFactory")
+ transient JMSContext context1;
+
+ // JMSContext CDI injection specifying TopicConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/TopicConnectionFactory")
+ transient JMSContext context2;
+
+ // JMSContext CDI injection specifying ConnectionFactory,
+ // Password Credentials, and Session Mode
+ @Inject
+ @JMSConnectionFactory("jms/ConnectionFactory")
+ @JMSPasswordCredential(userName = "j2ee", password = "j2ee")
+ @JMSSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE)
+ transient JMSContext context3;
+
+ // JMSContext CDI injection for default Connection Factory
+ @Inject
+ transient JMSContext context4;
+
+ @Resource(name = "jms/MyConnectionFactory")
+ private transient ConnectionFactory cfactory;
+
+ @Resource(name = "jms/MyQueueConnectionFactory")
+ private transient QueueConnectionFactory qcfactory;
+
+ @Resource(name = "jms/MyTopicConnectionFactory")
+ private transient TopicConnectionFactory tcfactory;
+
+ @Resource(name = "jms/MY_QUEUE")
+ private transient Queue queue;
+
+ @Resource(name = "jms/MY_TOPIC")
+ private transient Topic topic;
+
+ @Resource(name = "mybean")
+ private MyManagedBean mybean;
+
+ /*
+ * Utility method to return the session mode as a String
+ */
+ private String printSessionMode(int sessionMode) {
+ switch (sessionMode) {
+ case JMSContext.SESSION_TRANSACTED:
+ return "SESSION_TRANSACTED";
+ case JMSContext.AUTO_ACKNOWLEDGE:
+ return "AUTO_ACKNOWLEDGE";
+ case JMSContext.CLIENT_ACKNOWLEDGE:
+ return "CLIENT_ACKNOWLEDGE";
+ case JMSContext.DUPS_OK_ACKNOWLEDGE:
+ return "DUPS_OK_ACKNOWLEDGE";
+ default:
+ return "UNEXPECTED_SESSIONMODE";
+ }
+ }
+
+ private void cleanup() {
+ logger.log(Logger.Level.INFO, "cleanup");
+ }
+
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ System.out.println("ServletClient:init() Entering");
+ System.out.println("queue=" + queue);
+ System.out.println("topic=" + topic);
+ System.out.println("cfactory=" + cfactory);
+ System.out.println("qcfactory=" + qcfactory);
+ System.out.println("tcfactory=" + tcfactory);
+ System.out.println("mybean=" + mybean);
+ if (queue == null || topic == null || context1 == null || context2 == null || context3 == null
+ || context4 == null || cfactory == null || qcfactory == null || tcfactory == null || mybean == null) {
+ throw new ServletException("init() failed: port injection failed");
+ }
+ System.out.println("ServletClient:init() Leaving");
+ }
+
+ public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+ boolean pass = true;
+ Properties p = new Properties();
+ res.setContentType("text/plain");
+ PrintWriter out = res.getWriter();
+
+ try {
+ String test = System.getProperty("TEST");
+ System.out.println("doGet: test to execute is: " + test);
+ if (test.equals("sendRecvQueueTestUsingCDIFromServlet")) {
+ if (sendRecvQueueTestUsingCDIFromServlet())
+ p.setProperty("TESTRESULT", "pass");
+ else
+ p.setProperty("TESTRESULT", "fail");
+ } else if (test.equals("sendRecvTopicTestUsingCDIFromServlet")) {
+ if (sendRecvTopicTestUsingCDIFromServlet())
+ p.setProperty("TESTRESULT", "pass");
+ else
+ p.setProperty("TESTRESULT", "fail");
+ } else if (test.equals("sendRecvUsingCDIDefaultFactoryFromServlet")) {
+ if (sendRecvUsingCDIDefaultFactoryFromServlet())
+ p.setProperty("TESTRESULT", "pass");
+ else
+ p.setProperty("TESTRESULT", "fail");
+ } else if (test.equals("verifySessionModeOnCDIJMSContextFromServlet")) {
+ if (verifySessionModeOnCDIJMSContextFromServlet())
+ p.setProperty("TESTRESULT", "pass");
+ else
+ p.setProperty("TESTRESULT", "fail");
+ } else if (test.equals("testRestrictionsOnCDIJMSContextFromServlet")) {
+ if (testRestrictionsOnCDIJMSContextFromServlet())
+ p.setProperty("TESTRESULT", "pass");
+ else
+ p.setProperty("TESTRESULT", "fail");
+ } else if (test.equals("sendRecvQueueTestUsingCDIFromManagedBean")) {
+ if (sendRecvQueueTestUsingCDIFromManagedBean())
+ p.setProperty("TESTRESULT", "pass");
+ else
+ p.setProperty("TESTRESULT", "fail");
+ } else if (test.equals("sendRecvTopicTestUsingCDIFromManagedBean")) {
+ if (sendRecvTopicTestUsingCDIFromManagedBean())
+ p.setProperty("TESTRESULT", "pass");
+ else
+ p.setProperty("TESTRESULT", "fail");
+ } else {
+ p.setProperty("TESTRESULT", "fail");
+ }
+ cleanup();
+ p.list(out);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "doGet: Exception: " + e);
+ System.out.println("doGet: Exception: " + e);
+ p.setProperty("TESTRESULT", "fail");
+ p.list(out);
+ }
+ out.close();
+ }
+
+ public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+ harnessProps = new Properties();
+ Enumeration enumlist = req.getParameterNames();
+ while (enumlist.hasMoreElements()) {
+ String name = (String) enumlist.nextElement();
+ String value = req.getParameter(name);
+ harnessProps.setProperty(name, value);
+ }
+
+ try {
+ TestUtil.init(harnessProps);
+ mybean.init(harnessProps);
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ } catch (Exception e) {
+ System.out.println("doPost: Exception: " + e);
+ e.printStackTrace();
+ throw new ServletException("unable to initialize remote logging");
+ }
+ doGet(req, res);
+ harnessProps = null;
+ }
+
+ public boolean sendRecvQueueTestUsingCDIFromServlet() {
+ boolean pass = true;
+ JMSConsumer consumer = null;
+ System.out.println("sendRecvQueueTestUsingCDIFromServlet");
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ logger.log(Logger.Level.INFO, "Using CDI injected context1 specifying QueueConnectionFactory");
+
+ // Create JMSConsumer from JMSContext
+ consumer = context1.createConsumer(queue);
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ messageSent = context1.createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvQueueTestUsingCDIFromServlet");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ context1.createProducer().send(queue, messageSent);
+ logger.log(Logger.Level.INFO, "Receiving TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "No message was received");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message Sent: \"" + messageSent.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Message Received: \"" + messageReceived.getText() + "\"");
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ consumer.receive(timeout);
+ while (consumer.receiveNoWait() != null)
+ ;
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+ return pass;
+ }
+
+ public boolean sendRecvTopicTestUsingCDIFromServlet() {
+ boolean pass = true;
+ JMSConsumer consumer = null;
+ System.out.println("sendRecvTopicTestUsingCDIFromServlet");
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+
+ logger.log(Logger.Level.INFO, "Using CDI injected context2 specifying TopicConnectionFactory");
+
+ // Create JMSConsumer from JMSContext
+ consumer = context2.createConsumer(topic);
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ messageSent = context2.createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvTopicTestUsingCDIFromServlet");
+ logger.log(Logger.Level.INFO, "Sending TextMessage");
+ context2.createProducer().send(topic, messageSent);
+ logger.log(Logger.Level.INFO, "Receiving TextMessage");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+
+ // Check to see if correct message received
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "No message was received");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message Sent: \"" + messageSent.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Message Received: \"" + messageReceived.getText() + "\"");
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+ return pass;
+ }
+
+ public boolean sendRecvUsingCDIDefaultFactoryFromServlet() {
+ boolean pass = true;
+ JMSConsumer consumer = null;
+ JMSConsumer consumer2 = null;
+ try {
+ TextMessage messageSent = null;
+ TextMessage messageReceived = null;
+ TextMessage messageReceived2 = null;
+
+ logger.log(Logger.Level.INFO, "Using CDI injected context4 using default system connection factory");
+
+ // Create JMSConsumer from JMSContext for Queue
+ logger.log(Logger.Level.INFO, "Creating Consumer for Queue");
+ consumer = context4.createConsumer(queue);
+
+ // Create JMSConsumer from JMSContext for Topic
+ logger.log(Logger.Level.INFO, "Creating Consumer for Topic");
+ consumer2 = context4.createConsumer(topic);
+
+ logger.log(Logger.Level.INFO, "Creating TextMessage");
+ messageSent = context4.createTextMessage();
+ messageSent.setText("just a test");
+ messageSent.setStringProperty("COM_SUN_JMS_TESTNAME", "sendRecvUsingCDIDefaultFactoryFromServlet");
+ logger.log(Logger.Level.INFO, "Sending TextMessage to Queue");
+ context4.createProducer().send(queue, messageSent);
+ logger.log(Logger.Level.INFO, "Sending TextMessage to Topic");
+ context4.createProducer().send(topic, messageSent);
+ logger.log(Logger.Level.INFO, "Receiving TextMessage from Queue consumer");
+ messageReceived = (TextMessage) consumer.receive(timeout);
+ logger.log(Logger.Level.INFO, "Receiving TextMessage from Topic consumer");
+ messageReceived2 = (TextMessage) consumer2.receive(timeout);
+
+ // Check to see if correct message received from Queue consumer
+ logger.log(Logger.Level.INFO, "Check received message from Queue consumer");
+ if (messageReceived == null) {
+ logger.log(Logger.Level.ERROR, "No message was received");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message Sent: \"" + messageSent.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Message Received: \"" + messageReceived.getText() + "\"");
+ if (messageReceived.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ pass = false;
+ }
+ }
+
+ // Check to see if correct message received from Queue consumer
+ logger.log(Logger.Level.INFO, "Check received message from Topic consumer");
+ if (messageReceived2 == null) {
+ logger.log(Logger.Level.ERROR, "No message was received");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Message Sent: \"" + messageSent.getText() + "\"");
+ logger.log(Logger.Level.INFO, "Message Received: \"" + messageReceived2.getText() + "\"");
+ if (messageReceived2.getText().equals(messageSent.getText())) {
+ logger.log(Logger.Level.INFO, "Received correct message");
+ } else {
+ logger.log(Logger.Level.ERROR, "Received incorrect message");
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ consumer.receive(timeout);
+ while (consumer.receiveNoWait() != null)
+ ;
+ consumer.close();
+ consumer2.close();
+ } catch (Exception e) {
+ }
+ }
+ return pass;
+ }
+
+ public boolean verifySessionModeOnCDIJMSContextFromServlet() {
+ boolean pass = true;
+ System.out.println("verifySessionModeOnCDIJMSContextFromServlet");
+ try {
+ logger.log(Logger.Level.INFO,
+ "Checking session mode of context3 should be " + printSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE));
+ if (context3.getSessionMode() != JMSContext.DUPS_OK_ACKNOWLEDGE) {
+ logger.log(Logger.Level.ERROR,
+ "Incorrect session mode returned: " + printSessionMode(context3.getSessionMode())
+ + " expected: " + printSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE));
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Returned correct session mode: " + printSessionMode(JMSContext.DUPS_OK_ACKNOWLEDGE));
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Checking session mode of context2 should be " + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
+ if (context2.getSessionMode() != JMSContext.AUTO_ACKNOWLEDGE) {
+ logger.log(Logger.Level.ERROR,
+ "Incorrect session mode returned: " + printSessionMode(context2.getSessionMode())
+ + " expected: " + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Returned correct session mode: " + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
+ }
+
+ logger.log(Logger.Level.INFO,
+ "Checking session mode of context1 should be " + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
+ if (context1.getSessionMode() != JMSContext.AUTO_ACKNOWLEDGE) {
+ logger.log(Logger.Level.ERROR,
+ "Incorrect session mode returned: " + printSessionMode(context1.getSessionMode())
+ + " expected: " + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO,
+ "Returned correct session mode: " + printSessionMode(JMSContext.AUTO_ACKNOWLEDGE));
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+ return pass;
+ }
+
+ public boolean testRestrictionsOnCDIJMSContextFromServlet() {
+ boolean pass = true;
+ System.out.println("testRestrictionsOnCDIJMSContextFromServlet");
+ try {
+ logger.log(Logger.Level.INFO, "Calling JMSContext.acknowledge() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.acknowledge();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.setClientID(String) MUST throw IllegalStateRuntimeException");
+ try {
+ context1.setClientID("test");
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.setExceptionListener(ExceptionListener) MUST throw IllegalStateRuntimeException");
+ try {
+ context1.setExceptionListener(null);
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling JMSContext.start() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.start();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling JMSContext.stop() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.stop();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling JMSContext.commit() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.commit();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling JMSContext.rollback() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.rollback();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling JMSContext.recover() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.recover();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO,
+ "Calling JMSContext.setAutoStart(boolean) MUST throw IllegalStateRuntimeException");
+ try {
+ context1.setAutoStart(true);
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ logger.log(Logger.Level.INFO, "Calling JMSContext.close() MUST throw IllegalStateRuntimeException");
+ try {
+ context1.close();
+ } catch (IllegalStateRuntimeException e) {
+ logger.log(Logger.Level.INFO, "Caught expected IllegalStateRuntimeException");
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected Exception: " + e);
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+ return pass;
+ }
+
+ public boolean sendRecvQueueTestUsingCDIFromManagedBean() {
+ logger.log(Logger.Level.INFO, "DEBUG: sendRecvQueueTestUsingCDIFromManagedBean");
+ return mybean.sendRecvQueueTestUsingCDIFromManagedBean();
+ }
+
+ public boolean sendRecvTopicTestUsingCDIFromManagedBean() {
+ logger.log(Logger.Level.INFO, "DEBUG: sendRecvTopicTestUsingCDIFromManagedBean");
+ return mybean.sendRecvTopicTestUsingCDIFromManagedBean();
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/Client.java
deleted file mode 100644
index a6c7397cda..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/Client.java
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-package com.sun.ts.tests.jms.ee20.cditests.mdb;
-
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.porting.TSURL;
-import com.sun.ts.lib.util.TestUtil;
-
-import jakarta.ejb.EJB;
-
-public class Client extends EETest {
- // The webserver defaults (overidden by harness properties)
- private static final String PROTOCOL = "http";
-
- private static final String HOSTNAME = "localhost";
-
- private static final int PORTNUM = 8000;
-
- private TSURL ctsurl = new TSURL();
-
- private Properties props = null;
-
- private String hostname = HOSTNAME;
-
- private int portnum = PORTNUM;
-
- // URL properties used by the test
- private URL url = null;
-
- private URLConnection urlConn = null;
-
- private String SERVLET = "/cditestsmdb_web/ServletTest";
-
- @EJB(name = "ejb/CDITestsMDBClntBean")
- static EjbClientIF ejbclient;
-
- private static final long serialVersionUID = 1L;
-
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup */
-
- /*
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- * webServerHost; webServerPort;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- boolean pass = true;
- try {
- // get props
- timeout = Integer.parseInt(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- hostname = p.getProperty("webServerHost");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- if (hostname == null) {
- throw new Exception("'webServerHost' in ts.jte must not be null");
- }
- try {
- portnum = Integer.parseInt(p.getProperty("webServerPort"));
- } catch (Exception e) {
- throw new Exception("'webServerPort' in ts.jte must be a number");
- }
- TestUtil.logMsg("AppClient DEBUG: ejbclient=" + ejbclient);
- if (ejbclient == null) {
- throw new Exception("setup failed: ejbclient injection failure");
- } else {
- ejbclient.init(p);
- }
- } catch (Exception e) {
- throw new Exception("setup failed:", e);
- }
- ejbclient.init(p);
- TestUtil.logMsg("setup ok");
- }
-
- public void cleanup() throws Exception {
- TestUtil.logMsg("cleanup ok");
- }
-
- /*
- * @testName: testCDIInjectionOfMDBWithQueueReplyFromEjb
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:280;
- *
- * @test_Strategy: Test CDI injection in a MDB. Send a message to the MDB and
- * MDB sends a reply back to the Reply Queue using the CDI injected
- * JMSContext.
- */
- public void testCDIInjectionOfMDBWithQueueReplyFromEjb() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------------------------------------");
- TestUtil.logMsg("testCDIInjectionOfMDBWithQueueReplyFromEjb");
- TestUtil.logMsg("------------------------------------------");
- boolean passEjb = ejbclient
- .echo("testCDIInjectionOfMDBWithQueueReplyFromEjb");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Ejb");
- } else {
- TestUtil.logMsg("CDI injection test passed from Ejb");
- }
- passEjb = ejbclient.echo("testCDIInjectionOfMDBWithQueueReplyFromEjb");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Ejb");
- } else {
- TestUtil.logMsg("CDI injection test passed from Ejb");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Ejb");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("testCDIInjectionOfMDBWithQueueReplyFromEjb failed");
- }
- }
-
- /*
- * @testName: testCDIInjectionOfMDBWithTopicReplyFromEjb
- *
- * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
- * JMS:JAVADOC:1128; JMS:SPEC:280;
- *
- * @test_Strategy: Test CDI injection in a MDB. Send a message to the MDB and
- * MDB sends a reply back to the Reply Topic using the CDI injected
- * JMSContext.
- */
- public void testCDIInjectionOfMDBWithTopicReplyFromEjb() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------------------------------------");
- TestUtil.logMsg("testCDIInjectionOfMDBWithTopicReplyFromEjb");
- TestUtil.logMsg("------------------------------------------");
- boolean passEjb = ejbclient
- .echo("testCDIInjectionOfMDBWithTopicReplyFromEjb");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Ejb");
- } else {
- TestUtil.logMsg("CDI injection test passed from Ejb");
- }
- passEjb = ejbclient.echo("testCDIInjectionOfMDBWithTopicReplyFromEjb");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("CDI injection test failed from Ejb");
- } else {
- TestUtil.logMsg("CDI injection test passed from Ejb");
- }
- } catch (Exception e) {
- TestUtil.logErr("CDI injection test failed from Ejb");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("testCDIInjectionOfMDBWithTopicReplyFromEjb failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/ClientIT.java
new file mode 100644
index 0000000000..c1413b900d
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/ClientIT.java
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package com.sun.ts.tests.jms.ee20.cditests.mdb;
+
+import java.lang.System.Logger;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.porting.TSURL;
+
+import jakarta.ejb.EJB;
+
+
+public class ClientIT {
+ // The webserver defaults
+ private static final String PROTOCOL = "http";
+
+ private static final String HOSTNAME = "localhost";
+
+ private static final int PORTNUM = 8000;
+
+ private TSURL ctsurl = new TSURL();
+
+ private Properties props = null;
+
+ private String hostname = HOSTNAME;
+
+ private int portnum = PORTNUM;
+
+ // URL properties used by the test
+ private URL url = null;
+
+ private URLConnection urlConn = null;
+
+ private String SERVLET = "/cditestsmdb_web/ServletTest";
+
+ @EJB(name = "ejb/CDITestsMDBClntBean")
+ static EjbClientIF ejbclient;
+
+ private static final long serialVersionUID = 1L;
+
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /* Test setup */
+
+ /*
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ * webServerHost; webServerPort;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ boolean pass = true;
+ try {
+ // get props
+ timeout = Integer.parseInt(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ hostname = System.getProperty("webServerHost");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ if (hostname == null) {
+ throw new Exception("'webServerHost' is null");
+ }
+ try {
+ portnum = Integer.parseInt(System.getProperty("webServerPort"));
+ } catch (Exception e) {
+ throw new Exception("'webServerPort' in must be a number");
+ }
+ logger.log(Logger.Level.INFO, "AppClient DEBUG: ejbclient=" + ejbclient);
+ if (ejbclient == null) {
+ throw new Exception("setup failed: ejbclient injection failure");
+ } else {
+ // ejbclient.init(p);
+ }
+ } catch (Exception e) {
+ throw new Exception("setup failed:", e);
+ }
+ // ejbclient.init(p);
+ logger.log(Logger.Level.INFO, "setup ok");
+ }
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ logger.log(Logger.Level.INFO, "cleanup ok");
+ }
+
+ /*
+ * @testName: testCDIInjectionOfMDBWithQueueReplyFromEjb
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:280;
+ *
+ * @test_Strategy: Test CDI injection in a MDB. Send a message to the MDB and
+ * MDB sends a reply back to the Reply Queue using the CDI injected JMSContext.
+ */
+ @Test
+ public void testCDIInjectionOfMDBWithQueueReplyFromEjb() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------------------------------------");
+ logger.log(Logger.Level.INFO, "testCDIInjectionOfMDBWithQueueReplyFromEjb");
+ logger.log(Logger.Level.INFO, "------------------------------------------");
+ boolean passEjb = ejbclient.echo("testCDIInjectionOfMDBWithQueueReplyFromEjb");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Ejb");
+ }
+ passEjb = ejbclient.echo("testCDIInjectionOfMDBWithQueueReplyFromEjb");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Ejb");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("testCDIInjectionOfMDBWithQueueReplyFromEjb failed");
+ }
+ }
+
+ /*
+ * @testName: testCDIInjectionOfMDBWithTopicReplyFromEjb
+ *
+ * @assertion_ids: JMS:JAVADOC:1120; JMS:JAVADOC:1121; JMS:JAVADOC:1127;
+ * JMS:JAVADOC:1128; JMS:SPEC:280;
+ *
+ * @test_Strategy: Test CDI injection in a MDB. Send a message to the MDB and
+ * MDB sends a reply back to the Reply Topic using the CDI injected JMSContext.
+ */
+ @Test
+ public void testCDIInjectionOfMDBWithTopicReplyFromEjb() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------------------------------------");
+ logger.log(Logger.Level.INFO, "testCDIInjectionOfMDBWithTopicReplyFromEjb");
+ logger.log(Logger.Level.INFO, "------------------------------------------");
+ boolean passEjb = ejbclient.echo("testCDIInjectionOfMDBWithTopicReplyFromEjb");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Ejb");
+ }
+ passEjb = ejbclient.echo("testCDIInjectionOfMDBWithTopicReplyFromEjb");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "CDI injection test passed from Ejb");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "CDI injection test failed from Ejb");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("testCDIInjectionOfMDBWithTopicReplyFromEjb failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/EjbClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/EjbClient.java
index 3c7aa92946..dd7c43f560 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/EjbClient.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/EjbClient.java
@@ -16,6 +16,7 @@
package com.sun.ts.tests.jms.ee20.cditests.mdb;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.RemoteLoggingInitException;
@@ -39,189 +40,184 @@
@Remote({ EjbClientIF.class })
public class EjbClient implements EjbClientIF {
- private static final boolean debug = false;
-
- private static final long serialVersionUID = 1L;
-
- long timeout;
-
- private static int testsExecuted = 0;
-
- // JMSContext CDI injection specifying ConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/ConnectionFactory")
- transient JMSContext context;
-
- @Resource(name = "jms/MyConnectionFactory")
- private transient ConnectionFactory cfactory;
-
- @Resource(name = "jms/MDB_QUEUE")
- private transient Queue queueToMDB;
-
- @Resource(name = "jms/mdbReplyQueue")
- private transient Queue replyQueue;
-
- @Resource(name = "jms/mdbReplyTopic")
- private transient Topic replyTopic;
-
- private void cleanup() {
- TestUtil.logMsg("cleanup");
- }
-
- @PostConstruct
- public void postConstruct() {
- System.out.println("EjbClient:postConstruct()");
- System.out.println("cfactory=" + cfactory);
- System.out.println("queueToMDB=" + queueToMDB);
- System.out.println("replyQueue=" + replyQueue);
- System.out.println("replyTopic=" + replyTopic);
- if (context == null || cfactory == null || queueToMDB == null
- || replyQueue == null || replyTopic == null) {
- throw new EJBException("postConstruct failed: injection failure");
- }
- }
-
- public void init(Properties p) {
- try {
- TestUtil.init(p);
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- } catch (RemoteLoggingInitException e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("init: failed");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("init: failed");
- }
- }
-
- public boolean echo(String testName) {
- boolean pass = false;
-
- if (testName.equals("testCDIInjectionOfMDBWithQueueReplyFromEjb"))
- pass = testCDIInjectionOfMDBWithQueueReplyFromEjb();
- else if (testName.equals("testCDIInjectionOfMDBWithTopicReplyFromEjb"))
- pass = testCDIInjectionOfMDBWithTopicReplyFromEjb();
- cleanup();
- return pass;
- }
-
- public boolean testCDIInjectionOfMDBWithQueueReplyFromEjb() {
- boolean pass = true;
- TextMessage messageSent = null;
- TextMessage messageRecv = null;
- JMSConsumer consumer = null;
- try {
- TestUtil.logMsg("Creating TextMessage to send to MDB MsgBeanQ");
- messageSent = context.createTextMessage();
- messageSent.setText("Send message to MDB MsgBeanQ");
- messageSent.setStringProperty("TESTNAME",
- "testCDIInjectionOfMDBWithQueueReplyFromEjb");
-
- TestUtil.logMsg("Creating JMSConsumer for MDB MsgBeanQ Reply Queue");
- consumer = context.createConsumer(replyQueue);
-
- TestUtil.logMsg("Sending TextMessage to MDB MsgBeanQ");
- context.createProducer().send(queueToMDB, messageSent);
-
- for (int i = 1; i < 10; ++i) {
- TestUtil
- .logMsg("Try receiving reply message from MDB MsgBeanQ (loop count="
- + i + ")");
- messageRecv = (TextMessage) consumer.receive(timeout);
- if (messageRecv != null)
- break;
- }
- if (messageRecv != null) {
- String testname = messageRecv.getStringProperty("TESTNAME");
- String reason = messageRecv.getStringProperty("REASON");
- String jmscontext = messageRecv.getStringProperty("JMSCONTEXT");
- String status = messageRecv.getStringProperty("STATUS");
- if (status.equals("Pass")) {
- TestUtil.logMsg("TEST=" + testname + " PASSED for JMSCONTEXT="
- + jmscontext + " REASON=" + reason);
- pass = true;
- } else {
- TestUtil.logErr("TEST=" + testname + " FAILED for JMSCONTEXT="
- + jmscontext + " REASON=" + reason);
- pass = false;
- }
- } else {
- TestUtil.logErr("Did no receive a reply message from MDB MsgBeanQ");
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- consumer.receive(timeout);
- while (consumer.receiveNoWait() != null)
- ;
- consumer.close();
- } catch (Exception e) {
- }
- }
- return pass;
- }
-
- public boolean testCDIInjectionOfMDBWithTopicReplyFromEjb() {
- boolean pass = true;
- TextMessage messageSent = null;
- TextMessage messageRecv = null;
- JMSConsumer consumer = null;
- try {
- TestUtil.logMsg("Creating TextMessage to send to MDB MsgBeanQ");
- messageSent = context.createTextMessage();
- messageSent.setText("Send message to MDB MsgBeanQ");
- messageSent.setStringProperty("TESTNAME",
- "testCDIInjectionOfMDBWithTopicReplyFromEjb");
-
- TestUtil.logMsg("Creating JMSConsumer for MDB MsgBeanQ Reply Topic");
- consumer = context.createConsumer(replyTopic);
-
- TestUtil.logMsg("Sending TextMessage to MDB MsgBeanQ");
- context.createProducer().send(queueToMDB, messageSent);
-
- for (int i = 1; i < 10; ++i) {
- TestUtil
- .logMsg("Try receiving reply message from MDB MsgBeanQ (loop count="
- + i + ")");
- messageRecv = (TextMessage) consumer.receive(timeout);
- if (messageRecv != null)
- break;
- }
- if (messageRecv != null) {
- String testname = messageRecv.getStringProperty("TESTNAME");
- String reason = messageRecv.getStringProperty("REASON");
- String jmscontext = messageRecv.getStringProperty("JMSCONTEXT");
- String status = messageRecv.getStringProperty("STATUS");
- if (status.equals("Pass")) {
- TestUtil.logMsg("TEST=" + testname + " PASSED for JMSCONTEXT="
- + jmscontext + " REASON=" + reason);
- pass = true;
- } else {
- TestUtil.logErr("TEST=" + testname + " FAILED for JMSCONTEXT="
- + jmscontext + " REASON=" + reason);
- pass = false;
- }
- } else {
- TestUtil.logErr("Did no receive a reply message from MDB MsgBeanQ");
- pass = false;
- }
-
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- consumer.receive(timeout);
- while (consumer.receiveNoWait() != null)
- ;
- consumer.close();
- } catch (Exception e) {
- }
- }
- return pass;
- }
+ private static final boolean debug = false;
+
+ private static final long serialVersionUID = 1L;
+
+ long timeout;
+
+ private static int testsExecuted = 0;
+
+ private static final Logger logger = (Logger) System.getLogger(EjbClient.class.getName());
+
+ // JMSContext CDI injection specifying ConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/ConnectionFactory")
+ transient JMSContext context;
+
+ @Resource(name = "jms/MyConnectionFactory")
+ private transient ConnectionFactory cfactory;
+
+ @Resource(name = "jms/MDB_QUEUE")
+ private transient Queue queueToMDB;
+
+ @Resource(name = "jms/mdbReplyQueue")
+ private transient Queue replyQueue;
+
+ @Resource(name = "jms/mdbReplyTopic")
+ private transient Topic replyTopic;
+
+ private void cleanup() {
+ logger.log(Logger.Level.INFO, "cleanup");
+ }
+
+ @PostConstruct
+ public void postConstruct() {
+ System.out.println("EjbClient:postConstruct()");
+ System.out.println("cfactory=" + cfactory);
+ System.out.println("queueToMDB=" + queueToMDB);
+ System.out.println("replyQueue=" + replyQueue);
+ System.out.println("replyTopic=" + replyTopic);
+ if (context == null || cfactory == null || queueToMDB == null || replyQueue == null || replyTopic == null) {
+ throw new EJBException("postConstruct failed: injection failure");
+ }
+ }
+
+ public void init(Properties p) {
+ try {
+ TestUtil.init(p);
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ } catch (RemoteLoggingInitException e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("init: failed");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("init: failed");
+ }
+ }
+
+ public boolean echo(String testName) {
+ boolean pass = false;
+
+ if (testName.equals("testCDIInjectionOfMDBWithQueueReplyFromEjb"))
+ pass = testCDIInjectionOfMDBWithQueueReplyFromEjb();
+ else if (testName.equals("testCDIInjectionOfMDBWithTopicReplyFromEjb"))
+ pass = testCDIInjectionOfMDBWithTopicReplyFromEjb();
+ cleanup();
+ return pass;
+ }
+
+ public boolean testCDIInjectionOfMDBWithQueueReplyFromEjb() {
+ boolean pass = true;
+ TextMessage messageSent = null;
+ TextMessage messageRecv = null;
+ JMSConsumer consumer = null;
+ try {
+ logger.log(Logger.Level.INFO, "Creating TextMessage to send to MDB MsgBeanQ");
+ messageSent = context.createTextMessage();
+ messageSent.setText("Send message to MDB MsgBeanQ");
+ messageSent.setStringProperty("TESTNAME", "testCDIInjectionOfMDBWithQueueReplyFromEjb");
+
+ logger.log(Logger.Level.INFO, "Creating JMSConsumer for MDB MsgBeanQ Reply Queue");
+ consumer = context.createConsumer(replyQueue);
+
+ logger.log(Logger.Level.INFO, "Sending TextMessage to MDB MsgBeanQ");
+ context.createProducer().send(queueToMDB, messageSent);
+
+ for (int i = 1; i < 10; ++i) {
+ logger.log(Logger.Level.INFO, "Try receiving reply message from MDB MsgBeanQ (loop count=" + i + ")");
+ messageRecv = (TextMessage) consumer.receive(timeout);
+ if (messageRecv != null)
+ break;
+ }
+ if (messageRecv != null) {
+ String testname = messageRecv.getStringProperty("TESTNAME");
+ String reason = messageRecv.getStringProperty("REASON");
+ String jmscontext = messageRecv.getStringProperty("JMSCONTEXT");
+ String status = messageRecv.getStringProperty("STATUS");
+ if (status.equals("Pass")) {
+ logger.log(Logger.Level.INFO,
+ "TEST=" + testname + " PASSED for JMSCONTEXT=" + jmscontext + " REASON=" + reason);
+ pass = true;
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "TEST=" + testname + " FAILED for JMSCONTEXT=" + jmscontext + " REASON=" + reason);
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Did no receive a reply message from MDB MsgBeanQ");
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ consumer.receive(timeout);
+ while (consumer.receiveNoWait() != null)
+ ;
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+ return pass;
+ }
+
+ public boolean testCDIInjectionOfMDBWithTopicReplyFromEjb() {
+ boolean pass = true;
+ TextMessage messageSent = null;
+ TextMessage messageRecv = null;
+ JMSConsumer consumer = null;
+ try {
+ logger.log(Logger.Level.INFO, "Creating TextMessage to send to MDB MsgBeanQ");
+ messageSent = context.createTextMessage();
+ messageSent.setText("Send message to MDB MsgBeanQ");
+ messageSent.setStringProperty("TESTNAME", "testCDIInjectionOfMDBWithTopicReplyFromEjb");
+
+ logger.log(Logger.Level.INFO, "Creating JMSConsumer for MDB MsgBeanQ Reply Topic");
+ consumer = context.createConsumer(replyTopic);
+
+ logger.log(Logger.Level.INFO, "Sending TextMessage to MDB MsgBeanQ");
+ context.createProducer().send(queueToMDB, messageSent);
+
+ for (int i = 1; i < 10; ++i) {
+ logger.log(Logger.Level.INFO, "Try receiving reply message from MDB MsgBeanQ (loop count=" + i + ")");
+ messageRecv = (TextMessage) consumer.receive(timeout);
+ if (messageRecv != null)
+ break;
+ }
+ if (messageRecv != null) {
+ String testname = messageRecv.getStringProperty("TESTNAME");
+ String reason = messageRecv.getStringProperty("REASON");
+ String jmscontext = messageRecv.getStringProperty("JMSCONTEXT");
+ String status = messageRecv.getStringProperty("STATUS");
+ if (status.equals("Pass")) {
+ logger.log(Logger.Level.INFO,
+ "TEST=" + testname + " PASSED for JMSCONTEXT=" + jmscontext + " REASON=" + reason);
+ pass = true;
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "TEST=" + testname + " FAILED for JMSCONTEXT=" + jmscontext + " REASON=" + reason);
+ pass = false;
+ }
+ } else {
+ logger.log(Logger.Level.ERROR, "Did no receive a reply message from MDB MsgBeanQ");
+ pass = false;
+ }
+
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ consumer.receive(timeout);
+ while (consumer.receiveNoWait() != null)
+ ;
+ consumer.close();
+ } catch (Exception e) {
+ }
+ }
+ return pass;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/EjbClientIF.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/EjbClientIF.java
index 4758eaabd8..119d2052da 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/EjbClientIF.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/EjbClientIF.java
@@ -18,7 +18,7 @@
public interface EjbClientIF {
- public void init(java.util.Properties p);
+ public void init(java.util.Properties p);
- public boolean echo(String testName);
+ public boolean echo(String testName);
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/MsgBeanQ.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/MsgBeanQ.java
index 47b2d0db55..677ec79068 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/MsgBeanQ.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/mdb/MsgBeanQ.java
@@ -19,6 +19,7 @@
*/
package com.sun.ts.tests.jms.ee20.cditests.mdb;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.TSNamingContext;
@@ -37,136 +38,132 @@
import jakarta.jms.Topic;
public class MsgBeanQ implements MessageDrivenBean, MessageListener {
- private static final long serialVersionUID = 1L;
-
- private Properties p = new Properties();
-
- private TSNamingContext context = null;
-
- private transient MessageDrivenContext mdc = null;
-
- // JMSContext CDI injection specifying QueueConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/QueueConnectionFactory")
- transient JMSContext context1;
-
- // JMSContext CDI injection specifying TopicConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/TopicConnectionFactory")
- transient JMSContext context2;
-
- @Resource(name = "jms/mdbReplyQueue")
- private transient Queue replyQueue;
-
- @Resource(name = "jms/mdbReplyTopic")
- private transient Topic replyTopic;
-
- public MsgBeanQ() {
- }
-
- public void ejbCreate() {
- System.out.println("MsgBeanQ.ejbCreate()!");
- }
-
- public void setMessageDrivenContext(MessageDrivenContext mdc) {
- System.out.println("MsgBeanQ.setMessageDrivenContext()!");
- this.mdc = mdc;
- }
-
- public void ejbRemove() {
- System.out.println("MsgBeanQ.ejbRemove()!");
- }
-
- public EJBContext getEJBContext() {
- return this.mdc;
- }
-
- // ================== business methods ====================================
- public void onMessage(jakarta.jms.Message msg) {
- System.out.println("MsgBeanQ.onMessage(): entering MDB");
- System.out.println("MsgBeanQ.onMessage(): JMSContext context1=" + context1);
- System.out.println("MsgBeanQ.onMessage(): JMSContext context2=" + context2);
- boolean status = false;
- String reason = null;
- String testname = null;
- try {
- testname = msg.getStringProperty("TESTNAME");
- } catch (JMSException e) {
- reason = "MsgBeanQ.onMessage(): failed to get TESTNAME from message";
- if (context1 == null || context2 == null)
- reason = reason + ", failed CDI injection of JMSContext";
- System.out.println(reason);
- return;
- }
- if (context1 == null || context2 == null) {
- reason = "MsgBeanQ.onMessage(): failed CDI injection of JMSContext";
- System.out.println(reason);
- if (testname.equals("testCDIInjectionOfMDBWithQueueReplyFromEjb"))
- sendReplyToQ(testname, status, reason, context1, replyQueue);
- else
- sendReplyToT(testname, status, reason, context2, replyTopic);
- }
-
- // reply to all messages that have a testname.
- status = true;
- reason = "MsgBeanQ.onMessage(): received message from TESTNAME=" + testname;
- System.out.println(reason);
- if (testname.equals("testCDIInjectionOfMDBWithQueueReplyFromEjb"))
- sendReplyToQ(testname, status, reason, context1, replyQueue);
- else
- sendReplyToT(testname, status, reason, context2, replyTopic);
- System.out.println("MsgBeanQ.onMessage(): leaving MDB");
- }
-
- private void sendReplyToQ(String testname, boolean status, String reason,
- JMSContext context, Queue qReply) {
- TextMessage msg = null;
- System.out.println("MsgBeanQ.sendReplyToQ(): entering");
- try {
- msg = context.createTextMessage();
- msg.setStringProperty("TESTNAME", testname);
- msg.setStringProperty("JMSCONTEXT", "context1");
- msg.setStringProperty("REASON", reason);
- msg.setText(testname);
- if (status) {
- msg.setStringProperty("STATUS", "Pass");
- } else {
- msg.setStringProperty("STATUS", "Fail");
- }
- System.out.println(
- "MsgBeanQ.sendReplyToQ(): sending reply with TESTNAME=" + testname
- + " STATUS=" + status + " JMSCONTEXT=context1 REASON=" + reason);
- context.createProducer().send(qReply, msg);
- } catch (Exception e) {
- throw new java.lang.IllegalStateException(
- "Failed to send reply to ReplyQueue");
- }
- System.out.println("MsgBeanQ.sendReplyToQ(): leaving");
- }
-
- private void sendReplyToT(String testname, boolean status, String reason,
- JMSContext context, Topic tReply) {
- TextMessage msg = null;
- System.out.println("MsgBeanQ.sendReplyToT(): entering");
- try {
- msg = context.createTextMessage();
- msg.setStringProperty("TESTNAME", testname);
- msg.setStringProperty("JMSCONTEXT", "context2");
- msg.setStringProperty("REASON", reason);
- msg.setText(testname);
- if (status) {
- msg.setStringProperty("STATUS", "Pass");
- } else {
- msg.setStringProperty("STATUS", "Fail");
- }
- System.out.println(
- "MsgBeanQ.sendReplyToT(): sending reply with TESTNAME=" + testname
- + " STATUS=" + status + " JMSCONTEXT=context2 REASON=" + reason);
- context.createProducer().send(tReply, msg);
- } catch (Exception e) {
- throw new java.lang.IllegalStateException(
- "Failed to send reply to ReplyTopic");
- }
- System.out.println("MsgBeanQ.sendReplyToT(): leaving");
- }
+ private static final long serialVersionUID = 1L;
+
+ private Properties p = new Properties();
+
+ private TSNamingContext context = null;
+
+ private transient MessageDrivenContext mdc = null;
+
+ private static final Logger logger = (Logger) System.getLogger(MsgBeanQ.class.getName());
+
+ // JMSContext CDI injection specifying QueueConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/QueueConnectionFactory")
+ transient JMSContext context1;
+
+ // JMSContext CDI injection specifying TopicConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/TopicConnectionFactory")
+ transient JMSContext context2;
+
+ @Resource(name = "jms/mdbReplyQueue")
+ private transient Queue replyQueue;
+
+ @Resource(name = "jms/mdbReplyTopic")
+ private transient Topic replyTopic;
+
+ public MsgBeanQ() {
+ }
+
+ public void ejbCreate() {
+ System.out.println("MsgBeanQ.ejbCreate()!");
+ }
+
+ public void setMessageDrivenContext(MessageDrivenContext mdc) {
+ System.out.println("MsgBeanQ.setMessageDrivenContext()!");
+ this.mdc = mdc;
+ }
+
+ public void ejbRemove() {
+ System.out.println("MsgBeanQ.ejbRemove()!");
+ }
+
+ public EJBContext getEJBContext() {
+ return this.mdc;
+ }
+
+ // ================== business methods ====================================
+ public void onMessage(jakarta.jms.Message msg) {
+ System.out.println("MsgBeanQ.onMessage(): entering MDB");
+ System.out.println("MsgBeanQ.onMessage(): JMSContext context1=" + context1);
+ System.out.println("MsgBeanQ.onMessage(): JMSContext context2=" + context2);
+ boolean status = false;
+ String reason = null;
+ String testname = null;
+ try {
+ testname = msg.getStringProperty("TESTNAME");
+ } catch (JMSException e) {
+ reason = "MsgBeanQ.onMessage(): failed to get TESTNAME from message";
+ if (context1 == null || context2 == null)
+ reason = reason + ", failed CDI injection of JMSContext";
+ System.out.println(reason);
+ return;
+ }
+ if (context1 == null || context2 == null) {
+ reason = "MsgBeanQ.onMessage(): failed CDI injection of JMSContext";
+ System.out.println(reason);
+ if (testname.equals("testCDIInjectionOfMDBWithQueueReplyFromEjb"))
+ sendReplyToQ(testname, status, reason, context1, replyQueue);
+ else
+ sendReplyToT(testname, status, reason, context2, replyTopic);
+ }
+
+ // reply to all messages that have a testname.
+ status = true;
+ reason = "MsgBeanQ.onMessage(): received message from TESTNAME=" + testname;
+ System.out.println(reason);
+ if (testname.equals("testCDIInjectionOfMDBWithQueueReplyFromEjb"))
+ sendReplyToQ(testname, status, reason, context1, replyQueue);
+ else
+ sendReplyToT(testname, status, reason, context2, replyTopic);
+ System.out.println("MsgBeanQ.onMessage(): leaving MDB");
+ }
+
+ private void sendReplyToQ(String testname, boolean status, String reason, JMSContext context, Queue qReply) {
+ TextMessage msg = null;
+ System.out.println("MsgBeanQ.sendReplyToQ(): entering");
+ try {
+ msg = context.createTextMessage();
+ msg.setStringProperty("TESTNAME", testname);
+ msg.setStringProperty("JMSCONTEXT", "context1");
+ msg.setStringProperty("REASON", reason);
+ msg.setText(testname);
+ if (status) {
+ msg.setStringProperty("STATUS", "Pass");
+ } else {
+ msg.setStringProperty("STATUS", "Fail");
+ }
+ System.out.println("MsgBeanQ.sendReplyToQ(): sending reply with TESTNAME=" + testname + " STATUS=" + status
+ + " JMSCONTEXT=context1 REASON=" + reason);
+ context.createProducer().send(qReply, msg);
+ } catch (Exception e) {
+ throw new java.lang.IllegalStateException("Failed to send reply to ReplyQueue");
+ }
+ System.out.println("MsgBeanQ.sendReplyToQ(): leaving");
+ }
+
+ private void sendReplyToT(String testname, boolean status, String reason, JMSContext context, Topic tReply) {
+ TextMessage msg = null;
+ System.out.println("MsgBeanQ.sendReplyToT(): entering");
+ try {
+ msg = context.createTextMessage();
+ msg.setStringProperty("TESTNAME", testname);
+ msg.setStringProperty("JMSCONTEXT", "context2");
+ msg.setStringProperty("REASON", reason);
+ msg.setText(testname);
+ if (status) {
+ msg.setStringProperty("STATUS", "Pass");
+ } else {
+ msg.setStringProperty("STATUS", "Fail");
+ }
+ System.out.println("MsgBeanQ.sendReplyToT(): sending reply with TESTNAME=" + testname + " STATUS=" + status
+ + " JMSCONTEXT=context2 REASON=" + reason);
+ context.createProducer().send(tReply, msg);
+ } catch (Exception e) {
+ throw new java.lang.IllegalStateException("Failed to send reply to ReplyTopic");
+ }
+ System.out.println("MsgBeanQ.sendReplyToT(): leaving");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean1.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean1.java
index 7db7171ece..36f556b98f 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean1.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean1.java
@@ -16,6 +16,7 @@
package com.sun.ts.tests.jms.ee20.cditests.usecases;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.RemoteLoggingInitException;
@@ -44,154 +45,154 @@
@Remote({ BMBean1IF.class })
public class BMBean1 implements BMBean1IF {
- private static final long serialVersionUID = 1L;
-
- long timeout;
-
- // JMSContext CDI injection specifying ConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/ConnectionFactory")
- JMSContext context;
-
- @Resource(name = "jms/MyConnectionFactory")
- ConnectionFactory cfactory;
-
- @Resource(name = "jms/MY_QUEUE")
- Queue queue;
-
- @Resource(name = "jms/MY_TOPIC")
- Topic topic;
-
- @EJB(name = "ejb/CDIUseCasesBMBEAN2")
- BMBean2IF bmbean2;
-
- @Inject
- UserTransaction ut;
-
- @PostConstruct
- public void postConstruct() {
- System.out.println("BMBean1:postConstruct()");
- System.out.println("queue=" + queue);
- System.out.println("topic=" + topic);
- System.out.println("cfactory=" + cfactory);
- System.out.println("bmbean2=" + bmbean2);
- System.out.println("ut=" + ut);
- if (queue == null || topic == null || context == null || cfactory == null
- || bmbean2 == null || ut == null) {
- throw new EJBException("postConstruct failed: injection failure");
- }
- }
-
- public void init(Properties p) {
- TestUtil.logMsg("BMBean1.init()");
- try {
- TestUtil.init(p);
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- } catch (RemoteLoggingInitException e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("BMBean1.init: failed");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("BMBean1.init: failed");
- }
- }
-
- public boolean cleanupQueue(int numOfMsgs) {
- int count = 0;
- String message = null;
- TestUtil.logMsg("BMBean1.cleanupQueue()");
- try {
- JMSConsumer consumer = context.createConsumer(queue);
- for (int i = 0; i < numOfMsgs; i++) {
- message = consumer.receiveBody(String.class, timeout);
- if (message != null) {
- TestUtil.logMsg("Cleanup message: [" + message + "]");
- count++;
- }
- }
- while ((message = consumer.receiveBody(String.class, timeout)) != null) {
- TestUtil.logMsg("Cleanup message: [" + message + "]");
- count++;
- }
- consumer.close();
- TestUtil.logMsg("Cleaned up " + count + " messages from Queue (numOfMsgs="
- + numOfMsgs + ")");
- if (count == numOfMsgs)
- return true;
- else
- return false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("CMBean1.cleanupQueue: failed");
- }
- }
-
- public void method1() {
- TestUtil.logMsg("BMBean1.method1(): JMSContext context=" + context);
- JMSProducer producer = context.createProducer();
- TestUtil.logMsg("Sending message [Message 1]");
- producer.send(queue, "Message 1");
- TestUtil.logMsg("Sending message [Message 2]");
- producer.send(queue, "Message 2");
- }
-
- public void method2() {
- TestUtil.logMsg("BMBean1.method2(): JMSContext context=" + context);
- TestUtil.logMsg("Sending message [Message 1]");
- context.createProducer().send(queue, "Message 1");
- TestUtil.logMsg("Calling BMBean2.method2()");
- bmbean2.method2();
- }
-
- public void method3() {
- try {
- TestUtil.logMsg("BMBean1.method3()");
- TestUtil.logMsg("Begin First User Transaction");
- ut.begin();
- TestUtil.logMsg("JMSContext context=" + context);
- JMSProducer producer = context.createProducer();
- TestUtil.logMsg("Sending message [Message 1]");
- producer.send(queue, "Message 1");
- TestUtil.logMsg("Sending message [Message 2]");
- producer.send(queue, "Message 2");
- TestUtil.logMsg("Commit First User Transaction");
- ut.commit();
- TestUtil.logMsg("Begin Second User Transaction");
- ut.begin();
- producer = context.createProducer();
- TestUtil.logMsg("Sending message [Message 3]");
- producer.send(queue, "Message 3");
- TestUtil.logMsg("Sending message [Message 4]");
- producer.send(queue, "Message 4");
- TestUtil.logMsg("Commit Second User Transaction");
- ut.commit();
- } catch (Exception e) {
- throw new EJBException(e);
- }
- }
-
- public void method4() {
- TestUtil.logMsg("BMBean1.method4(): JMSContext context=" + context);
- try {
- JMSProducer producer = context.createProducer();
- TestUtil.logMsg("Sending message [Message 1]");
- producer.send(queue, "Message 1");
- TestUtil.logMsg("Sending message [Message 2]");
- producer.send(queue, "Message 2");
- TestUtil.logMsg("Begin User Transaction");
- ut.begin();
- producer = context.createProducer();
- TestUtil.logMsg("Sending message [Message 3]");
- producer.send(queue, "Message 3");
- TestUtil.logMsg("Commit User Transaction");
- ut.commit();
- producer = context.createProducer();
- TestUtil.logMsg("Sending message [Message 4]");
- producer.send(queue, "Message 4");
- TestUtil.logMsg("Sending message [Message 5]");
- producer.send(queue, "Message 5");
- } catch (Exception e) {
- throw new EJBException(e);
- }
- }
+ private static final long serialVersionUID = 1L;
+
+ long timeout;
+
+ private static final Logger logger = (Logger) System.getLogger(BMBean1.class.getName());
+
+ // JMSContext CDI injection specifying ConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/ConnectionFactory")
+ JMSContext context;
+
+ @Resource(name = "jms/MyConnectionFactory")
+ ConnectionFactory cfactory;
+
+ @Resource(name = "jms/MY_QUEUE")
+ Queue queue;
+
+ @Resource(name = "jms/MY_TOPIC")
+ Topic topic;
+
+ @EJB(name = "ejb/CDIUseCasesBMBEAN2")
+ BMBean2IF bmbean2;
+
+ @Inject
+ UserTransaction ut;
+
+ @PostConstruct
+ public void postConstruct() {
+ System.out.println("BMBean1:postConstruct()");
+ System.out.println("queue=" + queue);
+ System.out.println("topic=" + topic);
+ System.out.println("cfactory=" + cfactory);
+ System.out.println("bmbean2=" + bmbean2);
+ System.out.println("ut=" + ut);
+ if (queue == null || topic == null || context == null || cfactory == null || bmbean2 == null || ut == null) {
+ throw new EJBException("postConstruct failed: injection failure");
+ }
+ }
+
+ public void init(Properties p) {
+ logger.log(Logger.Level.INFO, "BMBean1.init()");
+ try {
+ TestUtil.init(p);
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ } catch (RemoteLoggingInitException e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("BMBean1.init: failed");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("BMBean1.init: failed");
+ }
+ }
+
+ public boolean cleanupQueue(int numOfMsgs) {
+ int count = 0;
+ String message = null;
+ logger.log(Logger.Level.INFO, "BMBean1.cleanupQueue()");
+ try {
+ JMSConsumer consumer = context.createConsumer(queue);
+ for (int i = 0; i < numOfMsgs; i++) {
+ message = consumer.receiveBody(String.class, timeout);
+ if (message != null) {
+ logger.log(Logger.Level.INFO, "Cleanup message: [" + message + "]");
+ count++;
+ }
+ }
+ while ((message = consumer.receiveBody(String.class, timeout)) != null) {
+ logger.log(Logger.Level.INFO, "Cleanup message: [" + message + "]");
+ count++;
+ }
+ consumer.close();
+ logger.log(Logger.Level.INFO, "Cleaned up " + count + " messages from Queue (numOfMsgs=" + numOfMsgs + ")");
+ if (count == numOfMsgs)
+ return true;
+ else
+ return false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("CMBean1.cleanupQueue: failed");
+ }
+ }
+
+ public void method1() {
+ logger.log(Logger.Level.INFO, "BMBean1.method1(): JMSContext context=" + context);
+ JMSProducer producer = context.createProducer();
+ logger.log(Logger.Level.INFO, "Sending message [Message 1]");
+ producer.send(queue, "Message 1");
+ logger.log(Logger.Level.INFO, "Sending message [Message 2]");
+ producer.send(queue, "Message 2");
+ }
+
+ public void method2() {
+ logger.log(Logger.Level.INFO, "BMBean1.method2(): JMSContext context=" + context);
+ logger.log(Logger.Level.INFO, "Sending message [Message 1]");
+ context.createProducer().send(queue, "Message 1");
+ logger.log(Logger.Level.INFO, "Calling BMBean2.method2()");
+ bmbean2.method2();
+ }
+
+ public void method3() {
+ try {
+ logger.log(Logger.Level.INFO, "BMBean1.method3()");
+ logger.log(Logger.Level.INFO, "Begin First User Transaction");
+ ut.begin();
+ logger.log(Logger.Level.INFO, "JMSContext context=" + context);
+ JMSProducer producer = context.createProducer();
+ logger.log(Logger.Level.INFO, "Sending message [Message 1]");
+ producer.send(queue, "Message 1");
+ logger.log(Logger.Level.INFO, "Sending message [Message 2]");
+ producer.send(queue, "Message 2");
+ logger.log(Logger.Level.INFO, "Commit First User Transaction");
+ ut.commit();
+ logger.log(Logger.Level.INFO, "Begin Second User Transaction");
+ ut.begin();
+ producer = context.createProducer();
+ logger.log(Logger.Level.INFO, "Sending message [Message 3]");
+ producer.send(queue, "Message 3");
+ logger.log(Logger.Level.INFO, "Sending message [Message 4]");
+ producer.send(queue, "Message 4");
+ logger.log(Logger.Level.INFO, "Commit Second User Transaction");
+ ut.commit();
+ } catch (Exception e) {
+ throw new EJBException(e);
+ }
+ }
+
+ public void method4() {
+ logger.log(Logger.Level.INFO, "BMBean1.method4(): JMSContext context=" + context);
+ try {
+ JMSProducer producer = context.createProducer();
+ logger.log(Logger.Level.INFO, "Sending message [Message 1]");
+ producer.send(queue, "Message 1");
+ logger.log(Logger.Level.INFO, "Sending message [Message 2]");
+ producer.send(queue, "Message 2");
+ logger.log(Logger.Level.INFO, "Begin User Transaction");
+ ut.begin();
+ producer = context.createProducer();
+ logger.log(Logger.Level.INFO, "Sending message [Message 3]");
+ producer.send(queue, "Message 3");
+ logger.log(Logger.Level.INFO, "Commit User Transaction");
+ ut.commit();
+ producer = context.createProducer();
+ logger.log(Logger.Level.INFO, "Sending message [Message 4]");
+ producer.send(queue, "Message 4");
+ logger.log(Logger.Level.INFO, "Sending message [Message 5]");
+ producer.send(queue, "Message 5");
+ } catch (Exception e) {
+ throw new EJBException(e);
+ }
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean1IF.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean1IF.java
index f604b1e91f..94690c461e 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean1IF.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean1IF.java
@@ -17,15 +17,15 @@
package com.sun.ts.tests.jms.ee20.cditests.usecases;
public interface BMBean1IF {
- public void init(java.util.Properties p);
+ public void init(java.util.Properties p);
- public boolean cleanupQueue(int numOfMsgs);
+ public boolean cleanupQueue(int numOfMsgs);
- public void method1();
+ public void method1();
- public void method2();
+ public void method2();
- public void method3();
+ public void method3();
- public void method4();
+ public void method4();
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean2.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean2.java
index a5334daa41..30f8753700 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean2.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean2.java
@@ -16,6 +16,7 @@
package com.sun.ts.tests.jms.ee20.cditests.usecases;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.RemoteLoggingInitException;
@@ -40,49 +41,51 @@
@Remote({ BMBean2IF.class })
public class BMBean2 implements BMBean2IF {
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 1L;
- // JMSContext CDI injection specifying ConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/ConnectionFactory")
- JMSContext context;
+ // JMSContext CDI injection specifying ConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/ConnectionFactory")
+ JMSContext context;
- @Resource(name = "jms/MyConnectionFactory")
- ConnectionFactory cfactory;
+ @Resource(name = "jms/MyConnectionFactory")
+ ConnectionFactory cfactory;
- @Resource(name = "jms/MY_QUEUE")
- Queue queue;
+ @Resource(name = "jms/MY_QUEUE")
+ Queue queue;
- @Resource(name = "jms/MY_TOPIC")
- Topic topic;
+ @Resource(name = "jms/MY_TOPIC")
+ Topic topic;
- @PostConstruct
- public void postConstruct() {
- System.out.println("BMBean2:postConstruct()");
- System.out.println("queue=" + queue);
- System.out.println("topic=" + topic);
- System.out.println("cfactory=" + cfactory);
- if (queue == null || topic == null || context == null || cfactory == null) {
- throw new EJBException("postConstruct failed: injection failure");
- }
- }
+ @PostConstruct
+ public void postConstruct() {
+ System.out.println("BMBean2:postConstruct()");
+ System.out.println("queue=" + queue);
+ System.out.println("topic=" + topic);
+ System.out.println("cfactory=" + cfactory);
+ if (queue == null || topic == null || context == null || cfactory == null) {
+ throw new EJBException("postConstruct failed: injection failure");
+ }
+ }
- public void init(Properties p) {
- TestUtil.logMsg("BMBean2.init()");
- try {
- TestUtil.init(p);
- } catch (RemoteLoggingInitException e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("BMBean2.init: failed");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("BMBean2.init: failed");
- }
- }
+ private static final Logger logger = (Logger) System.getLogger(BMBean2.class.getName());
- public void method2() {
- TestUtil.logMsg("BMBean2.method2(): JMSContext context=" + context);
- TestUtil.logMsg("Sending message [Message 2]");
- context.createProducer().send(queue, "Message 2");
- }
+ public void init(Properties p) {
+ logger.log(Logger.Level.INFO, "BMBean2.init()");
+ try {
+ TestUtil.init(p);
+ } catch (RemoteLoggingInitException e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("BMBean2.init: failed");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("BMBean2.init: failed");
+ }
+ }
+
+ public void method2() {
+ logger.log(Logger.Level.INFO, "BMBean2.method2(): JMSContext context=" + context);
+ logger.log(Logger.Level.INFO, "Sending message [Message 2]");
+ context.createProducer().send(queue, "Message 2");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean2IF.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean2IF.java
index 92a1c6ac28..b99856f175 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean2IF.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/BMBean2IF.java
@@ -17,7 +17,7 @@
package com.sun.ts.tests.jms.ee20.cditests.usecases;
public interface BMBean2IF {
- public void init(java.util.Properties p);
+ public void init(java.util.Properties p);
- public void method2();
+ public void method2();
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean1.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean1.java
index 4f85772a39..7cd3a3fd98 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean1.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean1.java
@@ -16,6 +16,7 @@
package com.sun.ts.tests.jms.ee20.cditests.usecases;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.RemoteLoggingInitException;
@@ -45,143 +46,143 @@
@Remote({ CMBean1IF.class })
public class CMBean1 implements CMBean1IF {
- private static final long serialVersionUID = 1L;
-
- long timeout;
-
- // JMSContext CDI injection specifying ConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/ConnectionFactory")
- JMSContext context;
-
- @Resource(name = "jms/MyConnectionFactory")
- ConnectionFactory cfactory;
-
- @Resource(name = "jms/MY_QUEUE")
- Queue queue;
-
- @Resource(name = "jms/MY_TOPIC")
- Topic topic;
-
- @EJB(name = "ejb/CDIUseCasesCMBEAN2")
- CMBean2IF cmbean2;
-
- @PostConstruct
- public void postConstruct() {
- System.out.println("CMBean1:postConstruct()");
- System.out.println("queue=" + queue);
- System.out.println("topic=" + topic);
- System.out.println("cfactory=" + cfactory);
- System.out.println("cmbean2=" + cmbean2);
- if (queue == null || topic == null || context == null || cfactory == null
- || cmbean2 == null) {
- throw new EJBException("postConstruct failed: injection failure");
- }
- }
-
- @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
- public void init(Properties p) {
- TestUtil.logMsg("CMBean1.init()");
- try {
- TestUtil.init(p);
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- } catch (RemoteLoggingInitException e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("CMBean1.init: failed");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("CMBean1.init: failed");
- }
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- public boolean cleanupQueue(int numOfMsgs) {
- int count = 0;
- String message = null;
- TestUtil.logMsg("CMBean1.cleanupQueue()");
- try {
- JMSConsumer consumer = context.createConsumer(queue);
- for (int i = 0; i < numOfMsgs; i++) {
- message = consumer.receiveBody(String.class, timeout);
- if (message != null) {
- TestUtil.logMsg("Cleanup message: [" + message + "]");
- count++;
- }
- }
- while ((message = consumer.receiveBody(String.class, timeout)) != null) {
- TestUtil.logMsg("Cleanup message: [" + message + "]");
- count++;
- }
- consumer.close();
- TestUtil.logMsg("Cleaned up " + count + " messages from Queue (numOfMsgs="
- + numOfMsgs + ")");
- if (count == numOfMsgs)
- return true;
- else
- return false;
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("CMBean1.cleanupQueue: failed");
- }
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void method1a() {
- TestUtil.logMsg("CMBean1.method1a(): JMSContext context=" + context);
- TestUtil.logMsg("Sending message [Message 1]");
- context.createProducer().send(queue, "Message 1");
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void method1b() {
- TestUtil.logMsg("CMBean1.method1b(): JMSContext context=" + context);
- TestUtil.logMsg("Sending message [Message 2]");
- context.createProducer().send(queue, "Message 2");
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void method2() {
- TestUtil.logMsg("CMBean1.method2(): JMSContext context=" + context);
- TestUtil.logMsg("Calling CMBean2.method2a() followed by Bean2.method2b()");
- cmbean2.method2a();
- cmbean2.method2b();
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void method3() {
- TestUtil.logMsg("CMBean1.method3(): JMSContext context=" + context);
- TestUtil.logMsg("Sending message [Message 1]");
- context.createProducer().send(queue, "Message 1");
- TestUtil.logMsg("Calling CMBean2.method3()");
- cmbean2.method3();
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void method4() {
- TestUtil.logMsg("CMBean1.method4(): JMSContext context=" + context);
- JMSProducer producer = context.createProducer();
- TestUtil.logMsg("Sending message [Message 1]");
- producer.send(queue, "Message 1");
- TestUtil.logMsg("Sending message [Message 2]");
- producer.send(queue, "Message 2");
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void method5() {
- TestUtil.logMsg("CMBean1.method5(): JMSContext context=" + context);
- JMSProducer producer = context.createProducer();
- TestUtil.logMsg("Sending message [Message 1]");
- producer.send(queue, "Message 1");
- cmbean2.method5();
- TestUtil.logMsg("Sending message [Message 3]");
- producer.send(queue, "Message 3");
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void method6() {
- TestUtil.logMsg("CMBean1.method6(): JMSContext context=" + context);
- TestUtil.logMsg("Sending message [Message 1]");
- context.createProducer().send(queue, "Message 1");
- cmbean2.method6();
- }
+ private static final long serialVersionUID = 1L;
+
+ long timeout;
+
+ // JMSContext CDI injection specifying ConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/ConnectionFactory")
+ JMSContext context;
+
+ @Resource(name = "jms/MyConnectionFactory")
+ ConnectionFactory cfactory;
+
+ @Resource(name = "jms/MY_QUEUE")
+ Queue queue;
+
+ @Resource(name = "jms/MY_TOPIC")
+ Topic topic;
+
+ @EJB(name = "ejb/CDIUseCasesCMBEAN2")
+ CMBean2IF cmbean2;
+
+ private static final Logger logger = (Logger) System.getLogger(CMBean1.class.getName());
+
+ @PostConstruct
+ public void postConstruct() {
+ System.out.println("CMBean1:postConstruct()");
+ System.out.println("queue=" + queue);
+ System.out.println("topic=" + topic);
+ System.out.println("cfactory=" + cfactory);
+ System.out.println("cmbean2=" + cmbean2);
+ if (queue == null || topic == null || context == null || cfactory == null || cmbean2 == null) {
+ throw new EJBException("postConstruct failed: injection failure");
+ }
+ }
+
+ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
+ public void init(Properties p) {
+ logger.log(Logger.Level.INFO, "CMBean1.init()");
+ try {
+ TestUtil.init(p);
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ } catch (RemoteLoggingInitException e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("CMBean1.init: failed");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("CMBean1.init: failed");
+ }
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public boolean cleanupQueue(int numOfMsgs) {
+ int count = 0;
+ String message = null;
+ logger.log(Logger.Level.INFO, "CMBean1.cleanupQueue()");
+ try {
+ JMSConsumer consumer = context.createConsumer(queue);
+ for (int i = 0; i < numOfMsgs; i++) {
+ message = consumer.receiveBody(String.class, timeout);
+ if (message != null) {
+ logger.log(Logger.Level.INFO, "Cleanup message: [" + message + "]");
+ count++;
+ }
+ }
+ while ((message = consumer.receiveBody(String.class, timeout)) != null) {
+ logger.log(Logger.Level.INFO, "Cleanup message: [" + message + "]");
+ count++;
+ }
+ consumer.close();
+ logger.log(Logger.Level.INFO, "Cleaned up " + count + " messages from Queue (numOfMsgs=" + numOfMsgs + ")");
+ if (count == numOfMsgs)
+ return true;
+ else
+ return false;
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("CMBean1.cleanupQueue: failed");
+ }
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public void method1a() {
+ logger.log(Logger.Level.INFO, "CMBean1.method1a(): JMSContext context=" + context);
+ logger.log(Logger.Level.INFO, "Sending message [Message 1]");
+ context.createProducer().send(queue, "Message 1");
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public void method1b() {
+ logger.log(Logger.Level.INFO, "CMBean1.method1b(): JMSContext context=" + context);
+ logger.log(Logger.Level.INFO, "Sending message [Message 2]");
+ context.createProducer().send(queue, "Message 2");
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public void method2() {
+ logger.log(Logger.Level.INFO, "CMBean1.method2(): JMSContext context=" + context);
+ logger.log(Logger.Level.INFO, "Calling CMBean2.method2a() followed by Bean2.method2b()");
+ cmbean2.method2a();
+ cmbean2.method2b();
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public void method3() {
+ logger.log(Logger.Level.INFO, "CMBean1.method3(): JMSContext context=" + context);
+ logger.log(Logger.Level.INFO, "Sending message [Message 1]");
+ context.createProducer().send(queue, "Message 1");
+ logger.log(Logger.Level.INFO, "Calling CMBean2.method3()");
+ cmbean2.method3();
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public void method4() {
+ logger.log(Logger.Level.INFO, "CMBean1.method4(): JMSContext context=" + context);
+ JMSProducer producer = context.createProducer();
+ logger.log(Logger.Level.INFO, "Sending message [Message 1]");
+ producer.send(queue, "Message 1");
+ logger.log(Logger.Level.INFO, "Sending message [Message 2]");
+ producer.send(queue, "Message 2");
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public void method5() {
+ logger.log(Logger.Level.INFO, "CMBean1.method5(): JMSContext context=" + context);
+ JMSProducer producer = context.createProducer();
+ logger.log(Logger.Level.INFO, "Sending message [Message 1]");
+ producer.send(queue, "Message 1");
+ cmbean2.method5();
+ logger.log(Logger.Level.INFO, "Sending message [Message 3]");
+ producer.send(queue, "Message 3");
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public void method6() {
+ logger.log(Logger.Level.INFO, "CMBean1.method6(): JMSContext context=" + context);
+ logger.log(Logger.Level.INFO, "Sending message [Message 1]");
+ context.createProducer().send(queue, "Message 1");
+ cmbean2.method6();
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean1IF.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean1IF.java
index 96ca11d4b1..fc60c31e72 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean1IF.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean1IF.java
@@ -17,21 +17,21 @@
package com.sun.ts.tests.jms.ee20.cditests.usecases;
public interface CMBean1IF {
- public void init(java.util.Properties p);
+ public void init(java.util.Properties p);
- public boolean cleanupQueue(int numOfMsgs);
+ public boolean cleanupQueue(int numOfMsgs);
- public void method1a();
+ public void method1a();
- public void method1b();
+ public void method1b();
- public void method2();
+ public void method2();
- public void method3();
+ public void method3();
- public void method4();
+ public void method4();
- public void method5();
+ public void method5();
- public void method6();
+ public void method6();
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean2.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean2.java
index 706c92f6b3..652c1bf7a6 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean2.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean2.java
@@ -16,6 +16,7 @@
package com.sun.ts.tests.jms.ee20.cditests.usecases;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.RemoteLoggingInitException;
@@ -42,84 +43,86 @@
@Remote({ CMBean2IF.class })
public class CMBean2 implements CMBean2IF {
- private static final long serialVersionUID = 1L;
-
- // JMSContext CDI injection specifying ConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/ConnectionFactory")
- JMSContext context;
-
- // JMSContext CDI injection specifying QueueConnectionFactory
- @Inject
- @JMSConnectionFactory("jms/QueueConnectionFactory")
- JMSContext context2;
-
- @Resource(name = "jms/MyConnectionFactory")
- ConnectionFactory cfactory;
-
- @Resource(name = "jms/MY_QUEUE")
- Queue queue;
-
- @Resource(name = "jms/MY_TOPIC")
- Topic topic;
-
- @PostConstruct
- public void postConstruct() {
- System.out.println("CMBean2:postConstruct()");
- System.out.println("queue=" + queue);
- System.out.println("topic=" + topic);
- System.out.println("cfactory=" + cfactory);
- if (queue == null || topic == null || context == null || cfactory == null) {
- throw new EJBException("postConstruct failed: injection failure");
- }
- }
-
- @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
- public void init(Properties p) {
- TestUtil.logMsg("CMBean2.init()");
- try {
- TestUtil.init(p);
- } catch (RemoteLoggingInitException e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("CMBean2.init: failed");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("CMBean2.init: failed");
- }
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void method2a() {
- TestUtil.logMsg("CMBean2.method2a(): context=" + context);
- TestUtil.logMsg("Sending message [Message 1]");
- context.createProducer().send(queue, "Message 1");
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void method2b() {
- TestUtil.logMsg("CMBean2.method2b(): context=" + context);
- TestUtil.logMsg("Sending message [Message 2]");
- context.createProducer().send(queue, "Message 2");
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void method3() {
- TestUtil.logMsg("CMBean2.method3(): context=" + context);
- TestUtil.logMsg("Sending message [Message 2]");
- context.createProducer().send(queue, "Message 2");
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
- public void method5() {
- TestUtil.logMsg("CMBean2.method5(): context=" + context);
- TestUtil.logMsg("Sending message [Message 2]");
- context.createProducer().send(queue, "Message 2");
- }
-
- @TransactionAttribute(TransactionAttributeType.REQUIRED)
- public void method6() {
- TestUtil.logMsg("CMBean2.method6(): context=" + context);
- TestUtil.logMsg("Sending message [Message 2]");
- context2.createProducer().send(queue, "Message 2");
- }
+ private static final long serialVersionUID = 1L;
+
+ // JMSContext CDI injection specifying ConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/ConnectionFactory")
+ JMSContext context;
+
+ // JMSContext CDI injection specifying QueueConnectionFactory
+ @Inject
+ @JMSConnectionFactory("jms/QueueConnectionFactory")
+ JMSContext context2;
+
+ @Resource(name = "jms/MyConnectionFactory")
+ ConnectionFactory cfactory;
+
+ @Resource(name = "jms/MY_QUEUE")
+ Queue queue;
+
+ @Resource(name = "jms/MY_TOPIC")
+ Topic topic;
+
+ private static final Logger logger = (Logger) System.getLogger(CMBean2.class.getName());
+
+ @PostConstruct
+ public void postConstruct() {
+ System.out.println("CMBean2:postConstruct()");
+ System.out.println("queue=" + queue);
+ System.out.println("topic=" + topic);
+ System.out.println("cfactory=" + cfactory);
+ if (queue == null || topic == null || context == null || cfactory == null) {
+ throw new EJBException("postConstruct failed: injection failure");
+ }
+ }
+
+ @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
+ public void init(Properties p) {
+ logger.log(Logger.Level.INFO, "CMBean2.init()");
+ try {
+ TestUtil.init(p);
+ } catch (RemoteLoggingInitException e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("CMBean2.init: failed");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("CMBean2.init: failed");
+ }
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public void method2a() {
+ logger.log(Logger.Level.INFO, "CMBean2.method2a(): context=" + context);
+ logger.log(Logger.Level.INFO, "Sending message [Message 1]");
+ context.createProducer().send(queue, "Message 1");
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public void method2b() {
+ logger.log(Logger.Level.INFO, "CMBean2.method2b(): context=" + context);
+ logger.log(Logger.Level.INFO, "Sending message [Message 2]");
+ context.createProducer().send(queue, "Message 2");
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public void method3() {
+ logger.log(Logger.Level.INFO, "CMBean2.method3(): context=" + context);
+ logger.log(Logger.Level.INFO, "Sending message [Message 2]");
+ context.createProducer().send(queue, "Message 2");
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
+ public void method5() {
+ logger.log(Logger.Level.INFO, "CMBean2.method5(): context=" + context);
+ logger.log(Logger.Level.INFO, "Sending message [Message 2]");
+ context.createProducer().send(queue, "Message 2");
+ }
+
+ @TransactionAttribute(TransactionAttributeType.REQUIRED)
+ public void method6() {
+ logger.log(Logger.Level.INFO, "CMBean2.method6(): context=" + context);
+ logger.log(Logger.Level.INFO, "Sending message [Message 2]");
+ context2.createProducer().send(queue, "Message 2");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean2IF.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean2IF.java
index 26d7a3bd86..ad46c8e058 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean2IF.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/CMBean2IF.java
@@ -17,15 +17,15 @@
package com.sun.ts.tests.jms.ee20.cditests.usecases;
public interface CMBean2IF {
- public void init(java.util.Properties p);
+ public void init(java.util.Properties p);
- public void method2a();
+ public void method2a();
- public void method2b();
+ public void method2b();
- public void method3();
+ public void method3();
- public void method5();
+ public void method5();
- public void method6();
+ public void method6();
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/Client.java
deleted file mode 100644
index 5e15b5befa..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/Client.java
+++ /dev/null
@@ -1,579 +0,0 @@
-/*
- * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-package com.sun.ts.tests.jms.ee20.cditests.usecases;
-
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.porting.TSURL;
-import com.sun.ts.lib.util.TestUtil;
-
-import jakarta.ejb.EJB;
-
-public class Client extends EETest {
- // The webserver defaults (overidden by harness properties)
- private static final String PROTOCOL = "http";
-
- private static final String HOSTNAME = "localhost";
-
- private static final int PORTNUM = 8000;
-
- private TSURL ctsurl = new TSURL();
-
- private Properties props = null;
-
- private String hostname = HOSTNAME;
-
- private int portnum = PORTNUM;
-
- // URL properties used by the test
- private URL url = null;
-
- private URLConnection urlConn = null;
-
- @EJB(name = "ejb/CDIUseCasesCMBEAN1")
- static CMBean1IF cmbean1;
-
- @EJB(name = "ejb/CDIUseCasesCMBEAN2")
- static CMBean2IF cmbean2;
-
- @EJB(name = "ejb/CDIUseCasesBMBEAN1")
- static BMBean1IF bmbean1;
-
- @EJB(name = "ejb/CDIUseCasesBMBEAN2")
- static BMBean2IF bmbean2;
-
- private static final long serialVersionUID = 1L;
-
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup */
-
- /*
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- * webServerHost; webServerPort;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- boolean pass = true;
- try {
- // get props
- timeout = Integer.parseInt(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- hostname = p.getProperty("webServerHost");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- if (hostname == null) {
- throw new Exception("'webServerHost' in ts.jte must not be null");
- }
- try {
- portnum = Integer.parseInt(p.getProperty("webServerPort"));
- } catch (Exception e) {
- throw new Exception("'webServerPort' in ts.jte must be a number");
- }
- TestUtil.logMsg(
- "AppClient DEBUG: cmbean1=" + cmbean1 + " cmbean2=" + cmbean2);
- TestUtil.logMsg(
- "AppClient DEBUG: bmbean1=" + bmbean1 + " bmbean2=" + bmbean2);
- if (cmbean1 == null || cmbean2 == null || bmbean1 == null
- || bmbean2 == null) {
- throw new Exception("setup failed: ejb injection failure");
- } else {
- cmbean1.init(p);
- cmbean2.init(p);
- bmbean1.init(p);
- bmbean2.init(p);
- }
- } catch (Exception e) {
- throw new Exception("setup failed:", e);
- }
- TestUtil.logMsg("setup ok");
- }
-
- public void cleanup() throws Exception {
- TestUtil.logMsg("cleanup ok");
- }
-
- /*
- * @testName: beanUseCaseA
- *
- * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
- *
- * @test_Strategy: Use case A: Two methods on the same bean within separate
- * transactions. A remote client obtains a reference to Bean1 and calls the
- * methods method1a and method1b in turn.
- *
- * Bean1 is a stateless session bean configured to use container managed
- * transactions with the two business methods method1a and method1b. Each
- * method is configured to require a transaction. The bean has an injected
- * JMSContext. Each method uses the context to send a message.
- */
- public void beanUseCaseA() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------");
- TestUtil.logMsg("BeanUseCaseA");
- TestUtil.logMsg("------------");
- cmbean1.method1a();
- cmbean1.method1b();
- boolean status = cmbean1.cleanupQueue(2);
- if (!status) {
- pass = false;
- TestUtil.logErr("beanUseCaseA cleanup of Queue failed");
- } else {
- TestUtil.logMsg("beanUseCaseA passed");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.logErr("beanUseCaseA failed");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("beanUseCaseA failed");
- }
- }
-
- /*
- * @testName: beanUseCaseB
- *
- * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
- *
- * @test_Strategy: Use case B: Two methods on the same bean within the same
- * transaction. A remote client obtains a reference to Bean1 and calls
- * method2.
- *
- * Consider two stateless session beans, Bean1 and Bean2.
- *
- * Bean1 is configured to use container managed transactions and has a
- * business method method2, which is configured to require a transaction. This
- * invokes method2a and method2b on Bean2 in turn.
- *
- * Bean2 is also configured to use container managed transactions and has the
- * two business methods method2a and method2b which are configured to require
- * a transaction. The bean has an injected JMSContext. Each method uses the
- * context to send a message.
- */
- public void beanUseCaseB() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------");
- TestUtil.logMsg("BeanUseCaseB");
- TestUtil.logMsg("------------");
- cmbean1.method2();
- boolean status = cmbean1.cleanupQueue(2);
- if (!status) {
- pass = false;
- TestUtil.logErr("beanUseCaseB cleanup of Queue failed");
- } else {
- TestUtil.logMsg("beanUseCaseB passed");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.logErr("beanUseCaseB failed");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("beanUseCaseB failed");
- }
- }
-
- /*
- * @testName: beanUseCaseC
- *
- * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
- *
- * @test_Strategy: Use case C: One bean which calls another within the same
- * transaction transaction. A remote client obtains a reference to Bean1 and
- * calls method3.
- *
- * Consider two stateless session beans, Bean1 and Bean2.
- *
- * Bean1 is configured to use container managed transactions and has the
- * business method method3, which is configured to require a transaction. The
- * bean has an injected JMSContext. method3 uses this context to send a
- * message and then invokes method3 on Bean2.
- *
- * Bean2 is also configured to use container-managed transactions and has the
- * business method method3, which is also configured to require a transaction.
- * The bean also has an injected JMSContext with identical annotations to
- * Bean1. method3 simply uses this context to send a second message.
- */
- public void beanUseCaseC() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------");
- TestUtil.logMsg("BeanUseCaseC");
- TestUtil.logMsg("------------");
- cmbean1.method3();
- boolean status = cmbean1.cleanupQueue(2);
- if (!status) {
- pass = false;
- TestUtil.logErr("beanUseCaseC cleanup of Queue failed");
- } else {
- TestUtil.logMsg("beanUseCaseC passed");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.logErr("beanUseCaseC failed");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("beanUseCaseC failed");
- }
- }
-
- /*
- * @testName: beanUseCaseD
- *
- * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
- *
- * @test_Strategy: Use case D: One bean which sends two messages within the
- * same transaction. A remote client obtains a reference to Bean1 and calls
- * method4.
- *
- * Bean1 is configured to use container managed transactions and has a
- * business method method4 which is configured to require a transaction. The
- * bean has an injected JMSContext. method4 uses this context to send two
- * messages.
- */
- public void beanUseCaseD() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------");
- TestUtil.logMsg("BeanUseCaseD");
- TestUtil.logMsg("------------");
- cmbean1.method4();
- boolean status = cmbean1.cleanupQueue(2);
- if (!status) {
- pass = false;
- TestUtil.logErr("beanUseCaseD cleanup of Queue failed");
- } else {
- TestUtil.logMsg("beanUseCaseD passed");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.logErr("beanUseCaseD failed");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("beanUseCaseD failed");
- }
- }
-
- /*
- * @testName: beanUseCaseE
- *
- * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
- *
- * @test_Strategy: Use case E: One bean which sends two messages when there is
- * no transaction.
- *
- * Consider a stateless session bean Bean1. This is configured to use
- * bean-managed transactions and has a business method method1. The bean has
- * an injected JMSContext. method1 does not start a transaction and uses the
- * context to send two messages.
- *
- * A remote client obtains a reference to Bean1 and calls method1.
- */
- public void beanUseCaseE() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------");
- TestUtil.logMsg("BeanUseCaseE");
- TestUtil.logMsg("------------");
- bmbean1.method1();
- boolean status = bmbean1.cleanupQueue(2);
- if (!status) {
- pass = false;
- TestUtil.logErr("beanUseCaseE cleanup of Queue failed");
- } else {
- TestUtil.logMsg("beanUseCaseE passed");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.logErr("beanUseCaseE failed");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("beanUseCaseE failed");
- }
- }
-
- /*
- * @testName: beanUseCaseF
- *
- * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
- *
- * @test_Strategy: Use case F: One bean which calls another when there is no
- * transaction.
- *
- * Consider two stateless session beans, Bean1 and Bean2.
- *
- * Bean1 is configured to use bean-managed transactions and has a business
- * method method2. The bean has an injected JMSContext. method2 does not start
- * a transaction, uses this context to send a message, and then invoke method2
- * on Bean2.
- *
- * Bean2 is also configured to use bean-managed transactions and has a
- * business method method2. The bean has an injected JMSContext. method2 does
- * not start a transaction and simply uses this context to send a second
- * message.
- *
- * A remote client obtains a reference to Bean1 and calls method2.
- */
- public void beanUseCaseF() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------");
- TestUtil.logMsg("BeanUseCaseF");
- TestUtil.logMsg("------------");
- bmbean1.method2();
- boolean status = bmbean1.cleanupQueue(2);
- if (!status) {
- pass = false;
- TestUtil.logErr("beanUseCaseF cleanup of Queue failed");
- } else {
- TestUtil.logMsg("beanUseCaseF passed");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.logErr("beanUseCaseF failed");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("beanUseCaseF failed");
- }
- }
-
- /*
- * @testName: beanUseCaseG
- *
- * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
- *
- * @test_Strategy: Use case G: One bean method which uses two transactions.
- *
- * Consider a stateless session bean Bean1. This is configured to use
- * bean-managed transactions and has a business method, method3. The bean has
- * an injected JMSContext. method3 starts a transaction and uses the context
- * to send two messages. It then commits the transaction and starts a second
- * transaction. It then uses the context to send two further messages and
- * finally commits the second transaction.
- *
- * A remote client obtains a reference to Bean1 and calls method3.
- */
- public void beanUseCaseG() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------");
- TestUtil.logMsg("BeanUseCaseG");
- TestUtil.logMsg("------------");
- bmbean1.method3();
- boolean status = bmbean1.cleanupQueue(4);
- if (!status) {
- pass = false;
- TestUtil.logErr("beanUseCaseG cleanup of Queue failed");
- } else {
- TestUtil.logMsg("beanUseCaseG passed");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.logErr("beanUseCaseG failed");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("beanUseCaseG failed");
- }
- }
-
- /*
- * @testName: beanUseCaseH
- *
- * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
- *
- * @test_Strategy: Use case H. A bean which uses a context both outside and
- * within a transaction.
- *
- * Consider a stateless session bean Bean1. This is configured to use
- * bean-managed transactions and has a business method method4. The bean has
- * an injected JMSContext. method4 does not start a transaction and uses the
- * context variable to send two messages. It then starts a transaction and
- * uses the context variable to send a third message. It then commits the
- * transaction and uses the context variable to send a fourth and fifth more
- * messages.
- *
- * A remote client obtains a reference to Bean1 and calls method4.
- */
- public void beanUseCaseH() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------");
- TestUtil.logMsg("BeanUseCaseH");
- TestUtil.logMsg("------------");
- bmbean1.method4();
- boolean status = bmbean1.cleanupQueue(5);
- if (!status) {
- pass = false;
- TestUtil.logErr("beanUseCaseH cleanup of Queue failed");
- } else {
- TestUtil.logMsg("beanUseCaseH passed");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.logErr("beanUseCaseH failed");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("beanUseCaseH failed");
- }
- }
-
- /*
- * @testName: beanUseCaseJ
- *
- * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
- *
- * @test_Strategy: Use case J. Two separate container-managed transactions on
- * the same thread, one suspended before the second is started
- *
- * Consider two stateless session beans, Bean1 and Bean2.
- *
- * Bean1 is configured to use container-managed transactions and has a
- * business method method5, which is configured to require a transaction. The
- * bean has an injected JMSContext. method5 uses this context to send a
- * message and then invokes method5 on bean2. It then sends a further message.
- *
- * Bean2 is also configured to use container-managed transactions and has a
- * business method method5, which is configured to require a new transaction.
- * The bean has an injected JMSContext. method5 simply uses this context to
- * send a message.
- *
- * A remote client obtains a reference to Bean1 and calls method5.
- */
- public void beanUseCaseJ() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------");
- TestUtil.logMsg("BeanUseCaseJ");
- TestUtil.logMsg("------------");
- cmbean1.method5();
- boolean status = cmbean1.cleanupQueue(3);
- if (!status) {
- pass = false;
- TestUtil.logErr("beanUseCaseJ cleanup of Queue failed");
- } else {
- TestUtil.logMsg("beanUseCaseJ passed");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.logErr("beanUseCaseJ failed");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("beanUseCaseJ failed");
- }
- }
-
- /*
- * @testName: beanUseCaseK
- *
- * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
- *
- * @test_Strategy: Use case K. One bean which calls another within the same
- * transaction, but using different connection factories
- *
- * (Note that this use case is identical to use case C except that the two
- * beans specify different connection factories).
- *
- * Consider two stateless session beans, Bean1 and Bean2
- *
- * Bean1 is configured to use container-managed transactions and has a
- * business method method6, which is configured to require a transaction. The
- * bean has an injected JMSContext. method6 uses this context to send a
- * message and then invokes method6 on Bean2.
- *
- * Bean2 is also configured to use container-managed transactions and has a
- * business method method6, which is also configured to require a transaction.
- * The bean also has an injected JMSContext to Bean1, but specifies a
- * different connection factory. method6 simply uses this context to send a
- * second message.
- *
- * A remote client obtains a reference to Bean1 and calls method6
- */
- public void beanUseCaseK() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("------------");
- TestUtil.logMsg("BeanUseCaseK");
- TestUtil.logMsg("------------");
- cmbean1.method6();
- boolean status = cmbean1.cleanupQueue(2);
- if (!status) {
- pass = false;
- TestUtil.logErr("beanUseCaseK cleanup of Queue failed");
- } else {
- TestUtil.logMsg("beanUseCaseK passed");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught unexpected exception: " + e);
- TestUtil.logErr("beanUseCaseK failed");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("beanUseCaseK failed");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/ClientIT.java
new file mode 100644
index 0000000000..9093f4d215
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/cditests/usecases/ClientIT.java
@@ -0,0 +1,580 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package com.sun.ts.tests.jms.ee20.cditests.usecases;
+
+import java.lang.System.Logger;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.porting.TSURL;
+
+import jakarta.ejb.EJB;
+
+
+public class ClientIT {
+ // The webserver defaults (overidden by harness properties)
+ private static final String PROTOCOL = "http";
+
+ private static final String HOSTNAME = "localhost";
+
+ private static final int PORTNUM = 8000;
+
+ private TSURL ctsurl = new TSURL();
+
+ private Properties props = null;
+
+ private String hostname = HOSTNAME;
+
+ private int portnum = PORTNUM;
+
+ // URL properties used by the test
+ private URL url = null;
+
+ private URLConnection urlConn = null;
+
+ @EJB(name = "ejb/CDIUseCasesCMBEAN1")
+ static CMBean1IF cmbean1;
+
+ @EJB(name = "ejb/CDIUseCasesCMBEAN2")
+ static CMBean2IF cmbean2;
+
+ @EJB(name = "ejb/CDIUseCasesBMBEAN1")
+ static BMBean1IF bmbean1;
+
+ @EJB(name = "ejb/CDIUseCasesBMBEAN2")
+ static BMBean2IF bmbean2;
+
+ private static final long serialVersionUID = 1L;
+
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /* Test setup */
+
+ /*
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ * webServerHost; webServerPort;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ boolean pass = true;
+ try {
+ // get props
+ timeout = Integer.parseInt(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ hostname = System.getProperty("webServerHost");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ if (hostname == null) {
+ throw new Exception("'webServerHost' is null");
+ }
+ try {
+ portnum = Integer.parseInt(System.getProperty("webServerPort"));
+ } catch (Exception e) {
+ throw new Exception("'webServerPort' in must be a number");
+ }
+ logger.log(Logger.Level.INFO, "AppClient DEBUG: cmbean1=" + cmbean1 + " cmbean2=" + cmbean2);
+ logger.log(Logger.Level.INFO, "AppClient DEBUG: bmbean1=" + bmbean1 + " bmbean2=" + bmbean2);
+ if (cmbean1 == null || cmbean2 == null || bmbean1 == null || bmbean2 == null) {
+ throw new Exception("setup failed: ejb injection failure");
+ } else {
+ // cmbean1.init(p);
+ // cmbean2.init(p);
+ // bmbean1.init(p);
+ // bmbean2.init(p);
+ }
+ } catch (Exception e) {
+ throw new Exception("setup failed:", e);
+ }
+ logger.log(Logger.Level.INFO, "setup ok");
+ }
+
+ @AfterEach
+ public void cleanup() throws Exception {
+ logger.log(Logger.Level.INFO, "cleanup ok");
+ }
+
+ /*
+ * @testName: beanUseCaseA
+ *
+ * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
+ *
+ * @test_Strategy: Use case A: Two methods on the same bean within separate
+ * transactions. A remote client obtains a reference to Bean1 and calls the
+ * methods method1a and method1b in turn.
+ *
+ * Bean1 is a stateless session bean configured to use container managed
+ * transactions with the two business methods method1a and method1b. Each method
+ * is configured to require a transaction. The bean has an injected JMSContext.
+ * Each method uses the context to send a message.
+ */
+ @Test
+ public void beanUseCaseA() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------");
+ logger.log(Logger.Level.INFO, "BeanUseCaseA");
+ logger.log(Logger.Level.INFO, "------------");
+ cmbean1.method1a();
+ cmbean1.method1b();
+ boolean status = cmbean1.cleanupQueue(2);
+ if (!status) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "beanUseCaseA cleanup of Queue failed");
+ } else {
+ logger.log(Logger.Level.INFO, "beanUseCaseA passed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ logger.log(Logger.Level.ERROR, "beanUseCaseA failed");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("beanUseCaseA failed");
+ }
+ }
+
+ /*
+ * @testName: beanUseCaseB
+ *
+ * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
+ *
+ * @test_Strategy: Use case B: Two methods on the same bean within the same
+ * transaction. A remote client obtains a reference to Bean1 and calls method2.
+ *
+ * Consider two stateless session beans, Bean1 and Bean2.
+ *
+ * Bean1 is configured to use container managed transactions and has a business
+ * method method2, which is configured to require a transaction. This invokes
+ * method2a and method2b on Bean2 in turn.
+ *
+ * Bean2 is also configured to use container managed transactions and has the
+ * two business methods method2a and method2b which are configured to require a
+ * transaction. The bean has an injected JMSContext. Each method uses the
+ * context to send a message.
+ */
+ @Test
+ public void beanUseCaseB() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------");
+ logger.log(Logger.Level.INFO, "BeanUseCaseB");
+ logger.log(Logger.Level.INFO, "------------");
+ cmbean1.method2();
+ boolean status = cmbean1.cleanupQueue(2);
+ if (!status) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "beanUseCaseB cleanup of Queue failed");
+ } else {
+ logger.log(Logger.Level.INFO, "beanUseCaseB passed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ logger.log(Logger.Level.ERROR, "beanUseCaseB failed");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("beanUseCaseB failed");
+ }
+ }
+
+ /*
+ * @testName: beanUseCaseC
+ *
+ * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
+ *
+ * @test_Strategy: Use case C: One bean which calls another within the same
+ * transaction transaction. A remote client obtains a reference to Bean1 and
+ * calls method3.
+ *
+ * Consider two stateless session beans, Bean1 and Bean2.
+ *
+ * Bean1 is configured to use container managed transactions and has the
+ * business method method3, which is configured to require a transaction. The
+ * bean has an injected JMSContext. method3 uses this context to send a message
+ * and then invokes method3 on Bean2.
+ *
+ * Bean2 is also configured to use container-managed transactions and has the
+ * business method method3, which is also configured to require a transaction.
+ * The bean also has an injected JMSContext with identical annotations to Bean1.
+ * method3 simply uses this context to send a second message.
+ */
+ @Test
+ public void beanUseCaseC() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------");
+ logger.log(Logger.Level.INFO, "BeanUseCaseC");
+ logger.log(Logger.Level.INFO, "------------");
+ cmbean1.method3();
+ boolean status = cmbean1.cleanupQueue(2);
+ if (!status) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "beanUseCaseC cleanup of Queue failed");
+ } else {
+ logger.log(Logger.Level.INFO, "beanUseCaseC passed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ logger.log(Logger.Level.ERROR, "beanUseCaseC failed");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("beanUseCaseC failed");
+ }
+ }
+
+ /*
+ * @testName: beanUseCaseD
+ *
+ * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
+ *
+ * @test_Strategy: Use case D: One bean which sends two messages within the same
+ * transaction. A remote client obtains a reference to Bean1 and calls method4.
+ *
+ * Bean1 is configured to use container managed transactions and has a business
+ * method method4 which is configured to require a transaction. The bean has an
+ * injected JMSContext. method4 uses this context to send two messages.
+ */
+ @Test
+ public void beanUseCaseD() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------");
+ logger.log(Logger.Level.INFO, "BeanUseCaseD");
+ logger.log(Logger.Level.INFO, "------------");
+ cmbean1.method4();
+ boolean status = cmbean1.cleanupQueue(2);
+ if (!status) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "beanUseCaseD cleanup of Queue failed");
+ } else {
+ logger.log(Logger.Level.INFO, "beanUseCaseD passed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ logger.log(Logger.Level.ERROR, "beanUseCaseD failed");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("beanUseCaseD failed");
+ }
+ }
+
+ /*
+ * @testName: beanUseCaseE
+ *
+ * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
+ *
+ * @test_Strategy: Use case E: One bean which sends two messages when there is
+ * no transaction.
+ *
+ * Consider a stateless session bean Bean1. This is configured to use
+ * bean-managed transactions and has a business method method1. The bean has an
+ * injected JMSContext. method1 does not start a transaction and uses the
+ * context to send two messages.
+ *
+ * A remote client obtains a reference to Bean1 and calls method1.
+ */
+ @Test
+ public void beanUseCaseE() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------");
+ logger.log(Logger.Level.INFO, "BeanUseCaseE");
+ logger.log(Logger.Level.INFO, "------------");
+ bmbean1.method1();
+ boolean status = bmbean1.cleanupQueue(2);
+ if (!status) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "beanUseCaseE cleanup of Queue failed");
+ } else {
+ logger.log(Logger.Level.INFO, "beanUseCaseE passed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ logger.log(Logger.Level.ERROR, "beanUseCaseE failed");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("beanUseCaseE failed");
+ }
+ }
+
+ /*
+ * @testName: beanUseCaseF
+ *
+ * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
+ *
+ * @test_Strategy: Use case F: One bean which calls another when there is no
+ * transaction.
+ *
+ * Consider two stateless session beans, Bean1 and Bean2.
+ *
+ * Bean1 is configured to use bean-managed transactions and has a business
+ * method method2. The bean has an injected JMSContext. method2 does not start a
+ * transaction, uses this context to send a message, and then invoke method2 on
+ * Bean2.
+ *
+ * Bean2 is also configured to use bean-managed transactions and has a business
+ * method method2. The bean has an injected JMSContext. method2 does not start a
+ * transaction and simply uses this context to send a second message.
+ *
+ * A remote client obtains a reference to Bean1 and calls method2.
+ */
+ @Test
+ public void beanUseCaseF() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------");
+ logger.log(Logger.Level.INFO, "BeanUseCaseF");
+ logger.log(Logger.Level.INFO, "------------");
+ bmbean1.method2();
+ boolean status = bmbean1.cleanupQueue(2);
+ if (!status) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "beanUseCaseF cleanup of Queue failed");
+ } else {
+ logger.log(Logger.Level.INFO, "beanUseCaseF passed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ logger.log(Logger.Level.ERROR, "beanUseCaseF failed");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("beanUseCaseF failed");
+ }
+ }
+
+ /*
+ * @testName: beanUseCaseG
+ *
+ * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
+ *
+ * @test_Strategy: Use case G: One bean method which uses two transactions.
+ *
+ * Consider a stateless session bean Bean1. This is configured to use
+ * bean-managed transactions and has a business method, method3. The bean has an
+ * injected JMSContext. method3 starts a transaction and uses the context to
+ * send two messages. It then commits the transaction and starts a second
+ * transaction. It then uses the context to send two further messages and
+ * finally commits the second transaction.
+ *
+ * A remote client obtains a reference to Bean1 and calls method3.
+ */
+ @Test
+ public void beanUseCaseG() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------");
+ logger.log(Logger.Level.INFO, "BeanUseCaseG");
+ logger.log(Logger.Level.INFO, "------------");
+ bmbean1.method3();
+ boolean status = bmbean1.cleanupQueue(4);
+ if (!status) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "beanUseCaseG cleanup of Queue failed");
+ } else {
+ logger.log(Logger.Level.INFO, "beanUseCaseG passed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ logger.log(Logger.Level.ERROR, "beanUseCaseG failed");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("beanUseCaseG failed");
+ }
+ }
+
+ /*
+ * @testName: beanUseCaseH
+ *
+ * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
+ *
+ * @test_Strategy: Use case H. A bean which uses a context both outside and
+ * within a transaction.
+ *
+ * Consider a stateless session bean Bean1. This is configured to use
+ * bean-managed transactions and has a business method method4. The bean has an
+ * injected JMSContext. method4 does not start a transaction and uses the
+ * context variable to send two messages. It then starts a transaction and uses
+ * the context variable to send a third message. It then commits the transaction
+ * and uses the context variable to send a fourth and fifth more messages.
+ *
+ * A remote client obtains a reference to Bean1 and calls method4.
+ */
+ @Test
+ public void beanUseCaseH() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------");
+ logger.log(Logger.Level.INFO, "BeanUseCaseH");
+ logger.log(Logger.Level.INFO, "------------");
+ bmbean1.method4();
+ boolean status = bmbean1.cleanupQueue(5);
+ if (!status) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "beanUseCaseH cleanup of Queue failed");
+ } else {
+ logger.log(Logger.Level.INFO, "beanUseCaseH passed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ logger.log(Logger.Level.ERROR, "beanUseCaseH failed");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("beanUseCaseH failed");
+ }
+ }
+
+ /*
+ * @testName: beanUseCaseJ
+ *
+ * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
+ *
+ * @test_Strategy: Use case J. Two separate container-managed transactions on
+ * the same thread, one suspended before the second is started
+ *
+ * Consider two stateless session beans, Bean1 and Bean2.
+ *
+ * Bean1 is configured to use container-managed transactions and has a business
+ * method method5, which is configured to require a transaction. The bean has an
+ * injected JMSContext. method5 uses this context to send a message and then
+ * invokes method5 on bean2. It then sends a further message.
+ *
+ * Bean2 is also configured to use container-managed transactions and has a
+ * business method method5, which is configured to require a new transaction.
+ * The bean has an injected JMSContext. method5 simply uses this context to send
+ * a message.
+ *
+ * A remote client obtains a reference to Bean1 and calls method5.
+ */
+ @Test
+ public void beanUseCaseJ() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------");
+ logger.log(Logger.Level.INFO, "BeanUseCaseJ");
+ logger.log(Logger.Level.INFO, "------------");
+ cmbean1.method5();
+ boolean status = cmbean1.cleanupQueue(3);
+ if (!status) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "beanUseCaseJ cleanup of Queue failed");
+ } else {
+ logger.log(Logger.Level.INFO, "beanUseCaseJ passed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ logger.log(Logger.Level.ERROR, "beanUseCaseJ failed");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("beanUseCaseJ failed");
+ }
+ }
+
+ /*
+ * @testName: beanUseCaseK
+ *
+ * @assertion_ids: JMS:SPEC:277; JMS:SPEC:279; JMS:SPEC:280;
+ *
+ * @test_Strategy: Use case K. One bean which calls another within the same
+ * transaction, but using different connection factories
+ *
+ * (Note that this use case is identical to use case C except that the two beans
+ * specify different connection factories).
+ *
+ * Consider two stateless session beans, Bean1 and Bean2
+ *
+ * Bean1 is configured to use container-managed transactions and has a business
+ * method method6, which is configured to require a transaction. The bean has an
+ * injected JMSContext. method6 uses this context to send a message and then
+ * invokes method6 on Bean2.
+ *
+ * Bean2 is also configured to use container-managed transactions and has a
+ * business method method6, which is also configured to require a transaction.
+ * The bean also has an injected JMSContext to Bean1, but specifies a different
+ * connection factory. method6 simply uses this context to send a second
+ * message.
+ *
+ * A remote client obtains a reference to Bean1 and calls method6
+ */
+ @Test
+ public void beanUseCaseK() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "------------");
+ logger.log(Logger.Level.INFO, "BeanUseCaseK");
+ logger.log(Logger.Level.INFO, "------------");
+ cmbean1.method6();
+ boolean status = cmbean1.cleanupQueue(2);
+ if (!status) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "beanUseCaseK cleanup of Queue failed");
+ } else {
+ logger.log(Logger.Level.INFO, "beanUseCaseK passed");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught unexpected exception: " + e);
+ logger.log(Logger.Level.ERROR, "beanUseCaseK failed");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("beanUseCaseK failed");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/ActivationConfigBeanBase.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/ActivationConfigBeanBase.java
index b60823af97..9e54992cc8 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/ActivationConfigBeanBase.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/ActivationConfigBeanBase.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -23,6 +23,8 @@
import static com.sun.ts.tests.jms.ee20.ra.common.messaging.Constants.TEST_NAME_KEY;
import static com.sun.ts.tests.jms.ee20.ra.common.messaging.Constants.TEST_NUMBER_KEY;
+import java.lang.System.Logger;
+
import com.sun.ts.tests.jms.ee20.ra.common.messaging.StatusReporter;
import com.sun.ts.tests.jms.ee20.ra.common.messaging.TLogger;
@@ -31,58 +33,57 @@
import jakarta.jms.QueueConnectionFactory;
/**
- * This class must not implement jakarta.jms.MessageListener interface. A subclass
- * may choose one of the following to specify messaging type: implements
- * jakarta.jms.MessageListener; uses
+ * This class must not implement jakarta.jms.MessageListener interface. A
+ * subclass may choose one of the following to specify messaging type:
+ * implements jakarta.jms.MessageListener; uses
* annotation @MessageDriven(messageListenerInterface=MessageListener.class);
* uses descriptor element messaging-type
*/
abstract public class ActivationConfigBeanBase {
- public static final String test1 = "test1";
+ public static final String test1 = "test1";
+
+ abstract public jakarta.ejb.EJBContext getEJBContext();
- abstract public jakarta.ejb.EJBContext getEJBContext();
+ @Resource(name = "qFactory")
+ private QueueConnectionFactory qFactory;
- @Resource(name = "qFactory")
- private QueueConnectionFactory qFactory;
+ @Resource(name = "replyQueue")
+ private Queue replyQueue;
- @Resource(name = "replyQueue")
- private Queue replyQueue;
+ private static final Logger logger = (Logger) System.getLogger(ActivationConfigBeanBase.class.getName());
- // ================== business methods ====================================
- public void onMessage(jakarta.jms.Message msg) {
- TLogger.log("Entering onMessage method of: " + this.getClass().getName());
- boolean status = false;
- String reason = null;
- String testname = null;
- int testNumber = 0;
- try {
- testname = msg.getStringProperty(TEST_NAME_KEY);
- testNumber = msg.getIntProperty(TEST_NUMBER_KEY);
- } catch (jakarta.jms.JMSException e) {
- status = false;
- reason = "Failed to get test name/number from message: " + msg;
- TLogger.log(reason);
- StatusReporter.report(testname, status, reason,
- (QueueConnectionFactory) getEJBContext().lookup("qFactory"),
- (Queue) getEJBContext().lookup("replyQueue"));
- return;
- }
- if (testname == null) {
- // not the message from test client
- return;
- }
+ // ================== business methods ====================================
+ public void onMessage(jakarta.jms.Message msg) {
+ TLogger.log("Entering onMessage method of: " + this.getClass().getName());
+ boolean status = false;
+ String reason = null;
+ String testname = null;
+ int testNumber = 0;
+ try {
+ testname = msg.getStringProperty(TEST_NAME_KEY);
+ testNumber = msg.getIntProperty(TEST_NUMBER_KEY);
+ } catch (jakarta.jms.JMSException e) {
+ status = false;
+ reason = "Failed to get test name/number from message: " + msg;
+ TLogger.log(reason);
+ StatusReporter.report(testname, status, reason, (QueueConnectionFactory) getEJBContext().lookup("qFactory"),
+ (Queue) getEJBContext().lookup("replyQueue"));
+ return;
+ }
+ if (testname == null) {
+ // not the message from test client
+ return;
+ }
- // reply to all messages that have a testname. If the message should be
- // filtered out by selector but end up here, it also replies. Mostly
- // likely this is from client.sendReiveNegative(String, in). The client
- // will fail the test if such a reply reaches the client.
- status = true;
- reason = "ActivationConfigBeanBase received message from " + testname
- + ", testnum " + testNumber;
+ // reply to all messages that have a testname. If the message should be
+ // filtered out by selector but end up here, it also replies. Mostly
+ // likely this is from client.sendReiveNegative(String, in). The client
+ // will fail the test if such a reply reaches the client.
+ status = true;
+ reason = "ActivationConfigBeanBase received message from " + testname + ", testnum " + testNumber;
- TLogger.log(reason);
- StatusReporter.report(testname, status, reason,
- (QueueConnectionFactory) getEJBContext().lookup("qFactory"),
- (Queue) getEJBContext().lookup("replyQueue"));
- }
+ TLogger.log(reason);
+ StatusReporter.report(testname, status, reason, (QueueConnectionFactory) getEJBContext().lookup("qFactory"),
+ (Queue) getEJBContext().lookup("replyQueue"));
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/QueueClientBase.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/QueueClientBase.java
deleted file mode 100644
index 40fe13444e..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/QueueClientBase.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee20.ra.activationconfig.common;
-
-import jakarta.annotation.Resource;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueConnectionFactory;
-
-abstract public class QueueClientBase
- extends com.sun.ts.tests.jms.ee20.ra.common.messaging.QueueClientBase
- implements com.sun.ts.tests.jms.ee20.ra.common.messaging.Constants {
-
- @Resource(name = "sendQueue")
- private static Queue sendQueue;
-
- @Resource(name = "receiveQueue")
- private static Queue receiveQueue;
-
- @Resource(name = "queueConnectionFactory")
- private static QueueConnectionFactory queueConnectionFactory;
-
- protected void initSendQueue() {
- setSendQueue(sendQueue);
- }
-
- protected void initReceiveQueue() {
- setReceiveQueue(receiveQueue);
- }
-
- protected void initQueueConnectionFactory() {
- setQueueConnectionFactory(queueConnectionFactory);
- }
-
- /*
- * testName: test1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- public void test1() throws Exception {
- sendReceive("test1", 0);
- }
-
- /*
- * testName: negativeTest1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest1() throws Exception {
- // the next messages should be filtered out by the ActivationConfigBean
- sendReceiveNegative("test1", 1);
- }
-
- /*
- * testName: negativeTest2
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest2() throws Exception {
- // the next messages should be filtered out by the ActivationConfigBean
- sendReceiveNegative("negativeTest2", 0);
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/QueueClientBaseIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/QueueClientBaseIT.java
new file mode 100644
index 0000000000..36c19f9f07
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/QueueClientBaseIT.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee20.ra.activationconfig.common;
+
+import org.junit.jupiter.api.Test;
+
+import jakarta.annotation.Resource;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueConnectionFactory;
+
+abstract public class QueueClientBaseIT extends com.sun.ts.tests.jms.ee20.ra.common.messaging.QueueClientBase
+ implements com.sun.ts.tests.jms.ee20.ra.common.messaging.Constants {
+
+ @Resource(name = "sendQueue")
+ private static Queue sendQueue;
+
+ @Resource(name = "receiveQueue")
+ private static Queue receiveQueue;
+
+ @Resource(name = "queueConnectionFactory")
+ private static QueueConnectionFactory queueConnectionFactory;
+
+ protected void initSendQueue() {
+ setSendQueue(sendQueue);
+ }
+
+ protected void initReceiveQueue() {
+ setReceiveQueue(receiveQueue);
+ }
+
+ protected void initQueueConnectionFactory() {
+ setQueueConnectionFactory(queueConnectionFactory);
+ }
+
+ /*
+ * testName: test1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ @Test
+ public void test1() throws Exception {
+ sendReceive("test1", 0);
+ }
+
+ /*
+ * testName: negativeTest1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest1() throws Exception {
+ // the next messages should be filtered out by the ActivationConfigBean
+ sendReceiveNegative("test1", 1);
+ }
+
+ /*
+ * testName: negativeTest2
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest2() throws Exception {
+ // the next messages should be filtered out by the ActivationConfigBean
+ sendReceiveNegative("negativeTest2", 0);
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/TopicClientBase.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/TopicClientBase.java
deleted file mode 100644
index f3aa731a08..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/TopicClientBase.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee20.ra.activationconfig.common;
-
-import jakarta.annotation.Resource;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueConnectionFactory;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicConnectionFactory;
-
-abstract public class TopicClientBase
- extends com.sun.ts.tests.jms.ee20.ra.common.messaging.TopicClientBase
- implements com.sun.ts.tests.jms.ee20.ra.common.messaging.Constants {
-
- @Resource(name = "sendTopic")
- private static Topic sendTopic;
-
- @Resource(name = "receiveQueue")
- private static Queue receiveQueue;
-
- @Resource(name = "topicConnectionFactory")
- private static TopicConnectionFactory topicConnectionFactory;
-
- @Resource(name = "queueConnectionFactory")
- private static QueueConnectionFactory queueConnectionFactory;
-
- protected void initSendTopic() {
- setSendTopic(sendTopic);
- }
-
- protected void initReceiveQueue() {
- setReceiveQueue(receiveQueue);
- }
-
- protected void initTopicConnectionFactory() {
- setTopicConnectionFactory(topicConnectionFactory);
- }
-
- protected void initQueueConnectionFactory() {
- setQueueConnectionFactory(queueConnectionFactory);
- }
-
- /*
- * testName: test1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- public void test1() throws Exception {
- sendReceive("test1", 0);
- }
-
- /*
- * testName: negativeTest1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest1() throws Exception {
- // the next messages should be filtered out by the ActivationConfigBean
- sendReceiveNegative("test1", 1);
- }
-
- /*
- * testName: negativeTest2
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest2() throws Exception {
- // the next messages should be filtered out by the ActivationConfigBean
- sendReceiveNegative("negativeTest2", 0);
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/TopicClientBaseIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/TopicClientBaseIT.java
new file mode 100644
index 0000000000..382b3f9c3f
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/common/TopicClientBaseIT.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee20.ra.activationconfig.common;
+
+import org.junit.jupiter.api.Test;
+
+import jakarta.annotation.Resource;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueConnectionFactory;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicConnectionFactory;
+
+abstract public class TopicClientBaseIT extends com.sun.ts.tests.jms.ee20.ra.common.messaging.TopicClientBase
+ implements com.sun.ts.tests.jms.ee20.ra.common.messaging.Constants {
+
+ @Resource(name = "sendTopic")
+ private static Topic sendTopic;
+
+ @Resource(name = "receiveQueue")
+ private static Queue receiveQueue;
+
+ @Resource(name = "topicConnectionFactory")
+ private static TopicConnectionFactory topicConnectionFactory;
+
+ @Resource(name = "queueConnectionFactory")
+ private static QueueConnectionFactory queueConnectionFactory;
+
+ protected void initSendTopic() {
+ setSendTopic(sendTopic);
+ }
+
+ protected void initReceiveQueue() {
+ setReceiveQueue(receiveQueue);
+ }
+
+ protected void initTopicConnectionFactory() {
+ setTopicConnectionFactory(topicConnectionFactory);
+ }
+
+ protected void initQueueConnectionFactory() {
+ setQueueConnectionFactory(queueConnectionFactory);
+ }
+
+ /*
+ * testName: test1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ @Test
+ public void test1() throws Exception {
+ sendReceive("test1", 0);
+ }
+
+ /*
+ * testName: negativeTest1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest1() throws Exception {
+ // the next messages should be filtered out by the ActivationConfigBean
+ sendReceiveNegative("test1", 1);
+ }
+
+ /*
+ * testName: negativeTest2
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest2() throws Exception {
+ // the next messages should be filtered out by the ActivationConfigBean
+ sendReceiveNegative("negativeTest2", 0);
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/annotated/ActivationConfigBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/annotated/ActivationConfigBean.java
index 78c203f3ed..018410571f 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/annotated/ActivationConfigBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/annotated/ActivationConfigBean.java
@@ -35,26 +35,25 @@
//use annotation element messageListenerInterface, nor descritpor element
//messaging-type
@MessageDriven(name = "ActivationConfigBean", activationConfig = {
- @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/QueueConnectionFactory"),
- @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "MDB_QUEUE"),
- @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"),
- @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
- @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1") })
+ @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/QueueConnectionFactory"),
+ @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "MDB_QUEUE"),
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"),
+ @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
+ @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1") })
@TransactionManagement(TransactionManagementType.BEAN)
-public class ActivationConfigBean extends ActivationConfigBeanBase
- implements MessageListener {
+public class ActivationConfigBean extends ActivationConfigBeanBase implements MessageListener {
- @Resource(name = "mdc")
- private MessageDrivenContext mdc;
+ @Resource(name = "mdc")
+ private MessageDrivenContext mdc;
- public ActivationConfigBean() {
- super();
- }
+ public ActivationConfigBean() {
+ super();
+ }
- public EJBContext getEJBContext() {
- return this.mdc;
- }
+ public EJBContext getEJBContext() {
+ return this.mdc;
+ }
- // ================== business methods ====================================
+ // ================== business methods ====================================
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/annotated/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/annotated/Client.java
deleted file mode 100644
index 8518160753..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/annotated/Client.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee20.ra.activationconfig.queue.selectorauto.annotated;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.util.TestUtil;
-
-public class Client extends
- com.sun.ts.tests.jms.ee20.ra.activationconfig.common.QueueClientBase {
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.traceflag;
- * harness.log.port;
- */
-
- /*
- * @testName: test1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- public void test1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_QUEUE");
- TestUtil.logMsg(" destinationType=jakarta.jms.Queue");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
- TestUtil.logMsg("Send message that MATCHES the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil
- .logMsg("Must receive message back since it MATCHES message selector");
- super.test1();
- }
-
- /*
- * @testName: negativeTest1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_QUEUE");
- TestUtil.logMsg(" destinationType=jakarta.jms.Queue");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=1");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest1();
- }
-
- /*
- * @testName: negativeTest2
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest2() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_QUEUE");
- TestUtil.logMsg(" destinationType=jakarta.jms.Queue");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest2();
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/annotated/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/annotated/ClientIT.java
new file mode 100644
index 0000000000..ca57175a12
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/annotated/ClientIT.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee20.ra.activationconfig.queue.selectorauto.annotated;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.Test;
+
+
+public class ClientIT extends com.sun.ts.tests.jms.ee20.ra.activationconfig.common.QueueClientBaseIT {
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+
+ /*
+ * @testName: test1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ @Test
+ public void test1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_QUEUE");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Queue");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
+ logger.log(Logger.Level.INFO, "Send message that MATCHES the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must receive message back since it MATCHES message selector");
+ super.test1();
+ }
+
+ /*
+ * @testName: negativeTest1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_QUEUE");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Queue");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=1");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest1();
+ }
+
+ /*
+ * @testName: negativeTest2
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest2() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_QUEUE");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Queue");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest2();
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/descriptor/ActivationConfigBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/descriptor/ActivationConfigBean.java
index 868cdc3226..ed6a228c3a 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/descriptor/ActivationConfigBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/descriptor/ActivationConfigBean.java
@@ -35,20 +35,19 @@
//assembler not permitted to override transaction management type.
@TransactionManagement(TransactionManagementType.BEAN)
-public class ActivationConfigBean extends ActivationConfigBeanBase
- implements MessageListener {
+public class ActivationConfigBean extends ActivationConfigBeanBase implements MessageListener {
- @Resource(name = "mdc")
- private MessageDrivenContext mdc;
+ @Resource(name = "mdc")
+ private MessageDrivenContext mdc;
- public ActivationConfigBean() {
- super();
- }
+ public ActivationConfigBean() {
+ super();
+ }
- public EJBContext getEJBContext() {
- return this.mdc;
- }
+ public EJBContext getEJBContext() {
+ return this.mdc;
+ }
- // ================== business methods ====================================
+ // ================== business methods ====================================
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/descriptor/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/descriptor/Client.java
deleted file mode 100644
index db483bd18c..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/descriptor/Client.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee20.ra.activationconfig.queue.selectorauto.descriptor;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.util.TestUtil;
-
-public class Client extends
- com.sun.ts.tests.jms.ee20.ra.activationconfig.common.QueueClientBase {
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.traceflag;
- * harness.log.port;
- */
-
- /*
- * @testName: test1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- public void test1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_QUEUE");
- TestUtil.logMsg(" destinationType=jakarta.jms.Queue");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
- TestUtil.logMsg("Send message that MATCHES the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil
- .logMsg("Must receive message back since it MATCHES message selector");
- super.test1();
- }
-
- /*
- * @testName: negativeTest1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_QUEUE");
- TestUtil.logMsg(" destinationType=jakarta.jms.Queue");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=1");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest1();
- }
-
- /*
- * @testName: negativeTest2
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest2() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_QUEUE");
- TestUtil.logMsg(" destinationType=jakarta.jms.Queue");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest2();
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/descriptor/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/descriptor/ClientIT.java
new file mode 100644
index 0000000000..890f3c9b59
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectorauto/descriptor/ClientIT.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee20.ra.activationconfig.queue.selectorauto.descriptor;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.Test;
+
+
+public class ClientIT extends com.sun.ts.tests.jms.ee20.ra.activationconfig.common.QueueClientBaseIT {
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+
+ /*
+ * @testName: test1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ @Test
+ public void test1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_QUEUE");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Queue");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
+ logger.log(Logger.Level.INFO, "Send message that MATCHES the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must receive message back since it MATCHES message selector");
+ super.test1();
+ }
+
+ /*
+ * @testName: negativeTest1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_QUEUE");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Queue");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=1");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest1();
+ }
+
+ /*
+ * @testName: negativeTest2
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest2() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_QUEUE");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Queue");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest2();
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/annotated/ActivationConfigBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/annotated/ActivationConfigBean.java
index bad81e1fc7..f0d24feb2a 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/annotated/ActivationConfigBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/annotated/ActivationConfigBean.java
@@ -35,26 +35,25 @@
//use annotation element messageListenerInterface, nor descritpor element
//messaging-type
@MessageDriven(name = "ActivationConfigBean", activationConfig = {
- @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/QueueConnectionFactory"),
- @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "MDB_QUEUE"),
- @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"),
- @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Dups-ok-acknowledge"),
- @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1") })
+ @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/QueueConnectionFactory"),
+ @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "MDB_QUEUE"),
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Queue"),
+ @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Dups-ok-acknowledge"),
+ @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1") })
@TransactionManagement(TransactionManagementType.BEAN)
-public class ActivationConfigBean extends ActivationConfigBeanBase
- implements MessageListener {
+public class ActivationConfigBean extends ActivationConfigBeanBase implements MessageListener {
- @Resource(name = "mdc")
- private MessageDrivenContext mdc;
+ @Resource(name = "mdc")
+ private MessageDrivenContext mdc;
- public ActivationConfigBean() {
- super();
- }
+ public ActivationConfigBean() {
+ super();
+ }
- public EJBContext getEJBContext() {
- return this.mdc;
- }
+ public EJBContext getEJBContext() {
+ return this.mdc;
+ }
- // ================== business methods ====================================
+ // ================== business methods ====================================
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/annotated/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/annotated/Client.java
deleted file mode 100644
index 66f4d3b0f5..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/annotated/Client.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee20.ra.activationconfig.queue.selectordups.annotated;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.util.TestUtil;
-
-public class Client extends
- com.sun.ts.tests.jms.ee20.ra.activationconfig.common.QueueClientBase {
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.traceflag;
- * harness.log.port;
- */
-
- /*
- * @testName: test1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- public void test1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_QUEUE");
- TestUtil.logMsg(" destinationType=jakarta.jms.Queue");
- TestUtil.logMsg(" acknowledgeMode=Dups-ok-acknowledge");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
- TestUtil.logMsg("Send message that MATCHES the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil
- .logMsg("Must receive message back since it MATCHES message selector");
- super.test1();
- }
-
- /*
- * @testName: negativeTest1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_QUEUE");
- TestUtil.logMsg(" destinationType=jakarta.jms.Queue");
- TestUtil.logMsg(" acknowledgeMode=Dups-ok-acknowledge");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=1");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest1();
- }
-
- /*
- * @testName: negativeTest2
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest2() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_QUEUE");
- TestUtil.logMsg(" destinationType=jakarta.jms.Queue");
- TestUtil.logMsg(" acknowledgeMode=Dups-ok-acknowledge");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest2();
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/annotated/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/annotated/ClientIT.java
new file mode 100644
index 0000000000..a90f1041b9
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/annotated/ClientIT.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee20.ra.activationconfig.queue.selectordups.annotated;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.Test;
+
+
+public class ClientIT extends com.sun.ts.tests.jms.ee20.ra.activationconfig.common.QueueClientBaseIT {
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+
+ /*
+ * @testName: test1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ @Test
+ public void test1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_QUEUE");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Queue");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Dups-ok-acknowledge");
+ logger.log(Logger.Level.INFO, " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
+ logger.log(Logger.Level.INFO, "Send message that MATCHES the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must receive message back since it MATCHES message selector");
+ super.test1();
+ }
+
+ /*
+ * @testName: negativeTest1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_QUEUE");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Queue");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Dups-ok-acknowledge");
+ logger.log(Logger.Level.INFO, " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=1");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest1();
+ }
+
+ /*
+ * @testName: negativeTest2
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest2() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_QUEUE");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Queue");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Dups-ok-acknowledge");
+ logger.log(Logger.Level.INFO, " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest2();
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/descriptor/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/descriptor/Client.java
deleted file mode 100644
index 678f891bc6..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/descriptor/Client.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee20.ra.activationconfig.queue.selectordups.descriptor;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.util.TestUtil;
-
-public class Client extends
- com.sun.ts.tests.jms.ee20.ra.activationconfig.common.QueueClientBase {
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.traceflag;
- * harness.log.port;
- */
-
- /*
- * @testName: test1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- public void test1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_QUEUE");
- TestUtil.logMsg(" destinationType=jakarta.jms.Queue");
- TestUtil.logMsg(" acknowledgeMode=Dups-ok-acknowledge");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
- TestUtil.logMsg("Send message that MATCHES the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil
- .logMsg("Must receive message back since it MATCHES message selector");
- super.test1();
- }
-
- /*
- * @testName: negativeTest1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_QUEUE");
- TestUtil.logMsg(" destinationType=jakarta.jms.Queue");
- TestUtil.logMsg(" acknowledgeMode=Dups-ok-acknowledge");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=1");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest1();
- }
-
- /*
- * @testName: negativeTest2
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest2() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_QUEUE");
- TestUtil.logMsg(" destinationType=jakarta.jms.Queue");
- TestUtil.logMsg(" acknowledgeMode=Dups-ok-acknowledge");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest2();
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/descriptor/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/descriptor/ClientIT.java
new file mode 100644
index 0000000000..c68170f6fe
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/queue/selectordups/descriptor/ClientIT.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee20.ra.activationconfig.queue.selectordups.descriptor;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.Test;
+
+
+public class ClientIT extends com.sun.ts.tests.jms.ee20.ra.activationconfig.common.QueueClientBaseIT {
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+
+ /*
+ * @testName: test1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ @Test
+ public void test1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_QUEUE");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Queue");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Dups-ok-acknowledge");
+ logger.log(Logger.Level.INFO, " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
+ logger.log(Logger.Level.INFO, "Send message that MATCHES the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must receive message back since it MATCHES message selector");
+ super.test1();
+ }
+
+ /*
+ * @testName: negativeTest1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_QUEUE");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Queue");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Dups-ok-acknowledge");
+ logger.log(Logger.Level.INFO, " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=1");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest1();
+ }
+
+ /*
+ * @testName: negativeTest2
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest2() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_QUEUE");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Queue");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Dups-ok-acknowledge");
+ logger.log(Logger.Level.INFO, " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum < 1)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest2();
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/annotated/ActivationConfigBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/annotated/ActivationConfigBean.java
index e5c661fc37..4edf06f226 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/annotated/ActivationConfigBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/annotated/ActivationConfigBean.java
@@ -35,28 +35,27 @@
//use annotation element messageListenerInterface, nor descritpor element
//messaging-type
@MessageDriven(name = "ActivationConfigBean", activationConfig = {
- @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/QueueConnectionFactory"),
- @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "MY_TOPIC"),
- @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Topic"),
- @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
- @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
- @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "MySubscriptionName3ForRATests") })
+ @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/QueueConnectionFactory"),
+ @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "MY_TOPIC"),
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Topic"),
+ @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
+ @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
+ @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "MySubscriptionName3ForRATests") })
@TransactionManagement(TransactionManagementType.BEAN)
-public class ActivationConfigBean extends ActivationConfigBeanBase
- implements MessageListener {
+public class ActivationConfigBean extends ActivationConfigBeanBase implements MessageListener {
- @Resource(name = "mdc")
- private MessageDrivenContext mdc;
+ @Resource(name = "mdc")
+ private MessageDrivenContext mdc;
- public ActivationConfigBean() {
- super();
- }
+ public ActivationConfigBean() {
+ super();
+ }
- public EJBContext getEJBContext() {
- return this.mdc;
- }
+ public EJBContext getEJBContext() {
+ return this.mdc;
+ }
- // ================== business methods ====================================
+ // ================== business methods ====================================
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/annotated/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/annotated/Client.java
deleted file mode 100644
index f7eca3ef52..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/annotated/Client.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee20.ra.activationconfig.topic.noselnocidautodurable.annotated;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.util.TestUtil;
-
-public class Client extends
- com.sun.ts.tests.jms.ee20.ra.activationconfig.common.TopicClientBase {
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.traceflag;
- * harness.log.port;
- */
-
- /*
- * @testName: test1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.5; JMS:SPEC:276.6;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- public void test1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=Durable");
- TestUtil.logMsg(" subscriptionName=MySubscriptionName3ForRATests");
- TestUtil.logMsg("Send message to MDB");
- TestUtil.logMsg("Receive response from MDB");
- sendOnly("test1", 0);
- if (!checkOnResponse("test1")) {
- throw new Exception("checkOnResponse for test1 returned false.");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/annotated/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/annotated/ClientIT.java
new file mode 100644
index 0000000000..2586800d33
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/annotated/ClientIT.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee20.ra.activationconfig.topic.noselnocidautodurable.annotated;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.Test;
+
+
+public class ClientIT extends com.sun.ts.tests.jms.ee20.ra.activationconfig.common.TopicClientBaseIT {
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+
+ /*
+ * @testName: test1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.5; JMS:SPEC:276.6;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ @Test
+ public void test1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=Durable");
+ logger.log(Logger.Level.INFO, " subscriptionName=MySubscriptionName3ForRATests");
+ logger.log(Logger.Level.INFO, "Send message to MDB");
+ logger.log(Logger.Level.INFO, "Receive response from MDB");
+ sendOnly("test1", 0);
+ if (!checkOnResponse("test1")) {
+ throw new Exception("checkOnResponse for test1 returned false.");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/descriptor/ActivationConfigBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/descriptor/ActivationConfigBean.java
index a593d2f969..a0e1679528 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/descriptor/ActivationConfigBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/descriptor/ActivationConfigBean.java
@@ -35,19 +35,18 @@
//assembler not permitted to override transaction management type.
@TransactionManagement(TransactionManagementType.BEAN)
-public class ActivationConfigBean extends ActivationConfigBeanBase
- implements MessageListener {
- @Resource(name = "mdc")
- private MessageDrivenContext mdc;
+public class ActivationConfigBean extends ActivationConfigBeanBase implements MessageListener {
+ @Resource(name = "mdc")
+ private MessageDrivenContext mdc;
- public ActivationConfigBean() {
- super();
- }
+ public ActivationConfigBean() {
+ super();
+ }
- public EJBContext getEJBContext() {
- return this.mdc;
- }
+ public EJBContext getEJBContext() {
+ return this.mdc;
+ }
- // ================== business methods ====================================
+ // ================== business methods ====================================
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/descriptor/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/descriptor/Client.java
deleted file mode 100644
index 48d830c370..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/descriptor/Client.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee20.ra.activationconfig.topic.noselnocidautodurable.descriptor;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.util.TestUtil;
-
-public class Client extends
- com.sun.ts.tests.jms.ee20.ra.activationconfig.common.TopicClientBase {
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.traceflag;
- * harness.log.port;
- */
-
- /*
- * @testName: test1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.5; JMS:SPEC:276.6;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- public void test1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=Durable");
- TestUtil.logMsg(" subscriptionName=MySubscriptionName4ForRATests");
- TestUtil.logMsg("Send message to MDB");
- TestUtil.logMsg("Receive response from MDB");
- sendOnly("test1", 0);
- if (!checkOnResponse("test1")) {
- throw new Exception("checkOnResponse for test1 returned false.");
- }
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/descriptor/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/descriptor/ClientIT.java
new file mode 100644
index 0000000000..9452a9636c
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/noselnocidautodurable/descriptor/ClientIT.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee20.ra.activationconfig.topic.noselnocidautodurable.descriptor;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.Test;
+
+
+public class ClientIT extends com.sun.ts.tests.jms.ee20.ra.activationconfig.common.TopicClientBaseIT {
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /*
+ * @class.setup_props: jms_timeout; user; password; harness.log.traceflag;
+ * harness.log.port;
+ */
+
+ /*
+ * @testName: test1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.5; JMS:SPEC:276.6;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ @Test
+ public void test1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=Durable");
+ logger.log(Logger.Level.INFO, " subscriptionName=MySubscriptionName4ForRATests");
+ logger.log(Logger.Level.INFO, "Send message to MDB");
+ logger.log(Logger.Level.INFO, "Receive response from MDB");
+ sendOnly("test1", 0);
+ if (!checkOnResponse("test1")) {
+ throw new Exception("checkOnResponse for test1 returned false.");
+ }
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/annotated/ActivationConfigBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/annotated/ActivationConfigBean.java
index 936758502d..d7d52d72cb 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/annotated/ActivationConfigBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/annotated/ActivationConfigBean.java
@@ -35,30 +35,29 @@
//use annotation element messageListenerInterface, nor descritpor element
//messaging-type
@MessageDriven(name = "ActivationConfigBean", activationConfig = {
- @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/QueueConnectionFactory"),
- @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "MY_TOPIC"),
- @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Topic"),
- @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
- @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
- @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "MySubscriptionName1ForRATests"),
- @ActivationConfigProperty(propertyName = "clientId", propertyValue = "MyClientId1ForRATests"),
- @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999") })
+ @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/QueueConnectionFactory"),
+ @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "MY_TOPIC"),
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Topic"),
+ @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
+ @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
+ @ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "MySubscriptionName1ForRATests"),
+ @ActivationConfigProperty(propertyName = "clientId", propertyValue = "MyClientId1ForRATests"),
+ @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999") })
@TransactionManagement(TransactionManagementType.BEAN)
-public class ActivationConfigBean extends ActivationConfigBeanBase
- implements MessageListener {
+public class ActivationConfigBean extends ActivationConfigBeanBase implements MessageListener {
- @Resource(name = "mdc")
- private MessageDrivenContext mdc;
+ @Resource(name = "mdc")
+ private MessageDrivenContext mdc;
- public ActivationConfigBean() {
- super();
- }
+ public ActivationConfigBean() {
+ super();
+ }
- public EJBContext getEJBContext() {
- return this.mdc;
- }
+ public EJBContext getEJBContext() {
+ return this.mdc;
+ }
- // ================== business methods ====================================
+ // ================== business methods ====================================
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/annotated/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/annotated/Client.java
deleted file mode 100644
index 4cda978a7b..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/annotated/Client.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee20.ra.activationconfig.topic.selectorautociddurable.annotated;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.util.TestUtil;
-
-public class Client extends
- com.sun.ts.tests.jms.ee20.ra.activationconfig.common.TopicClientBase {
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.traceflag;
- * harness.log.port;
- */
-
- /*
- * @testName: test1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- * JMS:SPEC:276.7; JMS:SPEC:276.8; JMS:SPEC:276.9;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- public void test1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=Durable");
- TestUtil.logMsg(" subscriptionName=MySubscriptionName1ForRATests");
- TestUtil.logMsg(" clientId=MyClientId1ForRATests");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
- TestUtil.logMsg("Send message that MATCHES the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil
- .logMsg("Must receive message back since it MATCHES message selector");
- super.test1();
- }
-
- /*
- * @testName: negativeTest1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- * JMS:SPEC:276.7; JMS:SPEC:276.8; JMS:SPEC:276.9;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=Durable");
- TestUtil.logMsg(" subscriptionName=MySubscriptionName1ForRATests");
- TestUtil.logMsg(" clientId=MyClientId1ForRATests");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=1");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest1();
- }
-
- /*
- * @testName: negativeTest2
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- * JMS:SPEC:276.7; JMS:SPEC:276.8; JMS:SPEC:276.9;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest2() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=Durable");
- TestUtil.logMsg(" subscriptionName=MySubscriptionName1ForRATests");
- TestUtil.logMsg(" clientId=MyClientId1ForRATests");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest2();
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/annotated/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/annotated/ClientIT.java
new file mode 100644
index 0000000000..a8a0fcdfe1
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/annotated/ClientIT.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee20.ra.activationconfig.topic.selectorautociddurable.annotated;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.Test;
+
+
+public class ClientIT extends com.sun.ts.tests.jms.ee20.ra.activationconfig.common.TopicClientBaseIT {
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /*
+ * @class.setup_props: jms_timeout; user; password; harness.log.traceflag;
+ * harness.log.port;
+ */
+
+ /*
+ * @testName: test1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6; JMS:SPEC:276.7;
+ * JMS:SPEC:276.8; JMS:SPEC:276.9;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ @Test
+ public void test1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=Durable");
+ logger.log(Logger.Level.INFO, " subscriptionName=MySubscriptionName1ForRATests");
+ logger.log(Logger.Level.INFO, " clientId=MyClientId1ForRATests");
+ logger.log(Logger.Level.INFO,
+ " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
+ logger.log(Logger.Level.INFO, "Send message that MATCHES the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must receive message back since it MATCHES message selector");
+ super.test1();
+ }
+
+ /*
+ * @testName: negativeTest1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6; JMS:SPEC:276.7;
+ * JMS:SPEC:276.8; JMS:SPEC:276.9;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=Durable");
+ logger.log(Logger.Level.INFO, " subscriptionName=MySubscriptionName1ForRATests");
+ logger.log(Logger.Level.INFO, " clientId=MyClientId1ForRATests");
+ logger.log(Logger.Level.INFO,
+ " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=1");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest1();
+ }
+
+ /*
+ * @testName: negativeTest2
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6; JMS:SPEC:276.7;
+ * JMS:SPEC:276.8; JMS:SPEC:276.9;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest2() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=Durable");
+ logger.log(Logger.Level.INFO, " subscriptionName=MySubscriptionName1ForRATests");
+ logger.log(Logger.Level.INFO, " clientId=MyClientId1ForRATests");
+ logger.log(Logger.Level.INFO,
+ " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest2();
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/descriptor/ActivationConfigBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/descriptor/ActivationConfigBean.java
index c30152e7dd..6e4d03e9b1 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/descriptor/ActivationConfigBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/descriptor/ActivationConfigBean.java
@@ -35,19 +35,18 @@
//assembler not permitted to override transaction management type.
@TransactionManagement(TransactionManagementType.BEAN)
-public class ActivationConfigBean extends ActivationConfigBeanBase
- implements MessageListener {
- @Resource(name = "mdc")
- private MessageDrivenContext mdc;
+public class ActivationConfigBean extends ActivationConfigBeanBase implements MessageListener {
+ @Resource(name = "mdc")
+ private MessageDrivenContext mdc;
- public ActivationConfigBean() {
- super();
- }
+ public ActivationConfigBean() {
+ super();
+ }
- public EJBContext getEJBContext() {
- return this.mdc;
- }
+ public EJBContext getEJBContext() {
+ return this.mdc;
+ }
- // ================== business methods ====================================
+ // ================== business methods ====================================
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/descriptor/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/descriptor/Client.java
deleted file mode 100644
index 4d3fb17890..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/descriptor/Client.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee20.ra.activationconfig.topic.selectorautociddurable.descriptor;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.util.TestUtil;
-
-public class Client extends
- com.sun.ts.tests.jms.ee20.ra.activationconfig.common.TopicClientBase {
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.traceflag;
- * harness.log.port;
- */
-
- /*
- * @testName: test1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- * JMS:SPEC:276.7; JMS:SPEC:276.8; JMS:SPEC:276.9;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- public void test1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=Durable");
- TestUtil.logMsg(" subscriptionName=MySubscriptionName2ForRATests");
- TestUtil.logMsg(" clientId=MyClientId2ForRATests");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
- TestUtil.logMsg("Send message that MATCHES the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil
- .logMsg("Must receive message back since it MATCHES message selector");
- super.test1();
- }
-
- /*
- * @testName: negativeTest1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- * JMS:SPEC:276.7; JMS:SPEC:276.8; JMS:SPEC:276.9;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=Durable");
- TestUtil.logMsg(" subscriptionName=MySubscriptionName2ForRATests");
- TestUtil.logMsg(" clientId=MyClientId2ForRATests");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=1");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest1();
- }
-
- /*
- * @testName: negativeTest2
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- * JMS:SPEC:276.7; JMS:SPEC:276.8; JMS:SPEC:276.9;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest2() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Auto-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=Durable");
- TestUtil.logMsg(" subscriptionName=MySubscriptionName2ForRATests");
- TestUtil.logMsg(" clientId=MyClientId2ForRATests");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest2();
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/descriptor/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/descriptor/ClientIT.java
new file mode 100644
index 0000000000..41c1fc2bc0
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectorautociddurable/descriptor/ClientIT.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee20.ra.activationconfig.topic.selectorautociddurable.descriptor;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.Test;
+
+
+public class ClientIT extends com.sun.ts.tests.jms.ee20.ra.activationconfig.common.TopicClientBaseIT {
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+
+ /*
+ * @testName: test1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6; JMS:SPEC:276.7;
+ * JMS:SPEC:276.8; JMS:SPEC:276.9;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ @Test
+ public void test1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=Durable");
+ logger.log(Logger.Level.INFO, " subscriptionName=MySubscriptionName2ForRATests");
+ logger.log(Logger.Level.INFO, " clientId=MyClientId2ForRATests");
+ logger.log(Logger.Level.INFO,
+ " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
+ logger.log(Logger.Level.INFO, "Send message that MATCHES the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must receive message back since it MATCHES message selector");
+ super.test1();
+ }
+
+ /*
+ * @testName: negativeTest1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6; JMS:SPEC:276.7;
+ * JMS:SPEC:276.8; JMS:SPEC:276.9;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=Durable");
+ logger.log(Logger.Level.INFO, " subscriptionName=MySubscriptionName2ForRATests");
+ logger.log(Logger.Level.INFO, " clientId=MyClientId2ForRATests");
+ logger.log(Logger.Level.INFO,
+ " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=1");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest1();
+ }
+
+ /*
+ * @testName: negativeTest2
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6; JMS:SPEC:276.7;
+ * JMS:SPEC:276.8; JMS:SPEC:276.9;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest2() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Auto-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=Durable");
+ logger.log(Logger.Level.INFO, " subscriptionName=MySubscriptionName2ForRATests");
+ logger.log(Logger.Level.INFO, " clientId=MyClientId2ForRATests");
+ logger.log(Logger.Level.INFO,
+ " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest2();
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/annotated/ActivationConfigBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/annotated/ActivationConfigBean.java
index 8911ae3069..2e8cb0d6e9 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/annotated/ActivationConfigBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/annotated/ActivationConfigBean.java
@@ -35,28 +35,27 @@
//use annotation element messageListenerInterface, nor descritpor element
//messaging-type
@MessageDriven(name = "ActivationConfigBean", activationConfig = {
- @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/QueueConnectionFactory"),
- @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "MY_TOPIC"),
- @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Topic"),
- @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Dups-ok-acknowledge"),
- @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "NonDurable"),
- @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999") })
+ @ActivationConfigProperty(propertyName = "connectionFactoryLookup", propertyValue = "jms/QueueConnectionFactory"),
+ @ActivationConfigProperty(propertyName = "destinationLookup", propertyValue = "MY_TOPIC"),
+ @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "jakarta.jms.Topic"),
+ @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Dups-ok-acknowledge"),
+ @ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "NonDurable"),
+ @ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999") })
@TransactionManagement(TransactionManagementType.BEAN)
-public class ActivationConfigBean extends ActivationConfigBeanBase
- implements MessageListener {
+public class ActivationConfigBean extends ActivationConfigBeanBase implements MessageListener {
- @Resource(name = "mdc")
- private MessageDrivenContext mdc;
+ @Resource(name = "mdc")
+ private MessageDrivenContext mdc;
- public ActivationConfigBean() {
- super();
- }
+ public ActivationConfigBean() {
+ super();
+ }
- public EJBContext getEJBContext() {
- return this.mdc;
- }
+ public EJBContext getEJBContext() {
+ return this.mdc;
+ }
- // ================== business methods ====================================
+ // ================== business methods ====================================
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/annotated/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/annotated/Client.java
deleted file mode 100644
index 6d25755535..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/annotated/Client.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee20.ra.activationconfig.topic.selectordupsnondurable.annotated;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.util.TestUtil;
-
-public class Client extends
- com.sun.ts.tests.jms.ee20.ra.activationconfig.common.TopicClientBase {
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.traceflag;
- * harness.log.port;
- */
-
- /*
- * @testName: test1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- public void test1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Dups-ok-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=NonDurable");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
- TestUtil.logMsg("Send message that MATCHES the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil
- .logMsg("Must receive message back since it MATCHES message selector");
- super.test1();
- }
-
- /*
- * @testName: negativeTest1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Dups-ok-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=NonDurable");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=1");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest1();
- }
-
- /*
- * @testName: negativeTest2
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest2() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Dups-ok-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=NonDurable");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest2();
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/annotated/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/annotated/ClientIT.java
new file mode 100644
index 0000000000..2e1609ef25
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/annotated/ClientIT.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee20.ra.activationconfig.topic.selectordupsnondurable.annotated;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.Test;
+
+
+public class ClientIT extends com.sun.ts.tests.jms.ee20.ra.activationconfig.common.TopicClientBaseIT {
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+
+ /*
+ * @testName: test1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ @Test
+ public void test1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Dups-ok-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=NonDurable");
+ logger.log(Logger.Level.INFO,
+ " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
+ logger.log(Logger.Level.INFO, "Send message that MATCHES the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must receive message back since it MATCHES message selector");
+ super.test1();
+ }
+
+ /*
+ * @testName: negativeTest1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ public void negativeTest1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Dups-ok-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=NonDurable");
+ logger.log(Logger.Level.INFO,
+ " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=1");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest1();
+ }
+
+ /*
+ * @testName: negativeTest2
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest2() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Dups-ok-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=NonDurable");
+ logger.log(Logger.Level.INFO,
+ " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest2();
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/descriptor/ActivationConfigBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/descriptor/ActivationConfigBean.java
index c7da577c21..aae1111c1e 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/descriptor/ActivationConfigBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/descriptor/ActivationConfigBean.java
@@ -35,19 +35,18 @@
//assembler not permitted to override transaction management type.
@TransactionManagement(TransactionManagementType.BEAN)
-public class ActivationConfigBean extends ActivationConfigBeanBase
- implements MessageListener {
- @Resource(name = "mdc")
- private MessageDrivenContext mdc;
+public class ActivationConfigBean extends ActivationConfigBeanBase implements MessageListener {
+ @Resource(name = "mdc")
+ private MessageDrivenContext mdc;
- public ActivationConfigBean() {
- super();
- }
+ public ActivationConfigBean() {
+ super();
+ }
- public EJBContext getEJBContext() {
- return this.mdc;
- }
+ public EJBContext getEJBContext() {
+ return this.mdc;
+ }
- // ================== business methods ====================================
+ // ================== business methods ====================================
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/descriptor/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/descriptor/Client.java
deleted file mode 100644
index 8bbe06492f..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/descriptor/Client.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-
-package com.sun.ts.tests.jms.ee20.ra.activationconfig.topic.selectordupsnondurable.descriptor;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.util.TestUtil;
-
-public class Client extends
- com.sun.ts.tests.jms.ee20.ra.activationconfig.common.TopicClientBase {
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /*
- * @class.setup_props: jms_timeout; user; password; harness.log.traceflag;
- * harness.log.port;
- */
-
- /*
- * @testName: test1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- public void test1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Dups-ok-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=NonDurable");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
- TestUtil.logMsg("Send message that MATCHES the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil
- .logMsg("Must receive message back since it MATCHES message selector");
- super.test1();
- }
-
- /*
- * @testName: negativeTest1
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest1() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Dups-ok-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=NonDurable");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=test1");
- TestUtil.logMsg("Set message property: TestCaseNum=1");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest1();
- }
-
- /*
- * @testName: negativeTest2
- *
- * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2;
- * JMS:SPEC:276.3; JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
- *
- * @test_Strategy: test activation-config related elements in deployment
- * descriptors, and their annotation counterparts.
- *
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- public void negativeTest2() throws Exception {
- TestUtil.logMsg("Testing the following activationConfig properties");
- TestUtil.logMsg(" connectionFactoryLookup=jms/QueueConnectionFactory");
- TestUtil.logMsg(" destinationLookup=MDB_TOPIC");
- TestUtil.logMsg(" destinationType=jakarta.jms.Topic");
- TestUtil.logMsg(" acknowledgeMode=Dups-ok-acknowledge");
- TestUtil.logMsg(" subscriptionDurability=NonDurable");
- TestUtil.logMsg(
- " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
- TestUtil.logMsg("Send message that DOES NOT MATCH the message selector");
- TestUtil.logMsg("Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
- TestUtil.logMsg("Set message property: TestCaseNum=0");
- TestUtil.logMsg(
- "Must not receive message back since it DOES NOT MATCH message selector");
- super.negativeTest2();
- }
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/descriptor/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/descriptor/ClientIT.java
new file mode 100644
index 0000000000..ea41e6fa6e
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/activationconfig/topic/selectordupsnondurable/descriptor/ClientIT.java
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+
+package com.sun.ts.tests.jms.ee20.ra.activationconfig.topic.selectordupsnondurable.descriptor;
+
+import java.lang.System.Logger;
+
+import org.junit.jupiter.api.Test;
+
+
+public class ClientIT extends com.sun.ts.tests.jms.ee20.ra.activationconfig.common.TopicClientBaseIT {
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /*
+ * @class.setup_props: jms_timeout; user; password;
+ */
+
+ /*
+ * @testName: test1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ @Test
+ public void test1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Dups-ok-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=NonDurable");
+ logger.log(Logger.Level.INFO,
+ " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
+ logger.log(Logger.Level.INFO, "Send message that MATCHES the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must receive message back since it MATCHES message selector");
+ super.test1();
+ }
+
+ /*
+ * @testName: negativeTest1
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest1() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Dups-ok-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=NonDurable");
+ logger.log(Logger.Level.INFO,
+ " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=test1");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=1");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest1();
+ }
+
+ /*
+ * @testName: negativeTest2
+ *
+ * @assertion_ids: JMS:SPEC:276; JMS:SPEC:276.1; JMS:SPEC:276.2; JMS:SPEC:276.3;
+ * JMS:SPEC:276.4; JMS:SPEC:276.5; JMS:SPEC:276.6;
+ *
+ * @test_Strategy: test activation-config related elements in deployment
+ * descriptors, and their annotation counterparts.
+ *
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ @Test
+ public void negativeTest2() throws Exception {
+ logger.log(Logger.Level.INFO, "Testing the following activationConfig properties");
+ logger.log(Logger.Level.INFO, " connectionFactoryLookup=jms/QueueConnectionFactory");
+ logger.log(Logger.Level.INFO, " destinationLookup=MDB_TOPIC");
+ logger.log(Logger.Level.INFO, " destinationType=jakarta.jms.Topic");
+ logger.log(Logger.Level.INFO, " acknowledgeMode=Dups-ok-acknowledge");
+ logger.log(Logger.Level.INFO, " subscriptionDurability=NonDurable");
+ logger.log(Logger.Level.INFO,
+ " messageSelector=\"(COM_SUN_JMS_TESTNAME='test1' AND TestCaseNum NOT BETWEEN 1 AND 9999)\"");
+ logger.log(Logger.Level.INFO, "Send message that DOES NOT MATCH the message selector");
+ logger.log(Logger.Level.INFO, "Set message property: COM_SUN_JMS_TESTNAME=negativeTest2");
+ logger.log(Logger.Level.INFO, "Set message property: TestCaseNum=0");
+ logger.log(Logger.Level.INFO, "Must not receive message back since it DOES NOT MATCH message selector");
+ super.negativeTest2();
+ }
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/Constants.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/Constants.java
index 0c0fd98fb6..24d53ee5f4 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/Constants.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/Constants.java
@@ -21,27 +21,27 @@
package com.sun.ts.tests.jms.ee20.ra.common.messaging;
public interface Constants {
- public static final String PASSED = "PASSED";
+ public static final String PASSED = "PASSED";
- public static final String FAILED = "FAILED";
+ public static final String FAILED = "FAILED";
- public static final String TEST_NAME_KEY = "COM_SUN_JMS_TESTNAME";
+ public static final String TEST_NAME_KEY = "COM_SUN_JMS_TESTNAME";
- public static final String TEST_NUMBER_KEY = "TestCaseNum";
+ public static final String TEST_NUMBER_KEY = "TestCaseNum";
- public static final String FINDER_TEST_NAME_KEY = "testName";
+ public static final String FINDER_TEST_NAME_KEY = "testName";
- public static final long MESSAGE_TIME_TO_LIVE = 30 * 1000;
+ public static final long MESSAGE_TIME_TO_LIVE = 30 * 1000;
- /**
- * The two properties ar eno longer used. Number of seconds to sleep after
- * calling QueueConnection.createQueueSession(). This is currently used in
- * StatusReporter. Note that the QueueSession is cached in StatusReporter, so
- * the sleep occurs only at the first time. Without the sleep time, the first
- * test sending back result will fail with errors: Message resent too many
- * times; sending it to DLQ...
- */
- public static final int SLEEP_AFTER_CONNECT_SECONDS = 3;
+ /**
+ * The two properties ar eno longer used. Number of seconds to sleep after
+ * calling QueueConnection.createQueueSession(). This is currently used in
+ * StatusReporter. Note that the QueueSession is cached in StatusReporter, so
+ * the sleep occurs only at the first time. Without the sleep time, the first
+ * test sending back result will fail with errors: Message resent too many
+ * times; sending it to DLQ...
+ */
+ public static final int SLEEP_AFTER_CONNECT_SECONDS = 3;
- public static final int CLIENT_SLEEP_AFTER_SEND_SECONDS = 3;
+ public static final int CLIENT_SLEEP_AFTER_SEND_SECONDS = 3;
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/QueueClientBase.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/QueueClientBase.java
index fadba74bc7..2667b2c951 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/QueueClientBase.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/QueueClientBase.java
@@ -24,11 +24,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.lang.System.Logger;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Properties;
-import com.sun.ts.lib.util.TestUtil;
+import org.junit.jupiter.api.BeforeEach;
+
import com.sun.ts.tests.jms.commonee.Client;
import jakarta.jms.JMSException;
@@ -38,226 +40,210 @@
import jakarta.jms.Session;
abstract public class QueueClientBase extends Client implements Constants {
- private String currentTestName;
-
- //////////////////////////////////////////////////////////////////////
- // Queue related stuff
- //////////////////////////////////////////////////////////////////////
- // These are declared in super class jms.commonee.Client
- // protected QueueConnection qConnect;
- // protected QueueSession session;
- // protected QueueConnectionFactory qFactory;
- // protected QueueSender qSender;
- // protected Queue rcvrQueue;
- //
- private Queue sendQ;
-
- abstract protected void initSendQueue();
-
- abstract protected void initReceiveQueue();
-
- abstract protected void initQueueConnectionFactory();
-
- protected Queue getSendQueue() {
- return sendQ;
- }
-
- protected void setSendQueue(Queue q) {
- sendQ = q;
- }
-
- // this receive queue is also used by Topic MDB to send back response.
- protected Queue getReceiveQueue() {
- return rcvrQueue;
- }
-
- protected void setReceiveQueue(Queue q) {
- rcvrQueue = q;
- }
-
- protected QueueConnectionFactory getQueueConnectionFactory() {
- return qFactory;
- }
-
- protected void setQueueConnectionFactory(QueueConnectionFactory qf) {
- qFactory = qf;
- }
-
- protected String getCurrentTestName() {
- return currentTestName;
- }
-
- protected void setCurrentTestName(String tn) {
- currentTestName = tn;
- }
-
- /**
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client. Simplified version
- * since testname can be retrieved from props in setup().
- */
- protected void sendReceive() throws Exception {
- sendReceive(getCurrentTestName(), 0);
- }
-
- /**
- * Sends message and waits for response. The message should not reach the
- * target MDB, and no response should be received by this client.
- */
- protected void sendReceiveNegative(String testname, int testnum)
- throws Exception {
- sendOnly(testname, testnum);
- if (checkOnResponse(testname)) {
- throw new Exception("This is a negative test that expects no response,"
- + " but actually got a response.");
- } else {
- TLogger.log("No response, as expected");
- }
- }
-
- /**
- * Sends message and waits for response. The message should reach the target
- * MDB, and a response should be received by this client.
- */
- protected void sendReceive(String testname, int testnum) throws Exception {
- sendOnly(testname, testnum);
- // sometimes have to sleep for awhile. But we shouldn't interfere
- // with thread management
- if (!checkOnResponse(testname)) {
- throw new Exception("checkOnResponse for " + testname + " returned false.");
- }
- }
-
- protected void sendOnly(String testname, int testnum) throws Exception {
- try {
- createTestMessage(testname, testnum);
- MessageProducer producer = getMessageProducer();
- producer.setTimeToLive(MESSAGE_TIME_TO_LIVE);
- producer.send(msg);
- TLogger.log("message sent from testname: " + testname + ", testnum: "
- + testnum + ", using producer: " + producer);
- } catch (Exception e) {
- throw new Exception(e);
- }
- }
-
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- setCurrentTestName(p.getProperty(FINDER_TEST_NAME_KEY));
- initTestProperties(p);
-
- // used by both queue and topic MDB to send back response
- initReceiveQueue();
-
- try {
- configureQueue();
- configureTopic();
- } catch (JMSException ex) {
- throw new Exception(ex);
- }
- TLogger.log("get the connection and start up");
- TLogger.log("Client: connection started, now send initialization msg!");
- }
-
- protected MessageProducer getMessageProducer() throws JMSException {
- qSender = session.createSender(getSendQueue());
- return qSender;
- }
-
- protected void configureQueue() throws JMSException {
- initQueueConnectionFactory();
- qConnect = qFactory.createQueueConnection(jmsUser, jmsPassword);
- session = qConnect.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
- qConnect.start();
- initSendQueue();
- }
-
- protected void configureTopic() throws JMSException {
- }
-
- protected void urlTest(URL url) throws Exception {
- urlTest(url, PASSED);
- }
-
- protected void urlTest(URL url, String expectedFirstLine) throws Exception {
- HttpURLConnection conn = null;
- InputStream is = null;
- TLogger.log("About to connect to url: ");
- TLogger.log(url.toString());
- try {
- conn = (HttpURLConnection) (url.openConnection());
- int code = conn.getResponseCode();
- if (code != HttpURLConnection.HTTP_OK) {
- throw new Exception("Unexpected return code: " + code);
- }
-
- is = conn.getInputStream();
- BufferedReader input = new BufferedReader(new InputStreamReader(is));
- String line = input.readLine();
- if (line != null) {
- line = line.trim();
- }
- if (!expectedFirstLine.equals(line)) {
- throw new Exception("Wrong response. Expected: " + expectedFirstLine
- + ", received: " + line);
- } else {
- TLogger.log("Got expected response: " + line);
- }
- try {
- input.close();
- } catch (IOException e) {
- // ignore
- }
- } catch (IOException e) {
- throw new Exception(e);
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- // ignore
- }
- }
- if (conn != null) {
- conn.disconnect();
- }
- }
- }
-
- private void initTestProperties(Properties p) throws Exception {
- jmsUser = p.getProperty("user");
- if (jmsUser == null) {
- TestUtil.logTrace("user is null");
- throw new Exception("Error getting user");
- }
-
- jmsPassword = p.getProperty("password");
- if (jmsPassword == null) {
- TestUtil.logTrace("passwd is null");
- throw new Exception("Error getting pwd");
- }
-
- String time = p.getProperty("jms_timeout");
- if (time == null) {
- TestUtil.logTrace("time is null");
- throw new Exception("Error getting time");
- }
-
- hostname = p.getProperty("harness.host");
- if (hostname == null) {
- TestUtil.logTrace("Hostname is null");
- throw new Exception("Error getting hostname");
- }
- traceFlag = p.getProperty("harness.log.traceflag");
- if (traceFlag == null) {
- TestUtil.logTrace("Hostname is null");
- throw new Exception("Error getting traceflag");
- }
- logPort = p.getProperty("harness.log.port");
- if (logPort == null) {
- TestUtil.logTrace("logport is null");
- throw new Exception("Error getting port");
- }
- timeout = Integer.parseInt(time);
- }
+ private String currentTestName;
+
+ //////////////////////////////////////////////////////////////////////
+ // Queue related stuff
+ //////////////////////////////////////////////////////////////////////
+ // These are declared in super class jms.commonee.Client
+ // protected QueueConnection qConnect;
+ // protected QueueSession session;
+ // protected QueueConnectionFactory qFactory;
+ // protected QueueSender qSender;
+ // protected Queue rcvrQueue;
+ //
+ private Queue sendQ;
+
+ abstract protected void initSendQueue();
+
+ abstract protected void initReceiveQueue();
+
+ abstract protected void initQueueConnectionFactory();
+
+ private static final Logger logger = (Logger) System.getLogger(QueueClientBase.class.getName());
+
+ protected Queue getSendQueue() {
+ return sendQ;
+ }
+
+ protected void setSendQueue(Queue q) {
+ sendQ = q;
+ }
+
+ // this receive queue is also used by Topic MDB to send back response.
+ protected Queue getReceiveQueue() {
+ return rcvrQueue;
+ }
+
+ protected void setReceiveQueue(Queue q) {
+ rcvrQueue = q;
+ }
+
+ protected QueueConnectionFactory getQueueConnectionFactory() {
+ return qFactory;
+ }
+
+ protected void setQueueConnectionFactory(QueueConnectionFactory qf) {
+ qFactory = qf;
+ }
+
+ protected String getCurrentTestName() {
+ return currentTestName;
+ }
+
+ protected void setCurrentTestName(String tn) {
+ currentTestName = tn;
+ }
+
+ /**
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client. Simplified version
+ * since testname can be retrieved from props in setup().
+ */
+ protected void sendReceive() throws Exception {
+ sendReceive(getCurrentTestName(), 0);
+ }
+
+ /**
+ * Sends message and waits for response. The message should not reach the target
+ * MDB, and no response should be received by this client.
+ */
+ protected void sendReceiveNegative(String testname, int testnum) throws Exception {
+ sendOnly(testname, testnum);
+ if (checkOnResponse(testname)) {
+ throw new Exception("This is a negative test that expects no response," + " but actually got a response.");
+ } else {
+ TLogger.log("No response, as expected");
+ }
+ }
+
+ /**
+ * Sends message and waits for response. The message should reach the target
+ * MDB, and a response should be received by this client.
+ */
+ protected void sendReceive(String testname, int testnum) throws Exception {
+ sendOnly(testname, testnum);
+ // sometimes have to sleep for awhile. But we shouldn't interfere
+ // with thread management
+ if (!checkOnResponse(testname)) {
+ throw new Exception("checkOnResponse for " + testname + " returned false.");
+ }
+ }
+
+ protected void sendOnly(String testname, int testnum) throws Exception {
+ try {
+ createTestMessage(testname, testnum);
+ MessageProducer producer = getMessageProducer();
+ producer.setTimeToLive(MESSAGE_TIME_TO_LIVE);
+ producer.send(msg);
+ TLogger.log("message sent from testname: " + testname + ", testnum: " + testnum + ", using producer: "
+ + producer);
+ } catch (Exception e) {
+ throw new Exception(e);
+ }
+ }
+
+ @BeforeEach
+ public void setup() throws Exception {
+ setCurrentTestName(System.getProperty(FINDER_TEST_NAME_KEY));
+ // initTestProperties(p);
+
+ // used by both queue and topic MDB to send back response
+ initReceiveQueue();
+
+ try {
+ configureQueue();
+ configureTopic();
+ } catch (JMSException ex) {
+ throw new Exception(ex);
+ }
+ TLogger.log("get the connection and start up");
+ TLogger.log("Client: connection started, now send initialization msg!");
+ }
+
+ protected MessageProducer getMessageProducer() throws JMSException {
+ qSender = session.createSender(getSendQueue());
+ return qSender;
+ }
+
+ protected void configureQueue() throws JMSException {
+ initQueueConnectionFactory();
+ qConnect = qFactory.createQueueConnection(jmsUser, jmsPassword);
+ session = qConnect.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ qConnect.start();
+ initSendQueue();
+ }
+
+ protected void configureTopic() throws JMSException {
+ }
+
+ protected void urlTest(URL url) throws Exception {
+ urlTest(url, PASSED);
+ }
+
+ protected void urlTest(URL url, String expectedFirstLine) throws Exception {
+ HttpURLConnection conn = null;
+ InputStream is = null;
+ TLogger.log("About to connect to url: ");
+ TLogger.log(url.toString());
+ try {
+ conn = (HttpURLConnection) (url.openConnection());
+ int code = conn.getResponseCode();
+ if (code != HttpURLConnection.HTTP_OK) {
+ throw new Exception("Unexpected return code: " + code);
+ }
+
+ is = conn.getInputStream();
+ BufferedReader input = new BufferedReader(new InputStreamReader(is));
+ String line = input.readLine();
+ if (line != null) {
+ line = line.trim();
+ }
+ if (!expectedFirstLine.equals(line)) {
+ throw new Exception("Wrong response. Expected: " + expectedFirstLine + ", received: " + line);
+ } else {
+ TLogger.log("Got expected response: " + line);
+ }
+ try {
+ input.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ } catch (IOException e) {
+ throw new Exception(e);
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ if (conn != null) {
+ conn.disconnect();
+ }
+ }
+ }
+
+ private void initTestProperties(Properties p) throws Exception {
+ jmsUser = System.getProperty("user");
+ if (jmsUser == null) {
+ logger.log(Logger.Level.TRACE, "user is null");
+ throw new Exception("Error getting user");
+ }
+
+ jmsPassword = System.getProperty("password");
+ if (jmsPassword == null) {
+ logger.log(Logger.Level.TRACE, "passwd is null");
+ throw new Exception("Error getting pwd");
+ }
+
+ String time = System.getProperty("jms_timeout");
+ if (time == null) {
+ logger.log(Logger.Level.TRACE, "time is null");
+ throw new Exception("Error getting time");
+ }
+
+ timeout = Integer.parseInt(time);
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/StatusReporter.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/StatusReporter.java
index 2ccd3e1a58..232fd86e6a 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/StatusReporter.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/StatusReporter.java
@@ -30,77 +30,74 @@
import jakarta.jms.TextMessage;
public class StatusReporter implements Constants {
- private static StatusReporter reporter = new StatusReporter();
+ private static StatusReporter reporter = new StatusReporter();
- private static StatusReporter getInstance() {
- return reporter;
- }
+ private static StatusReporter getInstance() {
+ return reporter;
+ }
- public static void report(String testname, boolean result, String reason,
- QueueConnectionFactory qFactory, Queue replyQueue) {
- StatusReporter reporter = getInstance();
- reporter.report0(testname, result, reason, qFactory, replyQueue);
- }
+ public static void report(String testname, boolean result, String reason, QueueConnectionFactory qFactory,
+ Queue replyQueue) {
+ StatusReporter reporter = getInstance();
+ reporter.report0(testname, result, reason, qFactory, replyQueue);
+ }
- public static void report(String testname, boolean result,
- QueueConnectionFactory qFactory, Queue queueR) {
- report(testname, result, null, qFactory, queueR);
- }
+ public static void report(String testname, boolean result, QueueConnectionFactory qFactory, Queue queueR) {
+ report(testname, result, null, qFactory, queueR);
+ }
- private void report0(String testname, boolean result, String reason,
- QueueConnectionFactory qFactory, Queue queueR) {
- QueueConnection qConnection = null;
- QueueSession qSession = null;
+ private void report0(String testname, boolean result, String reason, QueueConnectionFactory qFactory,
+ Queue queueR) {
+ QueueConnection qConnection = null;
+ QueueSession qSession = null;
- try {
- qConnection = qFactory.createQueueConnection();
- qSession = qConnection.createQueueSession(false,
- Session.AUTO_ACKNOWLEDGE);
- sendTestResults(testname, result, reason, qSession, queueR);
- } catch (JMSException e) {
- String description = null;
- if (result) {
- description = "The test " + testname + " passed in the bean.";
- } else {
- description = "The test " + testname + " failed in the bean: " + reason;
- }
- throw new java.lang.IllegalStateException(description
- + " Failed to create connection/session in StatusReporter:", e);
- } finally {
- if (qConnection != null) {
- try {
- qConnection.close();
- } catch (Exception e) {
- // ignore
- }
- }
- }
- }
+ try {
+ qConnection = qFactory.createQueueConnection();
+ qSession = qConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
+ sendTestResults(testname, result, reason, qSession, queueR);
+ } catch (JMSException e) {
+ String description = null;
+ if (result) {
+ description = "The test " + testname + " passed in the bean.";
+ } else {
+ description = "The test " + testname + " failed in the bean: " + reason;
+ }
+ throw new java.lang.IllegalStateException(
+ description + " Failed to create connection/session in StatusReporter:", e);
+ } finally {
+ if (qConnection != null) {
+ try {
+ qConnection.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+ }
- public static void sendTestResults(String testCase, boolean results,
- String reason, QueueSession qSession, jakarta.jms.Queue queueR) {
- TextMessage msg = null;
- QueueSender mSender = null;
+ public static void sendTestResults(String testCase, boolean results, String reason, QueueSession qSession,
+ jakarta.jms.Queue queueR) {
+ TextMessage msg = null;
+ QueueSender mSender = null;
- try {
- // create a msg sender for the response queue
- mSender = qSession.createSender(queueR);
- // and we'll send a text msg
- msg = qSession.createTextMessage();
- msg.setStringProperty("TestCase", testCase);
- msg.setText(testCase);
- if (results) {
- msg.setStringProperty("Status", "Pass");
- } else {
- msg.setStringProperty("Status", "Fail");
- }
- mSender.send(msg);
- TLogger.log("Status message (" + results + ") sent for test " + testCase
- + ". Reason:" + reason);
- } catch (JMSException e) {
- TLogger.log("Failed to send back status:", e);
- } catch (Exception e) {
- TLogger.log("Failed to send back status:", e);
- }
- }
+ try {
+ // create a msg sender for the response queue
+ mSender = qSession.createSender(queueR);
+ // and we'll send a text msg
+ msg = qSession.createTextMessage();
+ msg.setStringProperty("TestCase", testCase);
+ msg.setText(testCase);
+ if (results) {
+ msg.setStringProperty("Status", "Pass");
+ } else {
+ msg.setStringProperty("Status", "Fail");
+ }
+ mSender.send(msg);
+ TLogger.log("Status message (" + results + ") sent for test " + testCase + ". Reason:" + reason);
+ } catch (JMSException e) {
+ TLogger.log("Failed to send back status:", e);
+ } catch (Exception e) {
+ TLogger.log("Failed to send back status:", e);
+ }
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/TLogger.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/TLogger.java
index 99fd8ba3e2..b7afc6c5f6 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/TLogger.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/TLogger.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -25,63 +25,51 @@
* System.out.println.
*/
public class TLogger {
- public static final String NL = System.getProperty("line.separator");
+ public static final String NL = System.getProperty("line.separator");
- private TLogger() {
- }
+ private TLogger() {
+ }
- public static void log(String... args) {
- String msg = null;
- if (args.length == 0) {
- return;
- } else if (args.length == 1) {
- msg = args[0];
- if (msg == null) {
- return;
- }
- } else {
- StringBuffer sb = new StringBuffer();
- for (String s : args) {
- sb.append(s).append(' ');
- }
- msg = sb.toString();
- }
- System.out.println(msg);
- }
+ public static void log(String... args) {
+ String msg = null;
+ if (args.length == 0) {
+ return;
+ } else if (args.length == 1) {
+ msg = args[0];
+ if (msg == null) {
+ return;
+ }
+ } else {
+ StringBuffer sb = new StringBuffer();
+ for (String s : args) {
+ sb.append(s).append(' ');
+ }
+ msg = sb.toString();
+ }
+ System.out.println(msg);
+ }
- public static void log(String arg, Throwable thr) {
- if (arg != null) {
- System.out.println(arg);
- }
- if (thr != null) {
- thr.printStackTrace();
- }
- }
+ public static void log(String arg, Throwable thr) {
+ if (arg != null) {
+ System.out.println(arg);
+ }
+ if (thr != null) {
+ thr.printStackTrace();
+ }
+ }
- public static void log(boolean status, String arg) {
- if (arg != null) {
- String s = status ? "PASSED: " : "FAILED: ";
- System.out.println(s + arg);
- }
- }
+ public static void log(boolean status, String arg) {
+ if (arg != null) {
+ String s = status ? "PASSED: " : "FAILED: ";
+ System.out.println(s + arg);
+ }
+ }
- public static void logMsg(String s) {
- log(s);
- }
+ public static void printStackTrace(Throwable th) {
+ th.printStackTrace();
+ }
- public static void logErr(String s) {
- log(s);
- }
-
- public static void logTrace(String s) {
- log(s);
- }
-
- public static void printStackTrace(Throwable th) {
- th.printStackTrace();
- }
-
- public static void main(String[] args) {
- TLogger.log("####");
- }
+ public static void main(String[] args) {
+ TLogger.log("####");
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/TopicClientBase.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/TopicClientBase.java
index 042911a36e..e8b4cc769a 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/TopicClientBase.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/ra/common/messaging/TopicClientBase.java
@@ -26,61 +26,60 @@
import jakarta.jms.Topic;
import jakarta.jms.TopicConnectionFactory;
-abstract public class TopicClientBase extends QueueClientBase
- implements Constants {
- //////////////////////////////////////////////////////////////////////
- // Topic related stuff
- //////////////////////////////////////////////////////////////////////
- // These are declared in super class jms.commonee.Client
- // protected TopicConnection tConnect;
- // protected TopicSession tSession;
- // protected TopicConnectionFactory tFactory;
- // protected TopicPublisher tPub;
+abstract public class TopicClientBase extends QueueClientBase implements Constants {
+ //////////////////////////////////////////////////////////////////////
+ // Topic related stuff
+ //////////////////////////////////////////////////////////////////////
+ // These are declared in super class jms.commonee.Client
+ // protected TopicConnection tConnect;
+ // protected TopicSession tSession;
+ // protected TopicConnectionFactory tFactory;
+ // protected TopicPublisher tPub;
- protected Topic sendTopic;
+ protected Topic sendTopic;
- abstract protected void initSendTopic();
+ abstract protected void initSendTopic();
- protected Topic getSendTopic() {
- return sendTopic;
- }
+ protected Topic getSendTopic() {
+ return sendTopic;
+ }
- protected void setSendTopic(Topic topic) {
- this.sendTopic = topic;
- }
+ protected void setSendTopic(Topic topic) {
+ this.sendTopic = topic;
+ }
- abstract protected void initTopicConnectionFactory();
+ abstract protected void initTopicConnectionFactory();
- protected TopicConnectionFactory getTopicConnectionFactory() {
- return tFactory;
- }
+ protected TopicConnectionFactory getTopicConnectionFactory() {
+ return tFactory;
+ }
- protected void setTopicConnectionFactory(TopicConnectionFactory tf) {
- tFactory = tf;
- }
+ protected void setTopicConnectionFactory(TopicConnectionFactory tf) {
+ tFactory = tf;
+ }
- //////////////////////////////////////////////////////////////////////
- // noop for Queue related methods
- //////////////////////////////////////////////////////////////////////
- final protected void initSendQueue() {
- }
+ //////////////////////////////////////////////////////////////////////
+ // noop for Queue related methods
+ //////////////////////////////////////////////////////////////////////
+ final protected void initSendQueue() {
+ }
- //////////////////////////////////////////////////////////////////////
+ //////////////////////////////////////////////////////////////////////
- @Override
- protected MessageProducer getMessageProducer() throws JMSException {
- // TopicPublisher tPub declared in jms.commonee.Client
- // TopicSession tSession declared in jms.commonee.Client
- tPub = tSession.createPublisher(getSendTopic());
- return tPub;
- }
+ @Override
+ protected MessageProducer getMessageProducer() throws JMSException {
+ // TopicPublisher tPub declared in jms.commonee.Client
+ // TopicSession tSession declared in jms.commonee.Client
+ tPub = tSession.createPublisher(getSendTopic());
+ return tPub;
+ }
- @Override
- protected void configureTopic() throws JMSException {
- initTopicConnectionFactory();
- tConnect = tFactory.createTopicConnection(jmsUser, jmsPassword);
- tSession = tConnect.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
- tConnect.start();
- initSendTopic();
- }
+ @Override
+ protected void configureTopic() throws JMSException {
+ initTopicConnectionFactory();
+ tConnect = tFactory.createTopicConnection(jmsUser, jmsPassword);
+ tSession = tConnect.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
+ tConnect.start();
+ initSendTopic();
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/Client.java
deleted file mode 100644
index fe9a0f7e9a..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/Client.java
+++ /dev/null
@@ -1,806 +0,0 @@
-/*
- * Copyright (c) 2013, 2018, 2020 Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2022 Contributors to Eclipse Foundation. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-package com.sun.ts.tests.jms.ee20.resourcedefs.annotations;
-
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.EETest;
-import com.sun.ts.lib.porting.TSURL;
-import com.sun.ts.lib.util.TSNamingContext;
-import com.sun.ts.lib.util.TestUtil;
-
-import jakarta.ejb.EJB;
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.JMSConnectionFactoryDefinition;
-import jakarta.jms.JMSConnectionFactoryDefinitions;
-import jakarta.jms.JMSConsumer;
-import jakarta.jms.JMSContext;
-import jakarta.jms.JMSDestinationDefinition;
-import jakarta.jms.JMSDestinationDefinitions;
-import jakarta.jms.JMSProducer;
-import jakarta.jms.Message;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueConnectionFactory;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicConnectionFactory;
-
-//-------------------------------------
-// JMS Destination Resource Definitions
-//-------------------------------------
-@JMSDestinationDefinition(
- description="Define Queue AppClientMyTestQueue",
- interfaceName="jakarta.jms.Queue",
- name="java:global/env/AppClientMyTestQueue",
- destinationName="AppClientMyTestQueue"
- )
-
-@JMSDestinationDefinition(
- description="Define Topic AppClientMyTestTopic",
- interfaceName="jakarta.jms.Topic",
- name="java:app/env/AppClientMyTestTopic",
- destinationName="AppClientMyTestTopic"
- )
-
-
-//-------------------------------------------
-// JMS ConnectionFactory Resource Definitions
-//-------------------------------------------
-@JMSConnectionFactoryDefinition(
- description="Define ConnectionFactory AppClientMyTestConnectionFactory",
- interfaceName="jakarta.jms.ConnectionFactory",
- name="java:global/AppClientMyTestConnectionFactory",
- user = "j2ee",
- password = "j2ee"
- )
-
-@JMSConnectionFactoryDefinition(
- description="Define QueueConnectionFactory AppClientMyTestQueueConnectionFactory",
- interfaceName="jakarta.jms.QueueConnectionFactory",
- name="java:app/AppClientMyTestQueueConnectionFactory",
- user = "j2ee",
- password = "j2ee"
- )
-
-@JMSConnectionFactoryDefinition(
- description="Define TopicConnectionFactory AppClientMyTestTopicConnectionFactory",
- interfaceName="jakarta.jms.TopicConnectionFactory",
- name="java:module/AppClientMyTestTopicConnectionFactory",
- user = "j2ee",
- password = "j2ee"
- )
-
-
-@JMSConnectionFactoryDefinition(
- description="Define Durable TopicConnectionFactory AppClientMyTestDurableTopicConnectionFactory",
- interfaceName="jakarta.jms.TopicConnectionFactory",
- name="java:comp/env/jms/AppClientMyTestDurableTopicConnectionFactory",
- user = "j2ee",
- password = "j2ee",
- clientId = "MyClientID",
- properties = { "Property1=10", "Property2=20" },
- transactional = false,
- maxPoolSize = 30,
- minPoolSize = 20
- )
-
-public class Client extends EETest {
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- protected transient ConnectionFactory dcf = null;
-
- protected transient ConnectionFactory cf = null;
-
- protected transient ConnectionFactory cfra = null;
-
- protected transient QueueConnectionFactory qcf = null;
-
- protected transient TopicConnectionFactory tcf = null;
-
- protected transient TopicConnectionFactory dtcf = null;
-
- protected transient Topic topic = null;
-
- protected transient Topic topica = null;
-
- protected transient Queue queue = null;
-
- protected transient JMSContext context = null;
-
- protected transient JMSConsumer consumerQ = null;
-
- protected transient JMSProducer producerQ = null;
-
- protected transient JMSConsumer consumerT = null;
-
- protected transient JMSProducer producerT = null;
-
- protected boolean queueTest = false;
-
- // Harness req's
- protected Properties props = null;
-
- // properties read from ts.jte file
- protected long timeout;
-
- protected String user;
-
- protected String password;
-
- protected String mode;
-
- // The webserver defaults (overidden by harness properties)
- private static final String PROTOCOL = "http";
-
- private static final String HOSTNAME = "localhost";
-
- private static final int PORTNUM = 8000;
-
- private TSURL ctsurl = new TSURL();
-
- private String hostname = HOSTNAME;
-
- private int portnum = PORTNUM;
-
- // URL properties used by the test
- private URL url = null;
-
- private transient URLConnection urlConn = null;
-
- private String SERVLET = "/resourcedefs_annotations_web/ServletTest";
-
- private String JSP = "/resourcedefs_annotations_web/JspClient.jsp";
-
- @EJB(name = "ejb/JMSResourceDefsEjbClientBean")
- static EjbClientIF ejbclient;
-
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup */
-
- /*
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- * webServerHost; webServerPort;
- */
- public void setup(String[] args, Properties p) throws Exception {
- props = p;
- boolean pass = true;
- try {
- // get props
- timeout = Integer.parseInt(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- hostname = p.getProperty("webServerHost");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- if (hostname == null) {
- throw new Exception("'webServerHost' in ts.jte must not be null");
- }
- try {
- portnum = Integer.parseInt(p.getProperty("webServerPort"));
- } catch (Exception e) {
- throw new Exception("'webServerPort' in ts.jte must be a number");
- }
- if (ejbclient == null) {
- throw new Exception("setup failed: ejbclient injection failure");
- }
- } catch (Exception e) {
- throw new Exception("setup failed:", e);
- }
- TestUtil.logMsg("setup ok");
- }
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- TestUtil.logMsg("cleanup ok");
- }
-
- /*
- * Lookup JMS Connection Factory and Destination Objects
- */
- private void doLookupJMSObjects() throws Exception {
- try {
- TestUtil.logMsg(
- "Lookup JMS factories defined in @JMSConnectionFactoryDefinitions");
- TestUtil.logMsg(
- "Lookup JMS destinations defined in @JMSDestinationDefinitions");
- TSNamingContext namingctx = new TSNamingContext();
- TestUtil.logMsg("Lookup java:comp/DefaultJMSConnectionFactory");
- dcf = (ConnectionFactory) namingctx
- .lookup("java:comp/DefaultJMSConnectionFactory");
- TestUtil.logMsg("Lookup java:global/AppClientMyTestConnectionFactory");
- cf = (ConnectionFactory) namingctx
- .lookup("java:global/AppClientMyTestConnectionFactory");
- TestUtil.logMsg("Lookup java:app/AppClientMyTestQueueConnectionFactory");
- qcf = (QueueConnectionFactory) namingctx
- .lookup("java:app/AppClientMyTestQueueConnectionFactory");
- TestUtil
- .logMsg("Lookup java:module/AppClientMyTestTopicConnectionFactory");
- tcf = (TopicConnectionFactory) namingctx
- .lookup("java:module/AppClientMyTestTopicConnectionFactory");
- TestUtil.logMsg(
- "Lookup java:comp/env/jms/AppClientMyTestDurableTopicConnectionFactory");
- dtcf = (TopicConnectionFactory) namingctx.lookup(
- "java:comp/env/jms/AppClientMyTestDurableTopicConnectionFactory");
- TestUtil.logMsg("Lookup java:global/env/AppClientMyTestQueue");
- queue = (Queue) namingctx.lookup("java:global/env/AppClientMyTestQueue");
- TestUtil.logMsg("Lookup java:app/env/AppClientMyTestTopic");
- topic = (Topic) namingctx.lookup("java:app/env/AppClientMyTestTopic");
-
- TestUtil.logMsg("Create JMSContext, JMSProducer's and JMSConsumer's");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- producerQ = context.createProducer();
- consumerQ = context.createConsumer(queue);
- producerT = context.createProducer();
- consumerT = context.createConsumer(topic);
- } catch (Exception e) {
- throw new Exception("doLookupJMSObjects failed:", e);
- }
- }
-
- /*
- * doCleanup()
- */
- private void doCleanup() throws Exception {
- try {
- if (queueTest && consumerQ != null) {
- TestUtil.logMsg("Flush any messages left on Queue");
- Message rmsg = consumerQ.receive(timeout);
- while (rmsg != null) {
- rmsg = consumerQ.receiveNoWait();
- if (rmsg == null) {
- rmsg = consumerQ.receiveNoWait();
- }
- }
- consumerQ.close();
- }
- if (consumerT != null)
- consumerT.close();
- TestUtil.logMsg("Close JMSContext Objects");
- if (context != null)
- context.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("doCleanup failed!", e);
- }
- }
-
- /*
- * @testName: sendAndRecvQueueTestFromAppClient
- *
- * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
- * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
- * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
- * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
- * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
- * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
- *
- * @test_Strategy: Send and receive a message to/from a Queue.
- *
- */
- public void sendAndRecvQueueTestFromAppClient() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- doLookupJMSObjects();
- queueTest = true;
- // send and receive TextMessage
- TestUtil.logMsg(
- "Creating TextMessage via JMSContext.createTextMessage(String)");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvQueueTestFromAppClient");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producerQ.send(queue, expTextMessage);
- TestUtil.logMsg("Receive TextMessage via JMSconsumer.receive(long)");
- TextMessage actTextMessage = (TextMessage) consumerQ.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("sendAndRecvQueueTestFromAppClient", e);
- } finally {
- try {
- doCleanup();
- } catch (Exception e) {
- throw new Exception("doCleanup failed: ", e);
- }
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvQueueTestFromAppClient failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTopicTestFromAppClient
- *
- * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
- * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
- * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
- * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
- * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
- * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
- *
- * @test_Strategy: Send and receive a message to/from a Topic.
- *
- */
- public void sendAndRecvTopicTestFromAppClient() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- doLookupJMSObjects();
- queueTest = false;
- // send and receive TextMessage
- TestUtil.logMsg(
- "Creating TextMessage via JMSContext.createTextMessage(String)");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvTopicTestFromAppClient");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producerT.send(topic, expTextMessage);
- TestUtil.logMsg("Receive TextMessage via JMSconsumer.receive(long)");
- TextMessage actTextMessage = (TextMessage) consumerT.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- }
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("sendAndRecvTopicTestFromAppClient", e);
- } finally {
- try {
- doCleanup();
- } catch (Exception e) {
- throw new Exception("doCleanup failed: ", e);
- }
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTopicTestFromAppClient failed");
- }
- }
-
- /*
- * @testName: sendAndRecvQueueTestFromServletClient
- *
- * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
- * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
- * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
- * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
- * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
- * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
- *
- * @test_Strategy: Send and receive a message to/from a Queue.
- *
- */
- public void sendAndRecvQueueTestFromServletClient() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("-------------------------------------");
- TestUtil.logMsg("sendAndRecvQueueTestFromServletClient");
- TestUtil.logMsg("-------------------------------------");
- url = ctsurl.getURL("http", hostname, portnum, SERVLET);
- TestUtil.logMsg("Servlet URL: " + url);
- props.setProperty("TEST", "sendAndRecvQueueTestFromServletClient");
- urlConn = TestUtil.sendPostData(props, url);
- Properties p = TestUtil.getResponseProperties(urlConn);
- String passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil
- .logErr("JMSConnectionFactoryDefinitions test failed from Servlet");
- TestUtil.logErr("JMSDestinationDefinitions test failed from Servlet");
- } else {
- TestUtil
- .logMsg("JMSConnectionFactoryDefinitions test passed from Servlet");
- TestUtil.logMsg("JMSDestinationDefinitions test passed from Servlet");
- }
- } catch (Exception e) {
- TestUtil
- .logErr("JMSConnectionFactoryDefinitions test failed from Servlet");
- TestUtil.logErr("JMSDestinationDefinitions test failed from Servlet");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvQueueTestFromServletClient failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTopicTestFromServletClient
- *
- * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
- * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
- * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
- * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
- * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
- * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
- *
- * @test_Strategy: Send and receive a message to/from a Topic.
- *
- */
- public void sendAndRecvTopicTestFromServletClient() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("-------------------------------------");
- TestUtil.logMsg("sendAndRecvTopicTestFromServletClient");
- TestUtil.logMsg("-------------------------------------");
- url = ctsurl.getURL("http", hostname, portnum, SERVLET);
- TestUtil.logMsg("Servlet URL: " + url);
- props.setProperty("TEST", "sendAndRecvTopicTestFromServletClient");
- urlConn = TestUtil.sendPostData(props, url);
- Properties p = TestUtil.getResponseProperties(urlConn);
- String passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil
- .logErr("JMSConnectionFactoryDefinitions test failed from Servlet");
- TestUtil.logErr("JMSDestinationDefinitions test failed from Servlet");
- } else {
- TestUtil
- .logMsg("JMSConnectionFactoryDefinitions test passed from Servlet");
- TestUtil.logMsg("JMSDestinationDefinitions test passed from Servlet");
- }
- } catch (Exception e) {
- TestUtil
- .logErr("JMSConnectionFactoryDefinitions test failed from Servlet");
- TestUtil.logErr("JMSDestinationDefinitions test failed from Servlet");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTopicTestFromServletClient failed");
- }
- }
-
- /*
- * @testName: sendAndRecvQueueTestFromJspClient
- *
- * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
- * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
- * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
- * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
- * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
- * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
- *
- * @test_Strategy: Send and receive a message to/from a Queue.
- *
- */
- public void sendAndRecvQueueTestFromJspClient() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("---------------------------------");
- TestUtil.logMsg("sendAndRecvQueueTestFromJspClient");
- TestUtil.logMsg("---------------------------------");
- url = ctsurl.getURL("http", hostname, portnum, JSP);
- TestUtil.logMsg("Jsp URL: " + url);
- props.setProperty("TEST", "sendAndRecvQueueTestFromJspClient");
- urlConn = TestUtil.sendPostData(props, url);
- Properties p = TestUtil.getResponseProperties(urlConn);
- String passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil.logErr("JMSConnectionFactoryDefinitions test failed from Jsp");
- TestUtil.logErr("JMSDestinationDefinitions test failed from Jsp");
- } else {
- TestUtil.logMsg("JMSConnectionFactoryDefinitions test passed from Jsp");
- TestUtil.logMsg("JMSDestinationDefinitions test passed from Jsp");
- }
- } catch (Exception e) {
- TestUtil.logErr("JMSConnectionFactoryDefinitions test failed from Jsp");
- TestUtil.logErr("JMSDestinationDefinitions test failed from Jsp");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvQueueTestFromJspClient failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTopicTestFromJspClient
- *
- * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
- * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
- * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
- * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
- * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
- * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
- *
- * @test_Strategy: Send and receive a message to/from a Topic.
- *
- */
- public void sendAndRecvTopicTestFromJspClient() throws Exception {
- boolean pass = true;
- try {
- TestUtil.logMsg("---------------------------------");
- TestUtil.logMsg("sendAndRecvTopicTestFromJspClient");
- TestUtil.logMsg("---------------------------------");
- url = ctsurl.getURL("http", hostname, portnum, JSP);
- TestUtil.logMsg("Jsp URL: " + url);
- props.setProperty("TEST", "sendAndRecvTopicTestFromJspClient");
- urlConn = TestUtil.sendPostData(props, url);
- Properties p = TestUtil.getResponseProperties(urlConn);
- String passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil.logErr("JMSConnectionFactoryDefinitions test failed from Jsp");
- TestUtil.logErr("JMSDestinationDefinitions test failed from Jsp");
- } else {
- TestUtil.logMsg("JMSConnectionFactoryDefinitions test passed from Jsp");
- TestUtil.logMsg("JMSDestinationDefinitions test passed from Jsp");
- }
- } catch (Exception e) {
- TestUtil.logErr("JMSConnectionFactoryDefinitions test failed from Jsp");
- TestUtil.logErr("JMSDestinationDefinitions test failed from Jsp");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTopicTestFromJspClient failed");
- }
- }
-
- /*
- * @testName: sendAndRecvQueueTestFromEjbClient
- *
- * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
- * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
- * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
- * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
- * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
- * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
- *
- * @test_Strategy: Send and receive a message to/from a Queue.
- *
- */
- public void sendAndRecvQueueTestFromEjbClient() throws Exception {
- boolean pass = true;
- try {
- ejbclient.init(props);
- TestUtil.logMsg("---------------------------------");
- TestUtil.logMsg("sendAndRecvQueueTestFromEjbClient");
- TestUtil.logMsg("---------------------------------");
- boolean passEjb = ejbclient.echo("sendAndRecvQueueTestFromEjbClient");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("JMSConnectionFactoryDefinitions test failed from Ejb");
- TestUtil.logErr("JMSDestinationDefinitions test failed from Ejb");
- } else {
- TestUtil.logMsg("JMSConnectionFactoryDefinitions test passed from Ejb");
- TestUtil.logMsg("JMSDestinationDefinitions test passed from Ejb");
- }
- } catch (Exception e) {
- TestUtil.logErr("JMSConnectionFactoryDefinitions test failed from Ejb");
- TestUtil.logErr("JMSDestinationDefinitions test failed from Ejb");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvQueueTestFromEjbClient failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTopicTestFromEjbClient
- *
- * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
- * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
- * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
- * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
- * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
- * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
- *
- * @test_Strategy: Send and receive a message to/from a Topic.
- *
- */
- public void sendAndRecvTopicTestFromEjbClient() throws Exception {
- boolean pass = true;
- try {
- ejbclient.init(props);
- TestUtil.logMsg("---------------------------------");
- TestUtil.logMsg("sendAndRecvTopicTestFromEjbClient");
- TestUtil.logMsg("---------------------------------");
- boolean passEjb = ejbclient.echo("sendAndRecvTopicTestFromEjbClient");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("JMSConnectionFactoryDefinitions test failed from Ejb");
- TestUtil.logErr("JMSDestinationDefinitions test failed from Ejb");
- } else {
- TestUtil.logMsg("JMSConnectionFactoryDefinitions test passed from Ejb");
- TestUtil.logMsg("JMSDestinationDefinitions test passed from Ejb");
- }
- } catch (Exception e) {
- TestUtil.logErr("JMSConnectionFactoryDefinitions test failed from Ejb");
- TestUtil.logErr("JMSDestinationDefinitions test failed from Ejb");
- pass = false;
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTopicTestFromEjbClient failed");
- }
- }
-
- /*
- * @testName: checkClientIDOnDurableConnFactoryTest
- *
- * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
- * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
- * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
- * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
- * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
- * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
- *
- * @test_Strategy: Check client id setting on durable connection factory
- *
- */
- public void checkClientIDOnDurableConnFactoryTest() throws Exception {
- boolean pass = true;
- JMSContext context = null;
- try {
- queueTest = false;
- doLookupJMSObjects();
- TestUtil.logMsg(
- "==============================================================");
- TestUtil.logMsg(
- "Verify admin configured client id is MyClientID from AppClient");
- TestUtil.logMsg(
- "==============================================================");
- TestUtil
- .logMsg("Create JMSContext from durable topic connection factory");
- TestUtil.logMsg(
- "Check the client id which is configured as MyClientID in the "
- + "JMSConnectionFactoryDefinition annotation");
- context = dtcf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- String clientid = context.getClientID();
- if (clientid == null) {
- TestUtil.logErr("Client ID value is null (expected MyClientID)");
- pass = false;
- } else if (clientid.equals("MyClientID")) {
- TestUtil.logMsg("Client ID value is correct (MyClientID)");
- } else {
- TestUtil
- .logErr("Client ID value is incorrect (expected MyClientID, got "
- + clientid + ")");
- pass = false;
- }
- context.close();
- context = null;
- try {
- doCleanup();
- } catch (Exception e) {
- TestUtil.logErr("Error in cleanup");
- }
- TestUtil.logMsg(
- "==================================================================");
- TestUtil.logMsg(
- "Verify admin configured client id is MyClientID from ServletClient");
- TestUtil.logMsg(
- "==================================================================");
- url = ctsurl.getURL("http", hostname, portnum, SERVLET);
- TestUtil.logMsg("Servlet URL: " + url);
- props.setProperty("TEST", "checkClientIDTestFromServletClient");
- urlConn = TestUtil.sendPostData(props, url);
- Properties p = TestUtil.getResponseProperties(urlConn);
- String passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil.logErr("Check ClientID test failed from Servlet");
- } else {
- TestUtil.logMsg("Check ClientID test passed from Servlet");
- }
- TestUtil.logMsg(
- "==============================================================");
- TestUtil.logMsg(
- "Verify admin configured client id is MyClientID from JspClient");
- TestUtil.logMsg(
- "==============================================================");
- url = ctsurl.getURL("http", hostname, portnum, JSP);
- TestUtil.logMsg("Jsp URL: " + url);
- props.setProperty("TEST", "checkClientIDTestFromJspClient");
- urlConn = TestUtil.sendPostData(props, url);
- p = TestUtil.getResponseProperties(urlConn);
- passStr = p.getProperty("TESTRESULT");
- if (passStr.equals("fail")) {
- pass = false;
- TestUtil.logErr("Check ClientID test failed from Jsp");
- } else {
- TestUtil.logMsg("Check ClientID test passed from Jsp");
- }
- TestUtil.logMsg(
- "==============================================================");
- TestUtil.logMsg(
- "Verify admin configured client id is MyClientID from EjbClient");
- TestUtil.logMsg(
- "==============================================================");
- boolean passEjb = ejbclient.echo("checkClientIDTestFromEjbClient");
- if (!passEjb) {
- pass = false;
- TestUtil.logErr("Check ClientID test failed from Ejb");
- } else {
- TestUtil.logMsg("Check ClientID test passed from Ejb");
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("checkClientIDOnDurableConnFactoryTest", e);
- } finally {
- try {
- if (context != null)
- context.close();
- doCleanup();
- } catch (Exception e) {
- TestUtil.logErr("Error cleanup " + e);
- }
- }
-
- if (!pass) {
- throw new Exception("checkClientIDOnDurableConnFactoryTest failed");
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/ClientIT.java
new file mode 100644
index 0000000000..8e5f753b92
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/ClientIT.java
@@ -0,0 +1,736 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2022 Contributors to Eclipse Foundation. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+package com.sun.ts.tests.jms.ee20.resourcedefs.annotations;
+
+import java.lang.System.Logger;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.porting.TSURL;
+import com.sun.ts.lib.util.TSNamingContext;
+import com.sun.ts.lib.util.TestUtil;
+
+import jakarta.ejb.EJB;
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.JMSConnectionFactoryDefinition;
+import jakarta.jms.JMSConsumer;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSDestinationDefinition;
+import jakarta.jms.JMSProducer;
+import jakarta.jms.Message;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueConnectionFactory;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicConnectionFactory;
+
+//-------------------------------------
+// JMS Destination Resource Definitions
+//-------------------------------------
+@JMSDestinationDefinition(description = "Define Queue AppClientMyTestQueue", interfaceName = "jakarta.jms.Queue", name = "java:global/env/AppClientMyTestQueue", destinationName = "AppClientMyTestQueue")
+
+@JMSDestinationDefinition(description = "Define Topic AppClientMyTestTopic", interfaceName = "jakarta.jms.Topic", name = "java:app/env/AppClientMyTestTopic", destinationName = "AppClientMyTestTopic")
+
+//-------------------------------------------
+// JMS ConnectionFactory Resource Definitions
+//-------------------------------------------
+@JMSConnectionFactoryDefinition(description = "Define ConnectionFactory AppClientMyTestConnectionFactory", interfaceName = "jakarta.jms.ConnectionFactory", name = "java:global/AppClientMyTestConnectionFactory", user = "j2ee", password = "j2ee")
+
+@JMSConnectionFactoryDefinition(description = "Define QueueConnectionFactory AppClientMyTestQueueConnectionFactory", interfaceName = "jakarta.jms.QueueConnectionFactory", name = "java:app/AppClientMyTestQueueConnectionFactory", user = "j2ee", password = "j2ee")
+
+@JMSConnectionFactoryDefinition(description = "Define TopicConnectionFactory AppClientMyTestTopicConnectionFactory", interfaceName = "jakarta.jms.TopicConnectionFactory", name = "java:module/AppClientMyTestTopicConnectionFactory", user = "j2ee", password = "j2ee")
+
+@JMSConnectionFactoryDefinition(description = "Define Durable TopicConnectionFactory AppClientMyTestDurableTopicConnectionFactory", interfaceName = "jakarta.jms.TopicConnectionFactory", name = "java:comp/env/jms/AppClientMyTestDurableTopicConnectionFactory", user = "j2ee", password = "j2ee", clientId = "MyClientID", properties = {
+ "Property1=10", "Property2=20" }, transactional = false, maxPoolSize = 30, minPoolSize = 20)
+
+
+public class ClientIT {
+ private static final long serialVersionUID = 1L;
+
+ // JMS objects
+ protected transient ConnectionFactory dcf = null;
+
+ protected transient ConnectionFactory cf = null;
+
+ protected transient ConnectionFactory cfra = null;
+
+ protected transient QueueConnectionFactory qcf = null;
+
+ protected transient TopicConnectionFactory tcf = null;
+
+ protected transient TopicConnectionFactory dtcf = null;
+
+ protected transient Topic topic = null;
+
+ protected transient Topic topica = null;
+
+ protected transient Queue queue = null;
+
+ protected transient JMSContext context = null;
+
+ protected transient JMSConsumer consumerQ = null;
+
+ protected transient JMSProducer producerQ = null;
+
+ protected transient JMSConsumer consumerT = null;
+
+ protected transient JMSProducer producerT = null;
+
+ protected boolean queueTest = false;
+
+ // Harness req's
+ protected Properties props = null;
+
+ // properties read
+ protected long timeout;
+
+ protected String user;
+
+ protected String password;
+
+ protected String mode;
+
+ // The webserver defaults (overidden by harness properties)
+ private static final String PROTOCOL = "http";
+
+ private static final String HOSTNAME = "localhost";
+
+ private static final int PORTNUM = 8000;
+
+ private TSURL ctsurl = new TSURL();
+
+ private String hostname = HOSTNAME;
+
+ private int portnum = PORTNUM;
+
+ // URL properties used by the test
+ private URL url = null;
+
+ private transient URLConnection urlConn = null;
+
+ private String SERVLET = "/resourcedefs_annotations_web/ServletTest";
+
+ private String JSP = "/resourcedefs_annotations_web/JspClient.jsp";
+
+ @EJB(name = "ejb/JMSResourceDefsEjbClientBean")
+ static EjbClientIF ejbclient;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /* Test setup */
+
+ /*
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ * webServerHost; webServerPort;
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ boolean pass = true;
+ try {
+ // get props
+ timeout = Integer.parseInt(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ hostname = System.getProperty("webServerHost");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ if (hostname == null) {
+ throw new Exception("'webServerHost' is null");
+ }
+ try {
+ portnum = Integer.parseInt(System.getProperty("webServerPort"));
+ } catch (Exception e) {
+ throw new Exception("'webServerPort' in must be a number");
+ }
+ if (ejbclient == null) {
+ throw new Exception("setup failed: ejbclient injection failure");
+ }
+ } catch (Exception e) {
+ throw new Exception("setup failed:", e);
+ }
+ logger.log(Logger.Level.INFO, "setup ok");
+ }
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ logger.log(Logger.Level.INFO, "cleanup ok");
+ }
+
+ /*
+ * Lookup JMS Connection Factory and Destination Objects
+ */
+ private void doLookupJMSObjects() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Lookup JMS factories defined in @JMSConnectionFactoryDefinitions");
+ logger.log(Logger.Level.INFO, "Lookup JMS destinations defined in @JMSDestinationDefinitions");
+ TSNamingContext namingctx = new TSNamingContext();
+ logger.log(Logger.Level.INFO, "Lookup java:comp/DefaultJMSConnectionFactory");
+ dcf = (ConnectionFactory) namingctx.lookup("java:comp/DefaultJMSConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:global/AppClientMyTestConnectionFactory");
+ cf = (ConnectionFactory) namingctx.lookup("java:global/AppClientMyTestConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:app/AppClientMyTestQueueConnectionFactory");
+ qcf = (QueueConnectionFactory) namingctx.lookup("java:app/AppClientMyTestQueueConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:module/AppClientMyTestTopicConnectionFactory");
+ tcf = (TopicConnectionFactory) namingctx.lookup("java:module/AppClientMyTestTopicConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:comp/env/jms/AppClientMyTestDurableTopicConnectionFactory");
+ dtcf = (TopicConnectionFactory) namingctx
+ .lookup("java:comp/env/jms/AppClientMyTestDurableTopicConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:global/env/AppClientMyTestQueue");
+ queue = (Queue) namingctx.lookup("java:global/env/AppClientMyTestQueue");
+ logger.log(Logger.Level.INFO, "Lookup java:app/env/AppClientMyTestTopic");
+ topic = (Topic) namingctx.lookup("java:app/env/AppClientMyTestTopic");
+
+ logger.log(Logger.Level.INFO, "Create JMSContext, JMSProducer's and JMSConsumer's");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ producerQ = context.createProducer();
+ consumerQ = context.createConsumer(queue);
+ producerT = context.createProducer();
+ consumerT = context.createConsumer(topic);
+ } catch (Exception e) {
+ throw new Exception("doLookupJMSObjects failed:", e);
+ }
+ }
+
+ /*
+ * doCleanup()
+ */
+ private void doCleanup() throws Exception {
+ try {
+ if (queueTest && consumerQ != null) {
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ Message rmsg = consumerQ.receive(timeout);
+ while (rmsg != null) {
+ rmsg = consumerQ.receiveNoWait();
+ if (rmsg == null) {
+ rmsg = consumerQ.receiveNoWait();
+ }
+ }
+ consumerQ.close();
+ }
+ if (consumerT != null)
+ consumerT.close();
+ logger.log(Logger.Level.INFO, "Close JMSContext Objects");
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("doCleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvQueueTestFromAppClient
+ *
+ * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
+ * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
+ * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
+ * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
+ * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
+ * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
+ *
+ * @test_Strategy: Send and receive a message to/from a Queue.
+ *
+ */
+ @Test
+ public void sendAndRecvQueueTestFromAppClient() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ doLookupJMSObjects();
+ queueTest = true;
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage via JMSContext.createTextMessage(String)");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvQueueTestFromAppClient");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producerQ.send(queue, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage via JMSconsumer.receive(long)");
+ TextMessage actTextMessage = (TextMessage) consumerQ.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("sendAndRecvQueueTestFromAppClient", e);
+ } finally {
+ try {
+ doCleanup();
+ } catch (Exception e) {
+ throw new Exception("doCleanup failed: ", e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvQueueTestFromAppClient failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTopicTestFromAppClient
+ *
+ * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
+ * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
+ * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
+ * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
+ * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
+ * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
+ *
+ * @test_Strategy: Send and receive a message to/from a Topic.
+ *
+ */
+ @Test
+ public void sendAndRecvTopicTestFromAppClient() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ doLookupJMSObjects();
+ queueTest = false;
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage via JMSContext.createTextMessage(String)");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvTopicTestFromAppClient");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producerT.send(topic, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage via JMSconsumer.receive(long)");
+ TextMessage actTextMessage = (TextMessage) consumerT.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ }
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("sendAndRecvTopicTestFromAppClient", e);
+ } finally {
+ try {
+ doCleanup();
+ } catch (Exception e) {
+ throw new Exception("doCleanup failed: ", e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTopicTestFromAppClient failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvQueueTestFromServletClient
+ *
+ * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
+ * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
+ * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
+ * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
+ * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
+ * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
+ *
+ * @test_Strategy: Send and receive a message to/from a Queue.
+ *
+ */
+ @Test
+ public void sendAndRecvQueueTestFromServletClient() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "-------------------------------------");
+ logger.log(Logger.Level.INFO, "sendAndRecvQueueTestFromServletClient");
+ logger.log(Logger.Level.INFO, "-------------------------------------");
+ url = ctsurl.getURL("http", hostname, portnum, SERVLET);
+ logger.log(Logger.Level.INFO, "Servlet URL: " + url);
+ props.setProperty("TEST", "sendAndRecvQueueTestFromServletClient");
+ urlConn = TestUtil.sendPostData(props, url);
+ Properties p = TestUtil.getResponseProperties(urlConn);
+ String passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "JMSConnectionFactoryDefinitions test failed from Servlet");
+ logger.log(Logger.Level.ERROR, "JMSDestinationDefinitions test failed from Servlet");
+ } else {
+ logger.log(Logger.Level.INFO, "JMSConnectionFactoryDefinitions test passed from Servlet");
+ logger.log(Logger.Level.INFO, "JMSDestinationDefinitions test passed from Servlet");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "JMSConnectionFactoryDefinitions test failed from Servlet");
+ logger.log(Logger.Level.ERROR, "JMSDestinationDefinitions test failed from Servlet");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvQueueTestFromServletClient failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTopicTestFromServletClient
+ *
+ * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
+ * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
+ * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
+ * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
+ * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
+ * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
+ *
+ * @test_Strategy: Send and receive a message to/from a Topic.
+ *
+ */
+ @Test
+ public void sendAndRecvTopicTestFromServletClient() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "-------------------------------------");
+ logger.log(Logger.Level.INFO, "sendAndRecvTopicTestFromServletClient");
+ logger.log(Logger.Level.INFO, "-------------------------------------");
+ url = ctsurl.getURL("http", hostname, portnum, SERVLET);
+ logger.log(Logger.Level.INFO, "Servlet URL: " + url);
+ props.setProperty("TEST", "sendAndRecvTopicTestFromServletClient");
+ urlConn = TestUtil.sendPostData(props, url);
+ Properties p = TestUtil.getResponseProperties(urlConn);
+ String passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "JMSConnectionFactoryDefinitions test failed from Servlet");
+ logger.log(Logger.Level.ERROR, "JMSDestinationDefinitions test failed from Servlet");
+ } else {
+ logger.log(Logger.Level.INFO, "JMSConnectionFactoryDefinitions test passed from Servlet");
+ logger.log(Logger.Level.INFO, "JMSDestinationDefinitions test passed from Servlet");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "JMSConnectionFactoryDefinitions test failed from Servlet");
+ logger.log(Logger.Level.ERROR, "JMSDestinationDefinitions test failed from Servlet");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTopicTestFromServletClient failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvQueueTestFromJspClient
+ *
+ * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
+ * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
+ * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
+ * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
+ * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
+ * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
+ *
+ * @test_Strategy: Send and receive a message to/from a Queue.
+ *
+ */
+ @Test
+ public void sendAndRecvQueueTestFromJspClient() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "---------------------------------");
+ logger.log(Logger.Level.INFO, "sendAndRecvQueueTestFromJspClient");
+ logger.log(Logger.Level.INFO, "---------------------------------");
+ url = ctsurl.getURL("http", hostname, portnum, JSP);
+ logger.log(Logger.Level.INFO, "Jsp URL: " + url);
+ props.setProperty("TEST", "sendAndRecvQueueTestFromJspClient");
+ urlConn = TestUtil.sendPostData(props, url);
+ Properties p = TestUtil.getResponseProperties(urlConn);
+ String passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "JMSConnectionFactoryDefinitions test failed from Jsp");
+ logger.log(Logger.Level.ERROR, "JMSDestinationDefinitions test failed from Jsp");
+ } else {
+ logger.log(Logger.Level.INFO, "JMSConnectionFactoryDefinitions test passed from Jsp");
+ logger.log(Logger.Level.INFO, "JMSDestinationDefinitions test passed from Jsp");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "JMSConnectionFactoryDefinitions test failed from Jsp");
+ logger.log(Logger.Level.ERROR, "JMSDestinationDefinitions test failed from Jsp");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvQueueTestFromJspClient failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTopicTestFromJspClient
+ *
+ * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
+ * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
+ * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
+ * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
+ * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
+ * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
+ *
+ * @test_Strategy: Send and receive a message to/from a Topic.
+ *
+ */
+ @Test
+ public void sendAndRecvTopicTestFromJspClient() throws Exception {
+ boolean pass = true;
+ try {
+ logger.log(Logger.Level.INFO, "---------------------------------");
+ logger.log(Logger.Level.INFO, "sendAndRecvTopicTestFromJspClient");
+ logger.log(Logger.Level.INFO, "---------------------------------");
+ url = ctsurl.getURL("http", hostname, portnum, JSP);
+ logger.log(Logger.Level.INFO, "Jsp URL: " + url);
+ props.setProperty("TEST", "sendAndRecvTopicTestFromJspClient");
+ urlConn = TestUtil.sendPostData(props, url);
+ Properties p = TestUtil.getResponseProperties(urlConn);
+ String passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "JMSConnectionFactoryDefinitions test failed from Jsp");
+ logger.log(Logger.Level.ERROR, "JMSDestinationDefinitions test failed from Jsp");
+ } else {
+ logger.log(Logger.Level.INFO, "JMSConnectionFactoryDefinitions test passed from Jsp");
+ logger.log(Logger.Level.INFO, "JMSDestinationDefinitions test passed from Jsp");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "JMSConnectionFactoryDefinitions test failed from Jsp");
+ logger.log(Logger.Level.ERROR, "JMSDestinationDefinitions test failed from Jsp");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTopicTestFromJspClient failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvQueueTestFromEjbClient
+ *
+ * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
+ * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
+ * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
+ * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
+ * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
+ * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
+ *
+ * @test_Strategy: Send and receive a message to/from a Queue.
+ *
+ */
+ @Test
+ public void sendAndRecvQueueTestFromEjbClient() throws Exception {
+ boolean pass = true;
+ try {
+ ejbclient.init(props);
+ logger.log(Logger.Level.INFO, "---------------------------------");
+ logger.log(Logger.Level.INFO, "sendAndRecvQueueTestFromEjbClient");
+ logger.log(Logger.Level.INFO, "---------------------------------");
+ boolean passEjb = ejbclient.echo("sendAndRecvQueueTestFromEjbClient");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "JMSConnectionFactoryDefinitions test failed from Ejb");
+ logger.log(Logger.Level.ERROR, "JMSDestinationDefinitions test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "JMSConnectionFactoryDefinitions test passed from Ejb");
+ logger.log(Logger.Level.INFO, "JMSDestinationDefinitions test passed from Ejb");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "JMSConnectionFactoryDefinitions test failed from Ejb");
+ logger.log(Logger.Level.ERROR, "JMSDestinationDefinitions test failed from Ejb");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvQueueTestFromEjbClient failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTopicTestFromEjbClient
+ *
+ * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
+ * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
+ * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
+ * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
+ * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
+ * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
+ *
+ * @test_Strategy: Send and receive a message to/from a Topic.
+ *
+ */
+ @Test
+ public void sendAndRecvTopicTestFromEjbClient() throws Exception {
+ boolean pass = true;
+ try {
+ ejbclient.init(props);
+ logger.log(Logger.Level.INFO, "---------------------------------");
+ logger.log(Logger.Level.INFO, "sendAndRecvTopicTestFromEjbClient");
+ logger.log(Logger.Level.INFO, "---------------------------------");
+ boolean passEjb = ejbclient.echo("sendAndRecvTopicTestFromEjbClient");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "JMSConnectionFactoryDefinitions test failed from Ejb");
+ logger.log(Logger.Level.ERROR, "JMSDestinationDefinitions test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "JMSConnectionFactoryDefinitions test passed from Ejb");
+ logger.log(Logger.Level.INFO, "JMSDestinationDefinitions test passed from Ejb");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "JMSConnectionFactoryDefinitions test failed from Ejb");
+ logger.log(Logger.Level.ERROR, "JMSDestinationDefinitions test failed from Ejb");
+ pass = false;
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTopicTestFromEjbClient failed");
+ }
+ }
+
+ /*
+ * @testName: checkClientIDOnDurableConnFactoryTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
+ * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
+ * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
+ * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
+ * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
+ * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
+ *
+ * @test_Strategy: Check client id setting on durable connection factory
+ *
+ */
+ @Test
+ public void checkClientIDOnDurableConnFactoryTest() throws Exception {
+ boolean pass = true;
+ JMSContext context = null;
+ try {
+ queueTest = false;
+ doLookupJMSObjects();
+ logger.log(Logger.Level.INFO, "==============================================================");
+ logger.log(Logger.Level.INFO, "Verify admin configured client id is MyClientID from AppClient");
+ logger.log(Logger.Level.INFO, "==============================================================");
+ logger.log(Logger.Level.INFO, "Create JMSContext from durable topic connection factory");
+ logger.log(Logger.Level.INFO, "Check the client id which is configured as MyClientID in the "
+ + "JMSConnectionFactoryDefinition annotation");
+ context = dtcf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ String clientid = context.getClientID();
+ if (clientid == null) {
+ logger.log(Logger.Level.ERROR, "Client ID value is null (expected MyClientID)");
+ pass = false;
+ } else if (clientid.equals("MyClientID")) {
+ logger.log(Logger.Level.INFO, "Client ID value is correct (MyClientID)");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Client ID value is incorrect (expected MyClientID, got " + clientid + ")");
+ pass = false;
+ }
+ context.close();
+ context = null;
+ try {
+ doCleanup();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error in cleanup");
+ }
+ logger.log(Logger.Level.INFO, "==================================================================");
+ logger.log(Logger.Level.INFO, "Verify admin configured client id is MyClientID from ServletClient");
+ logger.log(Logger.Level.INFO, "==================================================================");
+ url = ctsurl.getURL("http", hostname, portnum, SERVLET);
+ logger.log(Logger.Level.INFO, "Servlet URL: " + url);
+ props.setProperty("TEST", "checkClientIDTestFromServletClient");
+ urlConn = TestUtil.sendPostData(props, url);
+ Properties p = TestUtil.getResponseProperties(urlConn);
+ String passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Check ClientID test failed from Servlet");
+ } else {
+ logger.log(Logger.Level.INFO, "Check ClientID test passed from Servlet");
+ }
+ logger.log(Logger.Level.INFO, "==============================================================");
+ logger.log(Logger.Level.INFO, "Verify admin configured client id is MyClientID from JspClient");
+ logger.log(Logger.Level.INFO, "==============================================================");
+ url = ctsurl.getURL("http", hostname, portnum, JSP);
+ logger.log(Logger.Level.INFO, "Jsp URL: " + url);
+ props.setProperty("TEST", "checkClientIDTestFromJspClient");
+ urlConn = TestUtil.sendPostData(props, url);
+ p = TestUtil.getResponseProperties(urlConn);
+ passStr = System.getProperty("TESTRESULT");
+ if (passStr.equals("fail")) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Check ClientID test failed from Jsp");
+ } else {
+ logger.log(Logger.Level.INFO, "Check ClientID test passed from Jsp");
+ }
+ logger.log(Logger.Level.INFO, "==============================================================");
+ logger.log(Logger.Level.INFO, "Verify admin configured client id is MyClientID from EjbClient");
+ logger.log(Logger.Level.INFO, "==============================================================");
+ boolean passEjb = ejbclient.echo("checkClientIDTestFromEjbClient");
+ if (!passEjb) {
+ pass = false;
+ logger.log(Logger.Level.ERROR, "Check ClientID test failed from Ejb");
+ } else {
+ logger.log(Logger.Level.INFO, "Check ClientID test passed from Ejb");
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("checkClientIDOnDurableConnFactoryTest", e);
+ } finally {
+ try {
+ if (context != null)
+ context.close();
+ doCleanup();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error cleanup " + e);
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("checkClientIDOnDurableConnFactoryTest failed");
+ }
+ }
+
+}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/EjbClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/EjbClient.java
index e37f0c7386..08f0b630d6 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/EjbClient.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/EjbClient.java
@@ -17,6 +17,7 @@
package com.sun.ts.tests.jms.ee20.resourcedefs.annotations;
+import java.lang.System.Logger;
import java.util.Properties;
import com.sun.ts.lib.util.RemoteLoggingInitException;
@@ -30,11 +31,9 @@
import jakarta.ejb.TransactionManagementType;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.JMSConnectionFactoryDefinition;
-import jakarta.jms.JMSConnectionFactoryDefinitions;
import jakarta.jms.JMSConsumer;
import jakarta.jms.JMSContext;
import jakarta.jms.JMSDestinationDefinition;
-import jakarta.jms.JMSDestinationDefinitions;
import jakarta.jms.JMSProducer;
import jakarta.jms.Message;
import jakarta.jms.Queue;
@@ -46,341 +45,286 @@
//-------------------------------------
// JMS Destination Resource Definitions
//-------------------------------------
- @JMSDestinationDefinition(
- description="Define Queue EJBMyTestQueue",
- interfaceName="jakarta.jms.Queue",
- name="java:global/env/EJBMyTestQueue",
- destinationName="EJBMyTestQueue"
- )
-
- @JMSDestinationDefinition(
- description="Define Topic EJBMyTestTopic",
- interfaceName="jakarta.jms.Topic",
- name="java:app/env/EJBMyTestTopic",
- destinationName="EJBMyTestTopic"
- )
+@JMSDestinationDefinition(description = "Define Queue EJBMyTestQueue", interfaceName = "jakarta.jms.Queue", name = "java:global/env/EJBMyTestQueue", destinationName = "EJBMyTestQueue")
+
+@JMSDestinationDefinition(description = "Define Topic EJBMyTestTopic", interfaceName = "jakarta.jms.Topic", name = "java:app/env/EJBMyTestTopic", destinationName = "EJBMyTestTopic")
//-------------------------------------------
// JMS ConnectionFactory Resource Definitions
//-------------------------------------------
- @JMSConnectionFactoryDefinition(
- description="Define ConnectionFactory EJBMyTestConnectionFactory",
- interfaceName="jakarta.jms.ConnectionFactory",
- name="java:global/EJBMyTestConnectionFactory",
- user = "j2ee",
- password = "j2ee"
- )
-
- @JMSConnectionFactoryDefinition(
- description="Define QueueConnectionFactory EJBMyTestQueueConnectionFactory",
- interfaceName="jakarta.jms.QueueConnectionFactory",
- name="java:app/EJBMyTestQueueConnectionFactory",
- user = "j2ee",
- password = "j2ee"
- )
-
- @JMSConnectionFactoryDefinition(
- description="Define TopicConnectionFactory EJBMyTestTopicConnectionFactory",
- interfaceName="jakarta.jms.TopicConnectionFactory",
- name="java:module/EJBMyTestTopicConnectionFactory",
- user = "j2ee",
- password = "j2ee"
- )
-
- @JMSConnectionFactoryDefinition(
- description="Define Durable TopicConnectionFactory EJBMyTestDurableTopicConnectionFactory",
- interfaceName="jakarta.jms.TopicConnectionFactory",
- name="java:comp/env/jms/EJBMyTestDurableTopicConnectionFactory",
- user = "j2ee",
- password = "j2ee",
- clientId = "MyClientID",
- properties = { "Property1=10", "Property2=20" },
- transactional = false,
- maxPoolSize = 30,
- minPoolSize = 20
- )
+@JMSConnectionFactoryDefinition(description = "Define ConnectionFactory EJBMyTestConnectionFactory", interfaceName = "jakarta.jms.ConnectionFactory", name = "java:global/EJBMyTestConnectionFactory", user = "j2ee", password = "j2ee")
+
+@JMSConnectionFactoryDefinition(description = "Define QueueConnectionFactory EJBMyTestQueueConnectionFactory", interfaceName = "jakarta.jms.QueueConnectionFactory", name = "java:app/EJBMyTestQueueConnectionFactory", user = "j2ee", password = "j2ee")
+
+@JMSConnectionFactoryDefinition(description = "Define TopicConnectionFactory EJBMyTestTopicConnectionFactory", interfaceName = "jakarta.jms.TopicConnectionFactory", name = "java:module/EJBMyTestTopicConnectionFactory", user = "j2ee", password = "j2ee")
+
+@JMSConnectionFactoryDefinition(description = "Define Durable TopicConnectionFactory EJBMyTestDurableTopicConnectionFactory", interfaceName = "jakarta.jms.TopicConnectionFactory", name = "java:comp/env/jms/EJBMyTestDurableTopicConnectionFactory", user = "j2ee", password = "j2ee", clientId = "MyClientID", properties = {
+ "Property1=10", "Property2=20" }, transactional = false, maxPoolSize = 30, minPoolSize = 20)
@Stateful(name = "JMSResourceDefsEjbClientBean")
@Remote({ EjbClientIF.class })
@TransactionManagement(TransactionManagementType.BEAN)
public class EjbClient implements EjbClientIF {
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- protected transient ConnectionFactory cf = null;
-
- protected transient ConnectionFactory dcf = null;
-
- protected transient ConnectionFactory cfra = null;
-
- protected transient QueueConnectionFactory qcf = null;
-
- protected transient TopicConnectionFactory tcf = null;
-
- protected transient TopicConnectionFactory dtcf = null;
-
- protected transient Topic topic = null;
-
- protected transient Topic topica = null;
-
- protected transient Queue queue = null;
-
- protected transient JMSContext context = null;
-
- protected transient JMSConsumer consumerQ = null;
-
- protected transient JMSProducer producerQ = null;
-
- protected transient JMSConsumer consumerT = null;
-
- protected transient JMSProducer producerT = null;
-
- protected boolean queueTest = false;
-
- // Harness req's
- protected Properties props = null;
-
- // properties read from ts.jte file
- protected long timeout;
-
- protected String user;
-
- protected String password;
-
- protected String mode;
-
- /*
- * doCleanup()
- */
- private void doCleanup() throws Exception {
- try {
- if (queueTest && consumerQ != null) {
- TestUtil.logMsg("Flush any messages left on Queue");
- Message rmsg = consumerQ.receive(timeout);
- while (rmsg != null) {
- rmsg = consumerQ.receiveNoWait();
- if (rmsg == null) {
- rmsg = consumerQ.receiveNoWait();
- }
- }
- consumerQ.close();
- }
- if (consumerT != null)
- consumerT.close();
- TestUtil.logMsg("Close JMSContext Objects");
- if (context != null)
- context.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("doCleanup failed!", e);
- }
- }
-
- public void init(Properties p) {
- try {
- TestUtil.init(p);
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- doLookupJMSObjects();
- } catch (RemoteLoggingInitException e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("init: failed");
- } catch (Exception e) {
- TestUtil.printStackTrace(e);
- throw new EJBException("init: failed");
- }
- }
-
- public boolean echo(String testName) {
- boolean pass = false;
-
- if (testName.equals("sendAndRecvQueueTestFromEjbClient"))
- pass = sendAndRecvQueueTestFromEjbClient();
- else if (testName.equals("sendAndRecvTopicTestFromEjbClient"))
- pass = sendAndRecvTopicTestFromEjbClient();
- else if (testName.equals("checkClientIDTestFromEjbClient"))
- pass = checkClientIDTestFromEjbClient();
- try {
- doCleanup();
- } catch (Exception e) {
- pass = false;
- }
- return pass;
- }
-
- /*
- * Lookup JMS Connection Factory and Destination Objects
- */
- private void doLookupJMSObjects() throws Exception {
- try {
- TestUtil.logMsg(
- "Lookup JMS factories defined in @JMSConnectionFactoryDefinitions");
- TestUtil.logMsg(
- "Lookup JMS destinations defined in @JMSDestinationDefinitions");
- TSNamingContext namingctx = new TSNamingContext();
- TestUtil.logMsg("Lookup java:comp/DefaultJMSConnectionFactory");
- dcf = (ConnectionFactory) namingctx
- .lookup("java:comp/DefaultJMSConnectionFactory");
- TestUtil.logMsg("Lookup java:global/EJBMyTestConnectionFactory");
- cf = (ConnectionFactory) namingctx
- .lookup("java:global/EJBMyTestConnectionFactory");
- TestUtil.logMsg("Lookup java:app/EJBMyTestQueueConnectionFactory");
- qcf = (QueueConnectionFactory) namingctx
- .lookup("java:app/EJBMyTestQueueConnectionFactory");
- TestUtil.logMsg("Lookup java:module/EJBMyTestTopicConnectionFactory");
- tcf = (TopicConnectionFactory) namingctx
- .lookup("java:module/EJBMyTestTopicConnectionFactory");
- TestUtil.logMsg(
- "Lookup java:comp/env/jms/EJBMyTestDurableTopicConnectionFactory");
- dtcf = (TopicConnectionFactory) namingctx
- .lookup("java:comp/env/jms/EJBMyTestDurableTopicConnectionFactory");
- TestUtil.logMsg("Lookup java:global/env/EJBMyTestQueue");
- queue = (Queue) namingctx.lookup("java:global/env/EJBMyTestQueue");
- TestUtil.logMsg("Lookup java:app/env/EJBMyTestTopic");
- topic = (Topic) namingctx.lookup("java:app/env/EJBMyTestTopic");
-
- TestUtil.logMsg("Create JMSContext, JMSProducer's and JMSConsumer's");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- producerQ = context.createProducer();
- consumerQ = context.createConsumer(queue);
- producerT = context.createProducer();
- consumerT = context.createConsumer(topic);
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw e;
- }
- }
-
- public boolean sendAndRecvQueueTestFromEjbClient() {
- boolean pass = true;
- String message = "Where are you!";
- try {
- queueTest = true;
- // send and receive TextMessage
- TestUtil.logMsg(
- "Creating TextMessage via JMSContext.createTextMessage(String)");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvQueueTestFromEjbClient");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producerQ.send(queue, expTextMessage);
- TestUtil.logMsg("Receive TextMessage via JMSconsumer.receive(long)");
- TextMessage actTextMessage = (TextMessage) consumerQ.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
-
- return pass;
- }
-
- public boolean sendAndRecvTopicTestFromEjbClient() {
- boolean pass = true;
- String message = "Where are you!";
- try {
- queueTest = false;
- // send and receive TextMessage
- TestUtil.logMsg(
- "Creating TextMessage via JMSContext.createTextMessage(String)");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvTopicTestFromEjbClient");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producerT.send(topic, expTextMessage);
- TestUtil.logMsg("Receive TextMessage via JMSconsumer.receive(long)");
- TextMessage actTextMessage = (TextMessage) consumerT.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
- return pass;
- }
-
- public boolean checkClientIDTestFromEjbClient() {
- boolean pass = true;
- JMSContext context = null;
- try {
- queueTest = false;
- doLookupJMSObjects();
- TestUtil
- .logMsg("Create JMSContext from durable topic connection factory");
- TestUtil.logMsg(
- "Check the client id which is configured as MyClientID in the "
- + "JMSConnectionFactoryDefinition annotation");
- context = dtcf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- String clientid = context.getClientID();
- if (clientid == null) {
- TestUtil.logErr("Client ID value is null (expected MyClientID)");
- pass = false;
- } else if (clientid.equals("MyClientID")) {
- TestUtil.logMsg("Client ID value is correct (MyClientID)");
- } else {
- TestUtil
- .logErr("Client ID value is incorrect (expected MyClientID, got "
- + clientid + ")");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- if (context != null)
- context.close();
- } catch (Exception e) {
- }
- }
- return pass;
- }
+ private static final long serialVersionUID = 1L;
+
+ // JMS objects
+ protected transient ConnectionFactory cf = null;
+
+ protected transient ConnectionFactory dcf = null;
+
+ protected transient ConnectionFactory cfra = null;
+
+ protected transient QueueConnectionFactory qcf = null;
+
+ protected transient TopicConnectionFactory tcf = null;
+
+ protected transient TopicConnectionFactory dtcf = null;
+
+ protected transient Topic topic = null;
+
+ protected transient Topic topica = null;
+
+ protected transient Queue queue = null;
+
+ protected transient JMSContext context = null;
+
+ protected transient JMSConsumer consumerQ = null;
+
+ protected transient JMSProducer producerQ = null;
+
+ protected transient JMSConsumer consumerT = null;
+
+ protected transient JMSProducer producerT = null;
+
+ protected boolean queueTest = false;
+
+ // Harness req's
+ protected Properties props = null;
+
+ // properties read
+ protected long timeout;
+
+ protected String user;
+
+ protected String password;
+
+ protected String mode;
+
+ private static final Logger logger = (Logger) System.getLogger(EjbClient.class.getName());
+
+ /*
+ * doCleanup()
+ */
+ private void doCleanup() throws Exception {
+ try {
+ if (queueTest && consumerQ != null) {
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ Message rmsg = consumerQ.receive(timeout);
+ while (rmsg != null) {
+ rmsg = consumerQ.receiveNoWait();
+ if (rmsg == null) {
+ rmsg = consumerQ.receiveNoWait();
+ }
+ }
+ consumerQ.close();
+ }
+ if (consumerT != null)
+ consumerT.close();
+ logger.log(Logger.Level.INFO, "Close JMSContext Objects");
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("doCleanup failed!", e);
+ }
+ }
+
+ public void init(Properties p) {
+ try {
+ TestUtil.init(p);
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ doLookupJMSObjects();
+ } catch (RemoteLoggingInitException e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("init: failed");
+ } catch (Exception e) {
+ TestUtil.printStackTrace(e);
+ throw new EJBException("init: failed");
+ }
+ }
+
+ public boolean echo(String testName) {
+ boolean pass = false;
+
+ if (testName.equals("sendAndRecvQueueTestFromEjbClient"))
+ pass = sendAndRecvQueueTestFromEjbClient();
+ else if (testName.equals("sendAndRecvTopicTestFromEjbClient"))
+ pass = sendAndRecvTopicTestFromEjbClient();
+ else if (testName.equals("checkClientIDTestFromEjbClient"))
+ pass = checkClientIDTestFromEjbClient();
+ try {
+ doCleanup();
+ } catch (Exception e) {
+ pass = false;
+ }
+ return pass;
+ }
+
+ /*
+ * Lookup JMS Connection Factory and Destination Objects
+ */
+ private void doLookupJMSObjects() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Lookup JMS factories defined in @JMSConnectionFactoryDefinitions");
+ logger.log(Logger.Level.INFO, "Lookup JMS destinations defined in @JMSDestinationDefinitions");
+ TSNamingContext namingctx = new TSNamingContext();
+ logger.log(Logger.Level.INFO, "Lookup java:comp/DefaultJMSConnectionFactory");
+ dcf = (ConnectionFactory) namingctx.lookup("java:comp/DefaultJMSConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:global/EJBMyTestConnectionFactory");
+ cf = (ConnectionFactory) namingctx.lookup("java:global/EJBMyTestConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:app/EJBMyTestQueueConnectionFactory");
+ qcf = (QueueConnectionFactory) namingctx.lookup("java:app/EJBMyTestQueueConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:module/EJBMyTestTopicConnectionFactory");
+ tcf = (TopicConnectionFactory) namingctx.lookup("java:module/EJBMyTestTopicConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:comp/env/jms/EJBMyTestDurableTopicConnectionFactory");
+ dtcf = (TopicConnectionFactory) namingctx
+ .lookup("java:comp/env/jms/EJBMyTestDurableTopicConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:global/env/EJBMyTestQueue");
+ queue = (Queue) namingctx.lookup("java:global/env/EJBMyTestQueue");
+ logger.log(Logger.Level.INFO, "Lookup java:app/env/EJBMyTestTopic");
+ topic = (Topic) namingctx.lookup("java:app/env/EJBMyTestTopic");
+
+ logger.log(Logger.Level.INFO, "Create JMSContext, JMSProducer's and JMSConsumer's");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ producerQ = context.createProducer();
+ consumerQ = context.createConsumer(queue);
+ producerT = context.createProducer();
+ consumerT = context.createConsumer(topic);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw e;
+ }
+ }
+
+ public boolean sendAndRecvQueueTestFromEjbClient() {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ queueTest = true;
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage via JMSContext.createTextMessage(String)");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvQueueTestFromEjbClient");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producerQ.send(queue, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage via JMSconsumer.receive(long)");
+ TextMessage actTextMessage = (TextMessage) consumerQ.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+
+ return pass;
+ }
+
+ public boolean sendAndRecvTopicTestFromEjbClient() {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ queueTest = false;
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage via JMSContext.createTextMessage(String)");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvTopicTestFromEjbClient");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producerT.send(topic, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage via JMSconsumer.receive(long)");
+ TextMessage actTextMessage = (TextMessage) consumerT.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+ return pass;
+ }
+
+ public boolean checkClientIDTestFromEjbClient() {
+ boolean pass = true;
+ JMSContext context = null;
+ try {
+ queueTest = false;
+ doLookupJMSObjects();
+ logger.log(Logger.Level.INFO, "Create JMSContext from durable topic connection factory");
+ logger.log(Logger.Level.INFO, "Check the client id which is configured as MyClientID in the "
+ + "JMSConnectionFactoryDefinition annotation");
+ context = dtcf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ String clientid = context.getClientID();
+ if (clientid == null) {
+ logger.log(Logger.Level.ERROR, "Client ID value is null (expected MyClientID)");
+ pass = false;
+ } else if (clientid.equals("MyClientID")) {
+ logger.log(Logger.Level.INFO, "Client ID value is correct (MyClientID)");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Client ID value is incorrect (expected MyClientID, got " + clientid + ")");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ }
+ }
+ return pass;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/EjbClientIF.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/EjbClientIF.java
index 4f188361e6..f521ac200a 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/EjbClientIF.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/EjbClientIF.java
@@ -18,7 +18,7 @@
public interface EjbClientIF {
- public void init(java.util.Properties p);
+ public void init(java.util.Properties p);
- public boolean echo(String testName);
+ public boolean echo(String testName);
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/MyBean.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/MyBean.java
index e13b3400d4..7ec86f392c 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/MyBean.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/MyBean.java
@@ -18,68 +18,28 @@
package com.sun.ts.tests.jms.ee20.resourcedefs.annotations;
import jakarta.jms.JMSConnectionFactoryDefinition;
-import jakarta.jms.JMSConnectionFactoryDefinitions;
import jakarta.jms.JMSDestinationDefinition;
-import jakarta.jms.JMSDestinationDefinitions;
//-------------------------------------
// JMS Destination Resource Definitions
//-------------------------------------
-@JMSDestinationDefinition(
- description="Define Queue JSPMyTestQueue",
- interfaceName="jakarta.jms.Queue",
- name="java:global/env/JSPMyTestQueue",
- destinationName="JSPMyTestQueue"
- )
+@JMSDestinationDefinition(description = "Define Queue JSPMyTestQueue", interfaceName = "jakarta.jms.Queue", name = "java:global/env/JSPMyTestQueue", destinationName = "JSPMyTestQueue")
-@JMSDestinationDefinition(
- description="Define Topic JSPMyTestTopic",
- interfaceName="jakarta.jms.Topic",
- name="java:app/env/JSPMyTestTopic",
- destinationName="JSPMyTestTopic"
- )
+@JMSDestinationDefinition(description = "Define Topic JSPMyTestTopic", interfaceName = "jakarta.jms.Topic", name = "java:app/env/JSPMyTestTopic", destinationName = "JSPMyTestTopic")
//-------------------------------------------
// JMS ConnectionFactory Resource Definitions
//-------------------------------------------
-@JMSConnectionFactoryDefinition(
- description="Define ConnectionFactory JSPMyTestConnectionFactory",
- interfaceName="jakarta.jms.ConnectionFactory",
- name="java:global/JSPMyTestConnectionFactory",
- user = "j2ee",
- password = "j2ee"
- )
+@JMSConnectionFactoryDefinition(description = "Define ConnectionFactory JSPMyTestConnectionFactory", interfaceName = "jakarta.jms.ConnectionFactory", name = "java:global/JSPMyTestConnectionFactory", user = "j2ee", password = "j2ee")
-@JMSConnectionFactoryDefinition(
- description="Define QueueConnectionFactory JSPMyTestQueueConnectionFactory",
- interfaceName="jakarta.jms.QueueConnectionFactory",
- name="java:app/JSPMyTestQueueConnectionFactory",
- user = "j2ee",
- password = "j2ee"
- )
+@JMSConnectionFactoryDefinition(description = "Define QueueConnectionFactory JSPMyTestQueueConnectionFactory", interfaceName = "jakarta.jms.QueueConnectionFactory", name = "java:app/JSPMyTestQueueConnectionFactory", user = "j2ee", password = "j2ee")
-@JMSConnectionFactoryDefinition(
- description="Define TopicConnectionFactory JSPMyTestTopicConnectionFactory",
- interfaceName="jakarta.jms.TopicConnectionFactory",
- name="java:module/JSPMyTestTopicConnectionFactory",
- user = "j2ee",
- password = "j2ee"
- )
+@JMSConnectionFactoryDefinition(description = "Define TopicConnectionFactory JSPMyTestTopicConnectionFactory", interfaceName = "jakarta.jms.TopicConnectionFactory", name = "java:module/JSPMyTestTopicConnectionFactory", user = "j2ee", password = "j2ee")
-@JMSConnectionFactoryDefinition(
- description="Define Durable TopicConnectionFactory JSPMyTestDurableTopicConnectionFactory",
- interfaceName="jakarta.jms.TopicConnectionFactory",
- name="java:comp/env/jms/JSPMyTestDurableTopicConnectionFactory",
- user = "j2ee",
- password = "j2ee",
- clientId = "MyClientID",
- properties = { "Property1=10", "Property2=20" },
- transactional = false,
- maxPoolSize = 30,
- minPoolSize = 20
- )
+@JMSConnectionFactoryDefinition(description = "Define Durable TopicConnectionFactory JSPMyTestDurableTopicConnectionFactory", interfaceName = "jakarta.jms.TopicConnectionFactory", name = "java:comp/env/jms/JSPMyTestDurableTopicConnectionFactory", user = "j2ee", password = "j2ee", clientId = "MyClientID", properties = {
+ "Property1=10", "Property2=20" }, transactional = false, maxPoolSize = 30, minPoolSize = 20)
public class MyBean {
- public MyBean() {
- }
+ public MyBean() {
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/ServletClient.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/ServletClient.java
index 4d6d652cb4..b07ed711b4 100644
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/ServletClient.java
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/annotations/ServletClient.java
@@ -19,6 +19,7 @@
import java.io.IOException;
import java.io.PrintWriter;
+import java.lang.System.Logger;
import java.util.Enumeration;
import java.util.Properties;
@@ -27,11 +28,9 @@
import jakarta.jms.ConnectionFactory;
import jakarta.jms.JMSConnectionFactoryDefinition;
-import jakarta.jms.JMSConnectionFactoryDefinitions;
import jakarta.jms.JMSConsumer;
import jakarta.jms.JMSContext;
import jakarta.jms.JMSDestinationDefinition;
-import jakarta.jms.JMSDestinationDefinitions;
import jakarta.jms.JMSProducer;
import jakarta.jms.Message;
import jakarta.jms.Queue;
@@ -49,375 +48,318 @@
//-------------------------------------
// JMS Destination Resource Definitions
//-------------------------------------
-@JMSDestinationDefinition(
- description="Define Queue ServletMyTestQueue",
- interfaceName="jakarta.jms.Queue",
- name="java:global/env/ServletMyTestQueue",
- destinationName="ServletMyTestQueue"
- )
-
-@JMSDestinationDefinition(
- description="Define Topic ServletMyTestTopic",
- interfaceName="jakarta.jms.Topic",
- name="java:app/env/ServletMyTestTopic",
- destinationName="ServletMyTestTopic"
- )
+@JMSDestinationDefinition(description = "Define Queue ServletMyTestQueue", interfaceName = "jakarta.jms.Queue", name = "java:global/env/ServletMyTestQueue", destinationName = "ServletMyTestQueue")
+
+@JMSDestinationDefinition(description = "Define Topic ServletMyTestTopic", interfaceName = "jakarta.jms.Topic", name = "java:app/env/ServletMyTestTopic", destinationName = "ServletMyTestTopic")
//-------------------------------------------
// JMS ConnectionFactory Resource Definitions
//-------------------------------------------
-@JMSConnectionFactoryDefinition(
- description="Define ConnectionFactory ServletMyTestConnectionFactory",
- interfaceName="jakarta.jms.ConnectionFactory",
- name="java:global/ServletMyTestConnectionFactory",
- user = "j2ee",
- password = "j2ee"
- )
-
-@JMSConnectionFactoryDefinition(
- description="Define QueueConnectionFactory ServletMyTestQueueConnectionFactory",
- interfaceName="jakarta.jms.QueueConnectionFactory",
- name="java:app/ServletMyTestQueueConnectionFactory",
- user = "j2ee",
- password = "j2ee"
- )
-
-@JMSConnectionFactoryDefinition(
- description="Define TopicConnectionFactory ServletMyTestTopicConnectionFactory",
- interfaceName="jakarta.jms.TopicConnectionFactory",
- name="java:module/ServletMyTestTopicConnectionFactory",
- user = "j2ee",
- password = "j2ee"
- )
-
-@JMSConnectionFactoryDefinition(
- description="Define Durable TopicConnectionFactory ServletMyTestDurableTopicConnectionFactory",
- interfaceName="jakarta.jms.TopicConnectionFactory",
- name="java:comp/env/jms/ServletMyTestDurableTopicConnectionFactory",
- user = "j2ee",
- password = "j2ee",
- clientId = "MyClientID",
- properties = { "Property1=10", "Property2=20" },
- transactional = false,
- maxPoolSize = 30,
- minPoolSize = 20
- )
+@JMSConnectionFactoryDefinition(description = "Define ConnectionFactory ServletMyTestConnectionFactory", interfaceName = "jakarta.jms.ConnectionFactory", name = "java:global/ServletMyTestConnectionFactory", user = "j2ee", password = "j2ee")
+
+@JMSConnectionFactoryDefinition(description = "Define QueueConnectionFactory ServletMyTestQueueConnectionFactory", interfaceName = "jakarta.jms.QueueConnectionFactory", name = "java:app/ServletMyTestQueueConnectionFactory", user = "j2ee", password = "j2ee")
+
+@JMSConnectionFactoryDefinition(description = "Define TopicConnectionFactory ServletMyTestTopicConnectionFactory", interfaceName = "jakarta.jms.TopicConnectionFactory", name = "java:module/ServletMyTestTopicConnectionFactory", user = "j2ee", password = "j2ee")
+
+@JMSConnectionFactoryDefinition(description = "Define Durable TopicConnectionFactory ServletMyTestDurableTopicConnectionFactory", interfaceName = "jakarta.jms.TopicConnectionFactory", name = "java:comp/env/jms/ServletMyTestDurableTopicConnectionFactory", user = "j2ee", password = "j2ee", clientId = "MyClientID", properties = {
+ "Property1=10", "Property2=20" }, transactional = false, maxPoolSize = 30, minPoolSize = 20)
@WebServlet("/ServletTest")
public class ServletClient extends HttpServlet {
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- protected transient ConnectionFactory cf = null;
-
- protected transient ConnectionFactory dcf = null;
-
- protected transient ConnectionFactory cfra = null;
-
- protected transient QueueConnectionFactory qcf = null;
-
- protected transient TopicConnectionFactory tcf = null;
-
- protected transient TopicConnectionFactory dtcf = null;
-
- protected transient Topic topic = null;
-
- protected transient Topic topica = null;
-
- protected transient Queue queue = null;
-
- protected transient JMSContext context = null;
-
- protected transient JMSConsumer consumerQ = null;
-
- protected transient JMSProducer producerQ = null;
-
- protected transient JMSConsumer consumerT = null;
-
- protected transient JMSProducer producerT = null;
-
- protected boolean queueTest = false;
-
- // Harness req's
- protected Properties harnessProps = null;
-
- // properties read from ts.jte file
- protected long timeout;
-
- protected String user;
-
- protected String password;
-
- protected String mode;
-
- /*
- * doCleanup()
- */
- private void doCleanup() throws Exception {
- try {
- if (queueTest && consumerQ != null) {
- TestUtil.logMsg("Flush any messages left on Queue");
- Message rmsg = consumerQ.receive(timeout);
- while (rmsg != null) {
- rmsg = consumerQ.receiveNoWait();
- if (rmsg == null) {
- rmsg = consumerQ.receiveNoWait();
- }
- }
- consumerQ.close();
- }
- if (consumerT != null)
- consumerT.close();
- TestUtil.logMsg("Close JMSContext Objects");
- if (context != null)
- context.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("doCleanup failed!", e);
- }
- }
-
- public void init(ServletConfig config) throws ServletException {
- super.init(config);
- }
-
- public void doGet(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, IOException {
- boolean pass = true;
- Properties p = new Properties();
- res.setContentType("text/plain");
- PrintWriter out = res.getWriter();
-
- try {
- String test = harnessProps.getProperty("TEST");
- System.out.println("doGet: test to execute is: " + test);
- if (test.equals("sendAndRecvQueueTestFromServletClient")) {
- if (sendAndRecvQueueTestFromServletClient())
- p.setProperty("TESTRESULT", "pass");
- else
- p.setProperty("TESTRESULT", "fail");
- } else if (test.equals("sendAndRecvTopicTestFromServletClient")) {
- if (sendAndRecvTopicTestFromServletClient())
- p.setProperty("TESTRESULT", "pass");
- else
- p.setProperty("TESTRESULT", "fail");
- } else if (test.equals("checkClientIDTestFromServletClient")) {
- if (checkClientIDTestFromServletClient())
- p.setProperty("TESTRESULT", "pass");
- else
- p.setProperty("TESTRESULT", "fail");
- } else {
- p.setProperty("TESTRESULT", "fail");
- }
- doCleanup();
- p.list(out);
- } catch (Exception e) {
- TestUtil.logErr("doGet: Exception: " + e);
- System.out.println("doGet: Exception: " + e);
- p.setProperty("TESTRESULT", "fail");
- p.list(out);
- }
- out.close();
- }
-
- public void doPost(HttpServletRequest req, HttpServletResponse res)
- throws ServletException, IOException {
- harnessProps = new Properties();
- Enumeration enumlist = req.getParameterNames();
- while (enumlist.hasMoreElements()) {
- String name = (String) enumlist.nextElement();
- String value = req.getParameter(name);
- harnessProps.setProperty(name, value);
- }
-
- try {
- TestUtil.init(harnessProps);
- // get props
- timeout = Long.parseLong(harnessProps.getProperty("jms_timeout"));
- user = harnessProps.getProperty("user");
- password = harnessProps.getProperty("password");
- mode = harnessProps.getProperty("platform.mode");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
- doLookupJMSObjects();
- } catch (Exception e) {
- System.out.println("doPost: Exception: " + e);
- e.printStackTrace();
- throw new ServletException("unable to initialize remote logging");
- }
- doGet(req, res);
- harnessProps = null;
- }
-
- /*
- * Lookup JMS Connection Factory and Destination Objects
- */
- private void doLookupJMSObjects() throws Exception {
- try {
- TestUtil.logMsg(
- "Lookup JMS factories defined by @JMSConnectionFactoryDefinitions");
- TestUtil.logMsg(
- "Lookup JMS destinations defined by @JMSDestinationDefinitions");
- TSNamingContext namingctx = new TSNamingContext();
- TestUtil.logMsg("Lookup java:comp/DefaultJMSConnectionFactory");
- dcf = (ConnectionFactory) namingctx
- .lookup("java:comp/DefaultJMSConnectionFactory");
- TestUtil.logMsg("Lookup java:global/ServletMyTestConnectionFactory");
- cf = (ConnectionFactory) namingctx
- .lookup("java:global/ServletMyTestConnectionFactory");
- TestUtil.logMsg("Lookup java:app/ServletMyTestQueueConnectionFactory");
- qcf = (QueueConnectionFactory) namingctx
- .lookup("java:app/ServletMyTestQueueConnectionFactory");
- TestUtil.logMsg("Lookup java:module/ServletMyTestTopicConnectionFactory");
- tcf = (TopicConnectionFactory) namingctx
- .lookup("java:module/ServletMyTestTopicConnectionFactory");
- TestUtil.logMsg(
- "Lookup java:comp/env/jms/ServletMyTestDurableTopicConnectionFactory");
- dtcf = (TopicConnectionFactory) namingctx.lookup(
- "java:comp/env/jms/ServletMyTestDurableTopicConnectionFactory");
- TestUtil.logMsg("Lookup java:global/env/ServletMyTestQueue");
- queue = (Queue) namingctx.lookup("java:global/env/ServletMyTestQueue");
- TestUtil.logMsg("Lookup java:app/env/ServletMyTestTopic");
- topic = (Topic) namingctx.lookup("java:app/env/ServletMyTestTopic");
-
- TestUtil.logMsg("Create JMSContext, JMSProducer's and JMSConsumer's");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- producerQ = context.createProducer();
- consumerQ = context.createConsumer(queue);
- producerT = context.createProducer();
- consumerT = context.createConsumer(topic);
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw e;
- }
- }
-
- public boolean sendAndRecvQueueTestFromServletClient() {
- boolean pass = true;
- String message = "Where are you!";
- try {
- queueTest = true;
- // send and receive TextMessage
- TestUtil.logMsg(
- "Creating TextMessage via JMSContext.createTextMessage(String)");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvQueueTestFromServletClient");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producerQ.send(queue, expTextMessage);
- TestUtil.logMsg("Receive TextMessage via JMSconsumer.receive(long)");
- TextMessage actTextMessage = (TextMessage) consumerQ.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
-
- return pass;
- }
-
- public boolean sendAndRecvTopicTestFromServletClient() {
- boolean pass = true;
- String message = "Where are you!";
- try {
- queueTest = false;
- // send and receive TextMessage
- TestUtil.logMsg(
- "Creating TextMessage via JMSContext.createTextMessage(String)");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvTopicTestFromServletClient");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producerT.send(topic, expTextMessage);
- TestUtil.logMsg("Receive TextMessage via JMSconsumer.receive(long)");
- TextMessage actTextMessage = (TextMessage) consumerT.receive(timeout);
- if (actTextMessage == null) {
- TestUtil.logErr("Did not receive TextMessage");
- pass = false;
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- }
- return pass;
- }
-
- public boolean checkClientIDTestFromServletClient() {
- boolean pass = true;
- JMSContext context = null;
- try {
- queueTest = false;
- TestUtil
- .logMsg("Create JMSContext from durable topic connection factory");
- TestUtil.logMsg(
- "Check the client id which is configured as MyClientID in the "
- + "JMSConnectionFactoryDefinition annotation");
- context = dtcf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- String clientid = context.getClientID();
- if (clientid == null) {
- TestUtil.logErr("Client ID value is null (expected MyClientID)");
- pass = false;
- } else if (clientid.equals("MyClientID")) {
- TestUtil.logMsg("Client ID value is correct (MyClientID)");
- } else {
- TestUtil
- .logErr("Client ID value is incorrect (expected MyClientID, got "
- + clientid + ")");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- pass = false;
- } finally {
- try {
- if (context != null)
- context.close();
- doCleanup();
- } catch (Exception e) {
- TestUtil.logErr("Error in cleanup " + e);
- }
- }
- return pass;
- }
+ private static final long serialVersionUID = 1L;
+
+ // JMS objects
+ protected transient ConnectionFactory cf = null;
+
+ protected transient ConnectionFactory dcf = null;
+
+ protected transient ConnectionFactory cfra = null;
+
+ protected transient QueueConnectionFactory qcf = null;
+
+ protected transient TopicConnectionFactory tcf = null;
+
+ protected transient TopicConnectionFactory dtcf = null;
+
+ protected transient Topic topic = null;
+
+ protected transient Topic topica = null;
+
+ protected transient Queue queue = null;
+
+ protected transient JMSContext context = null;
+
+ protected transient JMSConsumer consumerQ = null;
+
+ protected transient JMSProducer producerQ = null;
+
+ protected transient JMSConsumer consumerT = null;
+
+ protected transient JMSProducer producerT = null;
+
+ protected boolean queueTest = false;
+
+ // Harness req's
+ protected Properties harnessProps = null;
+
+ // properties read
+ protected long timeout;
+
+ protected String user;
+
+ protected String password;
+
+ protected String mode;
+
+ private static final Logger logger = (Logger) System.getLogger(ServletClient.class.getName());
+
+ /*
+ * doCleanup()
+ */
+ private void doCleanup() throws Exception {
+ try {
+ if (queueTest && consumerQ != null) {
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ Message rmsg = consumerQ.receive(timeout);
+ while (rmsg != null) {
+ rmsg = consumerQ.receiveNoWait();
+ if (rmsg == null) {
+ rmsg = consumerQ.receiveNoWait();
+ }
+ }
+ consumerQ.close();
+ }
+ if (consumerT != null)
+ consumerT.close();
+ logger.log(Logger.Level.INFO, "Close JMSContext Objects");
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("doCleanup failed!", e);
+ }
+ }
+
+ public void init(ServletConfig config) throws ServletException {
+ super.init(config);
+ }
+
+ public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+ boolean pass = true;
+ Properties p = new Properties();
+ res.setContentType("text/plain");
+ PrintWriter out = res.getWriter();
+
+ try {
+ String test = System.getProperty("TEST");
+ System.out.println("doGet: test to execute is: " + test);
+ if (test.equals("sendAndRecvQueueTestFromServletClient")) {
+ if (sendAndRecvQueueTestFromServletClient())
+ p.setProperty("TESTRESULT", "pass");
+ else
+ p.setProperty("TESTRESULT", "fail");
+ } else if (test.equals("sendAndRecvTopicTestFromServletClient")) {
+ if (sendAndRecvTopicTestFromServletClient())
+ p.setProperty("TESTRESULT", "pass");
+ else
+ p.setProperty("TESTRESULT", "fail");
+ } else if (test.equals("checkClientIDTestFromServletClient")) {
+ if (checkClientIDTestFromServletClient())
+ p.setProperty("TESTRESULT", "pass");
+ else
+ p.setProperty("TESTRESULT", "fail");
+ } else {
+ p.setProperty("TESTRESULT", "fail");
+ }
+ doCleanup();
+ p.list(out);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "doGet: Exception: " + e);
+ System.out.println("doGet: Exception: " + e);
+ p.setProperty("TESTRESULT", "fail");
+ p.list(out);
+ }
+ out.close();
+ }
+
+ public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
+ harnessProps = new Properties();
+ Enumeration enumlist = req.getParameterNames();
+ while (enumlist.hasMoreElements()) {
+ String name = (String) enumlist.nextElement();
+ String value = req.getParameter(name);
+ harnessProps.setProperty(name, value);
+ }
+
+ try {
+ TestUtil.init(harnessProps);
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+ doLookupJMSObjects();
+ } catch (Exception e) {
+ System.out.println("doPost: Exception: " + e);
+ e.printStackTrace();
+ throw new ServletException("unable to initialize remote logging");
+ }
+ doGet(req, res);
+ harnessProps = null;
+ }
+
+ /*
+ * Lookup JMS Connection Factory and Destination Objects
+ */
+ private void doLookupJMSObjects() throws Exception {
+ try {
+ logger.log(Logger.Level.INFO, "Lookup JMS factories defined by @JMSConnectionFactoryDefinitions");
+ logger.log(Logger.Level.INFO, "Lookup JMS destinations defined by @JMSDestinationDefinitions");
+ TSNamingContext namingctx = new TSNamingContext();
+ logger.log(Logger.Level.INFO, "Lookup java:comp/DefaultJMSConnectionFactory");
+ dcf = (ConnectionFactory) namingctx.lookup("java:comp/DefaultJMSConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:global/ServletMyTestConnectionFactory");
+ cf = (ConnectionFactory) namingctx.lookup("java:global/ServletMyTestConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:app/ServletMyTestQueueConnectionFactory");
+ qcf = (QueueConnectionFactory) namingctx.lookup("java:app/ServletMyTestQueueConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:module/ServletMyTestTopicConnectionFactory");
+ tcf = (TopicConnectionFactory) namingctx.lookup("java:module/ServletMyTestTopicConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:comp/env/jms/ServletMyTestDurableTopicConnectionFactory");
+ dtcf = (TopicConnectionFactory) namingctx
+ .lookup("java:comp/env/jms/ServletMyTestDurableTopicConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:global/env/ServletMyTestQueue");
+ queue = (Queue) namingctx.lookup("java:global/env/ServletMyTestQueue");
+ logger.log(Logger.Level.INFO, "Lookup java:app/env/ServletMyTestTopic");
+ topic = (Topic) namingctx.lookup("java:app/env/ServletMyTestTopic");
+
+ logger.log(Logger.Level.INFO, "Create JMSContext, JMSProducer's and JMSConsumer's");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ producerQ = context.createProducer();
+ consumerQ = context.createConsumer(queue);
+ producerT = context.createProducer();
+ consumerT = context.createConsumer(topic);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw e;
+ }
+ }
+
+ public boolean sendAndRecvQueueTestFromServletClient() {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ queueTest = true;
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage via JMSContext.createTextMessage(String)");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvQueueTestFromServletClient");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producerQ.send(queue, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage via JMSconsumer.receive(long)");
+ TextMessage actTextMessage = (TextMessage) consumerQ.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+
+ return pass;
+ }
+
+ public boolean sendAndRecvTopicTestFromServletClient() {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ queueTest = false;
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage via JMSContext.createTextMessage(String)");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvTopicTestFromServletClient");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producerT.send(topic, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage via JMSconsumer.receive(long)");
+ TextMessage actTextMessage = (TextMessage) consumerT.receive(timeout);
+ if (actTextMessage == null) {
+ logger.log(Logger.Level.ERROR, "Did not receive TextMessage");
+ pass = false;
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ }
+ return pass;
+ }
+
+ public boolean checkClientIDTestFromServletClient() {
+ boolean pass = true;
+ JMSContext context = null;
+ try {
+ queueTest = false;
+ logger.log(Logger.Level.INFO, "Create JMSContext from durable topic connection factory");
+ logger.log(Logger.Level.INFO, "Check the client id which is configured as MyClientID in the "
+ + "JMSConnectionFactoryDefinition annotation");
+ context = dtcf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ String clientid = context.getClientID();
+ if (clientid == null) {
+ logger.log(Logger.Level.ERROR, "Client ID value is null (expected MyClientID)");
+ pass = false;
+ } else if (clientid.equals("MyClientID")) {
+ logger.log(Logger.Level.INFO, "Client ID value is correct (MyClientID)");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Client ID value is incorrect (expected MyClientID, got " + clientid + ")");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ pass = false;
+ } finally {
+ try {
+ if (context != null)
+ context.close();
+ doCleanup();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Error in cleanup " + e);
+ }
+ }
+ return pass;
+ }
}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/descriptor/Client.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/descriptor/Client.java
deleted file mode 100644
index 46bfbdc9c0..0000000000
--- a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/descriptor/Client.java
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
- * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v. 2.0, which is available at
- * http://www.eclipse.org/legal/epl-2.0.
- *
- * This Source Code may also be made available under the following Secondary
- * Licenses when the conditions for such availability set forth in the
- * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
- * version 2 with the GNU Classpath Exception, which is available at
- * https://www.gnu.org/software/classpath/license.html.
- *
- * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
- */
-
-/*
- * $Id$
- */
-package com.sun.ts.tests.jms.ee20.resourcedefs.descriptor;
-
-import java.util.Properties;
-
-import com.sun.javatest.Status;
-import com.sun.ts.lib.harness.ServiceEETest;
-import com.sun.ts.lib.util.TSNamingContext;
-import com.sun.ts.lib.util.TestUtil;
-
-import jakarta.jms.ConnectionFactory;
-import jakarta.jms.JMSConsumer;
-import jakarta.jms.JMSContext;
-import jakarta.jms.JMSProducer;
-import jakarta.jms.Message;
-import jakarta.jms.Queue;
-import jakarta.jms.QueueConnectionFactory;
-import jakarta.jms.TextMessage;
-import jakarta.jms.Topic;
-import jakarta.jms.TopicConnectionFactory;
-
-public class Client extends ServiceEETest {
- private static final String testName = "com.sun.ts.tests.jms.ee20.resourcedefs.descriptor.Client";
-
- private static final String testDir = System.getProperty("user.dir");
-
- private static final long serialVersionUID = 1L;
-
- // JMS objects
- private transient ConnectionFactory cf = null;
-
- private transient ConnectionFactory cfra = null;
-
- private transient QueueConnectionFactory qcf = null;
-
- private transient TopicConnectionFactory tcf = null;
-
- private transient TopicConnectionFactory dtcf = null;
-
- private transient Topic topic = null;
-
- private transient Topic topica = null;
-
- private transient Queue queue = null;
-
- private transient JMSContext context = null;
-
- private transient JMSConsumer consumerQ = null;
-
- private transient JMSProducer producerQ = null;
-
- private transient JMSConsumer consumerT = null;
-
- private transient JMSProducer producerT = null;
-
- private boolean queueTest = false;
-
- // Harness req's
- private Properties props = null;
-
- // properties read from ts.jte file
- long timeout;
-
- String user;
-
- String password;
-
- String mode;
-
- String vehicle;
-
- /* Run test in standalone mode */
-
- /**
- * Main method is used when not run from the JavaTest GUI.
- *
- * @param args
- */
- public static void main(String[] args) {
- Client theTests = new Client();
- Status s = theTests.run(args, System.out, System.err);
- s.exit();
- }
-
- /* Test setup: */
-
- /*
- * setup() is called before each test
- *
- * @class.setup_props: jms_timeout; user; password; platform.mode;
- *
- * @exception Fault
- */
- public void setup(String[] args, Properties p) throws Exception {
- try {
- // get props
- timeout = Long.parseLong(p.getProperty("jms_timeout"));
- user = p.getProperty("user");
- password = p.getProperty("password");
- mode = p.getProperty("platform.mode");
- vehicle = p.getProperty("vehicle");
-
- // check props for errors
- if (timeout < 1) {
- throw new Exception(
- "'jms_timeout' (milliseconds) in ts.jte must be > 0");
- }
- if (user == null) {
- throw new Exception("'user' in ts.jte must not be null ");
- }
- if (password == null) {
- throw new Exception("'password' in ts.jte must not be null ");
- }
- if (mode == null) {
- throw new Exception("'platform.mode' in ts.jte must not be null");
- }
-
- TestUtil.logMsg("Lookup JMS factories defined in Deployment Descriptors");
- TestUtil
- .logMsg("Lookup JMS destinations defined in Deployment Descriptors");
- TestUtil.logMsg(
- "See and tags in DD's");
- TSNamingContext namingctx = new TSNamingContext();
- String prefix = null;
- if (vehicle.equals("appclient"))
- prefix = "AppClient";
- else if (vehicle.equals("ejb"))
- prefix = "EJB";
- else if (vehicle.equals("servlet"))
- prefix = "Servlet";
- else if (vehicle.equals("jsp"))
- prefix = "JSP";
- TestUtil
- .logMsg("Lookup java:global/" + prefix + "MyTestConnectionFactory");
- cf = (ConnectionFactory) namingctx
- .lookup("java:global/" + prefix + "MyTestConnectionFactory");
- TestUtil
- .logMsg("Lookup java:app/" + prefix + "MyTestQueueConnectionFactory");
- qcf = (QueueConnectionFactory) namingctx
- .lookup("java:app/" + prefix + "MyTestQueueConnectionFactory");
- TestUtil.logMsg(
- "Lookup java:module/" + prefix + "MyTestTopicConnectionFactory");
- tcf = (TopicConnectionFactory) namingctx
- .lookup("java:module/" + prefix + "MyTestTopicConnectionFactory");
- TestUtil.logMsg("Lookup java:comp/env/jms/" + prefix
- + "MyTestDurableTopicConnectionFactory");
- dtcf = (TopicConnectionFactory) namingctx.lookup("java:comp/env/jms/"
- + prefix + "MyTestDurableTopicConnectionFactory");
- TestUtil.logMsg("Lookup java:global/env/" + prefix + "MyTestQueue");
- queue = (Queue) namingctx
- .lookup("java:global/env/" + prefix + "MyTestQueue");
- TestUtil.logMsg("Lookup java:app/env/" + prefix + "MyTestTopic");
- topic = (Topic) namingctx
- .lookup("java:app/env/" + prefix + "MyTestTopic");
-
- TestUtil.logMsg("Create JMSContext, JMSProducer's and JMSConsumer's");
- context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- producerQ = context.createProducer();
- consumerQ = context.createConsumer(queue);
- producerT = context.createProducer();
- consumerT = context.createConsumer(topic);
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("setup failed!", e);
- }
- }
-
- /* cleanup */
-
- /*
- * cleanup() is called after each test
- *
- * @exception Fault
- */
- public void cleanup() throws Exception {
- try {
- if (queueTest && consumerQ != null) {
- TestUtil.logMsg("Flush any messages left on Queue");
- Message rmsg = consumerQ.receive(timeout);
- while (rmsg != null) {
- rmsg = consumerQ.receiveNoWait();
- if (rmsg == null) {
- rmsg = consumerQ.receiveNoWait();
- }
- }
- consumerQ.close();
- }
- if (consumerT != null)
- consumerT.close();
- TestUtil.logMsg("Close JMSContext Objects");
- if (context != null)
- context.close();
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("cleanup failed!", e);
- }
- }
-
- /*
- * @testName: sendAndRecvQueueTest
- *
- * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
- * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
- * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
- * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
- * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
- * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
- *
- * @test_Strategy: Send and receive a message to/from a Queue.
- *
- */
- public void sendAndRecvQueueTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- queueTest = true;
- // send and receive TextMessage
- TestUtil.logMsg(
- "Creating TextMessage via JMSContext.createTextMessage(String)");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvQueueTest");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producerQ.send(queue, expTextMessage);
- TestUtil.logMsg("Receive TextMessage via JMSconsumer.receive(long)");
- TextMessage actTextMessage = (TextMessage) consumerQ.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("sendAndRecvQueueTest", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvQueueTest failed");
- }
- }
-
- /*
- * @testName: sendAndRecvTopicTest
- *
- * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
- * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
- * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
- * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
- * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
- * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
- *
- * @test_Strategy: Send and receive a message to/from a Topic.
- *
- */
- public void sendAndRecvTopicTest() throws Exception {
- boolean pass = true;
- String message = "Where are you!";
- try {
- queueTest = false;
- // send and receive TextMessage
- TestUtil.logMsg(
- "Creating TextMessage via JMSContext.createTextMessage(String)");
- TextMessage expTextMessage = context.createTextMessage(message);
- TestUtil.logMsg("Set some values in TextMessage");
- expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME",
- "sendAndRecvTopicTest");
- TestUtil.logMsg(
- "Sending TextMessage via JMSProducer.send(Destination, Message)");
- producerT.send(topic, expTextMessage);
- TestUtil.logMsg("Receive TextMessage via JMSconsumer.receive(long)");
- TextMessage actTextMessage = (TextMessage) consumerT.receive(timeout);
- if (actTextMessage == null) {
- throw new Exception("Did not receive TextMessage");
- } else {
- TestUtil.logMsg("Check the value in TextMessage");
- if (actTextMessage.getText().equals(expTextMessage.getText())) {
- TestUtil.logMsg("TextMessage is correct");
- } else {
- TestUtil.logErr(
- "TextMessage is incorrect expected " + expTextMessage.getText()
- + ", received " + actTextMessage.getText());
- pass = false;
- }
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("sendAndRecvTopicTest", e);
- }
-
- if (!pass) {
- throw new Exception("sendAndRecvTopicTest failed");
- }
- }
-
- /*
- * @testName: checkClientIDOnDurableConnFactoryTest
- *
- * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
- * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
- * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
- * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
- * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
- * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
- *
- * @test_Strategy: Check client id setting on durable connection factory
- *
- */
- public void checkClientIDOnDurableConnFactoryTest() throws Exception {
- boolean pass = true;
- JMSContext context = null;
- try {
- queueTest = false;
- TestUtil
- .logMsg("Create JMSContext from durable topic connection factory");
- TestUtil.logMsg(
- "Check the client id which is configured as MyClientID in the deployment descriptors");
- context = dtcf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
- String clientid = context.getClientID();
- if (clientid == null) {
- TestUtil.logErr("Client ID value is null (expected MyClientID)");
- pass = false;
- } else if (clientid.equals("MyClientID")) {
- TestUtil.logMsg("Client ID value is correct (MyClientID)");
- } else {
- TestUtil
- .logErr("Client ID value is incorrect (expected MyClientID, got "
- + clientid + ")");
- pass = false;
- }
- } catch (Exception e) {
- TestUtil.logErr("Caught exception: " + e);
- throw new Exception("checkClientIDOnDurableConnFactoryTest", e);
- } finally {
- try {
- if (context != null)
- context.close();
- } catch (Exception e) {
- }
- }
-
- if (!pass) {
- throw new Exception("checkClientIDOnDurableConnFactoryTest failed");
- }
- }
-
-}
diff --git a/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/descriptor/ClientIT.java b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/descriptor/ClientIT.java
new file mode 100644
index 0000000000..5ff72808d8
--- /dev/null
+++ b/jms/src/main/java/com/sun/ts/tests/jms/ee20/resourcedefs/descriptor/ClientIT.java
@@ -0,0 +1,349 @@
+/*
+ * Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v. 2.0, which is available at
+ * http://www.eclipse.org/legal/epl-2.0.
+ *
+ * This Source Code may also be made available under the following Secondary
+ * Licenses when the conditions for such availability set forth in the
+ * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
+ * version 2 with the GNU Classpath Exception, which is available at
+ * https://www.gnu.org/software/classpath/license.html.
+ *
+ * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
+ */
+
+/*
+ * $Id$
+ */
+package com.sun.ts.tests.jms.ee20.resourcedefs.descriptor;
+
+import java.lang.System.Logger;
+import java.util.Properties;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import com.sun.ts.lib.util.TSNamingContext;
+
+import jakarta.jms.ConnectionFactory;
+import jakarta.jms.JMSConsumer;
+import jakarta.jms.JMSContext;
+import jakarta.jms.JMSProducer;
+import jakarta.jms.Message;
+import jakarta.jms.Queue;
+import jakarta.jms.QueueConnectionFactory;
+import jakarta.jms.TextMessage;
+import jakarta.jms.Topic;
+import jakarta.jms.TopicConnectionFactory;
+
+
+public class ClientIT {
+ private static final String testName = "com.sun.ts.tests.jms.ee20.resourcedefs.descriptor.Client";
+
+ private static final String testDir = System.getProperty("user.dir");
+
+ private static final long serialVersionUID = 1L;
+
+ // JMS objects
+ private transient ConnectionFactory cf = null;
+
+ private transient ConnectionFactory cfra = null;
+
+ private transient QueueConnectionFactory qcf = null;
+
+ private transient TopicConnectionFactory tcf = null;
+
+ private transient TopicConnectionFactory dtcf = null;
+
+ private transient Topic topic = null;
+
+ private transient Topic topica = null;
+
+ private transient Queue queue = null;
+
+ private transient JMSContext context = null;
+
+ private transient JMSConsumer consumerQ = null;
+
+ private transient JMSProducer producerQ = null;
+
+ private transient JMSConsumer consumerT = null;
+
+ private transient JMSProducer producerT = null;
+
+ private boolean queueTest = false;
+
+ // Harness req's
+ private Properties props = null;
+
+ // properties read
+ long timeout;
+
+ String user;
+
+ String password;
+
+ String mode;
+
+ String vehicle;
+
+ private static final Logger logger = (Logger) System.getLogger(ClientIT.class.getName());
+
+ /* Test setup: */
+
+ /*
+ * setup() is called before each test
+ *
+ * @class.setup_props: jms_timeout; user; password; platform.mode;
+ *
+ * @exception Fault
+ */
+ @BeforeEach
+ public void setup() throws Exception {
+ try {
+ // get props
+ timeout = Long.parseLong(System.getProperty("jms_timeout"));
+ user = System.getProperty("user");
+ password = System.getProperty("password");
+ mode = System.getProperty("platform.mode");
+ vehicle = System.getProperty("vehicle");
+
+ // check props for errors
+ if (timeout < 1) {
+ throw new Exception("'jms_timeout' (milliseconds) in must be > 0");
+ }
+ if (user == null) {
+ throw new Exception("'user' is null ");
+ }
+ if (password == null) {
+ throw new Exception("'password' is null ");
+ }
+ if (mode == null) {
+ throw new Exception("'platform.mode' is null");
+ }
+
+ logger.log(Logger.Level.INFO, "Lookup JMS factories defined in Deployment Descriptors");
+ logger.log(Logger.Level.INFO, "Lookup JMS destinations defined in Deployment Descriptors");
+ logger.log(Logger.Level.INFO, "See and tags in DD's");
+ TSNamingContext namingctx = new TSNamingContext();
+ String prefix = null;
+ if (vehicle.equals("appclient"))
+ prefix = "AppClient";
+ else if (vehicle.equals("ejb"))
+ prefix = "EJB";
+ else if (vehicle.equals("servlet"))
+ prefix = "Servlet";
+ else if (vehicle.equals("jsp"))
+ prefix = "JSP";
+ logger.log(Logger.Level.INFO, "Lookup java:global/" + prefix + "MyTestConnectionFactory");
+ cf = (ConnectionFactory) namingctx.lookup("java:global/" + prefix + "MyTestConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:app/" + prefix + "MyTestQueueConnectionFactory");
+ qcf = (QueueConnectionFactory) namingctx.lookup("java:app/" + prefix + "MyTestQueueConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:module/" + prefix + "MyTestTopicConnectionFactory");
+ tcf = (TopicConnectionFactory) namingctx.lookup("java:module/" + prefix + "MyTestTopicConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:comp/env/jms/" + prefix + "MyTestDurableTopicConnectionFactory");
+ dtcf = (TopicConnectionFactory) namingctx
+ .lookup("java:comp/env/jms/" + prefix + "MyTestDurableTopicConnectionFactory");
+ logger.log(Logger.Level.INFO, "Lookup java:global/env/" + prefix + "MyTestQueue");
+ queue = (Queue) namingctx.lookup("java:global/env/" + prefix + "MyTestQueue");
+ logger.log(Logger.Level.INFO, "Lookup java:app/env/" + prefix + "MyTestTopic");
+ topic = (Topic) namingctx.lookup("java:app/env/" + prefix + "MyTestTopic");
+
+ logger.log(Logger.Level.INFO, "Create JMSContext, JMSProducer's and JMSConsumer's");
+ context = cf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ producerQ = context.createProducer();
+ consumerQ = context.createConsumer(queue);
+ producerT = context.createProducer();
+ consumerT = context.createConsumer(topic);
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("setup failed!", e);
+ }
+ }
+
+ /* cleanup */
+
+ /*
+ * cleanup() is called after each test
+ *
+ * @exception Fault
+ */
+ @AfterEach
+ public void cleanup() throws Exception {
+ try {
+ if (queueTest && consumerQ != null) {
+ logger.log(Logger.Level.INFO, "Flush any messages left on Queue");
+ Message rmsg = consumerQ.receive(timeout);
+ while (rmsg != null) {
+ rmsg = consumerQ.receiveNoWait();
+ if (rmsg == null) {
+ rmsg = consumerQ.receiveNoWait();
+ }
+ }
+ consumerQ.close();
+ }
+ if (consumerT != null)
+ consumerT.close();
+ logger.log(Logger.Level.INFO, "Close JMSContext Objects");
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("cleanup failed!", e);
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvQueueTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
+ * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
+ * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
+ * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
+ * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
+ * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
+ *
+ * @test_Strategy: Send and receive a message to/from a Queue.
+ *
+ */
+ @Test
+ public void sendAndRecvQueueTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ queueTest = true;
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage via JMSContext.createTextMessage(String)");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvQueueTest");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producerQ.send(queue, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage via JMSconsumer.receive(long)");
+ TextMessage actTextMessage = (TextMessage) consumerQ.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("sendAndRecvQueueTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvQueueTest failed");
+ }
+ }
+
+ /*
+ * @testName: sendAndRecvTopicTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
+ * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
+ * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
+ * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
+ * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
+ * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
+ *
+ * @test_Strategy: Send and receive a message to/from a Topic.
+ *
+ */
+ @Test
+ public void sendAndRecvTopicTest() throws Exception {
+ boolean pass = true;
+ String message = "Where are you!";
+ try {
+ queueTest = false;
+ // send and receive TextMessage
+ logger.log(Logger.Level.INFO, "Creating TextMessage via JMSContext.createTextMessage(String)");
+ TextMessage expTextMessage = context.createTextMessage(message);
+ logger.log(Logger.Level.INFO, "Set some values in TextMessage");
+ expTextMessage.setStringProperty("COM_SUN_JMS_TESTNAME", "sendAndRecvTopicTest");
+ logger.log(Logger.Level.INFO, "Sending TextMessage via JMSProducer.send(Destination, Message)");
+ producerT.send(topic, expTextMessage);
+ logger.log(Logger.Level.INFO, "Receive TextMessage via JMSconsumer.receive(long)");
+ TextMessage actTextMessage = (TextMessage) consumerT.receive(timeout);
+ if (actTextMessage == null) {
+ throw new Exception("Did not receive TextMessage");
+ } else {
+ logger.log(Logger.Level.INFO, "Check the value in TextMessage");
+ if (actTextMessage.getText().equals(expTextMessage.getText())) {
+ logger.log(Logger.Level.INFO, "TextMessage is correct");
+ } else {
+ logger.log(Logger.Level.ERROR, "TextMessage is incorrect expected " + expTextMessage.getText()
+ + ", received " + actTextMessage.getText());
+ pass = false;
+ }
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("sendAndRecvTopicTest", e);
+ }
+
+ if (!pass) {
+ throw new Exception("sendAndRecvTopicTest failed");
+ }
+ }
+
+ /*
+ * @testName: checkClientIDOnDurableConnFactoryTest
+ *
+ * @assertion_ids: JMS:JAVADOC:1324; JMS:JAVADOC:1325; JMS:JAVADOC:1327;
+ * JMS:JAVADOC:1330; JMS:JAVADOC:1331; JMS:JAVADOC:1332; JMS:JAVADOC:1333;
+ * JMS:JAVADOC:1334; JMS:JAVADOC:1335; JMS:JAVADOC:1336; JMS:JAVADOC:1338;
+ * JMS:JAVADOC:1339; JMS:JAVADOC:1342; JMS:JAVADOC:1343; JMS:JAVADOC:1344;
+ * JMS:JAVADOC:1345; JMS:JAVADOC:1346; JMS:JAVADOC:1347; JMS:JAVADOC:1348;
+ * JMS:JAVADOC:1451; JMS:JAVADOC:1452;
+ *
+ * @test_Strategy: Check client id setting on durable connection factory
+ *
+ */
+ @Test
+ public void checkClientIDOnDurableConnFactoryTest() throws Exception {
+ boolean pass = true;
+ JMSContext context = null;
+ try {
+ queueTest = false;
+ logger.log(Logger.Level.INFO, "Create JMSContext from durable topic connection factory");
+ logger.log(Logger.Level.INFO,
+ "Check the client id which is configured as MyClientID in the deployment descriptors");
+ context = dtcf.createContext(user, password, JMSContext.AUTO_ACKNOWLEDGE);
+ String clientid = context.getClientID();
+ if (clientid == null) {
+ logger.log(Logger.Level.ERROR, "Client ID value is null (expected MyClientID)");
+ pass = false;
+ } else if (clientid.equals("MyClientID")) {
+ logger.log(Logger.Level.INFO, "Client ID value is correct (MyClientID)");
+ } else {
+ logger.log(Logger.Level.ERROR,
+ "Client ID value is incorrect (expected MyClientID, got " + clientid + ")");
+ pass = false;
+ }
+ } catch (Exception e) {
+ logger.log(Logger.Level.ERROR, "Caught exception: " + e);
+ throw new Exception("checkClientIDOnDurableConnFactoryTest", e);
+ } finally {
+ try {
+ if (context != null)
+ context.close();
+ } catch (Exception e) {
+ }
+ }
+
+ if (!pass) {
+ throw new Exception("checkClientIDOnDurableConnFactoryTest failed");
+ }
+ }
+
+}