// Path: src/main/java/com/lazerycode/jmeter/results/ResultScanner.java
// public class ResultScanner implements IResultScanner {
//     private static final Logger LOGGER = LoggerFactory.getLogger(ResultScanner.class);
//     private static final String XML_REQUEST_FAILURE_PATTERN = "s=\"false\"";
//     private static final String XML_REQUEST_SUCCESS_PATTERN = "s=\"true\"";
//     private final boolean countFailures;
//     private final boolean countSuccesses;
//     private final boolean onlyFailWhenMatchingFailureMessage;
//     private final boolean csv;
//     private final List<String> failureMessages;
//     private int successCount = 0;
//     private int failureCount = 0;
//     private int customFailureCount = 0;
// 
//     public ResultScanner(boolean countSuccesses, boolean countFailures, boolean isCsv, boolean onlyFailWhenMatchingFailureMessage, List<String> failureMessages) {
//         this.csv = isCsv;
//         this.countFailures = countFailures;
//         this.countSuccesses = countSuccesses;
//         this.onlyFailWhenMatchingFailureMessage = onlyFailWhenMatchingFailureMessage;
//         this.failureMessages = failureMessages;
//     }
// 
//     /**
//      * Work out how to parse the file (if at all)
//      *
//      * @param file File to parse
//      * @throws MojoExecutionException MojoExecutionException
//      */
//     public void parseResultFile(File file) throws MojoExecutionException {
//         if (!file.exists()) {
//             throw new MojoExecutionException("Unable to find " + file.getAbsolutePath());
//         }
//         LOGGER.info(" ");
//         LOGGER.info("Parsing results file '{}' as type: {}", file, this.csv ? "CSV" : "XML");
//         if (csv) {
//             CSVScanResult csvScanResult = CSVFileScanner.scanCsvForValues(file, failureMessages);
//             successCount = csvScanResult.getSuccessCount();
//             failureCount = csvScanResult.getFailureCount();
//             for (Map.Entry<String, Integer> entry : csvScanResult.getSpecificFailureMessages().entrySet()) {
//                 customFailureCount = customFailureCount + entry.getValue();
//                 LOGGER.info("Number of potential custom failures using '{}' in '{}': {}", entry.getKey(), file.getName(), customFailureCount);
//             }
//         } else {
//             if (countSuccesses) {
//                 successCount = scanXmlFileForPattern(file, Pattern.compile(XML_REQUEST_SUCCESS_PATTERN, Pattern.CASE_INSENSITIVE));
//             }
//             if (countFailures) {
//                 failureCount = scanXmlFileForPattern(file, Pattern.compile(XML_REQUEST_FAILURE_PATTERN, Pattern.CASE_INSENSITIVE));
//             }
//         }
//     }
// 
//     /**
//      * @return failureCount
//      */
//     @Override
//     public int getFailureCount() {
//         if (countFailures) {
//             if (onlyFailWhenMatchingFailureMessage) {
//                 return this.customFailureCount;
//             } else {
//                 return this.failureCount;
//             }
//         }
//         return 0;
//     }
// 
//     /**
//      * @return failureCount
//      */
//     @Override
//     public int getSuccessCount() {
//         if (countSuccesses) {
//             return this.successCount;
//         }
//         return 0;
//     }
// 
//     @Override
//     public int getTotalCount() {
//         return getSuccessCount() + getFailureCount();
//     }
// }


import com.lazerycode.jmeter.results.ResultScanner;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
package com.lazerycode.jmeter.testrunner;



public class BenchmarkResultScannerTest {

	/*
	All ignored by default

	These are here so we can perform benchmarks against the scanner code whenever we want to check it against an alternative implementation
	To create the data file you can use an NPM module called datagen:

		npm install -g datagen
		datagen init
		# Now populate generated filed as noted below
		datagen gen -s 10000000 -w 1 --out-file data1.xml

	Header:

		<?xml version="1.0" encoding="UTF-8"?>
		<testResults version="1.2">

	Footer:

		</testResults>

	Segment:

		<httpSample t="1187" lt="{segment_id}" ts="1133521593546" s="true" lb="/my_webapp/root/auth" rc="302" rm="Moved Temporarily" tn="Thread Group 1-1" dt="text"/>
		<httpSample t="16" lt="{segment_id}" ts="1133521593562" s="false" lb="/my_webapp/root/;jsessionid=xxx" rc="302" rm="Moved Temporarily" tn="Thread Group 1-1" dt="text"/>
	*/

    private static final boolean COUNT_FAILURES = true;
    private static final boolean DO_NOT_COUNT_FAILURES = false;
    private static final boolean COUNT_SUCCESSES = true;
    private static final boolean DO_NOT_COUNT_SUCCESSES = false;
    private static final boolean DEFAULT_IS_CSV = false;
    private static final boolean DEFAULT_ONLY_FAIL_WHEN_MATCHING_FAILURE_MESSAGES = false;
    private static final List<String> DEFAULT_FAILURE_LIST = new ArrayList<>();
    private static final String TEST_XML_FILE_LOCATION = "/Programming/OpenSource/jmeter-maven-plugin/data1.xml";

    @Ignore
    @Test
    public void countSuccessAndFailure() throws Exception {
        File resultsFile = new File(TEST_XML_FILE_LOCATION);
// Path: src/main/java/com/lazerycode/jmeter/results/ResultScanner.java
// public class ResultScanner implements IResultScanner {
//     private static final Logger LOGGER = LoggerFactory.getLogger(ResultScanner.class);
//     private static final String XML_REQUEST_FAILURE_PATTERN = "s=\"false\"";
//     private static final String XML_REQUEST_SUCCESS_PATTERN = "s=\"true\"";
//     private final boolean countFailures;
//     private final boolean countSuccesses;
//     private final boolean onlyFailWhenMatchingFailureMessage;
//     private final boolean csv;
//     private final List<String> failureMessages;
//     private int successCount = 0;
//     private int failureCount = 0;
//     private int customFailureCount = 0;
// 
//     public ResultScanner(boolean countSuccesses, boolean countFailures, boolean isCsv, boolean onlyFailWhenMatchingFailureMessage, List<String> failureMessages) {
//         this.csv = isCsv;
//         this.countFailures = countFailures;
//         this.countSuccesses = countSuccesses;
//         this.onlyFailWhenMatchingFailureMessage = onlyFailWhenMatchingFailureMessage;
//         this.failureMessages = failureMessages;
//     }
// 
//     /**
//      * Work out how to parse the file (if at all)
//      *
//      * @param file File to parse
//      * @throws MojoExecutionException MojoExecutionException
//      */
//     public void parseResultFile(File file) throws MojoExecutionException {
//         if (!file.exists()) {
//             throw new MojoExecutionException("Unable to find " + file.getAbsolutePath());
//         }
//         LOGGER.info(" ");
//         LOGGER.info("Parsing results file '{}' as type: {}", file, this.csv ? "CSV" : "XML");
//         if (csv) {
//             CSVScanResult csvScanResult = CSVFileScanner.scanCsvForValues(file, failureMessages);
//             successCount = csvScanResult.getSuccessCount();
//             failureCount = csvScanResult.getFailureCount();
//             for (Map.Entry<String, Integer> entry : csvScanResult.getSpecificFailureMessages().entrySet()) {
//                 customFailureCount = customFailureCount + entry.getValue();
//                 LOGGER.info("Number of potential custom failures using '{}' in '{}': {}", entry.getKey(), file.getName(), customFailureCount);
//             }
//         } else {
//             if (countSuccesses) {
//                 successCount = scanXmlFileForPattern(file, Pattern.compile(XML_REQUEST_SUCCESS_PATTERN, Pattern.CASE_INSENSITIVE));
//             }
//             if (countFailures) {
//                 failureCount = scanXmlFileForPattern(file, Pattern.compile(XML_REQUEST_FAILURE_PATTERN, Pattern.CASE_INSENSITIVE));
//             }
//         }
//     }
// 
//     /**
//      * @return failureCount
//      */
//     @Override
//     public int getFailureCount() {
//         if (countFailures) {
//             if (onlyFailWhenMatchingFailureMessage) {
//                 return this.customFailureCount;
//             } else {
//                 return this.failureCount;
//             }
//         }
//         return 0;
//     }
// 
//     /**
//      * @return failureCount
//      */
//     @Override
//     public int getSuccessCount() {
//         if (countSuccesses) {
//             return this.successCount;
//         }
//         return 0;
//     }
// 
//     @Override
//     public int getTotalCount() {
//         return getSuccessCount() + getFailureCount();
//     }
// }


// Path: src/test/java/com/lazerycode/jmeter/testrunner/BenchmarkResultScannerTest.java
import com.lazerycode.jmeter.results.ResultScanner;
import org.junit.Ignore;
import org.junit.Test;
import java.io.File;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

package com.lazerycode.jmeter.testrunner;



public class BenchmarkResultScannerTest {

	/*
	All ignored by default

	These are here so we can perform benchmarks against the scanner code whenever we want to check it against an alternative implementation
	To create the data file you can use an NPM module called datagen:

		npm install -g datagen
		datagen init
		# Now populate generated filed as noted below
		datagen gen -s 10000000 -w 1 --out-file data1.xml

	Header:

		<?xml version="1.0" encoding="UTF-8"?>
		<testResults version="1.2">

	Footer:

		</testResults>

	Segment:

		<httpSample t="1187" lt="{segment_id}" ts="1133521593546" s="true" lb="/my_webapp/root/auth" rc="302" rm="Moved Temporarily" tn="Thread Group 1-1" dt="text"/>
		<httpSample t="16" lt="{segment_id}" ts="1133521593562" s="false" lb="/my_webapp/root/;jsessionid=xxx" rc="302" rm="Moved Temporarily" tn="Thread Group 1-1" dt="text"/>
	*/

    private static final boolean COUNT_FAILURES = true;
    private static final boolean DO_NOT_COUNT_FAILURES = false;
    private static final boolean COUNT_SUCCESSES = true;
    private static final boolean DO_NOT_COUNT_SUCCESSES = false;
    private static final boolean DEFAULT_IS_CSV = false;
    private static final boolean DEFAULT_ONLY_FAIL_WHEN_MATCHING_FAILURE_MESSAGES = false;
    private static final List<String> DEFAULT_FAILURE_LIST = new ArrayList<>();
    private static final String TEST_XML_FILE_LOCATION = "/Programming/OpenSource/jmeter-maven-plugin/data1.xml";

    @Ignore
    @Test
    public void countSuccessAndFailure() throws Exception {
        File resultsFile = new File(TEST_XML_FILE_LOCATION);
        ResultScanner fileScanner = new ResultScanner(COUNT_SUCCESSES, COUNT_FAILURES, DEFAULT_IS_CSV, DEFAULT_ONLY_FAIL_WHEN_MATCHING_FAILURE_MESSAGES, DEFAULT_FAILURE_LIST);