@Test public void disconnectWithReceipt() throws Exception { logger.debug("Starting test disconnectWithReceipt()"); MessageExchange connect = MessageExchangeBuilder.connect("sess1").build(); this.relay.handleMessage(connect.message); this.responseHandler.expectMessages(connect); MessageExchange disconnect = MessageExchangeBuilder.disconnectWithReceipt("sess1", "r123").build(); this.relay.handleMessage(disconnect.message); this.responseHandler.expectMessages(disconnect); }
@Test(expected = MessageDeliveryException.class) public void messageDeliveryExceptionIfSystemSessionForwardFails() throws Exception { logger.debug("Starting test messageDeliveryExceptionIfSystemSessionForwardFails()"); stopActiveMqBrokerAndAwait(); this.eventPublisher.expectBrokerAvailabilityEvent(false); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.SEND); this.relay.handleMessage(MessageBuilder.createMessage("test".getBytes(), headers.getMessageHeaders())); }
@Test public void publishSubscribe() throws Exception { logger.debug("Starting test publishSubscribe()"); String sess1 = "sess1"; String sess2 = "sess2"; String subs1 = "subs1"; String destination = "/topic/test"; MessageExchange conn1 = MessageExchangeBuilder.connect(sess1).build(); MessageExchange conn2 = MessageExchangeBuilder.connect(sess2).build(); this.relay.handleMessage(conn1.message); this.relay.handleMessage(conn2.message); this.responseHandler.expectMessages(conn1, conn2); MessageExchange subscribe = MessageExchangeBuilder.subscribeWithReceipt(sess1, subs1, destination, "r1").build(); this.relay.handleMessage(subscribe.message); this.responseHandler.expectMessages(subscribe); MessageExchange send = MessageExchangeBuilder.send(destination, "foo").andExpectMessage(sess1, subs1).build(); this.relay.handleMessage(send.message); this.responseHandler.expectMessages(send); }
@Test public void brokerBecomingUnavailableTriggersErrorFrame() throws Exception { logger.debug("Starting test brokerBecomingUnavailableTriggersErrorFrame()"); String sess1 = "sess1"; MessageExchange connect = MessageExchangeBuilder.connect(sess1).build(); this.relay.handleMessage(connect.message); this.responseHandler.expectMessages(connect); MessageExchange error = MessageExchangeBuilder.error(sess1).build(); stopActiveMqBrokerAndAwait(); this.eventPublisher.expectBrokerAvailabilityEvent(false); this.responseHandler.expectMessages(error); }
@Test public void connectWhenBrokerNotAvailable() throws Exception { this.brokerRelay.start(); this.brokerRelay.stopInternal(); this.brokerRelay.handleMessage(connectMessage("sess1", "joe")); Message<byte[]> message = this.outboundChannel.getMessages().get(0); StompHeaderAccessor accessor = StompHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); assertEquals(StompCommand.ERROR, accessor.getCommand()); assertEquals("sess1", accessor.getSessionId()); assertEquals("joe", accessor.getUser().getName()); assertEquals("Broker not available.", accessor.getMessage()); }
@Test public void relayReconnectsIfBrokerComesBackUp() throws Exception { logger.debug("Starting test relayReconnectsIfBrokerComesBackUp()"); String sess1 = "sess1"; MessageExchange conn1 = MessageExchangeBuilder.connect(sess1).build(); this.relay.handleMessage(conn1.message); this.responseHandler.expectMessages(conn1); String subs1 = "subs1"; String destination = "/topic/test"; MessageExchange subscribe = MessageExchangeBuilder.subscribeWithReceipt(sess1, subs1, destination, "r1").build(); this.relay.handleMessage(subscribe.message); this.responseHandler.expectMessages(subscribe); MessageExchange error = MessageExchangeBuilder.error(sess1).build(); stopActiveMqBrokerAndAwait(); this.responseHandler.expectMessages(error); this.eventPublisher.expectBrokerAvailabilityEvent(false); startActiveMqBroker(); this.eventPublisher.expectBrokerAvailabilityEvent(true); }
@Test public void messageFromBrokerIsEnriched() throws Exception { this.brokerRelay.start(); this.brokerRelay.handleMessage(connectMessage("sess1", "joe")); assertEquals(2, this.tcpClient.getSentMessages().size()); assertEquals(StompCommand.CONNECT, this.tcpClient.getSentHeaders(0).getCommand()); assertEquals(StompCommand.CONNECT, this.tcpClient.getSentHeaders(1).getCommand()); this.tcpClient.handleMessage(message(StompCommand.MESSAGE, null, null, null)); Message<byte[]> message = this.outboundChannel.getMessages().get(0); StompHeaderAccessor accessor = StompHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); assertEquals("sess1", accessor.getSessionId()); assertEquals("joe", accessor.getUser().getName()); }
@Test public void sendAfterBrokerUnavailable() throws Exception { this.brokerRelay.start(); assertEquals(1, this.brokerRelay.getConnectionCount()); this.brokerRelay.handleMessage(connectMessage("sess1", "joe")); assertEquals(2, this.brokerRelay.getConnectionCount()); this.brokerRelay.stopInternal(); this.brokerRelay.handleMessage(message(StompCommand.SEND, "sess1", "joe", "/foo")); assertEquals(1, this.brokerRelay.getConnectionCount()); Message<byte[]> message = this.outboundChannel.getMessages().get(0); StompHeaderAccessor accessor = StompHeaderAccessor.getAccessor(message, StompHeaderAccessor.class); assertEquals(StompCommand.ERROR, accessor.getCommand()); assertEquals("sess1", accessor.getSessionId()); assertEquals("joe", accessor.getUser().getName()); assertEquals("Broker not available.", accessor.getMessage()); }
@Test public void destinationExcluded() throws Exception { this.brokerRelay.start(); SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.create(SimpMessageType.MESSAGE); headers.setSessionId("sess1"); headers.setDestination("/user/daisy/foo"); this.brokerRelay.handleMessage(MessageBuilder.createMessage(new byte[0], headers.getMessageHeaders())); assertEquals(1, this.tcpClient.getSentMessages().size()); StompHeaderAccessor headers1 = this.tcpClient.getSentHeaders(0); assertEquals(StompCommand.CONNECT, headers1.getCommand()); assertEquals(StompBrokerRelayMessageHandler.SYSTEM_SESSION_ID, headers1.getSessionId()); }
@Test public void virtualHost() throws Exception { this.brokerRelay.setVirtualHost("ABC"); this.brokerRelay.start(); this.brokerRelay.handleMessage(connectMessage("sess1", "joe")); assertEquals(2, this.tcpClient.getSentMessages().size()); StompHeaderAccessor headers1 = this.tcpClient.getSentHeaders(0); assertEquals(StompCommand.CONNECT, headers1.getCommand()); assertEquals(StompBrokerRelayMessageHandler.SYSTEM_SESSION_ID, headers1.getSessionId()); assertEquals("ABC", headers1.getHost()); StompHeaderAccessor headers2 = this.tcpClient.getSentHeaders(1); assertEquals(StompCommand.CONNECT, headers2.getCommand()); assertEquals("sess1", headers2.getSessionId()); assertEquals("ABC", headers2.getHost()); }
@Test public void loginAndPasscode() throws Exception { this.brokerRelay.setSystemLogin("syslogin"); this.brokerRelay.setSystemPasscode("syspasscode"); this.brokerRelay.setClientLogin("clientlogin"); this.brokerRelay.setClientPasscode("clientpasscode"); this.brokerRelay.start(); this.brokerRelay.handleMessage(connectMessage("sess1", "joe")); assertEquals(2, this.tcpClient.getSentMessages().size()); StompHeaderAccessor headers1 = this.tcpClient.getSentHeaders(0); assertEquals(StompCommand.CONNECT, headers1.getCommand()); assertEquals("syslogin", headers1.getLogin()); assertEquals("syspasscode", headers1.getPasscode()); StompHeaderAccessor headers2 = this.tcpClient.getSentHeaders(1); assertEquals(StompCommand.CONNECT, headers2.getCommand()); assertEquals("clientlogin", headers2.getLogin()); assertEquals("clientpasscode", headers2.getPasscode()); }