public static void validateKerberosPrincipal(
      KerberosPrincipal kerberosPrincipal) throws IOException {
    if (!StringUtils.isEmpty(kerberosPrincipal.getPrincipalName())) {
      if (!kerberosPrincipal.getPrincipalName().contains("/")) {
        throw new IllegalArgumentException(String.format(
            RestApiErrorMessages.ERROR_KERBEROS_PRINCIPAL_NAME_FORMAT,
            kerberosPrincipal.getPrincipalName()));
      }
    }
  }
@Test
  public void testKerberosPrincipalNameFormat() throws IOException {
    Service app = createValidApplication("comp-a");
    KerberosPrincipal kp = new KerberosPrincipal();
    kp.setPrincipalName("user@domain.com");
    app.setKerberosPrincipal(kp);

    try {
      ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal());
      Assert.fail(EXCEPTION_PREFIX + "service with invalid principal name " +
          "format.");
    } catch (IllegalArgumentException e) {
      assertEquals(
          String.format(
              RestApiErrorMessages.ERROR_KERBEROS_PRINCIPAL_NAME_FORMAT,
              kp.getPrincipalName()),
          e.getMessage());
    }

    kp.setPrincipalName("user/_HOST@domain.com");
    try {
      ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal());
    } catch (IllegalArgumentException e) {
      Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage());
    }

    kp.setPrincipalName(null);
    kp.setKeytab(null);
    try {
      ServiceApiUtil.validateKerberosPrincipal(app.getKerberosPrincipal());
    } catch (NullPointerException e) {
        Assert.fail(NO_EXCEPTION_PREFIX + e.getMessage());
    }
  }