Search in sources :

Example 1 with InvalidDestinationRuntimeException

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

the class InvalidDestinationTest method invalidDestinationRuntimeExceptionTests.

@Test
public void invalidDestinationRuntimeExceptionTests() throws Exception {
    JMSProducer producer = context.createProducer();
    Destination invalidDestination = null;
    Topic invalidTopic = null;
    String message = "hello world";
    byte[] bytesMsgSend = message.getBytes();
    Map<String, Object> mapMsgSend = new HashMap<>();
    mapMsgSend.put("s", "foo");
    mapMsgSend.put("b", true);
    mapMsgSend.put("i", 1);
    TextMessage expTextMessage = context.createTextMessage(message);
    try {
        producer.send(invalidDestination, expTextMessage);
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        producer.send(invalidDestination, message);
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    ObjectMessage om = context.createObjectMessage();
    StringBuffer sb = new StringBuffer(message);
    om.setObject(sb);
    try {
        producer.send(invalidDestination, om);
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        producer.send(invalidDestination, bytesMsgSend);
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        producer.send(invalidDestination, mapMsgSend);
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        context.createConsumer(invalidDestination);
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        context.createConsumer(invalidDestination, "lastMessage = TRUE");
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        context.createConsumer(invalidDestination, "lastMessage = TRUE", false);
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        context.createDurableConsumer(invalidTopic, "InvalidDestinationRuntimeException");
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        context.createDurableConsumer(invalidTopic, "InvalidDestinationRuntimeException", "lastMessage = TRUE", false);
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        context.createSharedDurableConsumer(invalidTopic, "InvalidDestinationRuntimeException");
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        context.createSharedDurableConsumer(invalidTopic, "InvalidDestinationRuntimeException", "lastMessage = TRUE");
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        context.unsubscribe("InvalidSubscriptionName");
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        context.createSharedConsumer(invalidTopic, "InvalidDestinationRuntimeException");
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
    try {
        context.createSharedConsumer(invalidTopic, "InvalidDestinationRuntimeException", "lastMessage = TRUE");
    } catch (InvalidDestinationRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("Expected InvalidDestinationRuntimeException, received " + e);
    }
}
Also used : Destination(javax.jms.Destination) HashMap(java.util.HashMap) JMSProducer(javax.jms.JMSProducer) InvalidDestinationRuntimeException(javax.jms.InvalidDestinationRuntimeException) InvalidDestinationException(javax.jms.InvalidDestinationException) InvalidDestinationRuntimeException(javax.jms.InvalidDestinationRuntimeException) ObjectMessage(javax.jms.ObjectMessage) Topic(javax.jms.Topic) TextMessage(javax.jms.TextMessage) Test(org.junit.Test)

Example 2 with InvalidDestinationRuntimeException

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

the class JmsContextTest method testInvalidDestination.

@Test
public void testInvalidDestination() {
    JMSProducer producer = context.createProducer();
    Message msg = context.createMessage();
    try {
        producer.send((Destination) null, msg);
        Assert.fail("null Destination");
    } catch (InvalidDestinationRuntimeException expected) {
    // no-op
    }
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) StreamMessage(javax.jms.StreamMessage) BytesMessage(javax.jms.BytesMessage) JMSProducer(javax.jms.JMSProducer) InvalidDestinationRuntimeException(javax.jms.InvalidDestinationRuntimeException) Test(org.junit.Test)

Aggregations

InvalidDestinationRuntimeException (javax.jms.InvalidDestinationRuntimeException)2 JMSProducer (javax.jms.JMSProducer)2 TextMessage (javax.jms.TextMessage)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 BytesMessage (javax.jms.BytesMessage)1 Destination (javax.jms.Destination)1 InvalidDestinationException (javax.jms.InvalidDestinationException)1 Message (javax.jms.Message)1 ObjectMessage (javax.jms.ObjectMessage)1 StreamMessage (javax.jms.StreamMessage)1 Topic (javax.jms.Topic)1