/*
   * Deploys and starts a channel, sets the source respond-from name to
   * RESPONSE_SOURCE_TRANSFORMED, sends messages, and asserts that:
   * - Each response returned is TRANSFORMED
   * - TEST_SIZE messages are processed
   *
   * Then sets the source respond-from name to
   * RESPONSE_DESTINATIONS_COMPLETED, sends messages, and asserts that:
   * - Each response returned is SENT
   * - 2*TEST_SIZE messages are processed
   *
   * Then sets the source respond-from name to the destination name, sends
   * messages, and asserts that:
   * - Each response returned is SENT
   * - 3*TEST_SIZE messages are processed
   *
   * Then sets the source respond-from name to an invalid destination name,
   * sends messages, and asserts that:
   * - Each response returned is null
   * - 4*TEST_SIZE messages are processed
   */
  @Test
  public final void testGetResponse() throws Exception {
    String destinationName = TestUtils.DEFAULT_DESTINATION_NAME;
    TestChannel channel = (TestChannel) TestUtils.createDefaultChannel(channelId, serverId);
    TestSourceConnector sourceConnector = (TestSourceConnector) channel.getSourceConnector();
    Response response = null;

    channel.deploy();
    channel.start();

    channel
        .getResponseSelector()
        .setRespondFromName(ResponseConnectorProperties.RESPONSE_SOURCE_TRANSFORMED);

    for (int i = 0; i < TEST_SIZE; i++) {
      response = sourceConnector.readTestMessage(testMessage).getSelectedResponse();
      assertEquals(Status.TRANSFORMED, response.getStatus());
    }

    assertEquals(TEST_SIZE, channel.getNumMessages());

    channel
        .getResponseSelector()
        .setRespondFromName(ResponseConnectorProperties.RESPONSE_DESTINATIONS_COMPLETED);

    for (int i = 0; i < TEST_SIZE; i++) {
      response = sourceConnector.readTestMessage(testMessage).getSelectedResponse();
      assertEquals(Status.SENT, response.getStatus());
    }

    assertEquals(TEST_SIZE * 2, channel.getNumMessages());

    channel.getResponseSelector().setRespondFromName("d1");

    for (int i = 0; i < TEST_SIZE; i++) {
      response = sourceConnector.readTestMessage(testMessage).getSelectedResponse();
      assertEquals(Status.SENT, response.getStatus());
    }

    assertEquals(TEST_SIZE * 3, channel.getNumMessages());

    channel.getResponseSelector().setRespondFromName(destinationName + "lolwut");

    for (int i = 0; i < TEST_SIZE; i++) {
      response = sourceConnector.readTestMessage(testMessage).getSelectedResponse();
      assertEquals(null, response);
    }

    assertEquals(TEST_SIZE * 4, channel.getNumMessages());

    channel.stop();
    channel.undeploy();
  }
示例#2
0
  @Override
  public boolean equals(Object other) {
    if (other instanceof Response) {
      Response otherResponse = (Response) other;
      if (status == otherResponse.getStatus()
          && message.equals(otherResponse.getMessage())
          && statusMessage.equals(otherResponse.getStatusMessage())
          && error.equals(otherResponse.getError())) {
        return true;
      }
    }

    return false;
  }