Example usage for javax.jms ObjectMessage getJMSCorrelationID

List of usage examples for javax.jms ObjectMessage getJMSCorrelationID

Introduction

In this page you can find the example usage for javax.jms ObjectMessage getJMSCorrelationID.

Prototype


String getJMSCorrelationID() throws JMSException;

Source Link

Document

Gets the correlation ID for the message.

Usage

From source file:com.alliander.osgp.acceptancetests.configurationmanagement.GetConfigurationDataSteps.java

@DomainStep("a get configuration response message with correlationId (.*), deviceId (.*), qresult (.*), qdescription (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*), (.*) is found in the queue (.*)")
public void givenAGetConfigurationResponseMessageIsFoundInQueue(final String correlationId,
        final String deviceId, final String qresult, final String qdescription, final String lightType,
        final String dcLights, final String dcMap, final String rcType, final String rcMap,
        final String shortInterval, final String preferredLinkType, final String meterType,
        final String longInterval, final String longIntervalType, final Boolean isFound) {
    LOGGER.info(/*  w  w w  . j a  va2s.  c  o  m*/
            "GIVEN: \"a get configuration response message with correlationId {}, deviceId {}, qresult {} and qdescription {} is found {}\".",
            correlationId, deviceId, qresult, qdescription, isFound);

    if (isFound) {
        final ObjectMessage messageMock = mock(ObjectMessage.class);

        try {
            when(messageMock.getJMSCorrelationID()).thenReturn(correlationId);
            when(messageMock.getStringProperty("OrganisationIdentification")).thenReturn(ORGANISATION_ID);
            when(messageMock.getStringProperty("DeviceIdentification")).thenReturn(deviceId);

            final ResponseMessageResultType result = ResponseMessageResultType.valueOf(qresult);
            Serializable dataObject = null;
            OsgpException exception = null;

            if (result.equals(ResponseMessageResultType.NOT_OK)) {
                dataObject = new FunctionalException(FunctionalExceptionType.VALIDATION_ERROR,
                        ComponentType.UNKNOWN, new ValidationException());
                exception = (OsgpException) dataObject;
            } else {

                final com.alliander.osgp.domain.core.valueobjects.LightType lighttype = StringUtils
                        .isBlank(lightType) ? null
                                : Enum.valueOf(com.alliander.osgp.domain.core.valueobjects.LightType.class,
                                        lightType);
                final Map<Integer, Integer> indexAddressMap = new HashMap<Integer, Integer>();

                final com.alliander.osgp.domain.core.valueobjects.DaliConfiguration daliconfiguration = new com.alliander.osgp.domain.core.valueobjects.DaliConfiguration(
                        22, indexAddressMap);

                final List<com.alliander.osgp.domain.core.valueobjects.RelayMap> relayMap = new ArrayList<>();
                final com.alliander.osgp.domain.core.valueobjects.RelayConfiguration relayConf = new com.alliander.osgp.domain.core.valueobjects.RelayConfiguration(
                        relayMap);

                final MeterType metertype = StringUtils.isBlank(meterType) ? null
                        : Enum.valueOf(MeterType.class, meterType);
                final LongTermIntervalType longtermintervalType = StringUtils.isBlank(longIntervalType) ? null
                        : Enum.valueOf(LongTermIntervalType.class, longIntervalType);

                final Integer shortinterval = StringUtils.isBlank(shortInterval) ? 0
                        : Integer.valueOf(shortInterval);
                final Integer longinterval = StringUtils.isBlank(longInterval) ? 0
                        : Integer.valueOf(longInterval);

                // construct new Configuration
                dataObject = new com.alliander.osgp.domain.core.valueobjects.Configuration(lighttype,
                        daliconfiguration, relayConf, shortinterval, LinkType.ETHERNET, metertype, longinterval,
                        longtermintervalType);
            }

            final ResponseMessage message = new ResponseMessage(correlationId, ORGANISATION_ID, deviceId,
                    result, exception, dataObject);

            when(messageMock.getObject()).thenReturn(message);

        } catch (final JMSException e) {
            e.printStackTrace();
        }

        when(this.commonResponsesJmsTemplateMock.receiveSelected(any(String.class))).thenReturn(messageMock);
    } else {
        when(this.commonResponsesJmsTemplateMock.receiveSelected(any(String.class))).thenReturn(null);
    }
}