public static void main(String[] args) {

    Thread threads[];

    int numThreads = 1;
    String numThreadsString =
        System.getProperty(BaseTestJAXBTranslator.class.getName() + ".threads");
    if (numThreadsString != null) {

      numThreads = Integer.parseInt(numThreadsString);
    }

    threads = new Thread[numThreads];

    for (int i = 0; i < threads.length; ++i) {

      threads[i] = new Thread(new BaseTestJAXBTranslator());
    }

    for (int i = 0; i < threads.length; ++i) {

      threads[i].start();
    }

    for (int i = 0; i < threads.length; ++i) {
      try {
        threads[i].join();

      } catch (InterruptedException e) {

        LOG.info("Thread " + i + " interrupted; will wait for remaining threads.", e);
      }
    }

    String statsReport = statisticsBean.createCSVReport();
    System.out.println(statsReport);
  }
  public void doTest() throws FileNotFoundException, ToolkitException {

    String sampleFilesDirectory =
        System.getProperty(
            BaseTestJAXBTranslator.class.getName() + ".sampleFilesDir",
            "src/test/data/sampleMessages");
    if (sampleFilesDirectory == null) {
      Assert.fail(
          "Test failed because system property "
              + BaseTestJAXBTranslator.class.getName()
              + ".sampleFilesDir was not set. It must be set to a directory containing sample NCIP messages.");
    }

    String fileNamesPattern =
        System.getProperty(
            BaseTestJAXBTranslator.class.getName() + ".fileNamesPattern",
            DEFAULT_FILENAMES_PATTERN);

    String fileNamesToOmitPattern =
        System.getProperty(
            BaseTestJAXBTranslator.class.getName() + ".fileNamesToOmitPattern",
            DEFAULT_FILENAMES_TO_OMIT_PATTERN);

    int iterations = 1;

    String iterationsString =
        System.getProperty(BaseTestJAXBTranslator.class.getName() + ".iterations");
    if (iterationsString != null) {

      iterations = Integer.parseInt(iterationsString);
    }

    File dir = new File(sampleFilesDirectory);

    FileFilter fileFilter =
        new FileFilter() {
          public boolean accept(File file) {
            return file.isFile();
          }
        };

    StringBuilder failuresList = new StringBuilder();
    File[] files = dir.listFiles(fileFilter);
    long initTranslateStreamToSvcElapsedTime = 0;
    long respTranslateStreamToSvcElapsedTime = 0;
    long initTranslateSvcToStreamElapsedTime = 0;
    long respTranslateSvcToStreamElapsedTime = 0;
    long initMsgStreamToSvcCount = 0;
    long respMsgStreamToSvcCount = 0;
    long initMsgSvcToStreamCount = 0;
    long respMsgSvcToStreamCount = 0;

    if (files != null) {

      long startTime = 0;
      long endTime = 0;

      for (int iteration = 0; iteration < iterations; ++iteration) {

        for (File file : files) {

          String fileName = file.getName();

          if ((fileNamesPattern == null
                  || fileNamesPattern.length() == 0
                  || fileName.matches(fileNamesPattern))
              && (fileNamesToOmitPattern == null
                  || fileNamesToOmitPattern.length() == 0
                  || !fileName.matches(fileNamesToOmitPattern))) {

            InputStream inStream = new FileInputStream(file);

            LOG.info("Testing " + fileName);

            ServiceContext serviceContext = serviceValidator.getInitialServiceContext();

            if (fileName.contains("Response")) {

              try {

                startTime = System.currentTimeMillis();

                NCIPResponseData responseData =
                    translator.createResponseData(serviceContext, inStream);

                endTime = System.currentTimeMillis();
                respTranslateStreamToSvcElapsedTime += (endTime - startTime);
                respMsgStreamToSvcCount++;

                Assert.assertNotNull(
                    "createResponseData returned null for " + fileName + ".", responseData);

                if (responseData != null) {

                  try {

                    startTime = System.currentTimeMillis();

                    InputStream responseStream =
                        translator.createResponseMessageStream(serviceContext, responseData);

                    endTime = System.currentTimeMillis();
                    respTranslateSvcToStreamElapsedTime += (endTime - startTime);
                    respMsgSvcToStreamCount++;

                    Assert.assertNotNull(responseStream);

                    if (performXMLDiff) {

                      performXMLDiff(responseStream, failuresList, file);
                    }

                  } catch (ServiceException e) {

                    LOG.debug(
                        "Exception in createResponseMessageStream for '" + fileName + "'.", e);
                    failuresList.append(
                        collectException("createResponseMessageStream", fileName, e));

                  } catch (ValidationException e) {

                    LOG.debug(
                        "Exception in createResponseMessageStream for '" + fileName + "'.", e);
                    failuresList.append(
                        collectException("createResponseMessageStream", fileName, e));
                  }
                }

              } catch (ServiceException e) {

                LOG.debug("Exception in createResponseData for '" + fileName + "'.", e);
                failuresList.append(collectException("createResponseData", fileName, e));

              } catch (ValidationException e) {

                LOG.debug("Exception in createResponseData for '" + fileName + "'.", e);
                failuresList.append(collectException("createResponseData", fileName, e));
              }

            } else {

              try {

                startTime = System.currentTimeMillis();

                NCIPInitiationData initiationData =
                    translator.createInitiationData(serviceContext, inStream);

                endTime = System.currentTimeMillis();
                initTranslateStreamToSvcElapsedTime += (endTime - startTime);
                initMsgStreamToSvcCount++;

                Assert.assertNotNull(
                    "createInitiationData returned null for " + fileName + ".", initiationData);

                if (initiationData != null) {

                  try {

                    startTime = System.currentTimeMillis();

                    InputStream initiationStream =
                        translator.createInitiationMessageStream(serviceContext, initiationData);

                    Assert.assertNotNull(initiationStream);

                    endTime = System.currentTimeMillis();
                    initTranslateSvcToStreamElapsedTime += (endTime - startTime);
                    initMsgSvcToStreamCount++;

                    if (performXMLDiff) {

                      performXMLDiff(initiationStream, failuresList, file);
                    }

                  } catch (ServiceException e) {

                    LOG.debug(
                        "Exception in createInitiationMessageStream for '" + fileName + "'.", e);
                    failuresList.append(
                        collectException("createInitiationMessageStream", fileName, e));

                  } catch (ValidationException e) {

                    LOG.debug(
                        "Exception in createInitiationMessageStream for '" + fileName + "'.", e);
                    failuresList.append(
                        collectException("createInitiationMessageStream", fileName, e));
                  }
                }

              } catch (ServiceException e) {

                LOG.debug("Exception in createInitiationData for '" + fileName + "'.", e);
                failuresList.append(collectException("createInitiationData", fileName, e));

              } catch (ValidationException e) {

                LOG.debug("Exception in createInitiationData for '" + fileName + "'.", e);
                failuresList.append(collectException("createInitiationData", fileName, e));
              }
            }
          }
        }
      }

      Assert.assertTrue(
          "One or more messages failed:" + System.getProperty("line.separator") + failuresList,
          failuresList.length() == 0);

    } else {
      Assert.fail(
          "No files were found in "
              + sampleFilesDirectory
              + ". Note: do not include a trailing slash in the path."
              + "Working directory: "
              + System.getProperty("user.dir"));
    }

    LOG.info(
        "Elapsed time for translating stream-to-service for initiation messages: "
            + initTranslateStreamToSvcElapsedTime
            + " for "
            + initMsgStreamToSvcCount
            + " messages; average "
            + computeAverage(initTranslateStreamToSvcElapsedTime, initMsgStreamToSvcCount));
    LOG.info(
        "Elapsed time for translating stream-to-service for response messages: "
            + respTranslateStreamToSvcElapsedTime
            + " for "
            + respMsgStreamToSvcCount
            + " messages; average "
            + computeAverage(respTranslateStreamToSvcElapsedTime, respMsgStreamToSvcCount));
    LOG.info(
        "Elapsed time for translating service-to-stream for initiation messages: "
            + initTranslateSvcToStreamElapsedTime
            + " for "
            + initMsgSvcToStreamCount
            + " messages; average "
            + computeAverage(initTranslateSvcToStreamElapsedTime, initMsgSvcToStreamCount));
    LOG.info(
        "Elapsed time for translating service-to-stream for response messages: "
            + respTranslateSvcToStreamElapsedTime
            + " for "
            + respMsgSvcToStreamCount
            + " messages; average "
            + computeAverage(respTranslateSvcToStreamElapsedTime, respMsgSvcToStreamCount));

    String statsReport = statisticsBean.createCSVReport();
    System.out.println(statsReport);
  }