Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# CHANGELOG
## v0.4.1
### Features
### Bugfix
- Fix of issue: [Library can't be used during robot --dry-run](https://github.com/MarketSquare/robotframework-jmslibrary/issues/6)

### Note
Some existing keywords are marked as deprecated and will be removed in a future release.

## v0.4.0
### Features

- Added parameter to set path to jvm library file. \
This configuration is required in special situations when the jvm library file is not automatically detected.

### Note
Some existing keywords are marked as deprecated and will be removed in a future release.


## v0.3.0
### Features
- Added support for JMS Topics
- Added basic support for JMS properties
- Added support for BytesMessages
- Internal Refactoring

### Note
Some existing keywords are marked as deprecated and will be removed in a future release.

## v0.2.0
### Features
- ActiveMQ and WebLogic Support
- Connect to both ActiveMQ and WebLogic JMS providers with a single library.
- Easily switch between providers using the type argument.

- Flexible Connection Configuration
- Configure server address, port, username, password, connection factory, and timeout.
- Customizable classpath for JMS JARs, supporting both default and user-supplied values.

- Producer and Consumer Management
- Create and manage multiple producers and consumers for different queues.
- Support for both queue and topic destinations.

- Message Operations
- Create, send, and receive text messages.
- Send messages directly to producers or queues.
- Receive messages with assertion support for test validation.
- Clear queues and receive all messages as a list.

- Assertion Integration
- Built-in assertion operators and formatters for validating message content in Robot Framework tests.
- Timeout Control
- Set global or per-keyword timeouts for message operations.

- Connection Lifecycle Management
- Start, stop, and close JMS connections cleanly.
- JVM shutdown support for resource cleanup.

### Example Usage
```
*** Settings ***
Library JMS

*** Test Cases ***
Send And Receive JMS Messages
Create Producer RobotQueue1
Send Hello from Robot Framework
Create Consumer RobotQueue1
Receive == Hello from Robot Framework
```

### Notes
Requires Java and appropriate JMS provider JARs in the classpath.
Compatible with Robot Framework and supports advanced assertion features for message validation.

For more details, see the library documentation or the docstring in the JMS class.
32 changes: 21 additions & 11 deletions JMS/JMS.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import jpype
import jpype.imports
from robot.api.deco import keyword, library
from robot.api.exceptions import Failure
import logging
from typing import Any, List, Optional, Union
from assertionengine import (
Expand All @@ -27,7 +28,7 @@ def __init__(
port=61616,
username=None,
password=None,
connection_factory="ConnectionFactory",
connection_factory_name="ConnectionFactory",
timeout = 2000,
jvmpath=None,
) -> None:
Expand Down Expand Up @@ -58,7 +59,8 @@ def __init__(
self.username = username
self.password = password
self.timeout = timeout
self.connection_factory = connection_factory
self.connection_factory_name = connection_factory_name
self.connection_factory = None
self.connection = None
self.producer = None
self.consumer = None
Expand All @@ -68,6 +70,9 @@ def __init__(
self.consumers = {}
self.queues = {}
self.topics = {}

def _get_connection_factory(self):

if self.type == "activemq":
import org.apache.activemq.command.ActiveMQTextMessage as TextMessage
import org.apache.activemq.command.ActiveMQBytesMessage as BytesMessage
Expand Down Expand Up @@ -99,7 +104,7 @@ def _get_weblogic_connection_factory_with_hashtable(self):
properties.put(Context.SECURITY_CREDENTIALS, self.password)

self.jndiContext = InitialContext(properties)
self.connectionFactory = self.jndiContext.lookup(self.connection_factory)
self.connection_factory = self.jndiContext.lookup(self.connection_factory_name)

def _get_weblogic_connection_factory_with_environment(self):
#Create a Context object
Expand All @@ -113,13 +118,13 @@ def _get_weblogic_connection_factory_with_environment(self):
env.setConnectionTimeout(10000)
env.setResponseReadTimeout(15000)
self.jndiContext = env.getInitialContext()
self.connectionFactory = self.jndiContext.lookup(self.connection_factory)
self.connection_factory = self.jndiContext.lookup(self.connection_factory_name)


def _get_activemq_connection_factory(self):
from org.apache.activemq import ActiveMQConnectionFactory as ConnectionFactory
# Create connection factory
self.connectionFactory = self.ConnectionFactory(
self.connection_factory = ConnectionFactory(
"tcp://{}:{}".format(self.server, self.port)
)

Expand All @@ -138,14 +143,14 @@ def _get_activemq_connection_factory_with_hashtable(self):
properties.put(Context.SECURITY_CREDENTIALS, self.password)

self.jndiContext = InitialContext(properties)
self.connectionFactory = self.jndiContext.lookup(self.connection_factory)
self.connection_factory = self.jndiContext.lookup(self.connection_factory_name)

def _create_weblogic_connection(self):
try:
from javax.jms import Session
except ImportError:
from jakarta.jms import Session
self.connection = self.connectionFactory.createConnection()
self.connection = self.connection_factory.createConnection()
self.session = self.connection.createSession(
False, Session.AUTO_ACKNOWLEDGE
)
Expand All @@ -157,11 +162,11 @@ def _create_activemq_connection(self):
except ImportError:
from jakarta.jms import Session
if self.username is not None and self.password is not None:
self.connection = self.connectionFactory.createConnection(
self.connection = self.connection_factory.createConnection(
self.username, self.password
)
else:
self.connection = self.connectionFactory.createConnection()
self.connection = self.connection_factory.createConnection()
self.session = self.connection.createSession(
False, Session.AUTO_ACKNOWLEDGE
)
Expand All @@ -175,8 +180,12 @@ def create_connection(self):
Create connection to JMS server
"""
if self.connection is not None:
print("Connection already created")
logging.debug("Connection already created")
return
try:
self._get_connection_factory()
except:
raise Failure("Failed to create connection")
if self.type == "weblogic":
self._create_weblogic_connection()
else:
Expand All @@ -203,11 +212,12 @@ def stop_connection(self):
def close_connection(self):
"""
Close connection to JMS server.
Shutdown JVM.
"""
# Close connection and clean up
self.stop_connection()
self.connection.close()
self.connection = None
self.connection_factory = None

@keyword
def create_producer_topic(self, topic: str):
Expand Down
Loading
Loading