@Test
  public void testStreamingEvent() {
    // Instantiate the resource
    ResourceImpl resourceImpl = new ResourceImpl(restItem);

    try {
      channel.queueDeclare(intTestQueue, false, false, false, null);
    } catch (Exception ex) {
      fail("Connectivity error to MQ while running Test" + ex);
      try {
        channel.close();
        connection.close();
      } catch (Exception otherEx) {
        // We couldn't close a connection that's already closed or
        // hasn't been open...
      }
    }

    // Here we build the queue ResourceImpl is going to connect to and we
    // will later publish to
    try {
      resourceImpl.startStreaming(createListeners());
    } catch (Exception ex) {
      fail("Error while starting streaming service: " + ex);
    }

    // Have a rest to let all the services start up properly
    try {
      Thread.sleep(5000);
      channel.basicPublish("", intTestQueue, null, mqMessage.getBytes());
    } catch (Exception ex) {
      fail("Cannot publish to MQ on test environment" + ex);
    }

    // A little rest to let the publication go through
    try {
      Thread.sleep(2000);
    } catch (Exception ex) {
    }

    // 1st test: did we get a callback on ConnectedEvent (Connected to MQ) ?
    assertTrue(connectedEventCalled);

    // 2nd test: The stream received event was triggered
    assertTrue(streamEventCalled);

    // 3rd test: And the message received was the same as posted on the
    // Queue
    assertEquals(mqMessage, recvdFromMq);

    resourceImpl.mqDisconnectEvent();
    // Have a rest to let all the services shut down up properly
    try {
      Thread.sleep(2000);
      channel.queuePurge(intTestQueue);
    } catch (Exception ex) {
      // Bit of housekeeping
    }
  }
  @Test
  public void testConnectedDisconnectedEvents() {
    // Instantiate the resource
    ResourceImpl resourceImpl = new ResourceImpl(restItem);

    try {
      channel.queueDeclare(intTestQueue, false, false, false, null);
    } catch (Exception ex) {
      fail("Connectivity error to MQ while running Test" + ex);
      try {
        channel.close();
        connection.close();
      } catch (Exception otherEx) {
        fail(
            "Error while closing MQ channle, may have been closed alreadyConnectivity error to MQ while running Test"
                + ex);
      }
    }

    // 1st test: We should, at this stage not received a ConnectedEvent yet
    assertFalse(connectedEventCalled);

    // Here we build the queue ResourceImpl is going to connect to and we
    // will later publish to
    try {
      resourceImpl.startStreaming(createListeners());
    } catch (Exception ex) {
      fail("Error while starting streaming: " + ex);
    }

    // Have a rest to let all the services start up properly
    try {
      Thread.sleep(5000);
    } catch (Exception ex) {
      // Cleaning a queue gave us problems? yikes!
    }

    // 2nd test: did we get a callback on ConnectedEvent (Connected to MQ) ?
    assertTrue(connectedEventCalled);

    // 3rd test: We should, at this stage not received a DisconnectedEvent
    // yet
    assertFalse(disconnectedEventCalled);

    resourceImpl.mqDisconnectEvent();
    // Have a rest to let all the services shut down up properly
    try {
      Thread.sleep(2000);
      channel.queuePurge(intTestQueue);
    } catch (Exception ex) {
      // Bit of housekeeping
    }

    // 4th test: did we get a callback on DisconnectedEvent (Disconnected
    // from MQ) ?
    assertTrue(disconnectedEventCalled);
  }
  @Test
  public void testDisconnectViaExceeded() {
    // Make the test run a little faster
    SystemProperties.setProperty("ss.echo_sender_interval", "1");
    SystemProperties.setProperty("ss.echo_max_missed_echos", "2");
    // Instatiate the resource
    ResourceImpl resourceImpl = new ResourceImpl(restItem);

    try {
      channel.queueDeclare(intTestQueue, false, false, false, null);
    } catch (Exception ex) {
      fail("Connectivity error to MQ while running Test" + ex);
      try {
        channel.close();
        connection.close();
      } catch (Exception otherEx) {
        // We couldn't close a connection that's already closed or
        // hasn't been open...
      }
    }

    // Here we build the queue ResourceImpl is going to connect to and we
    // will later publish to
    try {
      resourceImpl.startStreaming(createListeners());
    } catch (Exception ex) {
      fail("Error while starting streaming service: " + ex);
    }

    // Have a rest to let the echo count expire
    try {
      Thread.sleep(30000);
    } catch (Exception ex) {
      fail("Interrupted sleep cycle" + ex);
    }
    // 1st test: did the echo count get increased by the batch echo sends?
    assertTrue(disconnectedEventCalled);

    try {
      channel.queuePurge(resourceId);
      channel.close();
      connection.close();
    } catch (Exception otherEx) {
      // We couldn't close a connection that's already closed or hasn't
      // been open...
    }
  }