下面列出了怎么用javax.jms.InvalidSelectorException的API类实例代码及写法,或者点击链接到github查看源代码。
@Test(timeout = 20000)
public void testInvalidSelector() throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
Connection connection = testFixture.establishConnecton(testPeer);
connection.start();
testPeer.expectBegin();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
String topicName = "myTopic";
Topic destination = session.createTopic(topicName);
try {
session.createConsumer(destination, "3+5");
fail("Should have thrown a invalid selector exception");
} catch (InvalidSelectorException jmsse) {
}
testPeer.expectClose();
connection.close();
testPeer.waitForAllHandlersToComplete(1000);
}
}
public void testFunctionCall() throws Exception {
Object filter = parse("REGEX('sales.*', group)");
assertTrue("expected type", filter instanceof BooleanFunctionCallExpr);
LOG.info("function exp:" + filter);
// non existent function
try {
parse("DoesNotExist('sales.*', group)");
fail("expect ex on non existent function");
} catch (InvalidSelectorException expected) {
}
}
protected void assertInvalidSelector(Message message, String text) throws JMSException {
try {
SelectorParser.parse(text);
fail("Created a valid selector");
} catch (InvalidSelectorException e) {
}
}
@Test
public void testInvalidSelectorOnSubscription() throws Exception {
TopicConnection c = createTopicConnection();
c.setClientID("something");
TopicSession s = c.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
try {
s.createSubscriber(ActiveMQServerTestCase.topic1, "=TEST 'test'", false);
ProxyAssertSupport.fail("this should fail");
} catch (InvalidSelectorException e) {
// OK
}
}
@Test
public void testInvalidSelectorException() throws Exception {
Connection c = createConnection();
c.setClientID("sofiavergara");
Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
try {
s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "mysubscribption", "=TEST 'test'", true);
ProxyAssertSupport.fail("this should fail");
} catch (InvalidSelectorException e) {
// OK
}
}
/**
* Converts instances of sub-classes of {@link JMSException} into the corresponding sub-class of
* {@link JMSRuntimeException}.
*
* @param e
* @return
*/
public static JMSRuntimeException convertToRuntimeException(JMSException e) {
if (e instanceof javax.jms.IllegalStateException) {
return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof InvalidClientIDException) {
return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof InvalidDestinationException) {
return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof InvalidSelectorException) {
return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof JMSSecurityException) {
return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof MessageFormatException) {
return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof MessageNotWriteableException) {
return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof ResourceAllocationException) {
return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof TransactionInProgressException) {
return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof TransactionRolledBackException) {
return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
static String checkSelector(String selector) throws InvalidSelectorException {
if (selector != null) {
if (selector.trim().length() == 0) {
return null;
}
try {
SelectorParser.parse(selector);
} catch (FilterException e) {
throw new InvalidSelectorException(e.getMessage());
}
}
return selector;
}
public static JMSRuntimeException toRuntimeException(final JMSException e) {
if (e instanceof javax.jms.IllegalStateException) {
return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof InvalidClientIDException) {
return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof InvalidDestinationException) {
return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof InvalidSelectorException) {
return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof JMSSecurityException) {
return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof MessageFormatException) {
return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof MessageNotWriteableException) {
return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof ResourceAllocationException) {
return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof TransactionInProgressException) {
return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
if (e instanceof TransactionRolledBackException) {
return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
@Test(expected = InvalidSelectorRuntimeException.class)
public void testConvertsInvalidSelectorExceptionToInvalidSelectorRuntimeException() {
throw JMSExceptionSupport.createRuntimeException(new InvalidSelectorException("error"));
}
@Override
public void setSelector(String selector) throws InvalidSelectorException, UnsupportedOperationException {
}
@Test
public void testINVALID_FILTER_EXPRESSION() throws Exception {
doConvertException(INVALID_FILTER_EXPRESSION, InvalidSelectorException.class);
}
@Test(expected = InvalidSelectorRuntimeException.class)
public void testConvertsInvalidSelectorExceptionToInvalidSelectorRuntimeException() {
throw JmsExceptionSupport.createRuntimeException(new InvalidSelectorException("error"));
}