コード例 #1
0
  @Test(expected = AmcIllegalArgumentException.class)
  public void testUpdateConnectionAlreadyExists() throws Exception {
    logger.entry("\n\ntestUpdateConnectionAlreadyExists");

    Appliance applianceConnection = new Appliance();
    applianceConnection.name = "wamcdp3";
    applianceConnection.hostName = "wamcdp3.hursley.ibm.com";
    applianceConnection.ampPort = 5550;
    applianceConnection.adminUserId = "admin";
    applianceConnection.adminUserPassword = "******";
    when(device.getSymbolicName()).thenReturn("wamcdp3");

    WamtAppliance appliance = new TestWamtAppliance(manager, applianceConnection);

    Appliance updatedConnection = new Appliance();
    updatedConnection.name = "wamcdp4";
    updatedConnection.hostName = "wamcdp4.hursley.ibm.com";
    updatedConnection.ampPort = 5551;
    updatedConnection.adminUserId = "admins";
    updatedConnection.adminUserPassword = "******";

    doThrow(new AlreadyExistsInRepositoryException()).when(device).setSymbolicName("wamcdp4");

    appliance.updateConnection(updatedConnection);

    logger.exit("testUpdateConnectionAlreadyExists");
  }
コード例 #2
0
  public void testUpdateConnection() throws Exception {
    logger.entry("\n\ntestUpdateConnection");

    Appliance applianceConnection = new Appliance();
    applianceConnection.name = "wamcdp3";
    applianceConnection.hostName = "wamcdp3.hursley.ibm.com";
    applianceConnection.ampPort = 5550;
    applianceConnection.adminUserId = "admin";
    applianceConnection.adminUserPassword = "******";
    when(device.getSymbolicName()).thenReturn("wamcdp3");

    WamtAppliance appliance = new TestWamtAppliance(manager, applianceConnection);

    Appliance updatedConnection = new Appliance();
    updatedConnection.name = "wamcdp4";
    updatedConnection.hostName = "wamcdp4.hursley.ibm.com";
    updatedConnection.ampPort = 5551;
    updatedConnection.adminUserId = "admins";
    updatedConnection.adminUserPassword = "******";
    when(device.getSymbolicName()).thenReturn("wamcdp4");

    appliance.updateConnection(updatedConnection);

    assertEquals("incorrect appliance name", "wamcdp4", appliance.getName());
    assertEquals("incorrect host name", "wamcdp4.hursley.ibm.com", appliance.getHostname());
    assertEquals("incorrect AMP port", "5551", appliance.getAmpPort());
    assertEquals("incorrect user ID", "admins", appliance.getUserId());

    logger.exit("testUpdateConnection");
  }
  @Override
  public Response toResponse(Throwable exception) {
    if (logger.isEntryEnabled()) logger.entry("toResponse", exception);

    // Notwithstanding the efforts below to only log genuine error conditions
    // in normal production use, unconditionally stacktrace all exceptions
    // if trace is on.
    if (logger.isDebugEnabled()) logger.stacktrace(exception);

    ResponseBuilder responseBuilder;

    /* check if this is our special case of a wrapped, checked exception */
    if (exception instanceof AmcRuntimeomiserException) {
      exception = ((AmcRuntimeomiserException) exception).getAmcException();
    }

    if (exception instanceof LocalizedException) {
      responseBuilder = Response.status(((LocalizedException) exception).getHttpStatusCode());
      responseBuilder.type(MediaType.APPLICATION_JSON_TYPE);
      responseBuilder.entity(new ExceptionResponse(exception));

      if (exception instanceof AmcRuntimeException
          && ((AmcRuntimeException) exception).getMessageCode().equals("CWZBA0504E")) {
        // Stacktrace if this exception didn't have a specific message.
        // Exceptions with messages represent exceptional conditions in
        // WAMC's environment (eg, appliance gone away) rather than
        // errors in WAMC itself, and they generally don't require a
        // stacktrace to figure out what happened.
        logError(exception.getCause() == null ? exception : exception.getCause());
      }
    } else {
      responseBuilder = Response.status(Status.INTERNAL_SERVER_ERROR);
      responseBuilder.type(MediaType.APPLICATION_JSON_TYPE);
      final String message =
          (exception.getLocalizedMessage() == null)
              ? exception.getClass().getCanonicalName()
              : exception.getClass().getName() + ": " + exception.getLocalizedMessage();
      responseBuilder.entity(
          new ExceptionResponse(
              SecurityContext.getContext().getUser(),
              new Date(),
              "CWZBA0504E_UNEXPECTED_ERROR",
              message));

      // Always stacktrace un-wrapped exceptions, as they always represent
      // an unexpected error.
      logError(exception);
    }

    Response response = responseBuilder.build();

    if (logger.isEntryEnabled()) logger.exit("toResponse", response);
    return response;
  }
コード例 #4
0
  @Test(expected = AmcIllegalArgumentException.class)
  public void testAddApplianceAlreadyExists() throws ApplianceConnectionException {
    logger.entry("\n\ntestAddApplianceAlreadyExists");

    Appliance applianceConnection = new Appliance();
    applianceConnection.name = "dp3";
    applianceConnection.hostName = "wamcdp3.hursley.ibm.com";
    applianceConnection.ampPort = 5550;
    applianceConnection.adminUserId = "admin";
    applianceConnection.adminUserPassword = "******";

    new TestWamtAppliance(manager, applianceConnection);

    logger.exit("testAddApplianceAlreadyExists");
  }
コード例 #5
0
  @Test(expected = InvalidCredentialsException.class)
  public void testAddApplianceBadUsername() throws ApplianceConnectionException {
    logger.entry("\n\ntestAddApplianceBadUsername");

    Appliance applianceConnection = new Appliance();
    applianceConnection.name = "wamcdp5";
    applianceConnection.hostName = "wamcdp5.hursley.ibm.com";
    applianceConnection.ampPort = 5550;
    applianceConnection.adminUserId = "notright";
    applianceConnection.adminUserPassword = "******";

    new TestWamtAppliance(manager, applianceConnection);

    logger.exit("testAddApplianceBadUsername");
  }
コード例 #6
0
  @Test(expected = ApplianceConnectionException.class)
  public void testAddApplianceBadConnectionDetails() throws ApplianceConnectionException {
    logger.entry("\n\ntestAddApplianceBadConnectionDetails");

    Appliance applianceConnection = new Appliance();
    applianceConnection.name = "wamcdp5";
    applianceConnection.hostName = "blurb";
    applianceConnection.ampPort = 5550;
    applianceConnection.adminUserId = "admin";
    applianceConnection.adminUserPassword = "******";

    new TestWamtAppliance(manager, applianceConnection);

    logger.exit("testAddApplianceBadConnectionDetails");
  }
コード例 #7
0
  @Test
  public void testAddAppliance() throws Exception {
    logger.entry("\n\ntestAddAppliance");

    Appliance applianceConnection = new Appliance();
    applianceConnection.name = "wamcdp3";
    applianceConnection.hostName = "wamcdp3.hursley.ibm.com";
    applianceConnection.ampPort = 5550;
    applianceConnection.adminUserId = "admin";
    applianceConnection.adminUserPassword = "******";
    when(device.getSymbolicName()).thenReturn("wamcdp3");

    WamtAppliance appliance = new TestWamtAppliance(manager, applianceConnection);

    assertEquals("incorrect appliance name", "wamcdp3", appliance.getName());

    logger.exit("testAddAppliance");
  }