public void addFailure(Test test, AssertionFailedError error) {
   message = error.getMessage();
   failCount++;
   status = FAIL;
   TestInfo testInfo = testMap.get(test);
   testInfo.addFailure(error);
   message = Messages.getInstance().getString("UI.USER_TEST_SUITE_FAILED"); // $NON-NLS-1$
 }
 public void addError(Test test, Throwable error) {
   message = error.getMessage();
   errorCount++;
   status = FAIL;
   TestInfo testInfo = testMap.get(test);
   testInfo.addError(error);
   message = Messages.getInstance().getString("UI.USER_TEST_SUITE_FAILED"); // $NON-NLS-1$
 }
 public TestInfo(Test test, SuiteInfo suiteInfo) {
   this.test = test;
   this.suiteInfo = suiteInfo;
   String testName = test.toString();
   testName = testName.substring(0, testName.indexOf('('));
   methodName = testName;
   name = testName.substring(4);
   message = Messages.getInstance().getString("UI.USER_TEST_SUITE_NOT_RUN"); // $NON-NLS-1$
   result = new TestResult();
   result.addListener(this);
 }
  private void init(TestSuite all) {

    Enumeration suitesEnum = getSuites(all);

    suites = new ArrayList<SuiteInfo>();
    while (suitesEnum.hasMoreElements()) {
      TestSuite suite = (TestSuite) suitesEnum.nextElement();
      SuiteInfo suiteInfo = new SuiteInfo(suite);
      suites.add(suiteInfo);
      suiteInfo.init();
    }

    // TODO find out the JDBC driver for the Sample Data connection

    // TODO find out the JDBC driver for the Hibernate connection
    sampleDataDriver =
        Messages.getInstance().getString("UI.USER_TEST_SUITE_UNKNOWN"); // $NON-NLS-1$

    hibernateDriver = Messages.getInstance().getString("UI.USER_TEST_SUITE_UNKNOWN"); // $NON-NLS-1$
  }
 public void endTest() {
   if (status != FAIL) {
     passCount++;
     Date now = new Date();
     duration = (now.getTime() - timestamp.getTime());
     lastResult = PASS;
     message = Messages.getInstance().getString("UI.USER_TEST_SUITE_PASSED"); // $NON-NLS-1$
   } else {
     lastResult = FAIL;
   }
   status = NOT_RUNNING;
 }
 public Node getStatus(Element parent) {
   Element node = parent.addElement("suite"); // $NON-NLS-1$
   node.addAttribute("class", className); // $NON-NLS-1$
   node.addAttribute("name", name); // $NON-NLS-1$
   node.addAttribute("test-count", Integer.toString(testCount)); // $NON-NLS-1$
   node.addAttribute("run-count", Integer.toString(runCount)); // $NON-NLS-1$
   node.addAttribute("pass-count", Integer.toString(passCount)); // $NON-NLS-1$
   node.addAttribute("fail-count", Integer.toString(errorCount + failCount)); // $NON-NLS-1$
   Element messageNode = node.addElement("message"); // $NON-NLS-1$
   Element tests = node.addElement("tests"); // $NON-NLS-1$
   int currentPassCount = 0;
   int currentRunCount = 0;
   int currentFailCount = 0;
   for (int idx = 0; idx < testList.size(); idx++) {
     TestInfo test = testList.get(idx);
     test.getStatus(tests);
     if (test.lastResult == PASS) {
       currentPassCount++;
     }
     if (test.lastResult == FAIL) {
       currentFailCount++;
     }
     if (test.lastResult != test.NOT_RUN) {
       currentRunCount++;
     }
   }
   if (currentRunCount == 0) {
     message = Messages.getInstance().getString("UI.USER_TEST_SUITE_NOT_RUN"); // $NON-NLS-1$
   } else if (currentRunCount == currentPassCount && currentRunCount < testCount) {
     message = Messages.getInstance().getString("UI.USER_TEST_SUITE_SOME_PASSED"); // $NON-NLS-1$
   } else if (currentRunCount == currentPassCount && currentRunCount == testCount) {
     message = Messages.getInstance().getString("UI.USER_TEST_SUITE_ALL_PASSED"); // $NON-NLS-1$
   } else if (currentFailCount > 0) {
     message =
         Messages.getInstance().getString("UI.USER_TEST_SUITE_SOME_FAILURES"); // $NON-NLS-1$
   }
   messageNode.setText((message == null) ? "" : message); // $NON-NLS-1$
   return node;
 }
 public Node getStatus(Element parent) {
   Element node = parent.addElement("test"); // $NON-NLS-1$
   node.addAttribute("method", methodName); // $NON-NLS-1$
   node.addAttribute("name", name); // $NON-NLS-1$
   node.addAttribute(
       "last-run",
       (timestamp == null)
           ? Messages.getInstance().getString("UI.USER_TEST_SUITE_UNKNOWN")
           : DateFormat.getDateTimeInstance().format(timestamp)); // $NON-NLS-1$ //$NON-NLS-2$
   node.addAttribute("run-count", Integer.toString(runCount)); // $NON-NLS-1$
   node.addAttribute("pass-count", Integer.toString(passCount)); // $NON-NLS-1$
   node.addAttribute("fail-count", Integer.toString(errorCount + failCount)); // $NON-NLS-1$
   if (lastResult == FAIL) {
     node.addAttribute("duration", "-1"); // $NON-NLS-1$ //$NON-NLS-2$
   } else {
     node.addAttribute("duration", fmt.format(duration / 1000)); // $NON-NLS-1$
   }
   Element messageNode = node.addElement("message"); // $NON-NLS-1$
   messageNode.setText((message == null) ? "" : message); // $NON-NLS-1$
   return node;
 }
  public Document getStatus(IPentahoSession userSession) {
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("test-suites"); // $NON-NLS-1$
    Element propertiesNode = root.addElement("properties"); // $NON-NLS-1$
    Properties properties = System.getProperties();
    for (String propertyName : propertyNames) {
      String value = properties.getProperty(propertyName);
      Element propertyNode = propertiesNode.addElement("property"); // $NON-NLS-1$
      propertyNode.addAttribute("name", propertyName); // $NON-NLS-1$
      propertyNode.addAttribute("value", value); // $NON-NLS-1$
    }

    // add some standard settings
    Element propertyNode = propertiesNode.addElement("property"); // $NON-NLS-1$
    propertyNode.addAttribute(
        "name",
        Messages.getInstance()
            .getString("UI.USER_TEST_SUITE_SOLUTION_REPOSITORY")); // $NON-NLS-1$ //$NON-NLS-2$
    propertyNode.addAttribute(
        "value",
        PentahoSystem.get(IUnifiedRepository.class, userSession)
            .getClass()
            .toString()); //$NON-NLS-1$

    propertyNode = propertiesNode.addElement("property"); // $NON-NLS-1$
    propertyNode.addAttribute("name", "data.driver"); // $NON-NLS-1$ //$NON-NLS-2$
    propertyNode.addAttribute("value", sampleDataDriver); // $NON-NLS-1$
    propertyNode = propertiesNode.addElement("property"); // $NON-NLS-1$
    propertyNode.addAttribute("name", "repository.driver"); // $NON-NLS-1$ //$NON-NLS-2$
    propertyNode.addAttribute("value", hibernateDriver); // $NON-NLS-1$

    for (int idx = 0; idx < suites.size(); idx++) {
      SuiteInfo suiteInfo = suites.get(idx);
      suiteInfo.getStatus(root);
    }
    return doc;
  }
  public boolean compare(String testName, String extension) {

    InputStream goldenStream = null;
    InputStream tmpFileStream = null;

    String filePath =
        PentahoSystem.getApplicationContext()
            .getFileOutputPath("test/tmp/" + testName + extension); // $NON-NLS-1$
    try {
      File file = new File(filePath);
      tmpFileStream = new FileInputStream(file);
    } catch (Throwable e) {
      // this gets caught in the assert below
    }
    assertNotNull(
        Messages.getString("GenericTest.USER_TEST_FILE_INVALID", filePath),
        tmpFileStream); //$NON-NLS-1$

    filePath =
        PentahoSystem.getApplicationContext()
            .getFileOutputPath("test/golden/" + testName + extension); // $NON-NLS-1$
    try {
      File file = new File(filePath);
      goldenStream = new FileInputStream(file);
    } catch (Throwable e) {
      // this gets caught in the assert below
    }
    assertNotNull(
        Messages.getString("GenericTest.USER_TEST_FILE_INVALID", filePath),
        goldenStream); //$NON-NLS-1$

    // compare the two files

    int goldPos = 0;
    int tmpPos = 0;
    byte goldBuffer[] = new byte[2048];
    byte tmpBuffer[] = new byte[2048];
    int filePosition = 0;
    try {
      // read the start of both files
      goldPos = goldenStream.read(goldBuffer);
      tmpPos = tmpFileStream.read(tmpBuffer);
      // assume lock-step
      if (goldPos != tmpPos) {
        System.out.println(
            Messages.getString("GenericTest.USER_FILE_POINTERS_NOT_IN_STEP")); // $NON-NLS-1$
        return false;
      }
      while (goldPos > 0 && tmpPos > 0) {
        for (int index = 0; index < goldPos; index++) {
          assertEquals(
              Messages.getString(
                  "GenericTest.USER_FILES_DIFFER", Integer.toString(filePosition + index)),
              goldBuffer[index],
              tmpBuffer[index]); // $NON-NLS-1$
        }
        filePosition += goldPos;
        goldPos = goldenStream.read(goldBuffer);
        tmpPos = tmpFileStream.read(tmpBuffer);
      }
    } catch (Exception e) {
      return false;
    }
    return true;
  }
  public void test1() throws ObjectFactoryException {

    StandaloneSession session = new StandaloneSession("test");

    StandaloneApplicationContext appContext =
        new StandaloneApplicationContext("test-res/solution", "");

    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init(
        "test-res/solution/system/pentahoObjects.GlobalListPublisherTest.spring.xml", null);

    PentahoSystem.setObjectFactory(factory);
    PentahoSystem.setSystemSettingsService(
        factory.get(ISystemSettings.class, "systemSettingsService", session));
    PentahoSystem.init(appContext);

    List<ISessionStartupAction> actions = new ArrayList<ISessionStartupAction>();

    SessionStartupAction startupAction1 = new SessionStartupAction();
    startupAction1.setSessionType(PentahoSystem.SCOPE_GLOBAL);
    startupAction1.setActionPath("testsolution/testpath/test.xaction");
    startupAction1.setActionOutputScope(PentahoSystem.SCOPE_GLOBAL);
    actions.add(startupAction1);

    TestRuntimeContext context = new TestRuntimeContext();
    context.status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
    TestSolutionEngine engine =
        PentahoSystem.get(TestSolutionEngine.class, "ISolutionEngine", session);
    engine.testRuntime = context;
    Map<String, IActionParameter> outputs = new HashMap<String, IActionParameter>();
    TestActionParameter param = new TestActionParameter();
    param.setValue("testvalue");
    outputs.put("testoutput", param);
    context.outputParameters = outputs;

    engine.executeCount = 0;
    GlobalListsPublisher globals = new GlobalListsPublisher();
    assertEquals(
        Messages.getInstance().getString("GlobalListsPublisher.USER_SYSTEM_SETTINGS"),
        globals.getName());
    assertEquals(
        Messages.getInstance().getString("GlobalListsPublisher.USER_DESCRIPTION"),
        globals.getDescription());
    assertTrue(!globals.getName().startsWith("!"));
    assertTrue(!globals.getDescription().startsWith("!"));
    assertNotNull(globals.getLogger());
    String resultMsg = globals.publish(session);
    assertEquals(
        Messages.getInstance().getString("GlobalListsPublisher.USER_SYSTEM_SETTINGS_UPDATED"),
        resultMsg);

    assertEquals(0, engine.executeCount);
    PentahoSystem.setSessionStartupActions(actions);
    IParameterProvider globalParams = PentahoSystem.getGlobalParameters();

    resultMsg = globals.publish(session);
    assertEquals(1, engine.executeCount);
    assertEquals(
        Messages.getInstance().getString("GlobalListsPublisher.USER_SYSTEM_SETTINGS_UPDATED"),
        resultMsg);

    // check that we made it all the way to executing the startup action
    assertEquals(session, engine.initSession);
    assertEquals(startupAction1.getActionPath(), engine.actionPath);
    assertEquals("testvalue", globalParams.getParameter("testoutput"));

    param.setValue("testvalue2");

    resultMsg = globals.publish(session);
    assertEquals(
        Messages.getInstance().getString("GlobalListsPublisher.USER_SYSTEM_SETTINGS_UPDATED"),
        resultMsg);
    assertEquals(2, engine.executeCount);

    assertNotNull(globalParams);
    assertEquals("testvalue2", globalParams.getParameter("testoutput"));

    engine.errorMsg = "test exception";
    resultMsg = globals.publish(session);
    assertEquals(
        Messages.getInstance().getString("GlobalListsPublisher.USER_ERROR_PUBLISH_FAILED")
            + "test exception",
        resultMsg);
    assertEquals(3, engine.executeCount);
  }
 public void startTest() {
   runCount++;
   status = RUNNING;
   message = Messages.getInstance().getString("UI.USER_TEST_SUITE_RUNNING"); // $NON-NLS-1$
   timestamp = new Date();
 }
 public void startTest(Test test) {
   runCount++;
   TestInfo testInfo = testMap.get(test);
   testInfo.startTest();
   message = Messages.getInstance().getString("UI.USER_TEST_SUITE_RUNNING"); // $NON-NLS-1$
 }
 public void stop() {
   result.stop();
   status = NOT_RUNNING;
   message = Messages.getInstance().getString("UI.USER_TEST_SUITE_STOPPED"); // $NON-NLS-1$
 }