ManagedProperty messageCounter = component.getProperty("messageCounter");
assertNotNull("messageCounter", messageCounter);
// Clear any
Set<ManagedOperation> ops = component.getOperations();
ManagedOperation removeAllMessages = ManagedOperationMatcher.findOperation(ops, "removeAllMessages");
assertNotNull("removeAllMessages", removeAllMessages);
removeAllMessages.invoke();
assertEquals(SimpleValueSupport.wrap(0), messageCount.getValue());
// Send a message
Queue queue = (Queue) getInitialContext().lookup(jndiName);
assertNotNull(queue);
QueueConnectionFactory qCf = (QueueConnectionFactory) getInitialContext().lookup("ConnectionFactory");
QueueConnection c = qCf.createQueueConnection();
c.start();
QueueSession s = c.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = s.createSender(queue);
// Message 1
sender.send(s.createTextMessage("Hey!"));
SimpleValue messageCount1 = (SimpleValue) messageCount.getValue();
assertTrue((Integer) (messageCount1).getValue() > 0);
CompositeValue messageCounterCV = (CompositeValue) messageCounter.getValue();
log.info(messageCounterCV);
assertEquals(messageCounterCV.get("messageCount"), messageCount1);
// Message 2
sender.send(s.createTextMessage("Message2"));
SimpleValue messageCount2 = (SimpleValue) messageCount.getValue();
assertTrue(messageCount2.compareTo(messageCount1) > 0);
messageCounterCV = (CompositeValue) messageCounter.getValue();
assertEquals(messageCounterCV.get("messageCount"), messageCount2);
//
ManagedOperation listAllMessages = ManagedOperationMatcher.findOperation(ops, "listAllMessages");
assertNotNull("listAllMessages", listAllMessages);
MetaValue msgs = listAllMessages.invoke();
assertNotNull(msgs);
log.info("listAllMessages.MV: "+msgs);
assertTrue("msgs is a CollectionValue", msgs instanceof CollectionValue);
CollectionValue msgsCV = (CollectionValue) msgs;
MetaValue[] msgsMVs = msgsCV.getElements();