/** Tests for receiving authorization requests */
  public void postTestReceiveAuthorizatinonRequest() {
    logger.debug("Testing receive of authorization request!");

    // set first response isAccepted and responseString
    // the first authorization process is negative
    // the agent try to add us to his contact list and ask us for
    // authorization but we deny him
    String firstRequestResponse = "First Request will be denied!!!";
    authEventCollector.responseToRequest =
        new AuthorizationResponse(AuthorizationResponse.REJECT, firstRequestResponse);
    logger.debug("authEventCollector " + authEventCollector);
    authEventCollector.isAuthorizationRequestReceived = false;
    authEventCollector.authorizationRequestReason = null;
    fixture.testerAgent.getAuthCmdFactory().requestReasonStr = "Deny my first request!";
    fixture.testerAgent.getAuthCmdFactory().isErrorAddingReceived = false;
    fixture.testerAgent.getAuthCmdFactory().responseReasonStr = null;
    fixture.testerAgent.getAuthCmdFactory().isRequestAccepted = false;

    // be sure buddy is not already in the list
    fixture.testerAgent.deleteBuddy(fixture.ourUserID);
    fixture.testerAgent.addBuddy(fixture.ourUserID);

    // wait agent to receive error and to request us for our authorization
    authEventCollector.waitForAuthRequest(25000);

    // check have we received authorization request?
    assertTrue(
        "Error adding buddy not recieved or the buddy("
            + fixture.ourUserID
            + ") doesn't require authorization 1",
        fixture.testerAgent.getAuthCmdFactory().isErrorAddingReceived);

    assertTrue(
        "We haven't received any authorization request ",
        authEventCollector.isAuthorizationRequestReceived);

    assertNotNull(
        "We haven't received any reason for authorization",
        authEventCollector.authorizationRequestReason);

    assertEquals(
        "Error sent request reason is not as the received one",
        fixture.testerAgent.getAuthCmdFactory().requestReasonStr,
        authEventCollector.authorizationRequestReason);

    // wait agent to receive our response
    Object lock = new Object();
    synchronized (lock) {
      try {
        lock.wait(5000);
      } catch (Exception ex) {
      }
    }

    // check is correct - the received response from the agent
    assertNotNull(
        "Agent haven't received any reason from authorization reply",
        authEventCollector.authorizationRequestReason);

    assertEquals(
        "Received auth response from agent is not as the sent one",
        fixture.testerAgent.getAuthCmdFactory().responseReasonStr,
        firstRequestResponse);

    boolean isAcceptedAuthReuest =
        authEventCollector.responseToRequest.getResponseCode().equals(AuthorizationResponse.ACCEPT);
    assertEquals(
        "Agent received Response is not as the sent one",
        fixture.testerAgent.getAuthCmdFactory().isRequestAccepted,
        isAcceptedAuthReuest);

    // delete us from his list
    // be sure buddy is not already in the list
    fixture.testerAgent.deleteBuddy(fixture.ourUserID);

    // set second response isAccepted and responseString
    // the second test is the same as first, but this time we accept
    // the request and check that everything is OK.
    String secondRequestResponse = "Second Request will be accepted!!!";
    authEventCollector.responseToRequest =
        new AuthorizationResponse(AuthorizationResponse.ACCEPT, secondRequestResponse);
    authEventCollector.isAuthorizationRequestReceived = false;
    authEventCollector.authorizationRequestReason = null;
    fixture.testerAgent.getAuthCmdFactory().requestReasonStr = "Accept my second request!";
    fixture.testerAgent.getAuthCmdFactory().isErrorAddingReceived = false;
    fixture.testerAgent.getAuthCmdFactory().responseReasonStr = null;
    fixture.testerAgent.getAuthCmdFactory().isRequestAccepted = false;

    // add us to his list again
    fixture.testerAgent.addBuddy(fixture.ourUserID);

    // wait agent to receive error and to request us for our authorization
    authEventCollector.waitForAuthRequest(25000);

    // check have we received authorization request?
    assertTrue(
        "Error adding buddy not recieved or the buddy("
            + fixture.ourUserID
            + ") doesn't require authorization 2",
        fixture.testerAgent.getAuthCmdFactory().isErrorAddingReceived);

    assertTrue(
        "We haven't received any authorization request ",
        authEventCollector.isAuthorizationRequestReceived);

    assertNotNull(
        "We haven't received any reason for authorization",
        authEventCollector.authorizationRequestReason);

    assertEquals(
        "Error sent request reason is not as the received one",
        fixture.testerAgent.getAuthCmdFactory().requestReasonStr,
        authEventCollector.authorizationRequestReason);
    // wait agent to receive our response
    synchronized (lock) {
      try {
        lock.wait(5000);
      } catch (Exception ex) {
      }
    }
    // check is correct the received response from the agent
    assertNotNull(
        "Agent haven't received any reason from authorization reply",
        authEventCollector.authorizationRequestReason);

    assertEquals(
        "Received auth response from agent is not as the sent one",
        fixture.testerAgent.getAuthCmdFactory().responseReasonStr,
        secondRequestResponse);

    isAcceptedAuthReuest =
        authEventCollector.responseToRequest.getResponseCode().equals(AuthorizationResponse.ACCEPT);
    assertEquals(
        "Agent received Response is not as the sent one",
        fixture.testerAgent.getAuthCmdFactory().isRequestAccepted,
        isAcceptedAuthReuest);
  }