Search in sources :

Example 1 with ConnectionMetaData

use of javax.jms.ConnectionMetaData in project spring-boot by spring-projects.

the class JmsHealthIndicatorTests method jmsBrokerIsUp.

@Test
public void jmsBrokerIsUp() throws JMSException {
    ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
    given(connectionMetaData.getJMSProviderName()).willReturn("JMS test provider");
    Connection connection = mock(Connection.class);
    given(connection.getMetaData()).willReturn(connectionMetaData);
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    given(connectionFactory.createConnection()).willReturn(connection);
    JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
    Health health = indicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.UP);
    assertThat(health.getDetails().get("provider")).isEqualTo("JMS test provider");
    verify(connection, times(1)).close();
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) ConnectionMetaData(javax.jms.ConnectionMetaData) Connection(javax.jms.Connection) Test(org.junit.Test)

Example 2 with ConnectionMetaData

use of javax.jms.ConnectionMetaData in project spring-boot by spring-projects.

the class JmsHealthIndicatorTests method jmsBrokerCouldNotRetrieveProviderMetadata.

@Test
public void jmsBrokerCouldNotRetrieveProviderMetadata() throws JMSException {
    ConnectionMetaData connectionMetaData = mock(ConnectionMetaData.class);
    given(connectionMetaData.getJMSProviderName()).willThrow(new JMSException("test", "123"));
    Connection connection = mock(Connection.class);
    given(connection.getMetaData()).willReturn(connectionMetaData);
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    given(connectionFactory.createConnection()).willReturn(connection);
    JmsHealthIndicator indicator = new JmsHealthIndicator(connectionFactory);
    Health health = indicator.health();
    assertThat(health.getStatus()).isEqualTo(Status.DOWN);
    assertThat(health.getDetails().get("provider")).isNull();
    verify(connection, times(1)).close();
}
Also used : ConnectionFactory(javax.jms.ConnectionFactory) ConnectionMetaData(javax.jms.ConnectionMetaData) Connection(javax.jms.Connection) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Example 3 with ConnectionMetaData

use of javax.jms.ConnectionMetaData in project activemq-artemis by apache.

the class ManifestTest method testManifestEntries.

// Constants -----------------------------------------------------
// Static --------------------------------------------------------
// Attributes ----------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testManifestEntries() throws Exception {
    Properties props = System.getProperties();
    String userDir = props.getProperty("build.lib");
    UnitTestLogger.LOGGER.trace("userDir is " + userDir);
    // The jar must be there
    File file = new File("build/jars", "activemq-core.jar");
    Assert.assertTrue(file.exists());
    // Open the jar and load MANIFEST.MF
    JarFile jar = new JarFile(file);
    Manifest manifest = jar.getManifest();
    ActiveMQServer server = ActiveMQServers.newActiveMQServer(createBasicConfig());
    ConnectionMetaData meta = new ActiveMQConnectionMetaData(server.getVersion());
    // Compare the value from ConnectionMetaData and MANIFEST.MF
    Attributes attrs = manifest.getMainAttributes();
    Assert.assertEquals(meta.getProviderVersion(), attrs.getValue("ActiveMQ-Version"));
}
Also used : ActiveMQConnectionMetaData(org.apache.activemq.artemis.jms.client.ActiveMQConnectionMetaData) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ConnectionMetaData(javax.jms.ConnectionMetaData) ActiveMQConnectionMetaData(org.apache.activemq.artemis.jms.client.ActiveMQConnectionMetaData) Attributes(java.util.jar.Attributes) Properties(java.util.Properties) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 4 with ConnectionMetaData

use of javax.jms.ConnectionMetaData in project activemq-artemis by apache.

the class JMSXPropertyTest method supportsJMSXDeliveryCount.

/**
 * checks if the JMSX property <code>JMSXDeliveryCount</code> is supported.
 */
private boolean supportsJMSXDeliveryCount() throws Exception {
    ConnectionMetaData metaData = senderConnection.getMetaData();
    Enumeration enumeration = metaData.getJMSXPropertyNames();
    while (enumeration.hasMoreElements()) {
        String jmsxPropertyName = (String) enumeration.nextElement();
        if (jmsxPropertyName.equals("JMSXDeliveryCount")) {
            return true;
        }
    }
    return false;
}
Also used : Enumeration(java.util.Enumeration) ConnectionMetaData(javax.jms.ConnectionMetaData)

Example 5 with ConnectionMetaData

use of javax.jms.ConnectionMetaData in project activemq-artemis by apache.

the class JMSXPropertyTest method testSupportsJMSXGroupID.

/**
 * Test that the JMSX property <code>JMSXGroupID</code> is supported.
 */
@Test
public void testSupportsJMSXGroupID() {
    try {
        boolean found = false;
        ConnectionMetaData metaData = senderConnection.getMetaData();
        Enumeration enumeration = metaData.getJMSXPropertyNames();
        while (enumeration.hasMoreElements()) {
            String jmsxPropertyName = (String) enumeration.nextElement();
            if (jmsxPropertyName.equals("JMSXGroupID")) {
                found = true;
            }
        }
        Assert.assertTrue("JMSXGroupID property is not supported", found);
    } catch (JMSException e) {
        fail(e);
    }
}
Also used : Enumeration(java.util.Enumeration) ConnectionMetaData(javax.jms.ConnectionMetaData) JMSException(javax.jms.JMSException) Test(org.junit.Test)

Aggregations

ConnectionMetaData (javax.jms.ConnectionMetaData)9 Test (org.junit.Test)6 Connection (javax.jms.Connection)5 JMSException (javax.jms.JMSException)5 ConnectionFactory (javax.jms.ConnectionFactory)3 Enumeration (java.util.Enumeration)2 QueueConnection (javax.jms.QueueConnection)2 TopicConnection (javax.jms.TopicConnection)2 File (java.io.File)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 Properties (java.util.Properties)1 Attributes (java.util.jar.Attributes)1 JarFile (java.util.jar.JarFile)1 Manifest (java.util.jar.Manifest)1 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)1 ActiveMQConnectionMetaData (org.apache.activemq.artemis.jms.client.ActiveMQConnectionMetaData)1