예제 #1
0
 /**
  * Checks if there is the expected error message active for the given PM (incl. its sub-PMs).
  *
  * @param rootPm The root PM of the subtree to check the messages for.
  * @param expectedMsgInSubtree The expected message text in rootPm or any of its sub-PMs.
  * @deprecated Please use {@link _PmAssert.assertMessageText(PmObject rootPm, Severity
  *     minSeverity, String... expectedMessages)} instead.
  */
 @Deprecated
 public static void assertSingleErrorMessage(PmObject rootPm, String expectedMsgInSubtree) {
   List<PmMessage> errorMessages = PmMessageApi.getPmTreeMessages(rootPm, Severity.ERROR);
   assertEquals(
       "Error message expected but not found: " + expectedMsgInSubtree, 1, errorMessages.size());
   assertEquals(expectedMsgInSubtree, errorMessages.get(0).getTitle());
 }
예제 #2
0
 /**
  * Validates the PM tree having the given root instance. Fails if the subtree has any messages
  * after the validation call.
  *
  * @param rootPm The root of the PM tree to validate.
  */
 public static void validateSuccessful(PmObject rootPm) {
   if (!PmValidationApi.validateSubTree(rootPm)) {
     List<String> msgStrings = new ArrayList<String>();
     for (PmMessage m : PmMessageApi.getPmTreeMessages(rootPm, Severity.INFO)) {
       msgStrings.add(m.toString());
     }
     Assert.fail(
         "Unexpected messages after validation of "
             + rootPm.getPmRelativeName()
             + ":\n"
             + StringUtils.join(msgStrings.toArray(), "\n\t"));
   }
 }
예제 #3
0
 /**
  * Checks if a message text - severity combination exists for the given PM (incl. its sub-PMs).
  *
  * @param expectedMsgInSubtree The expected message text in rootPm or any of its sub-PMs.
  * @param severity The expected message severity.
  * @param rootPm The root PM of the subtree to check the messages for.
  */
 public static void assertMessage(
     String expectedMsgInSubtree, Severity severity, PmObject rootPm) {
   List<PmMessage> messages = PmMessageApi.getPmTreeMessages(rootPm, severity);
   List<String> messageStrings = new ArrayList<String>();
   for (PmMessage message : messages) {
     if (StringUtils.equals(expectedMsgInSubtree, message.getTitle())
         && message.getSeverity() == severity) {
       return;
     }
     messageStrings.add(message.getSeverity().name() + ": " + message.getTitle());
   }
   assertEquals(
       severity.name() + ": " + expectedMsgInSubtree, StringUtils.join(messageStrings, "\n"));
 }
예제 #4
0
 private static String subTreeMessagesToString(
     String msgPrefix, PmObject pm, Severity minSeverity) {
   List<PmMessage> mlist = PmMessageApi.getPmTreeMessages(pm, minSeverity);
   if (mlist.isEmpty()) {
     return "";
   } else {
     StringBuilder sb = new StringBuilder();
     for (PmMessage m : mlist) {
       if (sb.length() == 0) {
         sb.append("\n");
       }
       sb.append(m.getPm().getPmRelativeName()).append(": ").append(m).append("\n");
     }
     return StringUtils.defaultString(msgPrefix) + sb.toString();
   }
 }
예제 #5
0
  // @formatter:off
  public static void assertMessageText(
      PmObject rootPm, Severity minSeverity, String... expectedMessages) {
    List<PmMessage> messages = PmMessageApi.getPmTreeMessages(rootPm, minSeverity);
    if (messages.size() != expectedMessages.length) {
      StringBuilder sb =
          new StringBuilder(
              "Expected "
                  + expectedMessages.length
                  + " messages but found "
                  + messages.size()
                  + " messages."
                  + "\nFound messages: "
                  + messages
                  + "\nExpected messages: "
                  + Arrays.asList(expectedMessages)
                  + "\nPM context: "
                  + PmUtil.getAbsoluteName(rootPm));
      if (messages.size() > 0) {
        sb.append("\nFound message details:");
        for (PmMessage m : messages) {
          sb.append("\n\t" + getMessageTitlePrependByPmRelativeName(m));
        }
      }
      fail(sb.toString());
    }

    Set<String> expectedSet = new HashSet<String>(Arrays.asList(expectedMessages));
    for (PmMessage m : messages) {
      if (!expectedSet.contains(m.getTitle())
          && !expectedSet.contains(getMessageTitlePrependByPmRelativeName(m))) {
        fail(
            "Unexpected message found."
                + "\nFound messages: "
                + messages
                + "\nExpected messages: "
                + Arrays.asList(expectedMessages)
                + "\nPM context: "
                + PmUtil.getAbsoluteName(rootPm));
      }
    }
  }