Search in sources :

Example 1 with ActiveMQPropertyConversionException

use of org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException in project activemq-artemis by apache.

the class TypedPropertiesConversionTest method testLongProperty.

@Test
public void testLongProperty() throws Exception {
    Long val = RandomUtil.randomLong();
    props.putLongProperty(key, val);
    Assert.assertEquals(val, props.getLongProperty(key));
    Assert.assertEquals(new SimpleString(Long.toString(val)), props.getSimpleStringProperty(key));
    props.putSimpleStringProperty(key, new SimpleString(Long.toString(val)));
    Assert.assertEquals(val, props.getLongProperty(key));
    Byte byteVal = RandomUtil.randomByte();
    props.putByteProperty(key, byteVal);
    Assert.assertEquals(Long.valueOf(byteVal), props.getLongProperty(key));
    Short shortVal = RandomUtil.randomShort();
    props.putShortProperty(key, shortVal);
    Assert.assertEquals(Long.valueOf(shortVal), props.getLongProperty(key));
    Integer intVal = RandomUtil.randomInt();
    props.putIntProperty(key, intVal);
    Assert.assertEquals(Long.valueOf(intVal), props.getLongProperty(key));
    try {
        props.putBooleanProperty(key, RandomUtil.randomBoolean());
        props.getLongProperty(key);
        Assert.fail();
    } catch (ActiveMQPropertyConversionException e) {
    }
    try {
        props.getLongProperty(unknownKey);
        Assert.fail();
    } catch (NumberFormatException e) {
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQPropertyConversionException(org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException) Test(org.junit.Test)

Example 2 with ActiveMQPropertyConversionException

use of org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException in project activemq-artemis by apache.

the class TypedPropertiesConversionTest method testIntProperty.

@Test
public void testIntProperty() throws Exception {
    Integer val = RandomUtil.randomInt();
    props.putIntProperty(key, val);
    Assert.assertEquals(val, props.getIntProperty(key));
    Assert.assertEquals(new SimpleString(Integer.toString(val)), props.getSimpleStringProperty(key));
    props.putSimpleStringProperty(key, new SimpleString(Integer.toString(val)));
    Assert.assertEquals(val, props.getIntProperty(key));
    Byte byteVal = RandomUtil.randomByte();
    props.putByteProperty(key, byteVal);
    Assert.assertEquals(Integer.valueOf(byteVal), props.getIntProperty(key));
    try {
        props.putBooleanProperty(key, RandomUtil.randomBoolean());
        props.getIntProperty(key);
        Assert.fail();
    } catch (ActiveMQPropertyConversionException e) {
    }
    try {
        props.getIntProperty(unknownKey);
        Assert.fail();
    } catch (NumberFormatException e) {
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQPropertyConversionException(org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException) Test(org.junit.Test)

Example 3 with ActiveMQPropertyConversionException

use of org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException in project activemq-artemis by apache.

the class TypedPropertiesConversionTest method testByteProperty.

@Test
public void testByteProperty() throws Exception {
    Byte val = RandomUtil.randomByte();
    props.putByteProperty(key, val);
    Assert.assertEquals(val, props.getByteProperty(key));
    Assert.assertEquals(new SimpleString(Byte.toString(val)), props.getSimpleStringProperty(key));
    props.putSimpleStringProperty(key, new SimpleString(Byte.toString(val)));
    Assert.assertEquals(val, props.getByteProperty(key));
    try {
        props.putBooleanProperty(key, RandomUtil.randomBoolean());
        props.getByteProperty(key);
        Assert.fail();
    } catch (ActiveMQPropertyConversionException e) {
    }
    try {
        props.getByteProperty(unknownKey);
        Assert.fail();
    } catch (NumberFormatException e) {
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQPropertyConversionException(org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException) Test(org.junit.Test)

Example 4 with ActiveMQPropertyConversionException

use of org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException in project activemq-artemis by apache.

the class ActiveMQJMSProducer method getPropertyNames.

@Override
public Set<String> getPropertyNames() {
    try {
        Set<SimpleString> simplePropNames = properties.getPropertyNames();
        Set<String> propNames = new HashSet<>(simplePropNames.size());
        for (SimpleString str : simplePropNames) {
            propNames.add(str.toString());
        }
        return propNames;
    } catch (ActiveMQPropertyConversionException ce) {
        throw new MessageFormatRuntimeException(ce.getMessage());
    } catch (RuntimeException e) {
        throw new JMSRuntimeException(e.getMessage());
    }
}
Also used : MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException) JMSRuntimeException(javax.jms.JMSRuntimeException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException) ActiveMQPropertyConversionException(org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException) HashSet(java.util.HashSet) JMSRuntimeException(javax.jms.JMSRuntimeException)

Example 5 with ActiveMQPropertyConversionException

use of org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException in project activemq-artemis by apache.

the class ActiveMQJMSProducer method getObjectProperty.

@Override
public Object getObjectProperty(String name) {
    try {
        SimpleString key = new SimpleString(name);
        Object property = properties.getProperty(key);
        if (stringPropertyNames.contains(key)) {
            property = property.toString();
        }
        return property;
    } catch (ActiveMQPropertyConversionException ce) {
        throw new MessageFormatRuntimeException(ce.getMessage());
    } catch (RuntimeException e) {
        throw new JMSRuntimeException(e.getMessage());
    }
}
Also used : MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException) JMSRuntimeException(javax.jms.JMSRuntimeException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException) ActiveMQPropertyConversionException(org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException) JMSRuntimeException(javax.jms.JMSRuntimeException)

Aggregations

ActiveMQPropertyConversionException (org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException)12 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)12 Test (org.junit.Test)8 JMSRuntimeException (javax.jms.JMSRuntimeException)2 MessageFormatException (javax.jms.MessageFormatException)2 MessageFormatRuntimeException (javax.jms.MessageFormatRuntimeException)2 HashSet (java.util.HashSet)1 UnsignedByte (org.apache.qpid.proton.amqp.UnsignedByte)1 UnsignedInteger (org.apache.qpid.proton.amqp.UnsignedInteger)1 UnsignedLong (org.apache.qpid.proton.amqp.UnsignedLong)1 UnsignedShort (org.apache.qpid.proton.amqp.UnsignedShort)1