aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/testng/remote/strprotocol/SuiteMessage.java
blob: f568f957a8be028067f290d791ef704e54818884 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package org.testng.remote.strprotocol;

import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.testng.ISuite;
import org.testng.ITestNGMethod;
import org.testng.collections.Lists;
import org.testng.collections.Maps;


/**
 * A <code>IStringMessage</code> implementation for suite running events.
 *
 * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
 */
public class SuiteMessage implements IStringMessage {
  protected final String m_suiteName;
  protected final int m_testMethodCount;
  protected final boolean m_startSuite;
  private List<String> m_excludedMethods = Lists.newArrayList();
  private Map<String, String> m_descriptions;

  public SuiteMessage(final String suiteName, final boolean startSuiteRun, final int methodCount) {
    m_suiteName = suiteName;
    m_startSuite = startSuiteRun;
    m_testMethodCount = methodCount;
  }

  public SuiteMessage(final ISuite suite, final boolean startSuiteRun) {
    m_suiteName = suite.getName();
    m_testMethodCount =suite.getInvokedMethods().size();
    m_startSuite = startSuiteRun;
    Collection<ITestNGMethod> excludedMethods = suite.getExcludedMethods();
    if (excludedMethods != null && excludedMethods.size() > 0) {
      m_excludedMethods = Lists.newArrayList();
      m_descriptions = Maps.newHashMap();
      for (ITestNGMethod m : excludedMethods) {
        String methodName = m.getTestClass().getName() + "." + m.getMethodName();
        m_excludedMethods.add(methodName);
        if (m.getDescription() != null) m_descriptions.put(methodName, m.getDescription());
      }
    }
  }

  public void setExcludedMethods(List<String> methods) {
    m_excludedMethods = Lists.newArrayList();
    m_excludedMethods.addAll(methods);
  }

  public List<String> getExcludedMethods() {
    return m_excludedMethods;
  }

  public String getDescriptionForMethod(String methodName) {
    return m_descriptions.get(methodName);
  }

  public boolean isMessageOnStart() {
    return m_startSuite;
  }

  public String getSuiteName() {
    return m_suiteName;
  }

  public int getTestMethodCount() {
    return m_testMethodCount;
  }

  @Override
  public String getMessageAsString() {
    StringBuffer buf = new StringBuffer();

    buf.append(m_startSuite ? MessageHelper.SUITE_START : MessageHelper.SUITE_FINISH)
        .append(MessageHelper.DELIMITER)
        .append(m_suiteName)
        .append(MessageHelper.DELIMITER)
        .append(m_testMethodCount)
        ;

    if (m_excludedMethods != null && m_excludedMethods.size() > 0) {
      buf.append(MessageHelper.DELIMITER);
      buf.append(m_excludedMethods.size());
      for (String method : m_excludedMethods) {
        buf.append(MessageHelper.DELIMITER);
        buf.append(method);
      }
    }
    return buf.toString();
  }

  @Override
  public String toString() {
    return "[SuiteMessage suite:" + m_suiteName
        + (m_startSuite ? " starting" : " ending")
        + " methodCount:" + m_testMethodCount
        + "]";
  }

}