• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.testng.remote.strprotocol;
2 
3 import java.util.Collection;
4 import java.util.List;
5 import java.util.Map;
6 
7 import org.testng.ISuite;
8 import org.testng.ITestNGMethod;
9 import org.testng.collections.Lists;
10 import org.testng.collections.Maps;
11 
12 
13 /**
14  * A <code>IStringMessage</code> implementation for suite running events.
15  *
16  * @author <a href='mailto:the_mindstorm[at]evolva[dot]ro'>Alexandru Popescu</a>
17  */
18 public class SuiteMessage implements IStringMessage {
19   private static final long serialVersionUID = -4298528261942620419L;
20   protected final String m_suiteName;
21   protected final int m_testMethodCount;
22   protected final boolean m_startSuite;
23   private List<String> m_excludedMethods = Lists.newArrayList();
24   private Map<String, String> m_descriptions;
25 
SuiteMessage(final String suiteName, final boolean startSuiteRun, final int methodCount)26   public SuiteMessage(final String suiteName, final boolean startSuiteRun, final int methodCount) {
27     m_suiteName = suiteName;
28     m_startSuite = startSuiteRun;
29     m_testMethodCount = methodCount;
30   }
31 
SuiteMessage(final ISuite suite, final boolean startSuiteRun)32   public SuiteMessage(final ISuite suite, final boolean startSuiteRun) {
33     m_suiteName = suite.getName();
34     m_testMethodCount =suite.getInvokedMethods().size();
35     m_startSuite = startSuiteRun;
36     Collection<ITestNGMethod> excludedMethods = suite.getExcludedMethods();
37     if (excludedMethods != null && excludedMethods.size() > 0) {
38       m_excludedMethods = Lists.newArrayList();
39       m_descriptions = Maps.newHashMap();
40       for (ITestNGMethod m : excludedMethods) {
41         String methodName = m.getTestClass().getName() + "." + m.getMethodName();
42         m_excludedMethods.add(methodName);
43         if (m.getDescription() != null) m_descriptions.put(methodName, m.getDescription());
44       }
45     }
46   }
47 
setExcludedMethods(List<String> methods)48   public void setExcludedMethods(List<String> methods) {
49     m_excludedMethods = Lists.newArrayList();
50     m_excludedMethods.addAll(methods);
51   }
52 
getExcludedMethods()53   public List<String> getExcludedMethods() {
54     return m_excludedMethods;
55   }
56 
getDescriptionForMethod(String methodName)57   public String getDescriptionForMethod(String methodName) {
58     return m_descriptions.get(methodName);
59   }
60 
isMessageOnStart()61   public boolean isMessageOnStart() {
62     return m_startSuite;
63   }
64 
getSuiteName()65   public String getSuiteName() {
66     return m_suiteName;
67   }
68 
getTestMethodCount()69   public int getTestMethodCount() {
70     return m_testMethodCount;
71   }
72 
73   @Override
getMessageAsString()74   public String getMessageAsString() {
75     StringBuffer buf = new StringBuffer();
76 
77     buf.append(m_startSuite ? MessageHelper.SUITE_START : MessageHelper.SUITE_FINISH)
78         .append(MessageHelper.DELIMITER)
79         .append(m_suiteName)
80         .append(MessageHelper.DELIMITER)
81         .append(m_testMethodCount)
82         ;
83 
84     if (m_excludedMethods != null && m_excludedMethods.size() > 0) {
85       buf.append(MessageHelper.DELIMITER);
86       buf.append(m_excludedMethods.size());
87       for (String method : m_excludedMethods) {
88         buf.append(MessageHelper.DELIMITER);
89         buf.append(method);
90       }
91     }
92     return buf.toString();
93   }
94 
95   @Override
toString()96   public String toString() {
97     return "[SuiteMessage suite:" + m_suiteName
98         + (m_startSuite ? " starting" : " ending")
99         + " methodCount:" + m_testMethodCount
100         + "]";
101   }
102 
103 }
104