<commit_before>package hudson.plugins.plot;

import hudson.FilePath;
import hudson.plugins.plot.PlotPoint;
import hudson.plugins.plot.XMLSeries;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;

/**
 * Test an XML series.
 *
 * @author <NAME>
 *
 */
public class XMLSeriesTest extends SeriesTestCase {
    private static final String TEST_XML_FILE = "test.xml";
    private static final String TEST2_XML_FILE = "test2.xml";
    private static final String TEST3_XML_FILE = "test3.xml";

    private File workspaceDirFile;
    private FilePath workspaceRootDir;

    @Before
    public void setUp() {
        // first create a FilePath to load the test Properties file.
        workspaceDirFile = new File("target/test-classes/");
        workspaceRootDir = new FilePath(workspaceDirFile);
    }

    @After
    public void tearDown() {
        workspaceRootDir = null;
        workspaceDirFile = null;
    }

    public void testXMLSeries_WhenNodesSharingAParentHaveOneStringAndOneNumericContent_ThenCoalesceNodesToPointLabelledWithStringContent() {

        // Create a new XML series.
        String xpath = "//UIAction/name|//UIAction/numCalls";
        XMLSeries series = new XMLSeries(TEST2_XML_FILE, xpath, "NODESET", null);

        // test the basic subclass properties.
        testSeries(series, TEST2_XML_FILE, "", "xml");

        // load the series.
        List<PlotPoint> points = series.loadSeries(workspaceRootDir, 0,
                System.out);
        assertNotNull(points);
        assertEquals(4, points.size());
        Map<String, Double> map = new HashMap<String, Double>();
        for (int i = 0; i < points.size(); i++) {
            map.put(points.get(i).getLabel(),
                    Double.parseDouble(points.get(i).getYvalue()));
        }

        assertEquals(7, map.get("AxTermDataService.updateItem").intValue());
        assertEquals(2, map.get("AxTermDataService.createEntity").intValue());
        testPlotPoints(points, 4);
    }

    public void testXMLSeries_WhenNodesHaveNoContent_ThenCoalesceForAttributes() {
        // Create a new XML series.
        String xpath = "//testcase[@name='testOne'] | //testcase[@name='testTwo'] | //testcase[@name='testThree']";

        XMLSeries series = new XMLSeries(TEST_XML_FILE, xpath, "NODESET", null);

        // test the basic subclass properties.
        testSeries(series, TEST_XML_FILE, "", "xml");

        // load the series.
        List<PlotPoint> points = series.loadSeries(workspaceRootDir, 0,
                System.out);
        assertNotNull(points);
        assertEquals(points.size(), 3);
        assertEquals(points.get(0).getLabel(), "testOne");
        assertEquals(points.get(1).getLabel(), "testTwo");
        assertEquals(points.get(2).getLabel(), "testThree");
        testPlotPoints(points, 3);
    }
<commit_msg>XMLSeriesTest: Use a "foreach"-style loop<commit_after>package hudson.plugins.plot;

import hudson.FilePath;
import hudson.plugins.plot.PlotPoint;
import hudson.plugins.plot.XMLSeries;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;

/**
 * Test an XML series.
 *
 * @author <NAME>
 *
 */
public class XMLSeriesTest extends SeriesTestCase {
    private static final String TEST_XML_FILE = "test.xml";
    private static final String TEST2_XML_FILE = "test2.xml";
    private static final String TEST3_XML_FILE = "test3.xml";

    private File workspaceDirFile;
    private FilePath workspaceRootDir;

    @Before
    public void setUp() {
        // first create a FilePath to load the test Properties file.
        workspaceDirFile = new File("target/test-classes/");
        workspaceRootDir = new FilePath(workspaceDirFile);
    }

    @After
    public void tearDown() {
        workspaceRootDir = null;
        workspaceDirFile = null;
    }

    public void testXMLSeries_WhenNodesSharingAParentHaveOneStringAndOneNumericContent_ThenCoalesceNodesToPointLabelledWithStringContent() {

        // Create a new XML series.
        String xpath = "//UIAction/name|//UIAction/numCalls";
        XMLSeries series = new XMLSeries(TEST2_XML_FILE, xpath, "NODESET", null);

        // test the basic subclass properties.
        testSeries(series, TEST2_XML_FILE, "", "xml");

        // load the series.
        List<PlotPoint> points = series.loadSeries(workspaceRootDir, 0,
                System.out);
        assertNotNull(points);
        assertEquals(4, points.size());
        Map<String, Double> map = new HashMap<String, Double>();
        for (PlotPoint point : points) {
            map.put(point.getLabel(),
                    Double.parseDouble(point.getYvalue()));
        }

        assertEquals(7, map.get("AxTermDataService.updateItem").intValue());
        assertEquals(2, map.get("AxTermDataService.createEntity").intValue());
        testPlotPoints(points, 4);
    }

    public void testXMLSeries_WhenNodesHaveNoContent_ThenCoalesceForAttributes() {
        // Create a new XML series.
        String xpath = "//testcase[@name='testOne'] | //testcase[@name='testTwo'] | //testcase[@name='testThree']";

        XMLSeries series = new XMLSeries(TEST_XML_FILE, xpath, "NODESET", null);

        // test the basic subclass properties.
        testSeries(series, TEST_XML_FILE, "", "xml");

        // load the series.
        List<PlotPoint> points = series.loadSeries(workspaceRootDir, 0,
                System.out);
        assertNotNull(points);
        assertEquals(points.size(), 3);
        assertEquals(points.get(0).getLabel(), "testOne");
        assertEquals(points.get(1).getLabel(), "testTwo");
        assertEquals(points.get(2).getLabel(), "testThree");
        testPlotPoints(points, 3);
    }

{'fraction_non_alphanumeric': 0.11916482770327619, 'fraction_numerical': 0.005941266338482431, 'mean_word_length': 3.021843003412969, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7482508', 'n_tokens_mistral': 1735, 'n_tokens_neox': 1685, 'n_words': 381}