package com.occamlab.te.spi.executors.testng;

import java.util.Map;
import org.testng.ISuite;
import org.testng.ISuiteListener;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

/**
 * A suite listener that adds the supplied test run arguments to the collection
 * of suite-level parameters. Since this listener is the first one to be
 * registered it will be called first and the parameters it sets should be
 * available to all subsequent listeners.
 */
class PrimarySuiteListener implements ISuiteListener {

    private Document testRunArgs;

    /**
     * Constructs the listener. The test run arguments are expected to be
     * contained in an XML properties document. If a property has multiple
     * values they must be separated with a comma.
     * 
     * @param testRunArgs
     *            A DOM Document node that contains a set of XML properties.
     * 
     * @see java.util.Properties#loadFromXML(java.io.InputStream) loadFromXML
     */
    PrimarySuiteListener(Document testRunArgs) {
        this.testRunArgs = testRunArgs;
    }

    @Override
    public void onStart(ISuite suite) {
        if (null == this.testRunArgs) {
            return;
        }
        Map<String, String> params = suite.getXmlSuite().getParameters();
        NodeList entries = testRunArgs.getElementsByTagName("entry");
        for (int i = 0; i < entries.getLength(); i++) {
            Element entry = (Element) entries.item(i);
            params.put(entry.getAttribute("key"), entry.getTextContent());
        }
    }

    @Override
    public void onFinish(ISuite suite) {
    }
}

@@ -65,16 +65,85 @@
 l.Map;%0D%0A
+import java.util.logging.Level;%0D%0Aimport java.util.logging.Logger;%0D%0A%0D%0A
 import o
@@ -161,16 +161,16 @@
 Suite;%0D%0A
-
 import o
@@ -625,24 +625,120 @@
 stener %7B%0D%0A%0D%0A
+    private final static Logger LOGR = Logger.getLogger(PrimarySuiteListener.class.getName());%0D%0A
     private 
@@ -1227,32 +1227,515 @@
 testRunArgs) %7B%0D%0A
+        LOGR.log(Level.FINE, %22Initializing PrimarySuiteListener...%22);%0D%0A        if (null == testRunArgs) %7B%0D%0A            throw new NullPointerException(%22Test run input is null%22);%0D%0A        %7D%0D%0A        NodeList entries = testRunArgs.getElementsByTagName(%22entry%22);%0D%0A        if (entries.getLength() == 0) %7B%0D%0A            throw new IllegalArgumentException(%0D%0A                    String.format(%22No test run arguments found in %25s%22, testRunArgs.getDocumentElement().getNodeName()));%0D%0A        %7D%0D%0A
         this.tes
@@ -1828,81 +1828,8 @@
  %7B%0D%0A
-        if (null == this.testRunArgs) %7B%0D%0A            return;%0D%0A        %7D%0D%0A
     
@@ -2099,68 +2099,302 @@
     
-params.put(entry.getAttribute(%22key%22), entry.getTextContent()
+String value = entry.getTextContent().trim();%0D%0A            if (value.isEmpty()) %7B%0D%0A                continue;%0D%0A            %7D%0D%0A            params.put(entry.getAttribute(%22key%22), value);%0D%0A            LOGR.log(Level.FINE, %22Added parameter: %7B0%7D=%7B1%7D%22, new Object%5B%5D %7B entry.getAttribute(%22key%22), value %7D
 );%0D%0A

Add logging messages (FINE)